Options
All
  • Public
  • Public/Protected
  • All
Menu

Module Package

Index

Variables

TYPE_DATA

TYPE_DATA: number = 4

TYPE_HANDSHAKE

TYPE_HANDSHAKE: number = 1

TYPE_HANDSHAKE_ACK

TYPE_HANDSHAKE_ACK: number = 2

TYPE_HEARTBEAT

TYPE_HEARTBEAT: number = 3

TYPE_KICK

TYPE_KICK: number = 5

Functions

decode

  • decode(buffer: Buffer): object | object[]
  • Package protocol decode. See encode for package format.

    Parameters

    • buffer: Buffer

      byte array containing package content

    Returns object | object[]

    {type: package type, buffer: body byte array}

encode

  • encode(type: number, body?: Buffer): any
  • Package protocol encode.

    Pomelo package format: +------+-------------+------------------+ | type | body length | body | +------+-------------+------------------+

    Head: 4bytes 0: package type, 1 - handshake, 2 - handshake ack, 3 - heartbeat, 4 - data 5 - kick 1 - 3: big-endian body length Body: body length bytes

    Parameters

    • type: number

      package type

    • Optional body: Buffer

      body content in bytes

    Returns any

    new byte array that contains encode result