BinaryStream is a utility to efficiently encode and decode numbers to / from a Uint8Array. BinaryStream uses a number of internal typed arrays to avoid small array allocations when reading and writing.

Hierarchy

  • default

Constructors

Methods

  • readArray() reads a length-prefixed array of T elements from the buffer at the next 32-bit aligned offset, using the provided callback to read the individual elements

    Type Parameters

    • T

    Parameters

    • readElement: ((s) => T)
        • (s): T
        • Parameters

          Returns T

    Returns T[]

  • readCond() reads a boolean condition from the buffer, then either calls if_true if the condition was is true, otherwise if_false

    Type Parameters

    • T

    • F

    Parameters

    • fns: {
          if_false: (() => F);
          if_true: (() => T);
      }
      • if_false: (() => F)
          • (): F
          • Returns F

      • if_true: (() => T)
          • (): T
          • Returns T

    Returns T | F

  • readString() writes a length-prefixed UTF-16 string from the buffer at the next 32-bit aligned offset

    Returns string

  • writeArray() writes a length-prefixed array of T elements to the buffer at the next 32-bit aligned offset, using the provided callback to write the individual elements

    Type Parameters

    • T

    Parameters

    • value: readonly T[]
    • writeElement: ((s, element) => void)
        • (s, element): void
        • Parameters

          Returns void

    Returns void

  • writeBool() writes a boolean as 255 or 0 to the buffer at the next byte offset

    Parameters

    • value: boolean

    Returns void

  • writeCond() writes the boolean condition cond to the buffer, then either calls if_true if cond is true, otherwise if_false

    Type Parameters

    • T

    • F

    Parameters

    • cond: boolean
    • fns: {
          if_false: (() => F);
          if_true: (() => T);
      }
      • if_false: (() => F)
          • (): F
          • Returns F

      • if_true: (() => T)
          • (): T
          • Returns T

    Returns T | F

  • writeI16() writes a int16 to the buffer at the next 16-bit aligned offset

    Parameters

    • value: number

    Returns void

  • writeI32() writes a int32 to the buffer at the next 32-bit aligned offset

    Parameters

    • value: number

    Returns void

  • writeI64() writes a bitint to the buffer at the next 64-bit aligned offset

    Parameters

    • value: bigint

    Returns void

  • writeString() writes a length-prefixed UTF-16 string to the buffer at the next 32-bit aligned offset

    Parameters

    • value: string

    Returns void

  • writeU16() writes a uint16 to the buffer at the next 16-bit aligned offset

    Parameters

    • value: number

    Returns void

  • writeU32() writes a uint32 to the buffer at the next 32-bit aligned offset

    Parameters

    • value: number

    Returns void

Generated using TypeDoc