T - the type of elements handled by this coder, must extend Messagepublic class Proto2Coder<T extends com.google.protobuf.Message> extends AtomicCoder<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)
.addExtensionsFrom(MyProto.class));
Coder.Context, Coder.NonDeterministicException| Modifier and Type | Method and Description |
|---|---|
Proto2Coder<T> |
addExtensionsFrom(Class<?>... extensionHosts)
Deprecated.
|
Proto2Coder<T> |
addExtensionsFrom(Iterable<Class<?>> extensionHosts)
Deprecated.
|
com.google.cloud.dataflow.sdk.util.CloudObject |
asCloudObject()
Returns the
CloudObject that represents this Coder. |
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. |
boolean |
equals(Object other) |
String |
getEncodingId()
The encoding identifier is designed to support evolution as per the design of Protocol
Buffers.
|
int |
hashCode() |
static <T extends com.google.protobuf.Message> |
of(Class<T> protoMessageClass)
Returns a
Proto2Coder for the given Protobuf message class. |
static <T extends com.google.protobuf.Message> |
of(String protoMessageClassName,
List<String> extensionHostClassNames)
Constructor for JSON deserialization only.
|
Proto2Coder<T> |
withExtensionsFrom(Class<?>... extensionHosts)
|
Proto2Coder<T> |
withExtensionsFrom(Iterable<Class<?>> moreExtensionHosts)
Produces a
Proto2Coder like this one, but with the extensions from
the given classes registered. |
getCoderArguments, getInstanceComponentsverifyDeterministicconsistentWithEquals, getAllowedEncodings, getComponents, getEncodedElementByteSize, isRegisterByteSizeObserverCheap, registerByteSizeObserver, structuralValue, toString, verifyDeterministic, verifyDeterministicpublic static <T extends com.google.protobuf.Message> Proto2Coder<T> of(Class<T> protoMessageClass)
Proto2Coder for the given Protobuf message class.public Proto2Coder<T> withExtensionsFrom(Iterable<Class<?>> moreExtensionHosts)
Proto2Coder like this one, but with the extensions from
the given classes registered.moreExtensionHosts - an iterable of classes that define a static
method registerAllExtensions(ExtensionRegistry)public Proto2Coder<T> withExtensionsFrom(Class<?>... extensionHosts)
@Deprecated public Proto2Coder<T> addExtensionsFrom(Class<?>... extensionHosts)
withExtensionsFrom(java.lang.Iterable<java.lang.Class<?>>)this
for method chaining.extensionHosts - must be a class that defines a static
method name registerAllExtensions@Deprecated public Proto2Coder<T> addExtensionsFrom(Iterable<Class<?>> extensionHosts)
withExtensionsFrom(java.lang.Iterable<java.lang.Class<?>>)this
for method chaining.extensionHosts - must be a class that defines a static
method name registerAllExtensionspublic void encode(T value, OutputStream outStream, Coder.Context context) throws IOException
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 T decode(InputStream inStream, Coder.Context context) throws IOException
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 boolean equals(Object other)
equals in class StandardCoder<T extends com.google.protobuf.Message>public int hashCode()
hashCode in class StandardCoder<T extends com.google.protobuf.Message>public String getEncodingId()
In particular, the encoding identifier is guaranteed to be the same for Proto2Coder
instances of the same principal message class, and otherwise distinct. Loaded extensions do not
affect the id, nor does it encode the full schema.
When modifying a message class, here are the broadest guidelines; see the above link for greater detail.
required field.
optional or repeated fields, with sensible defaults.
Code consuming this message class should be prepared to support all versions of the class until it is certain that no remaining serialized instances exist.
If backwards incompatible changes must be made, the best recourse is to change the name of your Protocol Buffers message class.
getEncodingId in interface Coder<T extends com.google.protobuf.Message>getEncodingId in class StandardCoder<T extends com.google.protobuf.Message>StandardCoder.getAllowedEncodings()public static <T extends com.google.protobuf.Message> Proto2Coder<T> of(String protoMessageClassName, @Nullable List<String> extensionHostClassNames)
public com.google.cloud.dataflow.sdk.util.CloudObject asCloudObject()
CoderCloudObject that represents this Coder.asCloudObject in interface Coder<T extends com.google.protobuf.Message>asCloudObject in class StandardCoder<T extends com.google.protobuf.Message>