encode() — netty Function Reference
Architecture documentation for the encode() function in FastLzFrameEncoder.java from the netty codebase.
Entity Profile
Dependency Diagram
graph TD 64ae0fa9_8743_16dd_ed36_2ca16349d0a3["encode()"] 6f3dd4d9_7eba_6bcc_7f72_548653d94248["FastLzFrameEncoder"] 64ae0fa9_8743_16dd_ed36_2ca16349d0a3 -->|defined in| 6f3dd4d9_7eba_6bcc_7f72_548653d94248 style 64ae0fa9_8743_16dd_ed36_2ca16349d0a3 fill:#6366f1,stroke:#818cf8,color:#fff
Relationship Graph
Source Code
codec-compression/src/main/java/io/netty/handler/codec/compression/FastLzFrameEncoder.java lines 110–172
@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;
final int chunkLength;
if (length < MIN_LENGTH_TO_COMPRESSION) {
blockType = BLOCK_TYPE_NON_COMPRESSED;
out.ensureWritable(outputOffset + 2 + length);
final int outputPtr = outputOffset + 2;
if (checksum != null) {
checksum.reset();
checksum.update(in, idx, length);
out.setInt(outputIdx + CHECKSUM_OFFSET, (int) checksum.getValue());
}
out.setBytes(outputPtr, in, idx, length);
chunkLength = length;
} else {
// try to compress
if (checksum != null) {
checksum.reset();
checksum.update(in, idx, length);
out.setInt(outputIdx + CHECKSUM_OFFSET, (int) checksum.getValue());
}
final int maxOutputLength = calculateOutputBufferLength(length);
out.ensureWritable(outputOffset + 4 + maxOutputLength);
final int outputPtr = outputOffset + 4;
final int compressedLength = compress(in, in.readerIndex(), length, out, outputPtr, level);
if (compressedLength < length) {
blockType = BLOCK_TYPE_COMPRESSED;
chunkLength = compressedLength;
out.setShort(outputOffset, chunkLength);
outputOffset += 2;
} else {
blockType = BLOCK_TYPE_NON_COMPRESSED;
out.setBytes(outputOffset + 2, in, idx, length);
chunkLength = length;
}
}
out.setShort(outputOffset, length);
out.setByte(outputIdx + OPTIONS_OFFSET,
blockType | (checksum != null ? BLOCK_WITH_CHECKSUM : BLOCK_WITHOUT_CHECKSUM));
out.writerIndex(outputOffset + 2 + chunkLength);
in.skipBytes(length);
}
}
Domain
Subdomains
Defined In
Source
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/FastLzFrameEncoder.java.
Where is encode() defined?
encode() is defined in codec-compression/src/main/java/io/netty/handler/codec/compression/FastLzFrameEncoder.java at line 110.
Analyze Your Own Codebase
Get architecture documentation, dependency graphs, and domain analysis for your codebase in minutes.
Try Supermodel Free