Home / Class/ FastLzFrameEncoder Class — netty Architecture

FastLzFrameEncoder Class — netty Architecture

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

Entity Profile

Dependency Diagram

graph TD
  6f3dd4d9_7eba_6bcc_7f72_548653d94248["FastLzFrameEncoder"]
  5fbe5e03_eaeb_0144_5f7c_e903e48d8500["FastLzFrameEncoder.java"]
  6f3dd4d9_7eba_6bcc_7f72_548653d94248 -->|defined in| 5fbe5e03_eaeb_0144_5f7c_e903e48d8500
  a92d5a7e_9761_e809_1bed_26f39aeb9427["FastLzFrameEncoder()"]
  6f3dd4d9_7eba_6bcc_7f72_548653d94248 -->|method| a92d5a7e_9761_e809_1bed_26f39aeb9427
  64ae0fa9_8743_16dd_ed36_2ca16349d0a3["encode()"]
  6f3dd4d9_7eba_6bcc_7f72_548653d94248 -->|method| 64ae0fa9_8743_16dd_ed36_2ca16349d0a3

Relationship Graph

Source Code

codec-compression/src/main/java/io/netty/handler/codec/compression/FastLzFrameEncoder.java lines 45–173

public class FastLzFrameEncoder extends MessageToByteEncoder<ByteBuf> {
    /**
     * Compression level.
     */
    private final int level;

    /**
     * Underlying checksum calculator in use.
     */
    private final ByteBufChecksum checksum;

    /**
     * Creates a FastLZ encoder without checksum calculator and with auto detection of compression level.
     */
    public FastLzFrameEncoder() {
        this(LEVEL_AUTO, null);
    }

    /**
     * Creates a FastLZ encoder with specified compression level and without checksum calculator.
     *
     * @param level supports only these values:
     *        0 - Encoder will choose level automatically depending on the length of the input buffer.
     *        1 - Level 1 is the fastest compression and generally useful for short data.
     *        2 - Level 2 is slightly slower but it gives better compression ratio.
     */
    public FastLzFrameEncoder(int level) {
        this(level, null);
    }

    /**
     * Creates a FastLZ encoder with auto detection of compression
     * level and calculation of checksums as specified.
     *
     * @param validateChecksums
     *        If true, the checksum of each block will be calculated and this value
     *        will be added to the header of block.
     *        By default {@link FastLzFrameEncoder} uses {@link java.util.zip.Adler32}
     *        for checksum calculation.
     */
    public FastLzFrameEncoder(boolean validateChecksums) {
        this(LEVEL_AUTO, validateChecksums ? new Adler32() : null);
    }

    /**
     * Creates a FastLZ encoder with specified compression level and checksum calculator.
     *
     * @param level supports only these values:
     *        0 - Encoder will choose level automatically depending on the length of the input buffer.
     *        1 - Level 1 is the fastest compression and generally useful for short data.
     *        2 - Level 2 is slightly slower but it gives better compression ratio.
     * @param checksum
     *        the {@link Checksum} instance to use to check data for integrity.
     *        You may set {@code null} if you don't want to validate checksum of each block.
     */
    public FastLzFrameEncoder(int level, Checksum checksum) {
        super(ByteBuf.class);
        if (level != LEVEL_AUTO && level != LEVEL_1 && level != LEVEL_2) {
            throw new IllegalArgumentException(String.format(
                    "level: %d (expected: %d or %d or %d)", level, LEVEL_AUTO, LEVEL_1, LEVEL_2));
        }
        this.level = level;
        this.checksum = checksum == null ? null : ByteBufChecksum.wrapChecksum(checksum);
    }

    @Override
    protected void encode(ChannelHandlerContext ctx, ByteBuf in, ByteBuf out) throws Exception {
        final ByteBufChecksum checksum = this.checksum;

        for (;;) {
            if (!in.isReadable()) {
                return;
            }
            final int idx = in.readerIndex();
            final int length = Math.min(in.readableBytes(), MAX_CHUNK_LENGTH);

            final int outputIdx = out.writerIndex();
            out.setMedium(outputIdx, MAGIC_NUMBER);
            int outputOffset = outputIdx + CHECKSUM_OFFSET + (checksum != null ? 4 : 0);

            final byte blockType;

Frequently Asked Questions

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

Analyze Your Own Codebase

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

Try Supermodel Free