Options
All
  • Public
  • Public/Protected
  • All
Menu

Class AbstractDataType<ValueType, SourceType, CBORType>

An abstract implementation of the DataType interface

Type parameters

  • ValueType

    the value type of the data type

  • SourceType

    the type(s) from which a value can be constructed

  • CBORType: Bytes

    the binary type containing the CBOR data

Hierarchy

  • AbstractDataType

Implements

  • DataType<ValueType, SourceType, CBORType>

Index

Constructors

constructor

  • new AbstractDataType(typeName: string, valueClass: object, implementation: object, vToC: function, cToV: function, converters: any[], withBinaryDelta: boolean): AbstractDataType
  • Create a new instance of AbstractDataType

    Parameters

    • typeName: string

      the data type name

    • valueClass: object

      the constructor function creating the value type

    • implementation: object

      a constructor function that creates the binary CBOR representation

    • vToC: function

      a converter function that converts a value to binary CBOR data

        • (value: SourceType): CBORType
        • Parameters

          • value: SourceType

          Returns CBORType

    • cToV: function

      a converter function that converts the binary CBOR data to a value

        • (bytes: CBORType): ValueType | null
        • Parameters

          • bytes: CBORType

          Returns ValueType | null

    • converters: any[]

      an array of constructor functions. These will be added to the valueConverters map. Each constructor must implement a static toString function.

    • withBinaryDelta: boolean

      a flag indicating if the data type supports binary deltas

    Returns AbstractDataType

Properties

Private Optional binaryDeltaTypeImpl

binaryDeltaTypeImpl: BinaryDeltaTypeImpl<ValueType, SourceType, CBORType>

If the data type supports binary deltas, binaryDeltaTypeImpl contains the binary delta type

Private cToV

cToV: function

A converter function that converts the binary CBOR data to a value

param

the binary data

returns

an instance of the value type

Type declaration

    • (bytes: CBORType): ValueType | null
    • Parameters

      • bytes: CBORType

      Returns ValueType | null

Private implementation

implementation: object

A constructor function that creates the binary CBOR representation

param

the internal buffer

param

the offset of the slice

param

the number of bytes in the slice

returns

a new CBOR object

Type declaration

Private typeName

typeName: string

The data type name

Private vToC

vToC: function

A converter function that converts a value to binary CBOR data

param

the value in any of the allowed source types

returns

an instance of the CBOR type

Type declaration

    • (value: SourceType): CBORType
    • Parameters

      • value: SourceType

      Returns CBORType

valueClass

valueClass: object

The constructor function creating the value type

param

the arguments to the constructor

returns

a new value object

Type declaration

Private valueConverters

valueConverters: object

A map of value converters

Value converters convert binary data containing the CBOR value into a different value type.

The key of the map is a string representation of the destination type.

Type declaration

  • [type: string]: function
      • (buffer: Buffer | Bytes, offset?: undefined | number, length?: undefined | number): any
      • Parameters

        • buffer: Buffer | Bytes
        • Optional offset: undefined | number
        • Optional length: undefined | number

        Returns any

Methods

binaryDeltaType

  • The binary delta type

    Returns BinaryDeltaTypeImpl<ValueType, SourceType, CBORType>

    the delta type

canReadAs

  • canReadAs(valueClass: object): boolean
  • inheritdoc

    Parameters

    • valueClass: object

    Returns boolean

deltaType

  • inheritdoc

    Parameters

    Returns DeltaType<ValueType, SourceType, CBORType>

Abstract from

  • Create a new BufferSlice instance from data

    Parameters

    • value: SourceType | BufferSlice

      the value or CBOR data containing the record

    Returns BufferSlice

    a new Binary representation of the value

name

  • name(): string
  • The external type identifier.

    Returns string

    the name of this datatype

readAs

  • readAs(valueClass: object, buffer: Buffer | Bytes, offset?: undefined | number, length?: undefined | number): ValueType | null
  • inheritdoc

    Parameters

    • valueClass: object
    • buffer: Buffer | Bytes
    • Optional offset: undefined | number
    • Optional length: undefined | number

    Returns ValueType | null

readValue

  • readValue(buffer: Buffer | Bytes, offset?: undefined | number, length?: undefined | number): ValueType | null
  • inheritdoc

    Parameters

    • buffer: Buffer | Bytes
    • Optional offset: undefined | number
    • Optional length: undefined | number

    Returns ValueType | null

toBytes

  • toBytes(value: SourceType): Bytes
  • Convert a value to bytes

    throws

    an error if the supplied value could not be converted

    Parameters

    • value: SourceType

      the value

    Returns Bytes

    a CBOR representation of the value

toString

  • toString(): string
  • Convert the objet to a string

    Returns string

    a string representation of the AbstractDataType

Abstract validate

  • validate(value: SourceType): void
  • Check is a value is valid

    throws

    an error if the value is not valid

    Parameters

    • value: SourceType

      the value to check

    Returns void

writeValue

  • writeValue(value: SourceType): Buffer
  • Serialise a value to binary

    throws

    an error if the value can not be serialised

    Parameters

    • value: SourceType

    Returns Buffer

    the serialised value as a buffer