Class: RecordV2DataType

diffusion.datatypes. RecordV2DataType


new 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.

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.

Accessed via: diffusion.datatypes.recordv2();

Properties:
Name Type Description
diffusion.datatypes.RecordV2DataType.RecordV2 diffusion.datatypes.RecordV2

The RecordV2 data type value class

Since:
  • 6.0

Extends

Methods


canReadAs(valueType)

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).

Parameters:
Name Type Description
valueType function

the type to check

Since:
  • 6.0
Inherited From:
Returns:

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

Type
Boolean

deltaType( [name] [, delta])

Obtain a diffusion.datatypes.DeltaType by name or delta type.

Parameters:
Name Type Argument Description
name String <optional>

The name, as returned by diffusion.datatypes.DeltaType#name

delta Object <optional>

The delta, from which a type-appropriate delta support will be derived

Inherited From:
Returns:

the delta support

Type
diffusion.datatypes.DeltaType
Examples
// Get by name
var deltas = datatype.deltaType("binary");
// Get by type
var deltas = datatype.deltaType(delta);

name()

The external type identifier.

Inherited From:
Returns:

The name of this datatype.

Type
String

parseSchema(json)

Parse a schema from a JSON string.

Parameters:
Name Type Description
json String

json string containing a schema definition

Returns:

schema

Type
diffusion.datatypes.RecordV2.Schema

readAs(valueType, buffer [, offset] [, length])

Create a value of a compatible class from binary.

Parameters:
Name Type Argument Default Description
valueType function

the type of the result

buffer Buffer

the binary data

offset Number <optional>
0

the offset to read data from the buffer

length Number <optional>
buffer.length

the length of data to read from the buffer

Since:
  • 6.0
Inherited From:
Throws:

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

Returns:

the value in the form of the specified type

Type
Object

readValue(input [, offset] [, length])

Parse a value from binary.

Parameters:
Name Type Argument Description
input Buffer

The binary data

offset Number <optional>

The offset to start reading from the provided buffer

length Number <optional>

The length of the data to read

Inherited From:
Throws:

Error if the data is invalid for this type

Returns:

An instance of this data type value

Type
Object

schemaBuilder()

Creates a new schema builder.

Returns:

a new schema builder

Type
diffusion.datatypes.RecordV2.SchemaBuilder

valueBuilder()

Creates a new RecordV2Builder.

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

Returns:

a new records builder

Type
diffusion.datatypes.RecordV2.RecordV2Builder

withSchema(schema)

Bind a specific schema to a diffusion.datatypes.RecordV2DataType instance.

Parameters:
Name Type Description
schema diffusion.datatypes.RecordV2.Schema

schema to bind to the data type

Returns:

a diffusion.datatypes.RecordV2DataType bound to a specific schema


writeValue(value)

Serialise a value to binary

Parameters:
Name Type Description
value Object

The value to serialise

Inherited From:
Throws:

Error if the value can not be serialised

Returns:

The serialised value as a buffer

Type
Buffer