Options
All
  • Public
  • Public/Protected
  • All
Menu

Class AkeraMessage

This represent a message that can be sent between various akera.io components.

When sent first the message header is written (type and size) then the actual data payload.

Hierarchy

  • AkeraMessage

Index

Constructors

constructor

  • Creates a message that can be sent through a connection.

    Parameters

    • type: MessageType

      The type of the message.

    • Optional data: number | string | Object

      The data payload of the message: string or Buffer for binary data.

    Returns AkeraMessage

Accessors

data

  • get data(): Buffer
  • Returns the message data in binary format.

    Returns Buffer

header

  • get header(): Buffer
  • Returns the message header in binary format, used when sending the message.

    Returns Buffer

isComplete

  • get isComplete(): boolean
  • Returns true if the message data payload was received in full. This is only false while the message is being read.

    Returns boolean

lenght

  • get lenght(): number
  • Returns the lenght of the data payload (if any).

    Returns number

payload

  • get payload(): Buffer
  • Returns the complete message in binary format, including the header.

    Returns Buffer

totalLenght

  • get totalLenght(): number
  • Returns the total message lenght, including the header.

    Returns number

type

Methods

append

  • append(data: string | Buffer, offset?: number): number
  • Append more data to the message payload.

    Normally used when the message is being received through a connection untill the complete data is received.

    Parameters

    • data: string | Buffer

      The data chunk.

    • Default value offset: number = 0

      The offset where the new data chunk is to be appended.

    Returns number

Static parse

  • Reads a message from a data buffer starting from a given offset.

    This will return a message that can be complete or not depending if the whole message was present in the data buffer or not.

    If not enough data present in the buffer to read at least the message header this returns null.

    Parameters

    • data: Buffer

      The buffer containing the message data to be parsed.

    • Default value offset: number = 0

      The start offset from where to start reading the message (defaults to zero).

    Returns AkeraMessage