Class: RecordV2DataType

diffusion.datatypes. RecordV2DataType

new RecordV2DataType()

RecordV2 data type.

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

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) → {diffusion.datatypes.DeltaType}

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() → {String}

The external type identifier.
Inherited From:
Returns:
The name of this datatype.
Type
String

parseSchema(json) → {diffusion.datatypes.RecordV2.Schema}

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) → {Object}

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) → {Object}

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() → {diffusion.datatypes.RecordV2.SchemaBuilder}

Creates a new schema builder.
Returns:
a new schema builder
Type
diffusion.datatypes.RecordV2.SchemaBuilder

valueBuilder() → {diffusion.datatypes.RecordV2.RecordV2Builder}

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) → {Buffer}

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