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) |
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, 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 static <T extends com.google.protobuf.Message> Proto2Coder<T> of(String protoMessageClassName, 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>