Home / Function/ encode() — netty Function Reference

encode() — netty Function Reference

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

Entity Profile

Dependency Diagram

graph TD
  c98be7cc_8336_cbe5_75fa_58753a9b740c["encode()"]
  30e5e893_9366_6707_dcb5_d8aa1087057f["SnappyFrameEncoder"]
  c98be7cc_8336_cbe5_75fa_58753a9b740c -->|defined in| 30e5e893_9366_6707_dcb5_d8aa1087057f
  c9a18e44_b89b_a0f7_ea69_f3aa8d296fef["writeUnencodedChunk()"]
  c98be7cc_8336_cbe5_75fa_58753a9b740c -->|calls| c9a18e44_b89b_a0f7_ea69_f3aa8d296fef
  6b5c85aa_d986_c90b_1b80_90a76af27668["calculateAndWriteChecksum()"]
  c98be7cc_8336_cbe5_75fa_58753a9b740c -->|calls| 6b5c85aa_d986_c90b_1b80_90a76af27668
  6a3a9fdb_f6b2_f3cc_3d7b_2162896b33dc["setChunkLength()"]
  c98be7cc_8336_cbe5_75fa_58753a9b740c -->|calls| 6a3a9fdb_f6b2_f3cc_3d7b_2162896b33dc
  style c98be7cc_8336_cbe5_75fa_58753a9b740c fill:#6366f1,stroke:#818cf8,color:#fff

Relationship Graph

Source Code

codec-compression/src/main/java/io/netty/handler/codec/compression/SnappyFrameEncoder.java lines 78–117

    @Override
    protected void encode(ChannelHandlerContext ctx, ByteBuf in, ByteBuf out) throws Exception {
        if (!in.isReadable()) {
            return;
        }

        if (!started) {
            started = true;
            out.writeBytes(STREAM_START);
        }

        int dataLength = in.readableBytes();
        if (dataLength > MIN_COMPRESSIBLE_LENGTH) {
            for (;;) {
                final int lengthIdx = out.writerIndex() + 1;
                if (dataLength < MIN_COMPRESSIBLE_LENGTH) {
                    ByteBuf slice = in.readSlice(dataLength);
                    writeUnencodedChunk(slice, out, dataLength);
                    break;
                }

                out.writeInt(0);
                if (dataLength > sliceSize) {
                    ByteBuf slice = in.readSlice(sliceSize);
                    calculateAndWriteChecksum(slice, out);
                    snappy.encode(slice, out, sliceSize);
                    setChunkLength(out, lengthIdx);
                    dataLength -= sliceSize;
                } else {
                    ByteBuf slice = in.readSlice(dataLength);
                    calculateAndWriteChecksum(slice, out);
                    snappy.encode(slice, out, dataLength);
                    setChunkLength(out, lengthIdx);
                    break;
                }
            }
        } else {
            writeUnencodedChunk(in, out, dataLength);
        }
    }

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/SnappyFrameEncoder.java.
Where is encode() defined?
encode() is defined in codec-compression/src/main/java/io/netty/handler/codec/compression/SnappyFrameEncoder.java at line 78.
What does encode() call?
encode() calls 3 function(s): calculateAndWriteChecksum, setChunkLength, writeUnencodedChunk.

Analyze Your Own Codebase

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

Try Supermodel Free