Table of Contents

Interface IDeltaType

Namespace
PushTechnology.ClientInterface.Data
Assembly
Diffusion.Client.dll

The optional extension provided by IDataType implementations that support incremental changes to values.

public interface IDeltaType

Remarks

Each implementation specifies a value type and a delta type. Two values, oldValue and newValue, can be compared to produce a delta using Diff(object, object). The delta can be separately applied to oldValue to create newValue using Apply(object, object).

Delta types should provide a string representation. Equality is optional for delta types.

Deferred parsing

Implementations can choose not to fully validate values when they are read, but instead defer parsing until it is required. Consequently, all methods that accept values can throw System.IO.InvalidDataException.

Since 5.8

Properties

Name

Returns the external identifier for this delta type.

string Name { get; }

Property Value

string

The external identifier for this delta type.

NoChange

Returns a constant that indicates no changes between values.

object NoChange { get; }

Property Value

object

A constant that indicates no changes between values.

Remarks

This constant is returned by Diff(object, object) to indicate oldValue and newValue are equivalent. The result is guaranteed to be equal only to itself.

Methods

Apply(object, object)

Applies a delta to a value.

object Apply(object oldValue, object delta)

Parameters

oldValue object

The old value object.

delta object

The delta object to apply to the old value object.

Returns

object

The new value object. The old value object will be returned if the delta had no effect.

Diff(object, object)

Creates a delta from two values.

object Diff(object oldValue, object newValue)

Parameters

oldValue object

The old value object.

newValue object

The new value object.

Returns

object

The delta representing the difference between oldValue and newValue.

Remarks

If there are many differences between oldValue and newValue, the result might require more bytes to transmit than the new value, or be computationally expensive to apply. In this case, it is better to discard oldValue and publish newValue in its place. This can be checked using IsValueCheaper(object, object).

The implementation can return the special constant NoChange to indicate the oldValue and newValue are equivalent and there is no change to publish.

IsValueCheaper(object, object)

Calculates if value is cheaper than delta. The result is typically determined by the length of the serialized form but can also consider the complexity of the delta.

bool IsValueCheaper(object value, object delta)

Parameters

value object

The value object.

delta object

The delta object.

Returns

bool

True if value is considered cheaper than delta. Otherwise false.

ReadDelta(IBytes)

Creates a delta from IBytes.

object ReadDelta(IBytes input)

Parameters

input IBytes

The binary data.

Returns

object

The delta object.

Remarks

This is equivalent to calling ReadDelta(byte[]) with the result of ToByteArray() as argument.

Since 6.0.

ReadDelta(byte[])

Creates a delta from a binary segment.

object ReadDelta(byte[] input)

Parameters

input byte[]

The binary data. The implementation may re-use the array to avoid copying. The caller must ensure the array is not modified.

Returns

object

The delta object.

Remarks

This is equivalent to ReadDelta(input,0,input.Length).

ReadDelta(byte[], int, int)

Creates a delta from a binary segment.

object ReadDelta(byte[] input, int offset, int length)

Parameters

input byte[]

The binary data. The implementation may re-use the array to avoid copying. The caller must ensure the array is not modified.

offset int

The starting index of the segment.

length int

The length of the segment.

Returns

object

The delta object.

ToBytes(object)

Returns the serialized form of the given delta as IBytes.

IBytes ToBytes(object delta)

Parameters

delta object

The delta object.

Returns

IBytes

The delta as IBytes.

Remarks

Since 6.0.

WriteDelta(object, Stream)

Serializes a delta to binary.

void WriteDelta(object delta, Stream outputStream)

Parameters

delta object

The delta object.

outputStream Stream

The output stream.