com.google.cloud.dataflow.sdk.coders

## Class Proto2Coder<T extends com.google.protobuf.Message>

- java.lang.Object
- - com.google.cloud.dataflow.sdk.coders.StandardCoder<T>
  - - com.google.cloud.dataflow.sdk.coders.DeterministicStandardCoder<T>
    - - com.google.cloud.dataflow.sdk.coders.AtomicCoder<T>
      - - com.google.cloud.dataflow.sdk.coders.Proto2Coder<T>

Type Parameters:
  `T` - the type of elements handled by this coder, must extend `Message`

All Implemented Interfaces:
  Coder<T>, Serializable

Deprecated.
Use `ProtoCoder`.

    @Deprecated
    public class Proto2Coder<T extends com.google.protobuf.Message>
    extends AtomicCoder<T>

A `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));

See Also:
  Serialized Form

### Nested Class Summary

### Nested classes/interfaces inherited from interface com.google.cloud.dataflow.sdk.coders.Coder

`Coder.Context, Coder.NonDeterministicException`

### Method Summary

All Methods Static Methods Instance Methods Concrete Methods Deprecated Methods
`Proto2Coder<T>` `addExtensionsFrom(Class<?>... extensionHosts)` Deprecated. use `withExtensionsFrom(java.lang.Iterable<java.lang.Class<?>>)`
`Proto2Coder<T>` `addExtensionsFrom(Iterable<Class<?>> extensionHosts)` Deprecated. use `withExtensionsFrom(java.lang.Iterable<java.lang.Class<?>>)`
`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> Proto2Coder<T>` `of(Class<T> protoMessageClass)` Deprecated. Returns a `Proto2Coder` for the given Protobuf message class.
`static <T extends com.google.protobuf.Message> Proto2Coder<T>` `of(String protoMessageClassName, List<String> extensionHostClassNames)` Deprecated. Constructor for JSON deserialization only.
`static <T extends com.google.protobuf.Message> Proto2Coder<T>` `of(TypeDescriptor<T> protoMessageType)` Deprecated. Returns a `Proto2Coder` for the given Protobuf message class.
`Proto2Coder<T>` `withExtensionsFrom(Class<?>... extensionHosts)` Deprecated. See `withExtensionsFrom(Iterable)`.
`Proto2Coder<T>` `withExtensionsFrom(Iterable<Class<?>> moreExtensionHosts)` Deprecated. Produces a `Proto2Coder` like this one, but with the extensions from the given classes registered.

### Methods inherited from class com.google.cloud.dataflow.sdk.coders.AtomicCoder

`getCoderArguments, getInstanceComponents`

### Methods inherited from class com.google.cloud.dataflow.sdk.coders.DeterministicStandardCoder

`verifyDeterministic`

### Methods inherited from class com.google.cloud.dataflow.sdk.coders.StandardCoder

`consistentWithEquals, getAllowedEncodings, getComponents, getEncodedElementByteSize, isRegisterByteSizeObserverCheap, registerByteSizeObserver, structuralValue, toString, verifyDeterministic, verifyDeterministic`

### Methods inherited from class java.lang.Object

`clone, finalize, getClass, notify, notifyAll, wait, wait, wait`

### Method Detail

#### coderProvider

    public static CoderProvider coderProvider()

Deprecated.

#### of

    public static <T extends com.google.protobuf.Message> Proto2Coder<T> of(Class<T> protoMessageClass)

Deprecated.
Returns a `Proto2Coder` for the given Protobuf message class.

#### of

    public static <T extends com.google.protobuf.Message> Proto2Coder<T> of(TypeDescriptor<T> protoMessageType)

Deprecated.
Returns a `Proto2Coder` for the given Protobuf message class.

#### withExtensionsFrom

    public Proto2Coder<T> withExtensionsFrom(Iterable<Class<?>> moreExtensionHosts)

Deprecated.
Produces a `Proto2Coder` like this one, but with the extensions from the given classes registered.

Parameters:
  `moreExtensionHosts` - an iterable of classes that define a static method `registerAllExtensions(ExtensionRegistry)`

#### withExtensionsFrom

    public Proto2Coder<T> withExtensionsFrom(Class<?>... extensionHosts)

Deprecated.
See `withExtensionsFrom(Iterable)`.

#### addExtensionsFrom

    @Deprecated
    public Proto2Coder<T> addExtensionsFrom(Class<?>... extensionHosts)

Deprecated. use `withExtensionsFrom(java.lang.Iterable<java.lang.Class<?>>)`
Adds custom Protobuf extensions to the coder. Returns `this` for method chaining.

Parameters:
  `extensionHosts` - must be a class that defines a static method name `registerAllExtensions`

#### addExtensionsFrom

    @Deprecated
    public Proto2Coder<T> addExtensionsFrom(Iterable<Class<?>> extensionHosts)

Deprecated. use `withExtensionsFrom(java.lang.Iterable<java.lang.Class<?>>)`
Adds custom Protobuf extensions to the coder. Returns `this` for method chaining.

Parameters:
  `extensionHosts` - must be a class that defines a static method name `registerAllExtensions`

#### encode

    public void encode(T value,
                       OutputStream outStream,
                       Coder.Context context)
                throws IOException

Deprecated.
Description copied from interface: `Coder`
Encodes the given value of type `T` onto the given output stream in the given context.

Throws:
  `IOException` - if writing to the `OutputStream` fails for some reason
  `CoderException` - if the value could not be encoded for some reason

#### decode

    public T decode(InputStream inStream,
                    Coder.Context context)
             throws IOException

Deprecated.
Description copied from interface: `Coder`
Decodes a value of type `T` from the given input stream in the given context. Returns the decoded value.

Throws:
  `IOException` - if reading from the `InputStream` fails for some reason
  `CoderException` - if the value could not be decoded for some reason

#### equals

    public boolean equals(Object other)

Deprecated.
Description copied from class: `StandardCoder`

Overrides:
  `equals` in class `StandardCoder<T extends com.google.protobuf.Message>`
Returns:
  `true` if the two `StandardCoder` instances have the same class and equal components.

#### hashCode

    public int hashCode()

Deprecated.

Overrides:
  `hashCode` in class `StandardCoder<T extends com.google.protobuf.Message>`

#### getEncodingId

    public String getEncodingId()

Deprecated.
The encoding identifier is designed to support evolution as per the design of Protocol Buffers. In order to use this class effectively, carefully follow the advice in the Protocol Buffers documentation at Updating A Message Type.

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.

- Do not change the numeric tags for any fields.
- Never remove a `required` field.
- Only add `optional` or `repeated` fields, with sensible defaults.
- When changing the type of a field, consult the Protocol Buffers documentation to ensure the new and old types are interchangeable.

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.

Specified by:
  `getEncodingId` in interface `Coder<T extends com.google.protobuf.Message>`
Overrides:
  `getEncodingId` in class `StandardCoder<T extends com.google.protobuf.Message>`

#### of

    public static <T extends com.google.protobuf.Message> Proto2Coder<T> of(String protoMessageClassName,
                                                                            @Nullable
                                                                            List<String> extensionHostClassNames)

Deprecated.
Constructor for JSON deserialization only.

#### asCloudObject

    public com.google.cloud.dataflow.sdk.util.CloudObject asCloudObject()

Deprecated.
Description copied from interface: `Coder`
Returns the `CloudObject` that represents this `Coder`.

Specified by:
  `asCloudObject` in interface `Coder<T extends com.google.protobuf.Message>`
Overrides:
  `asCloudObject` in class `StandardCoder<T extends com.google.protobuf.Message>`