decode() — netty Function Reference
Architecture documentation for the decode() function in LzfDecoder.java from the netty codebase.
Entity Profile
Dependency Diagram
graph TD 0f8871cc_75ab_fa7d_b96f_70509ee4f69d["decode()"] 130573af_9337_fc82_bd56_8e750f2bc3ab["LzfDecoder"] 0f8871cc_75ab_fa7d_b96f_70509ee4f69d -->|defined in| 130573af_9337_fc82_bd56_8e750f2bc3ab style 0f8871cc_75ab_fa7d_b96f_70509ee4f69d fill:#6366f1,stroke:#818cf8,color:#fff
Relationship Graph
Source Code
codec-compression/src/main/java/io/netty/handler/codec/compression/LzfDecoder.java lines 111–243
@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) {
throw new DecompressionException("unexpected block identifier");
}
final int type = in.readByte();
switch (type) {
case BLOCK_TYPE_NON_COMPRESSED:
isCompressed = false;
currentState = State.DECOMPRESS_DATA;
break;
case BLOCK_TYPE_COMPRESSED:
isCompressed = true;
currentState = State.INIT_ORIGINAL_LENGTH;
break;
default:
throw new DecompressionException(String.format(
"unknown type of chunk: %d (expected: %d or %d)",
type, BLOCK_TYPE_NON_COMPRESSED, BLOCK_TYPE_COMPRESSED));
}
chunkLength = in.readUnsignedShort();
// chunkLength can never exceed MAX_CHUNK_LEN as MAX_CHUNK_LEN is 64kb and readUnsignedShort can
// never return anything bigger as well. Let's add some check any way to make things easier in terms
// of debugging if we ever hit this because of an bug.
if (chunkLength > LZFChunk.MAX_CHUNK_LEN) {
throw new DecompressionException(String.format(
"chunk length exceeds maximum: %d (expected: =< %d)",
chunkLength, LZFChunk.MAX_CHUNK_LEN));
}
if (type != BLOCK_TYPE_COMPRESSED) {
break;
}
// fall through
case INIT_ORIGINAL_LENGTH:
if (in.readableBytes() < 2) {
break;
}
originalLength = in.readUnsignedShort();
// originalLength can never exceed MAX_CHUNK_LEN as MAX_CHUNK_LEN is 64kb and readUnsignedShort can
// never return anything bigger as well. Let's add some check any way to make things easier in terms
// of debugging if we ever hit this because of an bug.
if (originalLength > LZFChunk.MAX_CHUNK_LEN) {
throw new DecompressionException(String.format(
"original length exceeds maximum: %d (expected: =< %d)",
chunkLength, LZFChunk.MAX_CHUNK_LEN));
}
currentState = State.DECOMPRESS_DATA;
// fall through
case DECOMPRESS_DATA:
final int chunkLength = this.chunkLength;
if (in.readableBytes() < chunkLength) {
break;
}
final int originalLength = this.originalLength;
if (isCompressed) {
final int idx = in.readerIndex();
final byte[] inputArray;
final int inPos;
if (in.hasArray()) {
inputArray = in.array();
inPos = in.arrayOffset() + idx;
} else {
inputArray = recycler.allocInputBuffer(chunkLength);
in.getBytes(idx, inputArray, 0, chunkLength);
inPos = 0;
}
Domain
Subdomains
Source
Frequently Asked Questions
What does decode() do?
decode() is a function in the netty codebase, defined in codec-compression/src/main/java/io/netty/handler/codec/compression/LzfDecoder.java.
Where is decode() defined?
decode() is defined in codec-compression/src/main/java/io/netty/handler/codec/compression/LzfDecoder.java at line 111.
Analyze Your Own Codebase
Get architecture documentation, dependency graphs, and domain analysis for your codebase in minutes.
Try Supermodel Free