public class UnionCoder extends StandardCoder<RawUnionValue>
Coder.Context, Coder.NonDeterministicException| Modifier and Type | Method and Description |
|---|---|
RawUnionValue |
decode(InputStream inStream,
Coder.Context context)
Decodes a value of type
T from the given input stream in
the given context. |
void |
encode(RawUnionValue union,
OutputStream outStream,
Coder.Context context)
Encodes the given value of type
T onto the given output stream
in the given context. |
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. |
List<? extends Coder<?>> |
getComponents()
|
boolean |
isRegisterByteSizeObserverCheap(RawUnionValue union,
Coder.Context context)
Since this coder uses elementCoders.get(index) and coders that are known to run in constant
time, we defer the return value to that coder.
|
static UnionCoder |
jsonOf(List<Coder<?>> elements) |
static UnionCoder |
of(List<Coder<?>> elementCoders)
Builds a union coder with the given list of element coders.
|
void |
registerByteSizeObserver(RawUnionValue union,
org.apache.beam.sdk.util.common.ElementByteSizeObserver observer,
Coder.Context context)
Notifies ElementByteSizeObserver about the byte size of the encoded value using this coder.
|
void |
verifyDeterministic()
Throw
Coder.NonDeterministicException if the coding is not deterministic. |
asCloudObject, consistentWithEquals, equals, getAllowedEncodings, getEncodedElementByteSize, getEncodingId, hashCode, structuralValue, toString, verifyDeterministic, verifyDeterministicpublic static UnionCoder of(List<Coder<?>> elementCoders)
public static UnionCoder jsonOf(List<Coder<?>> elements)
public void encode(RawUnionValue union, OutputStream outStream, Coder.Context context) throws IOException, CoderException
CoderT onto the given output stream
in the given context.IOException - if writing to the OutputStream fails
for some reasonCoderException - if the value could not be encoded for some reasonpublic RawUnionValue decode(InputStream inStream, Coder.Context context) throws IOException, CoderException
CoderT from the given input stream in
the given context. Returns the decoded value.IOException - if reading from the InputStream fails
for some reasonCoderException - if the value could not be decoded for some reasonpublic List<? extends Coder<?>> getCoderArguments()
CoderCoder 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.public List<? extends Coder<?>> getComponents()
StandardCodergetComponents in class StandardCoder<RawUnionValue>public boolean isRegisterByteSizeObserverCheap(RawUnionValue union, Coder.Context context)
isRegisterByteSizeObserverCheap in interface Coder<RawUnionValue>isRegisterByteSizeObserverCheap in class StandardCoder<RawUnionValue>false unless it is overridden. StandardCoder.registerByteSizeObserver(T, org.apache.beam.sdk.util.common.ElementByteSizeObserver, org.apache.beam.sdk.coders.Coder.Context)
invokes StandardCoder.getEncodedElementByteSize(T, org.apache.beam.sdk.coders.Coder.Context) which requires re-encoding an element
unless it is overridden. This is considered expensive.public void registerByteSizeObserver(RawUnionValue union, org.apache.beam.sdk.util.common.ElementByteSizeObserver observer, Coder.Context context) throws Exception
registerByteSizeObserver in interface Coder<RawUnionValue>registerByteSizeObserver in class StandardCoder<RawUnionValue>Exceptionpublic 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.
Coder.NonDeterministicException - if this coder is not deterministic.