Class BitString

BitString is a class that represents a bitstring in a buffer with a specified offset and length

Constructors

  • Constructing BitString from a buffer

    Parameters

    • data: Buffer

      data that contains the bitstring data. NOTE: We are expecting this buffer to be NOT modified

    • offset: number

      offset in bits from the start of the buffer

    • length: number

      length of the bitstring in bits

    Returns BitString

Properties

_data: Buffer
_length: number
_offset: number
EMPTY: BitString = ...

Accessors

Methods

  • Returns the bit at the specified index

    Parameters

    • index: number

      index of the bit

    Returns boolean

    true if the bit is set, false otherwise

    Throws

    Error if index is out of bounds

  • Checks for equality

    Parameters

    Returns boolean

    true if the bitstrings are equal, false otherwise

  • Try to get a buffer from the bitstring without allocations

    Parameters

    • offset: number

      offset in bits

    • length: number

      length in bits

    Returns null | Buffer

    buffer if the bitstring is aligned to bytes, null otherwise

  • Format to canonical string

    Returns string

    formatted bits as a string

  • Checks if supplied object is BitString

    Parameters

    • src: unknown

      is unknow object

    Returns src is BitString

    true if object is BitString and false otherwise