Home / Class/ FastLz Class — netty Architecture

FastLz Class — netty Architecture

Architecture documentation for the FastLz class in FastLz.java from the netty codebase.

Entity Profile

Dependency Diagram

graph TD
  98671d94_5a6d_343c_6d73_292cd19cfd19["FastLz"]
  3fa4b4ec_dbdc_a214_cf57_605c2404a3e3["FastLz.java"]
  98671d94_5a6d_343c_6d73_292cd19cfd19 -->|defined in| 3fa4b4ec_dbdc_a214_cf57_605c2404a3e3
  5a33eabf_cd2e_fc95_1f11_4368e1e56046["calculateOutputBufferLength()"]
  98671d94_5a6d_343c_6d73_292cd19cfd19 -->|method| 5a33eabf_cd2e_fc95_1f11_4368e1e56046
  2e9a6712_fc03_7631_0209_22e699baf3b2["compress()"]
  98671d94_5a6d_343c_6d73_292cd19cfd19 -->|method| 2e9a6712_fc03_7631_0209_22e699baf3b2
  95dcc9e7_c527_0c24_1626_72062722dde1["decompress()"]
  98671d94_5a6d_343c_6d73_292cd19cfd19 -->|method| 95dcc9e7_c527_0c24_1626_72062722dde1
  caa54910_d565_ad45_1f26_c35707051a0c["hashFunction()"]
  98671d94_5a6d_343c_6d73_292cd19cfd19 -->|method| caa54910_d565_ad45_1f26_c35707051a0c
  dd7e1ac4_b45d_9cfb_2ce3_1576201c58e8["readU16()"]
  98671d94_5a6d_343c_6d73_292cd19cfd19 -->|method| dd7e1ac4_b45d_9cfb_2ce3_1576201c58e8
  1a4dd2e7_714a_170e_6b0a_c83da43de949["FastLz()"]
  98671d94_5a6d_343c_6d73_292cd19cfd19 -->|method| 1a4dd2e7_714a_170e_6b0a_c83da43de949

Relationship Graph

Source Code

codec-compression/src/main/java/io/netty/handler/codec/compression/FastLz.java lines 29–560

final class FastLz {

    private static final int MAX_DISTANCE = 8191;
    private static final int MAX_FARDISTANCE = 65535 + MAX_DISTANCE - 1;

    private static final int HASH_LOG = 13;
    private static final int HASH_SIZE = 1 << HASH_LOG; // 8192
    private static final int HASH_MASK = HASH_SIZE - 1;

    private static final int MAX_COPY = 32;
    private static final int MAX_LEN = 256 + 8;

    private static final int MIN_RECOMENDED_LENGTH_FOR_LEVEL_2 = 1024 * 64;

    static final int MAGIC_NUMBER = 'F' << 16 | 'L' << 8 | 'Z';

    static final byte BLOCK_TYPE_NON_COMPRESSED = 0x00;
    static final byte     BLOCK_TYPE_COMPRESSED = 0x01;
    static final byte    BLOCK_WITHOUT_CHECKSUM = 0x00;
    static final byte       BLOCK_WITH_CHECKSUM = 0x10;

    static final int OPTIONS_OFFSET = 3;
    static final int CHECKSUM_OFFSET = 4;

    static final int MAX_CHUNK_LENGTH = 0xFFFF;

    /**
     * Do not call {@link #compress(ByteBuf, int, int, ByteBuf, int, int)} for input buffers
     * which length less than this value.
     */
    static final int MIN_LENGTH_TO_COMPRESSION = 32;

    /**
     * In this case {@link #compress(ByteBuf, int, int, ByteBuf, int, int)} will choose level
     * automatically depending on the length of the input buffer. If length less than
     * {@link #MIN_RECOMENDED_LENGTH_FOR_LEVEL_2} {@link #LEVEL_1} will be chosen,
     * otherwise {@link #LEVEL_2}.
     */
    static final int LEVEL_AUTO = 0;

    /**
     * Level 1 is the fastest compression and generally useful for short data.
     */
    static final int LEVEL_1 = 1;

    /**
     * Level 2 is slightly slower but it gives better compression ratio.
     */
    static final int LEVEL_2 = 2;

    /**
     * The output buffer must be at least 6% larger than the input buffer and can not be smaller than 66 bytes.
     * @param inputLength length of input buffer
     * @return Maximum output buffer length
     */
    static int calculateOutputBufferLength(int inputLength) {
        final int outputLength = (int) (inputLength * 1.06);
        return Math.max(outputLength, 66);
    }

    /**
     * Compress a block of data in the input buffer and returns the size of compressed block.
     * The size of input buffer is specified by length. The minimum input buffer size is 32.
     *
     * If the input is not compressible, the return value might be larger than length (input buffer size).
     */
    @SuppressWarnings("IdentityBinaryExpression")
    static int compress(final ByteBuf input, final int inOffset, final int inLength,
                        final ByteBuf output, final int outOffset, final int proposedLevel) {
        final int level;
        if (proposedLevel == LEVEL_AUTO) {
            level = inLength < MIN_RECOMENDED_LENGTH_FOR_LEVEL_2 ? LEVEL_1 : LEVEL_2;
        } else {
            level = proposedLevel;
        }

        int ip = 0;
        int ipBound = ip + inLength - 2;
        int ipLimit = ip + inLength - 12;

        int op = 0;

Frequently Asked Questions

What is the FastLz class?
FastLz is a class in the netty codebase, defined in codec-compression/src/main/java/io/netty/handler/codec/compression/FastLz.java.
Where is FastLz defined?
FastLz is defined in codec-compression/src/main/java/io/netty/handler/codec/compression/FastLz.java at line 29.

Analyze Your Own Codebase

Get architecture documentation, dependency graphs, and domain analysis for your codebase in minutes.

Try Supermodel Free