Interface IDataType<TValue>
- Namespace
- PushTechnology.ClientInterface.Data
- Assembly
- Diffusion.Client.dll
The data type that is specified for a particular value type. It provides methods to convert values to and from binary. Diffusion provides several IDataTypes implementations.
public interface IDataType<TValue> : IDataType
Type Parameters
TValueThe value type.
- Inherited Members
Remarks
This is a generic version of the IDataType interface that provides overloads for all object methods. It instead provides typed arguments and return values based on the given value type.
For more information about the data type interface, see IDataType.
Since 5.8
Methods
CanReadAs<TResult>()
Checks whether this data type is compatible with the given type parameter.
bool CanReadAs<TResult>()
Returns
- bool
True if the data type is compatible with the given type parameter. Otherwise false.
Type Parameters
TResultThe type to check for compatibility.
Remarks
This means that any valid binary representation of this data type can be read as an instance of the given
TResult.
Any value type can be read as a object TResult.
DeltaType<TDelta>()
Returns a IDeltaType by type.
IDeltaType<TValue, TDelta> DeltaType<TDelta>()
Returns
- IDeltaType<TValue, TDelta>
The delta type.
Type Parameters
TDeltaThe delta value type.
Exceptions
- ArgumentException
This data type does not provide a IDeltaType for the given type or it provides more than one IDeltaType but none is preferred.
ReadAs<TResult>(IBytes)
Creates a value of a compatible type from a binary.
TResult ReadAs<TResult>(IBytes bytes)
Parameters
bytesIBytesThe binary data.
Returns
- TResult
The value object.
Type Parameters
TResultThe type of the result.
Remarks
This is equivalent to calling ReadAs{T}(input.ToBytearray()).
Any value type can be read as a object TResult.
Exceptions
- ArgumentException
Failed to read
bytesas the givenTResulttype.- InvalidOperationException
The given type is incompatible with this data type.
ReadAs<TResult>(byte[])
Creates a value of a compatible type from a binary data segment.
TResult ReadAs<TResult>(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
- TResult
The value object.
Type Parameters
TResultThe type of the result.
Remarks
This is equivalent to calling ReadAs{T}(input, 0, input.Length).
Any value type can be read as a object TResult.
Exceptions
- ArgumentException
Failed to read
inputas the givenTResulttype.- InvalidOperationException
The given type is incompatible with this data type.
ReadAs<TResult>(byte[], int, int)
Creates a value of a compatible type from a binary data segment.
TResult ReadAs<TResult>(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 data segment.
lengthintThe length of the data segment.
Returns
- TResult
The value object.
Type Parameters
TResultThe type of the result.
Remarks
Any value type can be read as a object TResult.
Exceptions
- ArgumentException
Failed to read
inputas the givenTResulttype.- InvalidOperationException
The given type is incompatible with this data type.
ReadValue(IBytes)
Parses a value from binary.
TValue ReadValue(IBytes bytes)
Parameters
bytesIBytesThe binary data.
Returns
- TValue
The value.
Remarks
This is equivalent to ReadValue(bytes.ToByteArray()).
ReadValue(byte[])
Parses a value from a binary.
TValue ReadValue(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
- TValue
The value.
Remarks
This is equivalent to ReadValue(input,0,input.Length).
ReadValue(byte[], int, int)
Parses a value from a binary data segment.
TValue ReadValue(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 data segment.
lengthintThe length of the data segment.
Returns
- TValue
The value.
ToBytes(TValue)
Returns the serialized form of the given value as IBytes.
IBytes ToBytes(TValue value)
Parameters
valueTValueThe value to serialize.
Returns
Remarks
Since 6.0
Exceptions
- ArgumentException
Failed to read
valueas the given result type.
Validate(TValue)
Checks whether a value is valid.
void Validate(TValue value)
Parameters
valueTValueThe value to check for validity.
Remarks
A DataType implementation is not required to check the binary data supplied to ReadValue(byte[], int, int). This method can be used the check the value at a later time.
Exceptions
- InvalidDataException
The given value is invalid.
WriteValue(TValue, Stream)
Serializes a value to binary.
void WriteValue(TValue value, Stream outputStream)
Parameters
valueTValueThe value.
outputStreamStreamThe output stream.
Exceptions
- ArgumentException
The given
valueis invalid for this data type.