Options
All
  • Public
  • Public/Protected
  • All
Menu

Class Writer

A wrapper class which provides methods for writing data to a buffer.

Hierarchy

  • Writer

Index

Constructors

constructor

  • Creates a new Writer and initialises the wrapped buffer to the default size of 8.

    Returns Writer

Properties

buffer

buffer: Buffer

The wrapped buffer.

index

index: number

The current index of the buffer.

Private size

size: number

Methods

Private checkCapacity

  • checkCapacity(addedBytes: number): void
  • Ensures there is enough capacity in the current buffer to store addedBytes more bytes.

    Parameters

    • addedBytes: number

      The number of bytes which need to be added.

    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
  • Writes a 1 byte integer to the buffer.

    Parameters

    • value: number

      The value to write.

    Returns 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

writeHeader

  • writeHeader(id: number): void
  • Writes a packet header to the first 5 bytes of this writer's buffer.

    Parameters

    • id: number

      The id to write to the header.

    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