Table of Contents

Interface IDataType

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

Remarks

Value types should provide a string representation and define reasonable equality.

A data type can optionally support incremental changes to values, represented by one or more types of delta. A delta is the difference between two values. For large or composite values that change in small steps, it is more efficient to transmit an initial value followed by a delta for each change than to transmit a complete value for each change. The data type provides an implementation of IDeltaType for each type of delta it supports via DeltaType(string) and DeltaType(Type).

Since 5.8

Properties

TypeName

Returns the external type identifier.

string TypeName { get; }

Property Value

string

The external type identifier.

Methods

CanReadAs(Type)

Checks whether this data type is compatible with the given resultType.

bool CanReadAs(Type resultType)

Parameters

resultType Type

The type to check for compatibility.

Returns

bool

True if the data type is compatible with the given resultType. Otherwise false.

Remarks

This means that any valid binary representation of this data type can be read as an instance of the given resultType.

Any value type can be read as a object resultType.

Exceptions

ArgumentNullException

The given resultType is null.

DeltaType(string)

Returns a IDeltaType by name.

IDeltaType DeltaType(string typeName)

Parameters

typeName string

The delta type name as returned by Name.

Returns

IDeltaType

The delta type.

Exceptions

ArgumentException

This data type does not provide a IDeltaType with the given name.

DeltaType(Type)

Returns a IDeltaType by type.

IDeltaType DeltaType(Type valueDeltaType)

Parameters

valueDeltaType Type

The delta value type.

Returns

IDeltaType

The delta 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(Type, IBytes)

Creates a value of a compatible type from binary.

object ReadAs(Type resultType, IBytes bytes)

Parameters

resultType Type

The type of the result.

bytes IBytes

The binary data.

Returns

object

The value object.

Remarks

This is equivalent to calling ReadAs(type, input.ToByteArray()).

Any value type can be read as a object resultType.

Exceptions

ArgumentNullException

The given resultType is null.

ArgumentException

Failed to read bytes as the given resultType type.

InvalidDataException

The given resultType is incompatible with bytes data.

ReadAs(Type, byte[])

Creates a value of a compatible type from a binary data segment.

object ReadAs(Type resultType, byte[] input)

Parameters

resultType Type

The type of the result.

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

object

The value object.

Remarks

This is equivalent to calling ReadAs(type, input, 0, input.Length).

Any value type can be read as a object resultType.

Exceptions

ArgumentNullException

The given resultType is null.

ArgumentException

Failed to read input as the given resultType type.

InvalidOperationException

The given resultType is incompatible with input data.

ReadAs(Type, byte[], int, int)

Creates a value of a compatible type from a binary data segment.

object ReadAs(Type resultType, byte[] input, int offset, int length)

Parameters

resultType Type

The type of the result.

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

object

The value object.

Remarks

Any value type can be read as a object resultType.

Exceptions

ArgumentNullException

The given resultType is null.

ArgumentException

Failed to read input as the given resultType type.

InvalidOperationException

The given resultType is incompatible with input data.

ReadValue(IBytes)

Parses a value from binary.

object ReadValue(IBytes bytes)

Parameters

bytes IBytes

The binary data.

Returns

object

The value object.

Remarks

This is equivalent to ReadValue(bytes.ToByteArray()).

ReadValue(byte[])

Parses a value from a binary.

object 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

object

The value object.

Remarks

This is equivalent to ReadValue(input,0,input.Length).

ReadValue(byte[], int, int)

Parses a value from a binary data segment.

object 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

object

The value object.

ToBytes(object)

Returns the serialized form of the given value as IBytes.

IBytes ToBytes(object value)

Parameters

value object

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(object)

Checks whether a value is valid.

void Validate(object value)

Parameters

value object

The value object 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(object, Stream)

Serializes a value to binary.

void WriteValue(object value, Stream outputStream)

Parameters

value object

The value object.

outputStream Stream

The output stream.

Exceptions

ArgumentException

The given value is invalid for this data type.