Options
All
  • Public
  • Public/Protected
  • All
Menu

Interface RecordV2Delta

RecordV2 structural delta.

A RecordV2Delta describes the differences between two RecordV2 values. Unlike a binary delta, a structural delta can be queried to determine its effect. The RecordV2Delta.changes method provides details of which values have changed.

An instance can be created from two RecordV2 values using RecordV2.diff.

RecordV2Deltas are useful for identifying small changes to complex RecordV2 values. Here is an example of how to use this class to filter interesting changes from a value stream.

Example:

var datatype = diffusion.datatypes.recordv2();

session.addStream("topic", datatype).on('value', (path, spec, newValue, oldValue) => {
    var schema = datatype.parseSchema(spec.properties.SCHEMA);

    newValue.diff(oldValue).changes(schema).forEach((change) => {
        if (change.fieldName === "address") {
            // Do something with the changed address
            console.log(newValue.getFields());
        }
    });
});
author

Push Technology Limited

since

6.0

see

diffusion.datatypes.RecordV2.diff

Hierarchy

Index

Methods

asBuffer

  • asBuffer(): Buffer
  • Get a copy of the buffer containing this value.

    Returns Buffer

    This value in binary form

changes

  • Returns a list of the changes represented by the delta with reference to a specified schema.

    The schema supplied must comply with the data format of the delta. No validation takes place, so if the schema does not match the data then the results may be unpredictable.

    Parameters

    Returns Change[]

    the list of changes

copyTo

  • copyTo(target: Buffer, offset?: undefined | number): void
  • Copy the binary data to a provided buffer.

    Parameters

    • target: Buffer

      the buffer to copy data to

    • Optional offset: undefined | number

      the position in the target buffer at which data will be copied

    Returns void

length

  • length(): number
  • Get the number of bytes

    Returns number

    The length of the data in bytes