Options
All
  • Public
  • Public/Protected
  • All
Menu

Class Reader

A wrapper class which provides methods to read data from the raw bytes of a buffer.

Hierarchy

  • Reader

Index

Constructors

constructor

  • new Reader(size?: number): Reader
  • Creates a new Reader and initialises the wrapped buffer to the given size.

    Parameters

    • Default value size: number = Reader.DEFAULT_SIZE

      The size of the buffer.

    Returns Reader

Properties

Private _length

_length: number

buffer

buffer: Buffer

The wrapped buffer.

index

index: number

The current index of the buffer.

Static DEFAULT_SIZE

DEFAULT_SIZE: number = 4

The default size when this reader is reset.

Accessors

length

  • get length(): number
  • The length of the buffer.

    Returns number

remaining

  • get remaining(): number
  • The number of bytes between the end of the buffer and the current index.

    Returns 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
  • Reads a 1 byte integer from the buffer.

    Returns number

readByteArray

  • readByteArray(): number[]
  • Reads 2 bytes to get the length, then reads length bytes from the buffer.

    Returns number[]

readBytes

  • readBytes(size: number): number[]
  • Reads size bytes from the buffer.

    Parameters

    • size: number

      The number of bytes to read.

    Returns number[]

readFloat

  • readFloat(): number
  • Reads a 4 byte floating point number from the buffer.

    Returns number

readInt32

  • readInt32(): number
  • Reads a 4 byte integer from the buffer.

    Returns number

readShort

  • readShort(): number
  • Reads a 2 byte integer from the buffer.

    Returns 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
  • The same as readString(), but reads 4 bytes for the length.

    Returns string

readUInt32

  • readUInt32(): number
  • Reads a 4 byte unsigned integer from the buffer.

    Returns number

readUnsignedByte

  • readUnsignedByte(): number
  • Reads a 1 byte unsigned integer from the buffer.

    Returns number

readUnsignedShort

  • readUnsignedShort(): number
  • Reads a 2 byte unsigned integer from the buffer.

    Returns 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

Generated using TypeDoc