Interface IDataType

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.

Namespace: PushTechnology.ClientInterface.Data
Assembly: Diffusion.Client.dll
Syntax
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.

Declaration
string TypeName { get; }
Property Value
Type Description
System.String

The external type identifier.

Methods

CanReadAs(Type)

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

Declaration
bool CanReadAs(Type resultType)
Parameters
Type Name Description
Type resultType

The type to check for compatibility.

Returns
Type Description
System.Boolean

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 resultType.

DeltaType(String)

Returns a IDeltaType by name.

Declaration
IDeltaType DeltaType(string typeName)
Parameters
Type Name Description
System.String typeName

The delta type name as returned by Name.

Returns
Type Description
IDeltaType

The delta type.

DeltaType(Type)

Returns a IDeltaType by type.

Declaration
IDeltaType DeltaType(Type valueDeltaType)
Parameters
Type Name Description
Type valueDeltaType

The delta value type.

Returns
Type Description
IDeltaType

The delta type.

ReadAs(Type, IBytes)

Creates a value of a compatible type from binary.

Declaration
object ReadAs(Type resultType, IBytes bytes)
Parameters
Type Name Description
Type resultType

The type of the result.

IBytes bytes

The binary data.

Returns
Type Description
System.Object

The value object.

Remarks

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

Any value type can be read as a resultType.

ReadAs(Type, Byte[])

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

Declaration
object ReadAs(Type resultType, byte[] input)
Parameters
Type Name Description
Type resultType

The type of the result.

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
System.Object

The value object.

Remarks

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

Any value type can be read as a resultType.

ReadAs(Type, Byte[], Int32, Int32)

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

Declaration
object ReadAs(Type resultType, byte[] input, int offset, int length)
Parameters
Type Name Description
Type resultType

The type of the result.

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
System.Object

The value object.

Remarks

Any value type can be read as a resultType.

ReadValue(IBytes)

Parses a value from binary.

Declaration
object ReadValue(IBytes bytes)
Parameters
Type Name Description
IBytes bytes

The binary data.

Returns
Type Description
System.Object

The value object.

Remarks

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

ReadValue(Byte[])

Parses a value from a binary.

Declaration
object 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
System.Object

The value object.

Remarks

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

ReadValue(Byte[], Int32, Int32)

Parses a value from a binary data segment.

Declaration
object 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
System.Object

The value object.

ToBytes(Object)

Returns the serialized form of the given value as IBytes.

Declaration
IBytes ToBytes(object value)
Parameters
Type Name Description
System.Object value

The value to serialize.

Returns
Type Description
IBytes

The IBytes representing the serialized form of the given value.

Remarks

Since 6.0

Validate(Object)

Checks whether a value is valid.

Declaration
void Validate(object value)
Parameters
Type Name Description
System.Object value

The value object 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.

WriteValue(Object, Stream)

Serializes a value to binary.

Declaration
void WriteValue(object value, Stream outputStream)
Parameters
Type Name Description
System.Object value

The value object.

Stream outputStream

The output stream.

Back to top