T - the type of elements handled by this coder, must extend MessageProtoCoder.@Deprecated public class Proto2Coder<T extends com.google.protobuf.Message> extends AtomicCoder<T>
Coder using Google Protocol Buffers 2 binary format.
To learn more about Protocol Buffers, visit: https://developers.google.com/protocol-buffers
To use, specify the Coder type on a PCollection containing Protocol Buffers messages.
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()
Deprecated.
Returns the
CloudObject that represents this Coder. |
static CoderProvider |
coderProvider()
Deprecated.
|
T |
decode(InputStream inStream,
Coder.Context context)
Deprecated.
Decodes a value of type
T from the given input stream in
the given context. |
void |
encode(T value,
OutputStream outStream,
Coder.Context context)
Deprecated.
Encodes the given value of type
T onto the given output stream
in the given context. |
boolean |
equals(Object other)
Deprecated.
|
String |
getEncodingId()
Deprecated.
The encoding identifier is designed to support evolution as per the design of Protocol
Buffers.
|
int |
hashCode()
Deprecated.
|
static <T extends com.google.protobuf.Message> |
of(Class<T> protoMessageClass)
Deprecated.
Returns a
Proto2Coder for the given Protobuf message class. |
static <T extends com.google.protobuf.Message> |
of(String protoMessageClassName,
List<String> extensionHostClassNames)
Deprecated.
Constructor for JSON deserialization only.
|
static <T extends com.google.protobuf.Message> |
of(TypeDescriptor<T> protoMessageType)
Deprecated.
Returns a
Proto2Coder for the given Protobuf message class. |
Proto2Coder<T> |
withExtensionsFrom(Class<?>... extensionHosts)
Deprecated.
|
Proto2Coder<T> |
withExtensionsFrom(Iterable<Class<?>> moreExtensionHosts)
Deprecated.
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 CoderProvider coderProvider()
public static <T extends com.google.protobuf.Message> Proto2Coder<T> of(Class<T> protoMessageClass)
Proto2Coder for the given Protobuf message class.public static <T extends com.google.protobuf.Message> Proto2Coder<T> of(TypeDescriptor<T> protoMessageType)
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)
StandardCoderequals in class StandardCoder<T extends com.google.protobuf.Message>true if the two StandardCoder instances have the
same class and equal components.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>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>