T - the type of the values being transcodedpublic interface Coder<T>
extends java.io.Serializable
Coder<T> defines how to encode and decode values of type T into byte streams.
All methods of a Coder<T> are required to be thread safe.
Coders are serialized during job creation and deserialized
before use, via JSON serialization.
See SerializableCoder for an example of a Coder that adds
a custom field to the Coder serialization. It provides a
constructor annotated with JsonCreator, which is a factory method
used when deserializing a Coder instance.
See KvCoder for an example of a nested Coder type.
| Modifier and Type | Interface and Description |
|---|---|
static class |
Coder.Context
The context in which encoding or decoding is being done.
|
| Modifier and Type | Method and Description |
|---|---|
com.google.cloud.dataflow.sdk.util.CloudObject |
asCloudObject()
Returns the
CloudObject that represents this Coder. |
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. |
java.util.List<? extends Coder<?>> |
getCoderArguments()
If this is a
Coder for a parameterized type, returns the
list of Coders being used for each of the parameters, or
returns null if this cannot be done or this is not a
parameterized type. |
boolean |
isDeterministic()
Returns true if the coding is deterministic.
|
boolean |
isRegisterByteSizeObserverCheap(T value,
Coder.Context context)
Returns whether
registerByteSizeObserver(T, com.google.cloud.dataflow.sdk.util.common.ElementByteSizeObserver, com.google.cloud.dataflow.sdk.coders.Coder.Context) cheap enough to
call for every element, that is, if this Coder can
calculate the byte size of the element to be coded in roughly
constant time (or lazily). |
void |
registerByteSizeObserver(T value,
com.google.cloud.dataflow.sdk.util.common.ElementByteSizeObserver observer,
Coder.Context context)
Notifies the
ElementByteSizeObserver about the byte size
of the encoded value using this Coder. |
void encode(T value, java.io.OutputStream outStream, Coder.Context context) throws CoderException, java.io.IOException
T onto the given output stream
in the given context.java.io.IOException - if writing to the OutputStream fails
for some reasonCoderException - if the value could not be encoded for some reasonT decode(java.io.InputStream inStream, Coder.Context context) throws CoderException, java.io.IOException
T from the given input stream in
the given context. Returns the decoded value.java.io.IOException - if reading from the InputStream fails
for some reasonCoderException - if the value could not be decoded for some reasonjava.util.List<? extends Coder<?>> getCoderArguments()
Coder for a parameterized type, returns the
list of Coders being used for each of the parameters, or
returns null if this cannot be done or this is not a
parameterized type.com.google.cloud.dataflow.sdk.util.CloudObject asCloudObject()
CloudObject that represents this Coder.boolean isDeterministic()
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.
boolean isRegisterByteSizeObserverCheap(T value, Coder.Context context)
registerByteSizeObserver(T, com.google.cloud.dataflow.sdk.util.common.ElementByteSizeObserver, com.google.cloud.dataflow.sdk.coders.Coder.Context) cheap enough to
call for every element, that is, if this Coder can
calculate the byte size of the element to be coded in roughly
constant time (or lazily).
Not intended to be called by user code, but instead by
PipelineRunner
implementations.
void registerByteSizeObserver(T value, com.google.cloud.dataflow.sdk.util.common.ElementByteSizeObserver observer, Coder.Context context) throws java.lang.Exception
ElementByteSizeObserver about the byte size
of the encoded value using this Coder.
Not intended to be called by user code, but instead by
PipelineRunner
implementations.
java.lang.Exception