V
- value typepublic interface DataType<V>
implementations
.
Value types should provide a string representation
and define reasonable equality
. The value type
implementations used by Diffusion-provided data types do so.
A data type can optionally support incremental changes to values, represented
by one or more types of delta. For each type of delta it supports,
the data type provides an implementation of DeltaType
via
deltaType(String)
and deltaType(Class)
.
DeltaType
Modifier and Type | Method and Description |
---|---|
<D> DeltaType<? extends V,? extends D> |
deltaType(Class<D> deltaClass)
Obtain a
DeltaType by class. |
DeltaType<? extends V,?> |
deltaType(String name)
Obtain a
DeltaType by name. |
String |
getTypeName()
Returns the external type identifier.
|
V |
readValue(byte[] bytes)
Create a value from binary.
|
V |
readValue(byte[] bytes,
int offset,
int length)
Create a value from binary.
|
V |
readValue(Bytes bytes)
Create a value from binary.
|
void |
validate(V value)
Check whether a value is valid.
|
void |
writeValue(V value,
OutputStream out)
Serialize a value to binary.
|
String getTypeName()
void writeValue(V value, OutputStream out) throws IOException
IOException
V readValue(byte[] bytes, int offset, int length) throws InvalidDataException, IndexOutOfBoundsException
Implementations can choose not to fully validate values when they are
read, but instead defer parsing until it is required. See
validate(Object)
.
bytes
- The binary data. The implementation may re-use the array to
avoid copying so the caller must ensure the array is not modified.offset
- start of the data within byteslength
- length of the data within bytesInvalidDataException
- If bytes
does not represent a valid
V
. The implementation may defer validation; see
validate(Object)
.IndexOutOfBoundsException
- if either offset
or
length
is negative, or
offset + length > bytes.length
V readValue(byte[] bytes) throws InvalidDataException
readValue(in, 0, in.length)
.bytes
- The binary data. The implementation may re-use the array to
avoid copying so the caller must ensure the array is not modified.InvalidDataException
- If bytes
does not represent a valid
V
. The implementation may defer validation; see
validate(Object)
.V readValue(Bytes bytes) throws InvalidDataException
readValue(bytes.toByteArray())
.bytes
- The binary data.InvalidDataException
- If bytes
does not represent a valid
V
. The implementation may defer validation; see
validate(Object)
.void validate(V value) throws InvalidDataException
A DataType
implementation is not required to check the binary
data supplied to readValue(byte[], int, int)
can be parsed as a
value of type V
if doing so is unnecessarily costly. Instead a
value may simply wrap the binary data, and lazily deserialize as
required. This method can be used the check the value at a later time.
InvalidDataException
- if the value is invalidDeltaType<? extends V,?> deltaType(String name)
DeltaType
by name.name
- the name, as returned by DeltaType.getName()
IllegalArgumentException
- if this data type does not provide a
DeltaType
with the name typeName
DeltaType
<D> DeltaType<? extends V,? extends D> deltaType(Class<D> deltaClass)
DeltaType
by class.deltaClass
- the classIllegalArgumentException
- if this data type does not provide a
DeltaType
for deltas of class deltaClass
IllegalArgumentException
- if the data type provides more than one
DeltaType
for deltas of class deltaClass
, but
none is preferredDeltaType
Copyright © 2016 Push Technology Ltd. All Rights Reserved.