Options
All
  • Public
  • Public/Protected
  • All
Menu

Class PrimitiveDataType<ValueType, SourceType>

The primitive data type acts as the base class for primitive value types string, double, and Int64.

Type parameters

  • ValueType

    the value type of the data type

  • SourceType

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

Hierarchy

Implements

Index

Constructors

constructor

  • new PrimitiveDataType(typeName: string, valueClass: {}, serialise: (value: SourceType, encoder: Encoder) => void, cborTypePredicate: (valueType: types) => boolean, withBinaryDelta: boolean): PrimitiveDataType
  • Create a new instance of PrimitiveDataType

    Parameters

    • typeName: string

      the data type name

    • valueClass: {}

      the constructor function creating the value type

    • serialise: (value: SourceType, encoder: Encoder) => void

      serialise the value into a CBOR encoder

        • (value: SourceType, encoder: Encoder): void
        • Parameters

          • value: SourceType
          • encoder: Encoder

          Returns void

    • cborTypePredicate: (valueType: types) => boolean

      a predicate returning true if the CBOR type is supported by this data type.

        • (valueType: types): boolean
        • Parameters

          Returns boolean

    • withBinaryDelta: boolean

      a flag indicating if the data type supports binary deltas

    Returns PrimitiveDataType

Properties

Private fromValue

fromValue: (value: SourceType) => BytesImpl

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

Private serialise

serialise: (value: SourceType, encoder: Encoder) => void

Serialise the value into a CBOR encoder

param

the value to serialise

param

the encoder

Type declaration

    • (value: SourceType, encoder: Encoder): void
    • Parameters

      • value: SourceType
      • encoder: Encoder

      Returns void

Readonly valueClass

valueClass: {}

The constructor function creating the value type

param

the arguments to the constructor

returns

a new value object

Type declaration

Methods

binaryDeltaType

canReadAs

  • canReadAs(valueClass: {}): boolean
  • inheritdoc

    Parameters

    • valueClass: {}

    Returns boolean

deltaType

from

  • Create a new Bytes instance from data

    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.