Options
All
  • Public
  • Public/Protected
  • All
Menu

lap-protocol

Index

Functions

createClient

createServer

  • Create a new server instance. Each instance communicates with 1 client.

    Parameters

    • options: ProtocolOptions

      Options to use. See ProtocolOptions.

    • initialMessage: Buffer

      First message that was received (contains authentication information)

    • Optional authFn: (authBuf: Buffer) => true | ErrorObject

      Gets the authentication message that was passed to createClient. If it returns true the connection is accepted. Can return an instance of ErrorObject to provide the client a reason for tha failure. If not present, all connections are accepted.

    Returns Promise<[Protocol, Buffer, ErrorObject?]>

decodeClientId

  • decodeClientId(buf: Buffer): [Buffer, Buffer]
  • Decodes ClientId. Expects message in format: <1B length><Id of given length><Other data>

    Parameters

    • buf: Buffer

      Input message

    Returns [Buffer, Buffer]

    First is the Id, then the other data.

decodeSessionId

  • decodeSessionId(buf: Buffer): [number, Buffer]
  • Decode SessionId from Buffer. Reads the first 2B as UInt16 using Little Endian.

    Parameters

    • buf: Buffer

      Input Buffer

    Returns [number, Buffer]

    The decoded SessionId and the remaining message.

encodeClientId

  • encodeClientId(clientId: Buffer, rest?: Buffer): Buffer
  • Encodes ClientId. Creates the following format: <1B length><Id of given length><Other data>

    Parameters

    • clientId: Buffer

      Client Id in the form of a Buffer. Cannot be longer than 255B.

    • rest: Buffer = ...

      Remaining data to encode

    Returns Buffer

    The encoded Buffer

encodeSessionId

  • encodeSessionId(sessionId: number, rest?: Buffer): Buffer
  • Encodes SessionId together with the remaining Buffer. Writes UInt16 using Little Endian.

    Parameters

    • sessionId: number

      The SessionId to write. Must be in [0, 65535].

    • rest: Buffer = ...

      Remaining message to encode

    Returns Buffer

    Encoded message.

parse

  • parse(str: string): Record<string, any>
  • Deserializes a string according to the custom encoding

    Parameters

    • str: string

      String to deserialize

    Returns Record<string, any>

    Deserialized object

stringify

  • stringify(object: Record<string, any>): string
  • Serializes any object using custom Map and Buffer encoding

    Parameters

    • object: Record<string, any>

      Object to be serialized

    Returns string

    Serialized object

Generated using TypeDoc