new DataType()
A data type is specified for a particular value type. It provides methods to
convert values to and from binary. Diffusion provides several diffusion.datatypes.DataType
implementations.
A data type can optionally support incremental changes to values, represented by one or more types of delta. A delta is the difference between two values. For large or composite values that change in small steps, it is more efficient to transmit an initial value followed by a delta for each change than to transmit a complete value for each change. The data type provides an implementation of diffusion.datatypes.DeltaType for each type of delta it supports via diffusion.datatypes.DataType#deltaType.
- Since:
-
- 5.7
Methods
-
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 dela support will be derived Returns:
the delta supportExamples
// Get by name var deltas = datatype.deltaType("binary");
// Get by type var deltas = datatype.deltaType(delta);
-
name() → {String}
-
The external type identifier.
Returns:
The name of this datatype.- Type
- String
-
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 Throws:
Error if the data is invalid for this typeReturns:
An instance of this data type value- Type
- Object
-
writeValue(value) → {Buffer}
-
Serialise a value to binary
Parameters:
Name Type Description value
Object The value to serialise Throws:
Error if the value can not be serialisedReturns:
The serialised value as a buffer- Type
- Buffer