Home / Function/ encode() — netty Function Reference

encode() — netty Function Reference

Architecture documentation for the encode() function in LzfEncoder.java from the netty codebase.

Entity Profile

Dependency Diagram

graph TD
  3ba6d3de_599f_0037_5044_8cc82e1307ea["encode()"]
  cf653678_8419_ee5d_5141_4973b04e6b00["LzfEncoder"]
  3ba6d3de_599f_0037_5044_8cc82e1307ea -->|defined in| cf653678_8419_ee5d_5141_4973b04e6b00
  77db0f9f_0817_bb20_ff27_ef4f9b6506c5["encodeCompress()"]
  3ba6d3de_599f_0037_5044_8cc82e1307ea -->|calls| 77db0f9f_0817_bb20_ff27_ef4f9b6506c5
  251e5e57_80da_017e_b324_be7b805a8db5["encodeNonCompress()"]
  3ba6d3de_599f_0037_5044_8cc82e1307ea -->|calls| 251e5e57_80da_017e_b324_be7b805a8db5
  style 3ba6d3de_599f_0037_5044_8cc82e1307ea fill:#6366f1,stroke:#818cf8,color:#fff

Relationship Graph

Source Code

codec-compression/src/main/java/io/netty/handler/codec/compression/LzfEncoder.java lines 168–216

    @Override
    protected void encode(ChannelHandlerContext ctx, ByteBuf in, ByteBuf out) throws Exception {
        final int length = in.readableBytes();
        final int idx = in.readerIndex();
        final byte[] input;
        final int inputPtr;
        if (in.hasArray()) {
            input = in.array();
            inputPtr = in.arrayOffset() + idx;
        } else {
            input = recycler.allocInputBuffer(length);
            in.getBytes(idx, input, 0, length);
            inputPtr = 0;
        }

        // Estimate may apparently under-count by one in some cases.
        final int maxOutputLength = LZFEncoder.estimateMaxWorkspaceSize(length) + 1;
        out.ensureWritable(maxOutputLength);
        final byte[] output;
        final int outputPtr;
        if (out.hasArray()) {
            output = out.array();
            outputPtr = out.arrayOffset() + out.writerIndex();
        } else {
            output = new byte[maxOutputLength];
            outputPtr = 0;
        }

        final int outputLength;
        if (length >= compressThreshold) {
            // compress.
            outputLength = encodeCompress(input, inputPtr, length, output, outputPtr);
        } else {
            // not compress.
            outputLength = encodeNonCompress(input, inputPtr, length, output, outputPtr);
        }

        if (out.hasArray()) {
            out.writerIndex(out.writerIndex() + outputLength);
        } else {
            out.writeBytes(output, 0, outputLength);
        }

        in.skipBytes(length);

        if (!in.hasArray()) {
            recycler.releaseInputBuffer(input);
        }
    }

Domain

Subdomains

Frequently Asked Questions

What does encode() do?
encode() is a function in the netty codebase, defined in codec-compression/src/main/java/io/netty/handler/codec/compression/LzfEncoder.java.
Where is encode() defined?
encode() is defined in codec-compression/src/main/java/io/netty/handler/codec/compression/LzfEncoder.java at line 168.
What does encode() call?
encode() calls 2 function(s): encodeCompress, encodeNonCompress.

Analyze Your Own Codebase

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

Try Supermodel Free