T - The type of objects coded by this Coder.IntermediateT - The type of objects a T will be converted to for coding.public class DelegateCoder<T,IntermediateT> extends CustomCoder<T>
DelegateCoder<T, IntermediateT> wraps a Coder for IntermediateT and
encodes/decodes values of type Ts by converting
to/from IntermediateT and then encoding/decoding using the underlying
Coder<IntermediateT>.
The conversions from T to IntermediateT 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<InputT,OutputT>
A
CodingFunction<InputT, OutputT> is a serializable function
from InputT to OutputT that
may throw any Exception. |
Coder.Context, Coder.NonDeterministicException| Modifier | Constructor and Description |
|---|---|
protected |
DelegateCoder(Coder<IntermediateT> coder,
DelegateCoder.CodingFunction<T,IntermediateT> toFn,
DelegateCoder.CodingFunction<IntermediateT,T> fromFn) |
| Modifier and Type | Method and Description |
|---|---|
T |
decode(InputStream inStream,
Coder.Context context)
Decodes a value of type
T from the given input stream in
the given context. |
void |
encode(T value,
OutputStream outStream,
Coder.Context context)
Encodes the given value of type
T onto the given output stream
in the given context. |
static <T,IntermediateT> |
of(Coder<IntermediateT> coder,
DelegateCoder.CodingFunction<T,IntermediateT> toFn,
DelegateCoder.CodingFunction<IntermediateT,T> fromFn) |
Object |
structuralValue(T value)
Returns an object with an
Object.equals() method
that represents structural equality on the argument. |
String |
toString() |
void |
verifyDeterministic()
A delegate coder is deterministic if the underlying coder is deterministic.
|
asCloudObject, ofgetCoderArguments, getInstanceComponentsconsistentWithEquals, equals, getComponents, getEncodedElementByteSize, hashCode, isRegisterByteSizeObserverCheap, registerByteSizeObserver, verifyDeterministic, verifyDeterministicprotected DelegateCoder(Coder<IntermediateT> coder, DelegateCoder.CodingFunction<T,IntermediateT> toFn, DelegateCoder.CodingFunction<IntermediateT,T> fromFn)
public static <T,IntermediateT> DelegateCoder<T,IntermediateT> of(Coder<IntermediateT> coder, DelegateCoder.CodingFunction<T,IntermediateT> toFn, DelegateCoder.CodingFunction<IntermediateT,T> fromFn)
public void encode(T value, OutputStream outStream, Coder.Context context) throws CoderException, IOException
CoderT onto the given output stream
in the given context.CoderException - if the value could not be encoded for some reasonIOException - if writing to the OutputStream fails
for some reasonpublic T decode(InputStream inStream, Coder.Context context) throws CoderException, 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 reasonIOException - if reading from the InputStream fails
for some reasonpublic void verifyDeterministic()
throws Coder.NonDeterministicException
CodingFunction<T, IntermediateT> must
also be deterministic.verifyDeterministic in interface Coder<T>verifyDeterministic in class CustomCoder<T>Coder.NonDeterministicException - if this coder is not deterministic.public Object structuralValue(T value) throws 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>Exceptionpublic String toString()
toString in class StandardCoder<T>