Snappy Class — netty Architecture
Architecture documentation for the Snappy class in Snappy.java from the netty codebase.
Entity Profile
Dependency Diagram
graph TD 6a7984ff_ded6_5ba2_b4bb_f92d0d3986f8["Snappy"] c7a5624e_f050_1561_2ab5_08003d02f28e["Snappy.java"] 6a7984ff_ded6_5ba2_b4bb_f92d0d3986f8 -->|defined in| c7a5624e_f050_1561_2ab5_08003d02f28e bd40319d_37d7_6aef_2db0_d233b4de3669["Snappy()"] 6a7984ff_ded6_5ba2_b4bb_f92d0d3986f8 -->|method| bd40319d_37d7_6aef_2db0_d233b4de3669 0bdc44d1_71bc_b602_ed1c_b313cbe3b691["reset()"] 6a7984ff_ded6_5ba2_b4bb_f92d0d3986f8 -->|method| 0bdc44d1_71bc_b602_ed1c_b313cbe3b691 2c81d28d_4011_0232_9bac_669b46d6eed3["encode()"] 6a7984ff_ded6_5ba2_b4bb_f92d0d3986f8 -->|method| 2c81d28d_4011_0232_9bac_669b46d6eed3 499de467_1181_5401_2d71_b697c79fbb1f["hash()"] 6a7984ff_ded6_5ba2_b4bb_f92d0d3986f8 -->|method| 499de467_1181_5401_2d71_b697c79fbb1f bd5271ad_e0a7_6fc1_fedc_8d83fb7e74b5["getHashTable()"] 6a7984ff_ded6_5ba2_b4bb_f92d0d3986f8 -->|method| bd5271ad_e0a7_6fc1_fedc_8d83fb7e74b5 e21877d1_2b7f_3910_49c1_4b51e6159fcd["getHashTableFastThreadLocalArrayFill()"] 6a7984ff_ded6_5ba2_b4bb_f92d0d3986f8 -->|method| e21877d1_2b7f_3910_49c1_4b51e6159fcd 70d7f600_24fa_537e_e58f_7a425608478d["findMatchingLength()"] 6a7984ff_ded6_5ba2_b4bb_f92d0d3986f8 -->|method| 70d7f600_24fa_537e_e58f_7a425608478d 9bc0c49d_4e6c_a79d_a266_e9fdc2d4143e["bitsToEncode()"] 6a7984ff_ded6_5ba2_b4bb_f92d0d3986f8 -->|method| 9bc0c49d_4e6c_a79d_a266_e9fdc2d4143e a68ad8f3_8ce4_d2df_f94a_c25a5795c393["encodeLiteral()"] 6a7984ff_ded6_5ba2_b4bb_f92d0d3986f8 -->|method| a68ad8f3_8ce4_d2df_f94a_c25a5795c393 d29f08b5_907e_686e_c00a_161e362f7bdd["encodeCopyWithOffset()"] 6a7984ff_ded6_5ba2_b4bb_f92d0d3986f8 -->|method| d29f08b5_907e_686e_c00a_161e362f7bdd 5719cd76_7f65_93ab_f33b_8f7696b21cd0["encodeCopy()"] 6a7984ff_ded6_5ba2_b4bb_f92d0d3986f8 -->|method| 5719cd76_7f65_93ab_f33b_8f7696b21cd0 f2623adf_f9d0_6b9a_01bf_992a8c89c1e8["decode()"] 6a7984ff_ded6_5ba2_b4bb_f92d0d3986f8 -->|method| f2623adf_f9d0_6b9a_01bf_992a8c89c1e8 61395c44_d8f1_2ccc_d61d_8a1707cbc191["readPreamble()"] 6a7984ff_ded6_5ba2_b4bb_f92d0d3986f8 -->|method| 61395c44_d8f1_2ccc_d61d_8a1707cbc191
Relationship Graph
Source Code
codec-compression/src/main/java/io/netty/handler/codec/compression/Snappy.java lines 31–723
public final class Snappy {
private static final int MAX_HT_SIZE = 1 << 14;
private static final int MIN_COMPRESSIBLE_BYTES = 15;
// used as a return value to indicate that we haven't yet read our full preamble
private static final int PREAMBLE_NOT_FULL = -1;
private static final int NOT_ENOUGH_INPUT = -1;
// constants for the tag types
private static final int LITERAL = 0;
private static final int COPY_1_BYTE_OFFSET = 1;
private static final int COPY_2_BYTE_OFFSET = 2;
private static final int COPY_4_BYTE_OFFSET = 3;
// Hash table used to compress, shared between subsequent call to .encode()
private static final FastThreadLocal<short[]> HASH_TABLE = new FastThreadLocal<short[]>();
private static final boolean DEFAULT_REUSE_HASHTABLE =
SystemPropertyUtil.getBoolean("io.netty.handler.codec.compression.snappy.reuseHashTable", false);
public Snappy() {
this(DEFAULT_REUSE_HASHTABLE);
}
Snappy(boolean reuseHashtable) {
this.reuseHashtable = reuseHashtable;
}
public static Snappy withHashTableReuse() {
return new Snappy(true);
}
private final boolean reuseHashtable;
private State state = State.READING_PREAMBLE;
private byte tag;
private int written;
private enum State {
READING_PREAMBLE,
READING_TAG,
READING_LITERAL,
READING_COPY
}
public void reset() {
state = State.READING_PREAMBLE;
tag = 0;
written = 0;
}
public void encode(final ByteBuf in, final ByteBuf out, final int length) {
// Write the preamble length to the output buffer
for (int i = 0;; i ++) {
int b = length >>> i * 7;
if ((b & 0xFFFFFF80) != 0) {
out.writeByte(b & 0x7f | 0x80);
} else {
out.writeByte(b);
break;
}
}
int inIndex = in.readerIndex();
final int baseIndex = inIndex;
int hashTableSize = MathUtil.findNextPositivePowerOfTwo(length);
hashTableSize = Math.min(hashTableSize, MAX_HT_SIZE);
final short[] table = getHashTable(hashTableSize);
final int shift = Integer.numberOfLeadingZeros(hashTableSize) + 1;
int nextEmit = inIndex;
if (length - inIndex >= MIN_COMPRESSIBLE_BYTES) {
int nextHash = hash(in, ++inIndex, shift);
outer: while (true) {
int skip = 32;
int candidate;
int nextIndex = inIndex;
do {
Source
Frequently Asked Questions
What is the Snappy class?
Snappy is a class in the netty codebase, defined in codec-compression/src/main/java/io/netty/handler/codec/compression/Snappy.java.
Where is Snappy defined?
Snappy is defined in codec-compression/src/main/java/io/netty/handler/codec/compression/Snappy.java at line 31.
Analyze Your Own Codebase
Get architecture documentation, dependency graphs, and domain analysis for your codebase in minutes.
Try Supermodel Free