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
resultTypeTypeThe 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
resultTypeisnull.
DeltaType(string)
Returns a IDeltaType by name.
IDeltaType DeltaType(string typeName)
Parameters
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
valueDeltaTypeTypeThe 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
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
resultTypeisnull.- ArgumentException
Failed to read
bytesas the givenresultTypetype.- InvalidDataException
The given
resultTypeis incompatible withbytesdata.
ReadAs(Type, byte[])
Creates a value of a compatible type from a binary data segment.
object ReadAs(Type resultType, byte[] input)
Parameters
resultTypeTypeThe type of the result.
inputbyte[]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
resultTypeisnull.- ArgumentException
Failed to read
inputas the givenresultTypetype.- InvalidOperationException
The given
resultTypeis incompatible withinputdata.
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
resultTypeTypeThe type of the result.
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
- object
The value object.
Remarks
Any value type can be read as a object resultType.
Exceptions
- ArgumentNullException
The given
resultTypeisnull.- ArgumentException
Failed to read
inputas the givenresultTypetype.- InvalidOperationException
The given
resultTypeis incompatible withinputdata.
ReadValue(IBytes)
Parses a value from binary.
object ReadValue(IBytes bytes)
Parameters
bytesIBytesThe 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
inputbyte[]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
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
- object
The value object.
ToBytes(object)
Returns the serialized form of the given value as IBytes.
IBytes ToBytes(object value)
Parameters
valueobjectThe value to serialize.
Returns
Remarks
Since 6.0
Exceptions
- ArgumentException
Failed to read
valueas the given result type.
Validate(object)
Checks whether a value is valid.
void Validate(object value)
Parameters
valueobjectThe 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
Exceptions
- ArgumentException
The given
valueis invalid for this data type.