Options
All
  • Public
  • Public/Protected
  • All
Menu

Interface RecordV2DataType

Record-based data type.

This provides the ability to handle data in Diffusion proprietary 'record' format. This format allows string data to be organized into 'records' which in turn are made up of 'fields'. Each field is a string but may be handled as either an integer or a decimal field if required.

This format is compatible with legacy RECORD topics (removed in release 6.2) and therefore can be used to migrate client applications from using such topics with minimal change to the application.

The data can either be free format or constrained by a Schema.

In free format mode, no schema is associated with the data and the data will contain zero or more records, each comprising zero or more fields. In this mode the meaning of each field is entirely up to the application and no validation will be performed by Diffusion, either in the client library, or at the server. To write free format records, a RecordV2Builder can be used to create a RecordV2 object. Such a builder may be created using the RecordV2DataType.valueBuilder method.

When using a Schema then the permitted records and fields are defined by the schema. The schema names the records and the fields within them and provides a mechanism for direct access to the fields. The schema is also used to validate the data to ensure it complies with the schema definition.

In schema mode, data can be created and updated using a MutableRecordModel which allows records and fields to be conveniently set and updated by name. A base model can be created from a schema using the Schema.createMutableModel method. The model can at any time be used to create a new RecordV2 object. A consumer of a RecordV2 value can read it as a RecordModel by simply using the RecordV2.asModel method to produce an immutable representation of the data. When creating the data using a MutableRecordModel then the model ensures that the data is valid and therefore there is no need for the server or the consuming client to validate the data.

Schemas can be parsed from JSON strings or more simply using a SchemaBuilder obtained using the RecordV2DataType.schemaBuilder method. A schema can be bound to a RecordV2 data type instance using the method RecordV2DataType.withSchema. This method will return a new RecordV2DataType instance with the schema bound to it for validation.

A RecordV2 object can only be validated within the context of a Schema.

Accessed via: diffusion.datatypes.recordv2();

since

6.0

Hierarchy

Index

Properties

RecordV2

RecordV2: object

The RecordV2 data type value class

Type declaration

Methods

canReadAs

  • canReadAs(valueType: object): boolean
  • Test whether this data type is compatible with valueType. Compatibility with a valueType means than any valid binary representation of a value can be read as an instance of valueType.

    Every data type should be compatible with the following:

    • Value Type – the class corresponding to the data type's value type.

    For a data type with a value type of X, readAs(X, buffer) is equivalent to readValue(buffer).

    since

    6.0

    Parameters

    • valueType: object

      the type to check

    Returns boolean

    true if a binary representation created by this data type can read as an instance * of valueType

deltaType

  • Obtain a DeltaType by name or delta type.

    Example:

    // Get by name
    var deltas = datatype.deltaType("binary");

    Example:

    // Get by type
    var deltas = datatype.deltaType(delta);

    Parameters

    • Optional name: undefined | string

      the name, as returned by DeltaType.name

    Returns DeltaType<RecordV2, RecordV2, RecordV2>

    the delta type

name

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

    Returns string

    the name of this datatype

parseSchema

  • parseSchema(json: string): Schema
  • Parse a schema from a JSON string.

    Parameters

    • json: string

      json string containing a schema definition

    Returns Schema

    the schema

readAs

  • readAs<T>(valueType: object, buffer: Uint8Array, offset?: undefined | number, length?: undefined | number): T | null
  • readAs<T>(valueType: object, buffer: RecordV2): T | null
  • Create a value of a compatible class from binary.

    throws

    an InvalidDataError if valueType is incompatible with this data type, or buffer does not represent a valid value.

    since

    6.0

    Type parameters

    • T

    Parameters

    • valueType: object

      the type of the result

    • buffer: Uint8Array

      the binary data

    • Optional offset: undefined | number

      the offset to start reading from the provided buffer (default = 0)

    • Optional length: undefined | number

      the length of the data to read (default = input.length)

    Returns T | null

    the value in the form of the specified type

  • Type parameters

    • T

    Parameters

    Returns T | null

readValue

  • readValue(input: Uint8Array, offset?: undefined | number, length?: undefined | number): RecordV2 | null
  • readValue(input: RecordV2): RecordV2 | null
  • Parse a value from binary.

    throws

    an InvalidDataError error if the data is invalid for this type

    Parameters

    • input: Uint8Array

      the binary data

    • Optional offset: undefined | number

      the offset to start reading from the provided buffer (default = 0)

    • Optional length: undefined | number

      the length of the data to read (default = input.length)

    Returns RecordV2 | null

    an instance of this data type value

  • Parameters

    Returns RecordV2 | null

schemaBuilder

  • Creates a new schema builder.

    Returns SchemaBuilder

    a new schema builder

valueBuilder

  • Creates a new RecordV2Builder.

    Such a builder may be used to generate a free format RecordV2 format value that is not constrained by a Schema.

    Returns RecordV2Builder

    a new records builder

withSchema

writeValue

  • writeValue(value: RecordV2 | 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: RecordV2 | 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: RecordV2 | undefined | null): Uint8Array
  • Serialise a value to binary

    throws

    an IllegalArgumentError if the value cannot be serialised

    Parameters

    • value: RecordV2 | 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