ByteBufChecksum implementation for use with
Lz4FrameEncoder and Lz4FrameDecoder.
StreamingXXHash32#asChecksum() has a particularly nasty implementation
of Checksum#update(int) that allocates a single-element byte array for
every invocation.
In addition to that, it doesn't implement an overload that accepts a ByteBuffer
as an argument.
Combined, this means that we can't use ReflectiveByteBufChecksum at all,
and can't use SlowByteBufChecksum because of its atrocious performance
with direct byte buffers (allocating an array and making a JNI call for every byte
checksummed might be considered sub-optimal by some).
Block version of xxHash32 (XXHash32), however, does provide
XXHash32#hash(ByteBuffer, int) method that is efficient and does exactly
what we need, with a caveat that we can only invoke it once before having to reset.
This, however, is fine for our purposes, given the way we use it in
Lz4FrameEncoder and Lz4FrameDecoder:
reset(), followed by one update(), followed by getValue().
| Modifier and Type | Field and Description |
|---|---|
| private final int | |
| private boolean | |
| private int | |
| private static final XXHash32 |
| Access | Constructor and Description |
|---|---|
| public |
| Modifier and Type | Method and Description |
|---|---|
| public long | |
| public void | |
| public void | update(int
the byte to update the checksum with b)Implements java. |
| public void | update(byte[]
the byte array to update the checksum with b, int the start offset of the data off, int the number of bytes to use for the update len)Implements java. |
| public void | update(ByteBuf b, int off, int len)
Overrides io. |
| seed | back to summary |
|---|---|
| private final int seed | |
| used | back to summary |
|---|---|
| private boolean used | |
| value | back to summary |
|---|---|
| private int value | |
| XXHASH32 | back to summary |
|---|---|
| private static final XXHash32 XXHASH32 | |
| Lz4XXHash32 | back to summary |
|---|---|
public Lz4XXHash32(int seed)
| |
| getValue | back to summary |
|---|---|
| public long getValue() Implements java. Doc from java. Returns the current checksum value.
| |
| reset | back to summary |
|---|---|
| public void reset() Implements java. Doc from java. Resets the checksum to its initial value.
| |
| update | back to summary |
|---|---|
| public void update(int b) Implements java. Doc from java. Updates the current checksum with the specified byte.
| |
| update | back to summary |
|---|---|
| public void update(byte[] b, int off, int len) Implements java. Doc from java. Updates the current checksum with the specified array of bytes.
| |
| update | back to summary |
|---|---|
| public void update(ByteBuf b, int off, int len) Overrides io.
| |