Home / Class/ LzfDecoder Class — netty Architecture

LzfDecoder Class — netty Architecture

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

Entity Profile

Dependency Diagram

graph TD
  130573af_9337_fc82_bd56_8e750f2bc3ab["LzfDecoder"]
  134a7559_ba3c_000e_567b_9854718041b6["LzfDecoder.java"]
  130573af_9337_fc82_bd56_8e750f2bc3ab -->|defined in| 134a7559_ba3c_000e_567b_9854718041b6
  f8122868_128f_fc33_7456_9081da86c071["LzfDecoder()"]
  130573af_9337_fc82_bd56_8e750f2bc3ab -->|method| f8122868_128f_fc33_7456_9081da86c071
  0f8871cc_75ab_fa7d_b96f_70509ee4f69d["decode()"]
  130573af_9337_fc82_bd56_8e750f2bc3ab -->|method| 0f8871cc_75ab_fa7d_b96f_70509ee4f69d

Relationship Graph

Source Code

codec-compression/src/main/java/io/netty/handler/codec/compression/LzfDecoder.java lines 40–244

public class LzfDecoder extends ByteToMessageDecoder {
    /**
     * Current state of decompression.
     */
    private enum State {
        INIT_BLOCK,
        INIT_ORIGINAL_LENGTH,
        DECOMPRESS_DATA,
        CORRUPTED
    }

    private State currentState = State.INIT_BLOCK;

    /**
     * Magic number of LZF chunk.
     */
    private static final short MAGIC_NUMBER = BYTE_Z << 8 | BYTE_V;

    /**
     * Underlying decoder in use.
     */
    private ChunkDecoder decoder;

    /**
     * Object that handles details of buffer recycling.
     */
    private BufferRecycler recycler;

    /**
     * Length of current received chunk of data.
     */
    private int chunkLength;

    /**
     * Original length of current received chunk of data.
     * It is equal to {@link #chunkLength} for non compressed chunks.
     */
    private int originalLength;

    /**
     * Indicates is this chunk compressed or not.
     */
    private boolean isCompressed;

    /**
     * Creates a new LZF decoder with the most optimal available methods for underlying data access.
     * It will "unsafe" instance if one can be used on current JVM.
     * It should be safe to call this constructor as implementations are dynamically loaded; however, on some
     * non-standard platforms it may be necessary to use {@link #LzfDecoder(boolean)} with {@code true} param.
     */
    public LzfDecoder() {
        this(false);
    }

    /**
     * Creates a new LZF decoder with specified decoding instance.
     *
     * @param safeInstance
     *        If {@code true} decoder will use {@link ChunkDecoder} that only uses standard JDK access methods,
     *        and should work on all Java platforms and JVMs.
     *        Otherwise decoder will try to use highly optimized {@link ChunkDecoder} implementation that uses
     *        Sun JDK's {@link sun.misc.Unsafe} class (which may be included by other JDK's as well).
     */
    public LzfDecoder(boolean safeInstance) {
        decoder = safeInstance ?
                ChunkDecoderFactory.safeInstance()
              : ChunkDecoderFactory.optimalInstance();

        recycler = BufferRecycler.instance();
    }

    @Override
    protected void decode(ChannelHandlerContext ctx, ByteBuf in, List<Object> out) throws Exception {
        try {
            switch (currentState) {
            case INIT_BLOCK:
                if (in.readableBytes() < HEADER_LEN_NOT_COMPRESSED) {
                    break;
                }
                final int magic = in.readUnsignedShort();
                if (magic != MAGIC_NUMBER) {

Frequently Asked Questions

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

Analyze Your Own Codebase

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

Try Supermodel Free