Options
All
  • Public
  • Public/Protected
  • All
Menu

Class Tokeniser

Tokeniser for CBOR objects

Hierarchy

  • Tokeniser

Index

Constructors

constructor

  • new Tokeniser(data: Buffer, offset?: number, length?: number): Tokeniser
  • Create a tokeniser

    Parameters

    • data: Buffer

      the buffer to tokenise

    • Default value offset: number = 0

      the starting position in the buffer

    • Default value length: number = data.length

      the number of bytes to read from the buffer

    Returns Tokeniser

Properties

Private bufferOffset

bufferOffset: number

The offset from which to start reading in the buffer

Private context

context: Context

The token context

Private data

data: Buffer

The buffer to tokenise

Private length

length: number

The number of bytes in the buffer

Private pos

pos: number

The current position

Private Optional token

token: Token

The current token

Private Optional type

type: tokens

The current token type

Methods

getContext

  • Get the current context

    Returns Context

getToken

  • getToken(): Token | undefined
  • Get the current token

    Returns Token | undefined

hasRemaining

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

    Returns boolean

    true if there are more tokens

nextToken

  • nextToken(): Token | null
  • Read the next token and return it

    Returns Token | null

    the next token or null if no more tokens are remaining in the buffer

offset

  • offset(): number
  • Return the current reading position in the buffer

    Returns number

Private readBuffer

  • readBuffer(len: number): Buffer
  • Read a number of bytes and return them as a buffer

    Parameters

    • len: number

    Returns Buffer

    the byte read from the buffer

Private readByte

  • readByte(): number
  • Read a single byte from the buffer

    throws

    an error is there are no more bytes to read

    Returns number

    the byte read from the buffer

readCollectionLength

  • readCollectionLength(header: HeaderType): number | undefined
  • Read the length of a collection

    Parameters

    Returns number | undefined

    the number of elements in the collection or -1 for an empty collection

Private readFloat16

  • readFloat16(): number

Private readFloat32

  • readFloat32(): number
  • Read a 32 bit float from the buffer

    Returns number

    the value read from the buffer

Private readFloat64

  • readFloat64(): number
  • Read a 64 bit float from the buffer

    Returns number

    the value read from the buffer

Private readHeader

  • Read a value header from the buffer

    Returns HeaderType

    the header information read from the buffer

readHeaderValue

  • readHeaderValue(header: any, signed?: any): any
  • Read a header value

    Parameters

    • header: any

      the header type information

    • Default value signed: any = false

      a flag indicating if the value is negative

    Returns any

    the header value

Private readSimpleValue

  • readSimpleValue(type: additional): boolean | number | Error | null | undefined
  • Read a primitive value

    Parameters

    Returns boolean | number | Error | null | undefined

    the value that was read. A break is signalled by an Error being returned (not thrown).

Private readUint16

  • readUint16(): number
  • Read a 16 bit unsigned integer from the buffer

    Returns number

    the value read from the buffer

Private readUint32

  • readUint32(): number
  • Read a 32 bit unsigned integer from the buffer

    Returns number

    the value read from the buffer

Private readUint64

  • readUint64(signed: boolean): Int64Impl | number
  • Read a 64 bit unsigned integer from the buffer

    Parameters

    • signed: boolean

    Returns Int64Impl | number

    the value read from the buffer. If it is possible to represent the integer using the primitive number type, a number is returned, otherwise an Int64.

readValue

  • Read a value from the CBOR buffer

    throws

    an error if the value type was not recognised

    Parameters

    • header: HeaderType

      the type information from the vallue's header

    Returns TokenValueType | Error | undefined

    the value that was read

reset

  • reset(): void
  • Reset the tokeniser

    Returns void