The RecordV2 data type value class
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)
.
the type to check
true
if a binary representation created by this data
type can read as an instance * of valueType
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);
the name, as returned by DeltaType.name
the delta type
The external type identifier.
the name of this datatype
Parse a schema from a JSON string.
json string containing a schema definition
the schema
Create a value of a compatible class from binary.
the type of the result
the binary data
the offset to start reading from the provided buffer (default = 0
)
the length of the data to read (default = input.length
)
the value in the form of the specified type
Parse a value from binary.
When running the Diffusion Client in a browser context, access to the
Buffer
api is made available through diffusion.buffer.
the binary data
the offset to start reading from the provided buffer (default = 0
)
the length of the data to read (default = input.length
)
an instance of this data type value
Creates a new schema builder.
a new schema builder
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.
a new records builder
Bind a specific schema to a RecordV2DataType instance.
schema to bind to the data type
a RecordV2DataType bound to a specific schema
Serialise a value to binary
When running the Diffusion Client in a browser context, access to the
Buffer
api is made available through diffusion.buffer.
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.
the serialised value as a buffer
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.
A RecordV2 object can only be validated within the context of a Schema.
Accessed via:
diffusion.datatypes.recordv2();
6.0