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

Implements

  • DataType<ValueType, SourceType, CBORType>

Index

Constructors

constructor

  • new AbstractDataType(typeName: string, valueClass: {}, implementation: {}, vToC: (value: SourceType | undefined | null) => CBORType, cToV: (bytes: CBORType) => ValueType | null, converters: DataTypeConverter[], withBinaryDelta: boolean): AbstractDataType
  • Create a new instance of AbstractDataType

    Parameters

    • typeName: string

      the data type name

    • valueClass: {}

      the constructor function creating the value type

    • implementation: {}

      a constructor function that creates the binary CBOR representation

    • vToC: (value: SourceType | undefined | null) => CBORType

      a converter function that converts a value to binary CBOR data

        • (value: SourceType | undefined | null): CBORType
        • Parameters

          • value: SourceType | undefined | null

          Returns CBORType

    • cToV: (bytes: CBORType) => ValueType | null

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

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

          • bytes: CBORType

          Returns ValueType | null

    • converters: DataTypeConverter[]

      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 Readonly binaryDeltaTypeImpl

binaryDeltaTypeImpl: BinaryDeltaTypeImpl<ValueType, SourceType, CBORType>

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

Private Readonly cToV

cToV: (bytes: CBORType) => ValueType | null

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

param

the binary data

returns

an instance of the value type

throws

an InvalidDataError if the data cannot be read

Type declaration

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

      • bytes: CBORType

      Returns ValueType | null

Private Readonly implementation

implementation: {}

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 Readonly typeName

typeName: string

The data type name

Private Readonly vToC

vToC: (value: SourceType | undefined | null) => CBORType

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 | undefined | null): CBORType
    • Parameters

      • value: SourceType | undefined | null

      Returns CBORType

Readonly valueClass

valueClass: {}

The constructor function creating the value type

param

the arguments to the constructor

returns

a new value object

Type declaration

Private Readonly valueConverters

valueConverters: {}

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]: (buffer: Uint8Array | Bytes, offset?: undefined | number, length?: undefined | number) => any
      • (buffer: Uint8Array | Bytes, offset?: undefined | number, length?: undefined | number): any
      • Parameters

        • buffer: Uint8Array | 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: {}): boolean
  • inheritdoc

    Parameters

    • valueClass: {}

    Returns boolean

deltaType

  • inheritdoc

    Parameters

    Returns DeltaType<ValueType, SourceType, CBORType>

Abstract from

  • Create a new BufferSlice instance from data

    throws

    an IllegalArgumentError if the data cannot be converted

    Parameters

    • value: SourceType

      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<T>(valueClass: {}, buffer: Uint8Array | Bytes, offset?: undefined | number, length?: undefined | number): T
  • inheritdoc

    Type parameters

    • T

    Parameters

    • valueClass: {}
    • buffer: Uint8Array | Bytes
    • Optional offset: undefined | number
    • Optional length: undefined | number

    Returns T

readValue

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

    Parameters

    • buffer: Uint8Array | 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

writeValue

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

    throws

    an IllegalArgumentError if the value cannot be serialised

    deprecated

    since version 6.11. Buffer has been replaced by Uint8Array. Use writeValueToArray instead. This will be removed in a future release.

    Parameters

    • value: SourceType | undefined | null

      the value to serialise. For primitive and JSON datatypes the value can be undefined or null. In this case a null value will be serialised.

    Returns Buffer

    the serialised value as a buffer

writeValueToArray

  • writeValueToArray(value: SourceType | undefined | null): Uint8Array
  • Serialise a value to binary

    throws

    an IllegalArgumentError if the value cannot be serialised

    Parameters

    • value: SourceType | undefined | null

      the value to serialise. For primitive and JSON datatypes the value can be undefined or null. In this case a null value will be serialised.

    Returns Uint8Array

    the serialised value as a buffer

Copyright © 2025 DiffusionData Ltd. All Rights Reserved.