public class ByteArrayCoder extends AtomicCoder<byte[]>
If in a nested context, prefixes the encoded array with a VarInt encoding of the length.
Coder.Context, Coder.NonDeterministicException| Modifier and Type | Method and Description |
|---|---|
byte[] |
decode(java.io.InputStream inStream,
Coder.Context context)
Decodes a value of type
T from the given input stream in
the given context. |
void |
encode(byte[] value,
java.io.OutputStream outStream,
Coder.Context context)
Encodes the given value of type
T onto the given output stream
in the given context. |
protected long |
getEncodedElementByteSize(byte[] value,
Coder.Context context)
Returns the size in bytes of the encoded value using this
coder.
|
boolean |
isDeterministic()
Returns true if the coding is deterministic.
|
boolean |
isRegisterByteSizeObserverCheap(byte[] value,
Coder.Context context)
Returns true since registerByteSizeObserver() runs in constant time.
|
static ByteArrayCoder |
of() |
java.lang.Object |
structuralValue(byte[] value)
Returns an object with an
Object.equals() method
that represents structural equality on the argument. |
getCoderArguments, getInstanceComponentsasCloudObject, consistentWithEquals, equals, getComponents, hashCode, registerByteSizeObserver, toString, verifyDeterministic, verifyDeterministic, verifyDeterministicpublic static ByteArrayCoder of()
public void encode(byte[] value,
java.io.OutputStream outStream,
Coder.Context context)
throws java.io.IOException,
CoderException
CoderT onto the given output stream
in the given context.java.io.IOException - if writing to the OutputStream fails
for some reasonCoderException - if the value could not be encoded for some reasonpublic byte[] decode(java.io.InputStream inStream,
Coder.Context context)
throws java.io.IOException,
CoderException
CoderT from the given input stream in
the given context. Returns the decoded value.java.io.IOException - if reading from the InputStream fails
for some reasonCoderException - if the value could not be decoded for some reasonpublic boolean isDeterministic()
Coder In order for a Coder to be considered deterministic,
the following must be true:
Object.equals()
or Comparable.compareTo(), if supported) have the same
encoding.
Coder always produces a canonical encoding, which is the
same for an instance of an object even if produced on different
computers at different times.
public java.lang.Object structuralValue(byte[] value)
CoderObject.equals() method
that represents structural equality on the argument.
(and also implements a compatible Object.hashCode()).
For any two objects of type T, if their encoded bytes
are the same, then their structural values are equal
according to Object.equals().
Most notably, the structural value for an array coder should perform a structural comparison of the contents of the arrays, rather than the default behavior of comparing according to object identity.
See also Coder.consistentWithEquals().
structuralValue in interface Coder<byte[]>structuralValue in class StandardCoder<byte[]>public boolean isRegisterByteSizeObserverCheap(byte[] value,
Coder.Context context)
isRegisterByteSizeObserverCheap in interface Coder<byte[]>isRegisterByteSizeObserverCheap in class StandardCoder<byte[]>protected long getEncodedElementByteSize(byte[] value,
Coder.Context context)
throws java.lang.Exception
StandardCodergetEncodedElementByteSize in class StandardCoder<byte[]>java.lang.Exception