Table of Contents

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

TValue

The 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

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 object TResult.

DeltaType<TDelta>()

Returns a IDeltaType by type.

IDeltaType<TValue, TDelta> DeltaType<TDelta>()

Returns

IDeltaType<TValue, TDelta>

The delta type.

Type Parameters

TDelta

The 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

bytes IBytes

The binary data.

Returns

TResult

The value object.

Type Parameters

TResult

The 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 bytes as the given TResult type.

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

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

TResult

The value object.

Type Parameters

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 object TResult.

Exceptions

ArgumentException

Failed to read input as the given TResult type.

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

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 data segment.

length int

The length of the data segment.

Returns

TResult

The value object.

Type Parameters

TResult

The type of the result.

Remarks

Any value type can be read as a object TResult.

Exceptions

ArgumentException

Failed to read input as the given TResult type.

InvalidOperationException

The given type is incompatible with this data type.

ReadValue(IBytes)

Parses a value from binary.

TValue ReadValue(IBytes bytes)

Parameters

bytes IBytes

The 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

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

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

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 data segment.

length int

The 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

value TValue

The value to serialize.

Returns

IBytes

The IBytes representing the serialized form of the given value.

Remarks

Since 6.0

Exceptions

ArgumentException

Failed to read value as the given result type.

Validate(TValue)

Checks whether a value is valid.

void Validate(TValue value)

Parameters

value TValue

The 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

value TValue

The value.

outputStream Stream

The output stream.

Exceptions

ArgumentException

The given value is invalid for this data type.