Apply a delta to this JSON value to create a new value.
Convenient equivalent to:
diffusion.datatypes.JSON().deltaType(delta).apply(this, delta);
the binary delta to apply to this value
a new instance derived from applying the delta to this value
Get a copy of the array containing this value.
This value in binary form
Get a copy of the buffer containing this value.
This value in binary form
Copy the binary data to a provided buffer.
the buffer to copy data to
the position in the target buffer at which data will be copied
Compare this JSON value with an earlier version to create a delta.
Convenient equivalent to:
diffusion.datatypes.json().deltaType(type).diff(original, this);
Standard JSON objects may also be provided as the value to diff instead of a JSON instance.
Example:
const binaryDelta = jsonValue.diff({ foo : 'bar' });
Example:
const jsonDelta = jsonValue.diff({ foo : 'bar' }, 'json');
the value to diff against this
the type of delta to generate (default = 'binary')
a delta representing the difference between this and the provided value
Get this instance's value. Use this method to access the provided data when a JSON instance is received through the API.
Example:
session.addStream('foo', diffusion.datatypes.json())
.on('value', function(path, spec, value) {
// Get the actual value from the JSON instance
const data = value.get();
});
the JSON value
Compare this JSON value with an earlier version to create a structural json delta.
Convenient equivalent to:
this.diff(original, 'json');
Standard JSON objects may also be provided as the value to diff instead of a JSON instance.
Example:
const delta = jsonValue.jsonDiff({ foo : 'bar' });
the value to diff against this
a delta representing the difference between this and the provided value
Get the number of bytes
The length of the data in bytes
Immutable JSON data. The value is stored internally as a buffer.
JSON is "JavaScript Object Notation", a lightweight data-interchange format. See www.json.org.
To create an instance from an object, obtain a JSONDataType implementation from
diffusion.datatypes.json()
and call JSONDataType.from.The encapsulated value can be accessed by calling JSON.get.
CBOR representation
Internally the value is stored and transmitted not as a JSON string, but in CBOR format to reduce memory and network overhead. CBOR (Concise Binary Object Representation) is a standardized format for binary representation of structured data defined by RFC 7049. See www.cbor.io.
Rather than working with JSON strings it is possible, and usually preferable, for applications to work directly with the underlying CBOR-format binary representation. This avoids creating intermediate JSON strings, and allows access to CBOR features such as the byte string data type.
Each JSON value is represented as a single CBOR data item. CBOR supports composite data types just like JSON, so this data item can be an array or a map of other data items. The JSON
null
value is represented by the CBORnull
value.A particular advantage of working directly with the CBOR-format data is that binary data can be written to the value as a data item using the CBOR byte string type. The data item will be stored as part of the JSON value in binary form and transmitted without further conversion.
5.7