Options
All
  • Public
  • Public/Protected
  • All
Menu

Class PacketBuffer

A wrapper class for providing read/write methods on top of a Buffer.

Hierarchy

  • PacketBuffer

Index

Constructors

constructor

  • Creates a new PacketBuffer and initalizes the wrapped buffer to the given size.

    Parameters

    • Default value size: number = DEFAULT_SIZE

      The size of the buffer.

    Returns PacketBuffer

Properties

Private _length

_length: number

bufferIndex

bufferIndex: number

The current index of the buffer.

data

data: Buffer

The wrapped buffer.

Accessors

length

  • get length(): number

remaining

  • get remaining(): number

Methods

readBoolean

  • readBoolean(): boolean
  • Reads a single byte from the buffer, returns true if the byte is 1 and false otherwise.

    Returns boolean

readByte

  • readByte(): number

readByteArray

  • readByteArray(): number[]

readFloat

  • readFloat(): number

readInt32

  • readInt32(): number

readShort

  • readShort(): number

readString

  • readString(): string
  • Reads 2 bytes to get the length, reads length bytes from the buffer, then converts the result to a utf8 string.

    Returns string

readStringUTF32

  • readStringUTF32(): string

readUInt32

  • readUInt32(): number

readUnsignedByte

  • readUnsignedByte(): number

readUnsignedShort

  • readUnsignedShort(): number

reset

  • reset(): void
  • Resets the bufferIndex to 0 and allocates a fresh buffer of length DEFAULT_SIZE to the underlying buffer.

    Returns void

resizeBuffer

  • resizeBuffer(newSize: number): void
  • Changes the size of the buffer without affecting the contents.

    Parameters

    • newSize: number

      The new size of the buffer.

    Returns void

writeBoolean

  • writeBoolean(value: boolean): void
  • Writes a single byte to the buffer. Writes 1 if the value is true and 0 otherwise.

    Parameters

    • value: boolean

      The value to write.

    Returns void

writeByte

  • writeByte(value: number): void

writeByteArray

  • writeByteArray(value: number[]): void
  • Writes the length of the array as a 2 byte integer, then writes length bytes to the buffer.

    Parameters

    • value: number[]

      The value to write.

    Returns void

writeFloat

  • writeFloat(value: number): void
  • Writes a 4 byte floating point value to the buffer.

    Parameters

    • value: number

      The value to write.

    Returns void

writeInt32

  • writeInt32(value: number): void
  • Writes a 4 byte integer to the buffer.

    Parameters

    • value: number

      The value to write.

    Returns void

writeShort

  • writeShort(value: number): void
  • Writes a 2 byte integer to the buffer.

    Parameters

    • value: number

      The value to write.

    Returns void

writeString

  • writeString(value: string): void
  • Writes the length of the string as a 2 byte integer, then writes the string to the buffer.

    Parameters

    • value: string

      The value to write.

    Returns void

writeStringUTF32

  • writeStringUTF32(value: string): void
  • The same as writeString(), but writes 4 bytes for the length.

    Parameters

    • value: string

      The value to write.

    Returns void

writeUInt32

  • writeUInt32(value: number): void
  • Writes a 4 byte unsigned integer to the buffer.

    Parameters

    • value: number

      The value to write.

    Returns void

writeUnsignedByte

  • writeUnsignedByte(value: number): void
  • Writes a 1 byte unsigned integer to the buffer.

    Parameters

    • value: number

      The value to write.

    Returns void

writeUnsignedShort

  • writeUnsignedShort(value: number): void
  • Writes a 2 byte unsigned integer to the buffer.

    Parameters

    • value: number

      The value to write.

    Returns void

Generated using TypeDoc