The JSON 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
Returns a new JSON instance from a native JS object.
Passing a string will produce a JSON instance encoding a single string token. To produce a JSON datatype instance from a JSON string, use JSONDataType.fromJsonString instead.
This is useful in cases where providing the raw value may be ambiguous for SDK methods that infer the datatype from provided arguments, such as Messages.sendRequest.
Example:
// Value from object
var value = jsondatatype.from({
foo : "bar",
baz : [1, 2, 3]
});
Example:
// Datatype instance from string
var value = jsondatatype.from("this is a simple string");
the object data
a JSON data-type instance
Returns a new JSON instance from a JSON string.
Precision for numeric types is lost in the translation to the internal CBOR binary form and non-significant white space is not preserved.
Example:
// Datatype instance from a JSON string.
var value = jsondatatype.fromJsonString("{\"foo\" : \"bar\"}");
// The value contains the parsed object representation
value.get(); // => { foo : "bar" }
the JSON string
a JSON data-type instance
The external type identifier.
the name of this datatype
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.
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
Serialise a value to binary
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
Serialise a value to binary
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
JSON data type.
Accessed via:
diffusion.datatypes.json();
The JSON Data Type provides JSON values, which are a wrapper around native JSON objects.
For efficiency, the JSON value is serialized in binary form following the CBOR specification.
The implementation provides support for binary deltas.
JSON instances defer parsing of underlying binary data until required. If the data is not valid, an Error may be thrown when JSON.get is called.
5.7