Interface IDataType<TValue>
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.
Inherited Members
Namespace: PushTechnology.ClientInterface.Data
Assembly: Diffusion.Client.dll
Syntax
public interface IDataType<TValue> : IDataType
Type Parameters
| Name | Description |
|---|---|
| TValue | The value type. |
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.
Declaration
bool CanReadAs<TResult>()
Returns
| Type | Description |
|---|---|
| System.Boolean | True if the data type is compatible with the given type parameter. Otherwise false. |
Type Parameters
| Name | Description |
|---|---|
| TResult | The 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 System.Object TResult.
DeltaType<TDelta>()
Returns a IDeltaType by type.
Declaration
IDeltaType<TValue, TDelta> DeltaType<TDelta>()
Returns
| Type | Description |
|---|---|
| IDeltaType<TValue, TDelta> | The delta type. |
Type Parameters
| Name | Description |
|---|---|
| TDelta | The delta value type. |
Exceptions
| Type | Condition |
|---|---|
| System.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.
Declaration
TResult ReadAs<TResult>(IBytes bytes)
Parameters
| Type | Name | Description |
|---|---|---|
| IBytes | bytes | The binary data. |
Returns
| Type | Description |
|---|---|
| TResult | The value object. |
Type Parameters
| Name | Description |
|---|---|
| TResult | The type of the result. |
Remarks
This is equivalent to calling ReadAs{T}(input.ToBytearray()).
Any value type can be read as a System.Object TResult.
Exceptions
| Type | Condition |
|---|---|
| System.ArgumentException | Failed to read |
| System.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.
Declaration
TResult ReadAs<TResult>(byte[] input)
Parameters
| Type | Name | Description |
|---|---|---|
| System.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 |
|---|---|
| TResult | The value object. |
Type Parameters
| Name | Description |
|---|---|
| TResult | The type of the result. |
Remarks
This is equivalent to calling ReadAs{T}(input, 0, input.Length).
Any value type can be read as a System.Object TResult.
Exceptions
| Type | Condition |
|---|---|
| System.ArgumentException | Failed to read |
| System.InvalidOperationException | The given type is incompatible with this data type. |
ReadAs<TResult>(Byte[], Int32, Int32)
Creates a value of a compatible type from a binary data segment.
Declaration
TResult ReadAs<TResult>(byte[] input, int offset, int length)
Parameters
| Type | Name | Description |
|---|---|---|
| System.Byte[] | input | The binary data. The implementation may re-use the array to avoid copying. The caller must ensure the array is not modified. |
| System.Int32 | offset | The starting index of the data segment. |
| System.Int32 | length | The length of the data segment. |
Returns
| Type | Description |
|---|---|
| TResult | The value object. |
Type Parameters
| Name | Description |
|---|---|
| TResult | The type of the result. |
Remarks
Any value type can be read as a System.Object TResult.
Exceptions
| Type | Condition |
|---|---|
| System.ArgumentException | Failed to read |
| System.InvalidOperationException | The given type is incompatible with this data type. |
ReadValue(IBytes)
Parses a value from binary.
Declaration
TValue ReadValue(IBytes bytes)
Parameters
| Type | Name | Description |
|---|---|---|
| IBytes | bytes | The binary data. |
Returns
| Type | Description |
|---|---|
| TValue | The value. |
Remarks
This is equivalent to ReadValue(bytes.ToByteArray()).
ReadValue(Byte[])
Parses a value from a binary.
Declaration
TValue ReadValue(byte[] input)
Parameters
| Type | Name | Description |
|---|---|---|
| System.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 |
|---|---|
| TValue | The value. |
Remarks
This is equivalent to ReadValue(input,0,input.Length).
ReadValue(Byte[], Int32, Int32)
Parses a value from a binary data segment.
Declaration
TValue ReadValue(byte[] input, int offset, int length)
Parameters
| Type | Name | Description |
|---|---|---|
| System.Byte[] | input | The binary data. The implementation may re-use the array to avoid copying. The caller must ensure the array is not modified. |
| System.Int32 | offset | The starting index of the data segment. |
| System.Int32 | length | The length of the data segment. |
Returns
| Type | Description |
|---|---|
| TValue | The value. |
ToBytes(TValue)
Returns the serialized form of the given value as IBytes.
Declaration
IBytes ToBytes(TValue value)
Parameters
| Type | Name | Description |
|---|---|---|
| TValue | value | The value to serialize. |
Returns
| Type | Description |
|---|---|
| IBytes | The IBytes representing the serialized form of the given |
Remarks
Since 6.0
Exceptions
| Type | Condition |
|---|---|
| System.ArgumentException | Failed to read |
Validate(TValue)
Checks whether a value is valid.
Declaration
void Validate(TValue value)
Parameters
| Type | Name | Description |
|---|---|---|
| TValue | value | The value to check for validity. |
Remarks
A DataType implementation is not required to check the binary data supplied to ReadValue(Byte[], Int32, Int32). This method can be used the check the value at a later time.
Exceptions
| Type | Condition |
|---|---|
| System.IO.InvalidDataException | The given value is invalid. |
WriteValue(TValue, Stream)
Serializes a value to binary.
Declaration
void WriteValue(TValue value, Stream outputStream)
Parameters
| Type | Name | Description |
|---|---|---|
| TValue | value | The value. |
| System.IO.Stream | outputStream | The output stream. |
Exceptions
| Type | Condition |
|---|---|
| System.ArgumentException | The given |