Options
All
  • Public
  • Public/Protected
  • All
Menu

Class Decoder

Provide a higher-level interface around Tokeniser, to enable the reading of complex values as represented in arrays/objects etc.

Hierarchy

  • Decoder

Index

Constructors

constructor

  • new Decoder(initial: Buffer | Tokeniser, offset?: undefined | number, length?: undefined | number): Decoder
  • Create a decoder

    Parameters

    • initial: Buffer | Tokeniser

      the Buffer or Tokeniser to read from

    • Optional offset: undefined | number

      if a Buffer is supplied as first argument, the optional offset from which to start reading. Ignored otherwise.

    • Optional length: undefined | number

      if a Buffer is supplied as first argument, the optional number of bytes to read. Ignored otherwise.

    Returns Decoder

Properties

Private tokeniser

tokeniser: Tokeniser

The tokeniser to extract values from

Methods

hasRemaining

  • hasRemaining(): boolean
  • Check if more tokens can be read from the tokeniser

    Returns boolean

    true if there are more tokens

nextValue

  • Return the next value, parsed recursively.

    If no tokens can be read, a read error will be thrown.

    throws

    a read error if no value can be read

    Returns CBORValue

    the next value

nextValueExpecting

  • Return the next value, if its CBOR type is acceptable to cborTypePredicate

    parame

    cborTypePredicate a predicate that should return true if the CBOR type is acceptable, false otherwise.

    throws

    an error if no value can be read

    Parameters

    Returns CBORValue

    the next value