com.google.cloud.dataflow.sdk.coders

## Class ByteStringCoder

- 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<com.google.protobuf.ByteString>
      - - com.google.cloud.dataflow.sdk.coders.ByteStringCoder

All Implemented Interfaces:
  Coder<com.google.protobuf.ByteString>, Serializable

    public class ByteStringCoder
    extends AtomicCoder<com.google.protobuf.ByteString>

A `Coder` for `ByteString` objects based on their encoded Protocol Buffer form.

When this code is used in a nested `Coder.Context`, the serialized `ByteString` objects are first delimited by their size.

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
`boolean` `consistentWithEquals()` Returns `true` if this `Coder` is injective with respect to `Object.equals(java.lang.Object)`.
`com.google.protobuf.ByteString` `decode(InputStream inStream, Coder.Context context)` Decodes a value of type `T` from the given input stream in the given context.
`void` `encode(com.google.protobuf.ByteString value, OutputStream outStream, Coder.Context context)` Encodes the given value of type `T` onto the given output stream in the given context.
`protected long` `getEncodedElementByteSize(com.google.protobuf.ByteString value, Coder.Context context)` Returns the size in bytes of the encoded value using this coder.

`boolean`

`isRegisterByteSizeObserverCheap(com.google.protobuf.ByteString value, Coder.Context context)`
Returns whether `Coder.registerByteSizeObserver(T, com.google.cloud.dataflow.sdk.util.common.ElementByteSizeObserver, com.google.cloud.dataflow.sdk.coders.Coder.Context)` cheap enough to call for every element, that is, if this `Coder` can calculate the byte size of the element to be coded in roughly constant time (or lazily).

`static ByteStringCoder` `of()`

### 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

`asCloudObject, equals, getAllowedEncodings, getComponents, getEncodingId, hashCode, registerByteSizeObserver, structuralValue, toString, verifyDeterministic, verifyDeterministic`

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

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

### Method Detail

#### of

    public static ByteStringCoder of()

#### encode

    public void encode(com.google.protobuf.ByteString value,
                       OutputStream outStream,
                       Coder.Context context)
                throws IOException,
                       CoderException

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 com.google.protobuf.ByteString decode(InputStream inStream,
                                                 Coder.Context context)
                                          throws IOException

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

#### getEncodedElementByteSize

    protected long getEncodedElementByteSize(com.google.protobuf.ByteString value,
                                             Coder.Context context)
                                      throws Exception

Description copied from class: `StandardCoder`
Returns the size in bytes of the encoded value using this coder.

Overrides:
  `getEncodedElementByteSize` in class `StandardCoder<com.google.protobuf.ByteString>`
Throws:
  `Exception`

#### consistentWithEquals

    public boolean consistentWithEquals()

Returns `true` if this `Coder` is injective with respect to `Object.equals(java.lang.Object)`.

Whenever the encoded bytes of two values are equal, then the original values are equal according to `Objects.equals()`. Note that this is well-defined for `null`.

This condition is most notably false for arrays. More generally, this condition is false whenever `equals()` compares object identity, rather than performing a semantic/structural comparison.

Returns true; the encoded output of two invocations of `ByteStringCoder` in the same `Coder.Context` will be identical if and only if the original `ByteString` objects are equal according to `Object.equals(java.lang.Object)`.

Specified by:
  `consistentWithEquals` in interface `Coder<com.google.protobuf.ByteString>`
Overrides:
  `consistentWithEquals` in class `StandardCoder<com.google.protobuf.ByteString>`
Returns:
  `false` for `StandardCoder` unless overridden.

#### isRegisterByteSizeObserverCheap

    public boolean isRegisterByteSizeObserverCheap(com.google.protobuf.ByteString value,
                                                   Coder.Context context)

Returns whether `Coder.registerByteSizeObserver(T, com.google.cloud.dataflow.sdk.util.common.ElementByteSizeObserver, com.google.cloud.dataflow.sdk.coders.Coder.Context)` cheap enough to call for every element, that is, if this `Coder` can calculate the byte size of the element to be coded in roughly constant time (or lazily).

Not intended to be called by user code, but instead by `PipelineRunner` implementations.

Returns true. `ByteString.size()` returns the size of an array and a `VarInt`.

Specified by:
  `isRegisterByteSizeObserverCheap` in interface `Coder<com.google.protobuf.ByteString>`
Overrides:
  `isRegisterByteSizeObserverCheap` in class `StandardCoder<com.google.protobuf.ByteString>`
Returns:
  `false` unless it is overridden. `StandardCoder.registerByteSizeObserver(T, com.google.cloud.dataflow.sdk.util.common.ElementByteSizeObserver, com.google.cloud.dataflow.sdk.coders.Coder.Context)` invokes `StandardCoder.getEncodedElementByteSize(T, com.google.cloud.dataflow.sdk.coders.Coder.Context)` which requires re-encoding an element unless it is overridden. This is considered expensive.