Options
All
  • Public
  • Public/Protected
  • All
Menu

Class Encoder

Encoder to encode values into CBOR

Hierarchy

  • Encoder

Index

Constructors

constructor

  • Create an encoder

    Returns Encoder

Properties

Private bos

The output stream to encode into

Methods

break

  • Write a BREAK stop code. This is not constrained by any pre-written strucutural context.

    Returns Encoder

    this encoder

encode

  • encode(value: CBORValue, offset?: undefined | number, length?: undefined | number): this
  • Encode a value to a CBOR representation.

    If a buffer is provided, optional offset & length parameters may be provided to dictate which bytes are to be encoded.

    Parameters

    • value: CBORValue

      the value to encode

    • Optional offset: undefined | number

      the offset to use if encoding a buffer. Defaults to 0

    • Optional length: undefined | number

      the length to use if encoding a buffer. Defaults to the length of the buffer

    Returns this

    this encoder

flush

  • flush(): Uint8Array
  • Flush the encoded data and empty the internal buffer

    Returns Uint8Array

    the contents of the buffer

startArray

  • startArray(length?: undefined | number): Encoder
  • Write the header for an array.

    Data may be subsequently written. No constraints are applied to subsequent data, i.e the header for a fixed-length array may be immediately followed by a break flag

    Parameters

    • Optional length: undefined | number

      the length of the array. If not provided, this array will be considered indefinite-length

    Returns Encoder

    this encoder

startObject

  • startObject(length?: undefined | number): this
  • Write the header for an object.

    Data may be subsequently written. No constraints are applied to subsequent data, i.e the header for a fixed-length object may be immediately followed by a break flag

    Parameters

    • Optional length: undefined | number

      the number of keys in the object. If not provided, this object will be considered indefinite-length

    Returns this

    this encoder

Private writeArray

  • Write an array to the output stream

    Parameters

    Returns void

Private writeBinary

  • writeBinary(val: Uint8Array, offset?: undefined | number, length?: number): void
  • Write a Binary value to the output stream

    Parameters

    • val: Uint8Array
    • Optional offset: undefined | number

      the starting position in the buffer

    • Default value length: number = val.length

      the number of bytes to write

    Returns void

Private writeBoolean

  • writeBoolean(val: boolean): void
  • Write a boolean to the output stream

    Parameters

    • val: boolean

      the boolean to write

    Returns void

Private writeBreakHeader

  • writeBreakHeader(type: types): void
  • Write a break header to the output stream

    Parameters

    • type: types

      the header type

    Returns void

Private writeBuffer

  • writeBuffer(buf: Uint8Array, offset?: number, length?: number): void
  • Write a Uint8Array to the output stream

    Parameters

    • buf: Uint8Array

      the buffer to write

    • Default value offset: number = 0

      the starting position in the buffer

    • Default value length: number = buf.length

      the number of bytes to write

    Returns void

Private writeByte

  • writeByte(byte: number): void
  • Write a byte to the output stream

    Parameters

    • byte: number

      the byte to wryte

    Returns void

writeDouble

  • writeDouble(val: number): this
  • Write a double value.

    Parameters

    • val: number

      the double value to encode

    Returns this

    this encoder

writeInt64

  • Write an Int64Impl value.

    Parameters

    Returns this

    this encoder

Private writeNull

  • writeNull(): void
  • Write null to the output stream

    Returns void

Private writeNumber

  • writeNumber(val: number): void
  • Write a number of any type to the output stream

    Parameters

    • val: number

      the number to write

    Returns void

Private writeObject

  • Write an object to the output stream

    Parameters

    Returns void

Private writeString

  • writeString(val: string): void
  • Write a string to the output stream

    Parameters

    • val: string

      the string to write

    Returns void

Private writeToken

  • writeToken(type: types, val: number): void
  • Write a token to the output stream

    Parameters

    • type: types

      the token type

    • val: number

      the numeric value associated with the token

    Returns void

Private writeUint16

  • writeUint16(val: number): void
  • Write an unsigned 16 bit integer to the output stream

    Parameters

    • val: number

      the integer to write

    Returns void

Private writeUint32

  • writeUint32(val: number): void
  • Write an unsigned 32 bit integer to the output stream

    Parameters

    • val: number

      the integer to write

    Returns void

Private writeUint64

  • writeUint64(val: number): void
  • Write an unsigned 64 bit integer to the output stream

    Parameters

    • val: number

      the integer to write

    Returns void

Private writeUndefined

  • writeUndefined(): void
  • Write undefined to the output stream

    Returns void

Copyright © 2025 DiffusionData Ltd. All Rights Reserved.