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
TValueThe value type.
TDeltaThe 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
oldValueTValueThe old value.
deltaTDeltaThe 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
oldValueTValueThe old value.
newValueTValueThe 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
valueTValueThe value.
deltaTDeltaThe delta.
Returns
- bool
True if
valueis considered cheaper thandelta. Otherwise false.
ReadDelta(IBytes)
Creates a delta from IBytes.
TDelta ReadDelta(IBytes input)
Parameters
inputIBytesThe 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
inputbyte[]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
inputbyte[]The binary data. The implementation may re-use the array to avoid copying. The caller must ensure the array is not modified.
offsetintThe starting index of the segment.
lengthintThe 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
deltaTDeltaThe delta object.
Returns
Remarks
Since 6.0.
WriteDelta(TDelta, Stream)
Serializes a delta to binary.
void WriteDelta(TDelta delta, Stream outputStream)
Parameters
deltaTDeltaThe delta.
outputStreamStreamThe output stream.