public class ZstdCoder<T> extends Coder<T>
This coder uses the Zstandard compression library's direct compression methods (from byte[]
to byte[]
) and thus requires that the inner coder's encoded value must fit in a
byte[]
.
Coder.Context, Coder.NonDeterministicException
Modifier and Type | Method and Description |
---|---|
boolean |
consistentWithEquals()
|
T |
decode(java.io.InputStream is)
Decodes a value of type
T from the given input stream in the given context. |
void |
encode(T value,
java.io.OutputStream os)
Encodes the given value of type
T onto the given output stream. |
boolean |
equals(java.lang.Object o) |
java.util.List<? extends Coder<?>> |
getCoderArguments()
|
int |
hashCode() |
static <T> ZstdCoder<T> |
of(Coder<T> innerCoder)
Wraps the given coder into a
ZstdCoder . |
static <T> ZstdCoder<T> |
of(Coder<T> innerCoder,
byte[] dict)
Wraps the given coder into a
ZstdCoder . |
static <T> ZstdCoder<T> |
of(Coder<T> innerCoder,
byte[] dict,
int level)
Wraps the given coder into a
ZstdCoder . |
static <T> ZstdCoder<T> |
of(Coder<T> innerCoder,
int level)
Wraps the given coder into a
ZstdCoder . |
java.lang.Object |
structuralValue(T value)
Returns an object with an
Object.equals() method that represents structural equality on
the argument. |
java.lang.String |
toString() |
void |
verifyDeterministic()
Throw
Coder.NonDeterministicException if the coding is not deterministic. |
decode, encode, getEncodedElementByteSize, getEncodedTypeDescriptor, isRegisterByteSizeObserverCheap, registerByteSizeObserver, verifyDeterministic, verifyDeterministic
public static <T> ZstdCoder<T> of(Coder<T> innerCoder, byte[] dict, int level)
ZstdCoder
.public static <T> ZstdCoder<T> of(Coder<T> innerCoder, byte[] dict)
ZstdCoder
.public static <T> ZstdCoder<T> of(Coder<T> innerCoder, int level)
ZstdCoder
.public void encode(T value, java.io.OutputStream os) throws java.io.IOException
Coder
T
onto the given output stream.encode
in class Coder<T>
java.io.IOException
- if writing to the OutputStream
fails for some reasonCoderException
- if the value could not be encoded for some reasonpublic T decode(java.io.InputStream is) throws java.io.IOException
Coder
T
from the given input stream in the given context. Returns the
decoded value.decode
in class Coder<T>
java.io.IOException
- if reading from the InputStream
fails for some reasonCoderException
- if the value could not be decoded for some reasonpublic java.util.List<? extends Coder<?>> getCoderArguments()
Coder
Coder
for a parameterized type, returns the list of Coder
s being
used for each of the parameters in the same order they appear within the parameterized type's
type signature. If this cannot be done, or this Coder
does not encode/decode a
parameterized type, returns the empty list.getCoderArguments
in class Coder<T>
public void verifyDeterministic() throws Coder.NonDeterministicException
Coder.NonDeterministicException
if the coding is not deterministic.
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.
ZstdCoder
is deterministic if the inner coder is deterministic.
verifyDeterministic
in class Coder<T>
Coder.NonDeterministicException
- if this coder is not deterministic.public boolean consistentWithEquals()
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.
By default, returns false.
ZstdCoder
is consistent with equals if the inner coder is consistent with equals.
consistentWithEquals
in class Coder<T>
public java.lang.Object structuralValue(T value)
Object.equals()
method that represents structural equality on
the argument.
For any two values x
and y
of type T
, if their encoded bytes are the
same, then it must be the case that structuralValue(x).equals(structuralValue(y))
.
Most notably:
null
should be a proper object with an
equals()
method, even if the input value is null
.
See also Coder.consistentWithEquals()
.
By default, if this coder is Coder.consistentWithEquals()
, and the value is not null,
returns the provided object. Otherwise, encodes the value into a byte[]
, and returns an
object that performs array equality on the encoded bytes.
ZstdCoder
uses the structural value of the inner coder.
structuralValue
in class Coder<T>
public boolean equals(@Nullable java.lang.Object o)
equals
in class java.lang.Object
true
if the two ZstdCoder
instances have the same class, inner coder,
dictionary and compression level.public int hashCode()
hashCode
in class java.lang.Object
public java.lang.String toString()
toString
in class java.lang.Object