Interface IDeltaType<TValue, TDelta>
The optional extension provided by IDataType implementations that support incremental changes to values.
Inherited Members
Namespace: PushTechnology.ClientInterface.Data
Assembly: Diffusion.Client.dll
Syntax
public interface IDeltaType<TValue, TDelta> : IDeltaType
Type Parameters
Name | Description |
---|---|
TValue | The value type. |
TDelta | The delta type. |
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.
Declaration
TDelta NoChange { get; }
Property Value
Type | Description |
---|---|
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.
Declaration
TValue Apply(TValue oldValue, TDelta delta)
Parameters
Type | Name | Description |
---|---|---|
TValue | oldValue | The old value. |
TDelta | delta | The delta to apply to the old value. |
Returns
Type | Description |
---|---|
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.
Declaration
TDelta Diff(TValue oldValue, TValue newValue)
Parameters
Type | Name | Description |
---|---|---|
TValue | oldValue | The old value. |
TValue | newValue | The new value. |
Returns
Type | Description |
---|---|
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.
Declaration
bool IsValueCheaper(TValue value, TDelta delta)
Parameters
Type | Name | Description |
---|---|---|
TValue | value | The value. |
TDelta | delta | The delta. |
Returns
Type | Description |
---|---|
Boolean | True if |
ReadDelta(IBytes)
Creates a delta from IBytes.
Declaration
TDelta ReadDelta(IBytes input)
Parameters
Type | Name | Description |
---|---|---|
IBytes | input | The binary data. |
Returns
Type | Description |
---|---|
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.
Declaration
TDelta ReadDelta(byte[] input)
Parameters
Type | Name | Description |
---|---|---|
Byte[] | input | The binary data. The implementation may re-use the array to avoid copying. The caller must ensure the array is not modified. |
Returns
Type | Description |
---|---|
TDelta | The delta. |
Remarks
This is equivalent to ReadDelta(Byte[], Int32, Int32).
ReadDelta(Byte[], Int32, Int32)
Parses a delta from a binary segment.
Declaration
TDelta ReadDelta(byte[] input, int offset, int length)
Parameters
Type | Name | Description |
---|---|---|
Byte[] | input | The binary data. The implementation may re-use the array to avoid copying. The caller must ensure the array is not modified. |
Int32 | offset | The starting index of the segment. |
Int32 | length | The length of the segment. |
Returns
Type | Description |
---|---|
TDelta | The delta. |
ToBytes(TDelta)
Returns the serialized form of the given
delta
as IBytes.
Declaration
IBytes ToBytes(TDelta delta)
Parameters
Type | Name | Description |
---|---|---|
TDelta | delta | The delta object. |
Returns
Type | Description |
---|---|
IBytes | The delta as IBytes. |
Remarks
Since 6.0.
WriteDelta(TDelta, Stream)
Serializes a delta to binary.
Declaration
void WriteDelta(TDelta delta, Stream outputStream)
Parameters
Type | Name | Description |
---|---|---|
TDelta | delta | The delta. |
Stream | outputStream | The output stream. |