Table of Contents

Interface IDeltaType<TValue, TDelta>

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

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

public interface IDeltaType<TValue, TDelta> : IDeltaType

Type Parameters

TValue

The value type.

TDelta

The delta type.

Inherited Members

Remarks

This is a generic version of the IDeltaType interface that provides overloads for all object methods. It instead provides typed arguments and return values based on the given value and delta type.

For more information about the delta type interface, see IDeltaType.

Since 5.8

Properties

NoChange

Returns a constant that indicates no changes between values.

TDelta NoChange { get; }

Property Value

TDelta

A constant that indicates no changes between values.

Remarks

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

Methods

Apply(TValue, TDelta)

Applies a delta to a value.

TValue Apply(TValue oldValue, TDelta delta)

Parameters

oldValue TValue

The old value.

delta TDelta

The delta to apply to the old value.

Returns

TValue

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

Diff(TValue, TValue)

Creates a delta from two values.

TDelta Diff(TValue oldValue, TValue newValue)

Parameters

oldValue TValue

The old value.

newValue TValue

The new value.

Returns

TDelta

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(TValue, TDelta).

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

IsValueCheaper(TValue, TDelta)

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(TValue value, TDelta delta)

Parameters

value TValue

The value.

delta TDelta

The delta.

Returns

bool

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

ReadDelta(IBytes)

Creates a delta from IBytes.

TDelta ReadDelta(IBytes input)

Parameters

input IBytes

The binary data.

Returns

TDelta

The delta object.

Remarks

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

Since 6.0.

ReadDelta(byte[])

Parses a delta from a binary.

TDelta 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

TDelta

The delta.

Remarks

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

ReadDelta(byte[], int, int)

Parses a delta from a binary segment.

TDelta 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

TDelta

The delta.

ToBytes(TDelta)

Returns the serialized form of the given delta as IBytes.

IBytes ToBytes(TDelta delta)

Parameters

delta TDelta

The delta object.

Returns

IBytes

The delta as IBytes.

Remarks

Since 6.0.

WriteDelta(TDelta, Stream)

Serializes a delta to binary.

void WriteDelta(TDelta delta, Stream outputStream)

Parameters

delta TDelta

The delta.

outputStream Stream

The output stream.