T - the type of elements handled by this coder, must extend Messagepublic class Proto2Coder<T extends com.google.protobuf.Message> extends CustomCoder<T>
To learn more about Protocol Buffers, visit: https://developers.google.com/protocol-buffers
To use, specify the Coder type on a PCollection:
PCollection<MyProto.Message> records =
input.apply(...)
.setCoder(Proto2Coder.of(MyProto.Message.class));
Custom message extensions are also supported, but the coder must be made aware of them explicitly:
PCollection<MyProto.Message> records =
input.apply(...)
.setCoder(Proto2Coder.of(MyProto.Message.class)
.withExtensionsFrom(MyProto.class));
Coder.Context, Coder.NonDeterministicException| 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. |
static <T extends com.google.protobuf.Message> |
of(java.lang.Class<T> protoMessageClass)
Produces a new Proto2Coder instance, for a given Protobuf message class.
|
Proto2Coder<T> |
withExtensionsFrom(java.lang.Class<?>... extensionHosts)
Adds custom Protobuf extensions to the coder.
|
asCloudObject, isDeterministic, ofgetCoderArguments, getInstanceComponentsequals, getComponents, getEncodedElementByteSize, hashCode, isRegisterByteSizeObserverCheap, registerByteSizeObserver, toString, verifyDeterministic, verifyDeterministic, verifyDeterministicpublic static <T extends com.google.protobuf.Message> Proto2Coder<T> of(java.lang.Class<T> protoMessageClass)
public Proto2Coder<T> withExtensionsFrom(java.lang.Class<?>... extensionHosts)
extensionHosts - must be a class that defines a static
method name registerAllExtensionspublic void encode(T value, java.io.OutputStream outStream, Coder.Context context) throws java.io.IOException
CoderT 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 reasonpublic T decode(java.io.InputStream inStream, Coder.Context context) throws java.io.IOException
CoderT 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 reason