T - The type of objects coded by this Coder.DT - The type of objects a T will be converted to for coding.public class DelegateCoder<T,DT> extends CustomCoder<T>
DelegateCoder<T, DT> wraps a Coder<DT> and
encodes/decodes values of type Ts by converting
to/from DT and then encoding/decoding using the underlying
Coder<DT>.
The conversions from T to DT and vice versa
must be supplied as DelegateCoder.CodingFunction, a serializable
function that may throw any Exception. If a thrown
exception is an instance of CoderException or
IOException, it will be re-thrown, otherwise it will be wrapped as
a CoderException.
| Modifier and Type | Class and Description |
|---|---|
static interface |
DelegateCoder.CodingFunction<Input,Output>
A
CodingFunction<Input, Output> is a serializable function
from Input to Output that
may throw any Exception. |
Coder.Context, Coder.NonDeterministicException| Modifier | Constructor and Description |
|---|---|
protected |
DelegateCoder(Coder<DT> coder,
DelegateCoder.CodingFunction<T,DT> toFn,
DelegateCoder.CodingFunction<DT,T> fromFn) |
| Modifier and Type | Method and Description |
|---|---|
T |
decode(java.io.InputStream inStream,
Coder.Context context)
Decodes a value of type
T from the given input stream in
the given context. |
void |
encode(T value,
java.io.OutputStream outStream,
Coder.Context context)
Encodes the given value of type
T onto the given output stream
in the given context. |
boolean |
isDeterministic()
Deprecated.
|
static <T,DT> DelegateCoder<T,DT> |
of(Coder<DT> coder,
DelegateCoder.CodingFunction<T,DT> toFn,
DelegateCoder.CodingFunction<DT,T> fromFn) |
java.lang.Object |
structuralValue(T value)
Returns an object with an
Object.equals() method
that represents structural equality on the argument. |
java.lang.String |
toString() |
void |
verifyDeterministic()
Throw
Coder.NonDeterministicException if the coding is not deterministic. |
asCloudObject, ofgetCoderArguments, getInstanceComponentsconsistentWithEquals, equals, getComponents, getEncodedElementByteSize, hashCode, isRegisterByteSizeObserverCheap, registerByteSizeObserver, verifyDeterministic, verifyDeterministicprotected DelegateCoder(Coder<DT> coder, DelegateCoder.CodingFunction<T,DT> toFn, DelegateCoder.CodingFunction<DT,T> fromFn)
public static <T,DT> DelegateCoder<T,DT> of(Coder<DT> coder, DelegateCoder.CodingFunction<T,DT> toFn, DelegateCoder.CodingFunction<DT,T> fromFn)
public void encode(T value, java.io.OutputStream outStream, Coder.Context context) throws CoderException, java.io.IOException
CoderT onto the given output stream
in the given context.CoderException - if the value could not be encoded for some reasonjava.io.IOException - if writing to the OutputStream fails
for some reasonpublic T decode(java.io.InputStream inStream, Coder.Context context) throws CoderException, java.io.IOException
CoderT from the given input stream in
the given context. Returns the decoded value.CoderException - if the value could not be decoded for some reasonjava.io.IOException - if reading from the InputStream fails
for some reason@Deprecated public boolean isDeterministic()
Coder In order for a Coder to be considered deterministic,
the following must be true:
Object.equals()
or Comparable.compareTo(), if supported) have the same
encoding.
Coder always produces a canonical encoding, which is the
same for an instance of an object even if produced on different
computers at different times.
isDeterministic in interface Coder<T>isDeterministic in class CustomCoder<T>public void verifyDeterministic()
throws Coder.NonDeterministicException
CoderCoder.NonDeterministicException if the coding is not deterministic.
In order for a Coder to be considered deterministic,
the following must be true:
Object.equals()
or Comparable.compareTo(), if supported) have the same
encoding.
Coder always produces a canonical encoding, which is the
same for an instance of an object even if produced on different
computers at different times.
verifyDeterministic in interface Coder<T>verifyDeterministic in class StandardCoder<T>Coder.NonDeterministicException - if this coder is not deterministic.public java.lang.Object structuralValue(T value) throws java.lang.Exception
CoderObject.equals() method
that represents structural equality on the argument.
(and also implements a compatible Object.hashCode()).
For any two objects of type T, if their encoded bytes
are the same, then their structural values are equal
according to Object.equals().
Most notably, the structural value for an array coder should perform a structural comparison of the contents of the arrays, rather than the default behavior of comparing according to object identity.
See also Coder.consistentWithEquals().
structuralValue in interface Coder<T>structuralValue in class StandardCoder<T>java.lang.Exceptionpublic java.lang.String toString()
toString in class StandardCoder<T>