decode() — netty Function Reference
Architecture documentation for the decode() function in SnappyFrameDecoder.java from the netty codebase.
Entity Profile
Dependency Diagram
graph TD 0bffb48f_aaf2_5805_e639_4882f253554e["decode()"] 5f033f0f_5da6_662f_fbd6_9f67efbcc2e0["SnappyFrameDecoder"] 0bffb48f_aaf2_5805_e639_4882f253554e -->|defined in| 5f033f0f_5da6_662f_fbd6_9f67efbcc2e0 befef7cb_c88c_6738_dff4_0c81602c4e0f["checkByte()"] 0bffb48f_aaf2_5805_e639_4882f253554e -->|calls| befef7cb_c88c_6738_dff4_0c81602c4e0f style 0bffb48f_aaf2_5805_e639_4882f253554e fill:#6366f1,stroke:#818cf8,color:#fff
Relationship Graph
Source Code
codec-compression/src/main/java/io/netty/handler/codec/compression/SnappyFrameDecoder.java lines 84–231
@Override
protected void decode(ChannelHandlerContext ctx, ByteBuf in, List<Object> out) throws Exception {
if (corrupted) {
in.skipBytes(in.readableBytes());
return;
}
if (numBytesToSkip != 0) {
// The last chunkType we detected was RESERVED_SKIPPABLE and we still have some bytes to skip.
int skipBytes = Math.min(numBytesToSkip, in.readableBytes());
in.skipBytes(skipBytes);
numBytesToSkip -= skipBytes;
// Let's return and try again.
return;
}
try {
int idx = in.readerIndex();
final int inSize = in.readableBytes();
if (inSize < 4) {
// We need to be at least able to read the chunk type identifier (one byte),
// and the length of the chunk (3 bytes) in order to proceed
return;
}
final int chunkTypeVal = in.getUnsignedByte(idx);
final ChunkType chunkType = mapChunkType((byte) chunkTypeVal);
final int chunkLength = in.getUnsignedMediumLE(idx + 1);
switch (chunkType) {
case STREAM_IDENTIFIER:
if (chunkLength != SNAPPY_IDENTIFIER_LEN) {
throw new DecompressionException("Unexpected length of stream identifier: " + chunkLength);
}
if (inSize < 4 + SNAPPY_IDENTIFIER_LEN) {
break;
}
in.skipBytes(4);
int offset = in.readerIndex();
in.skipBytes(SNAPPY_IDENTIFIER_LEN);
checkByte(in.getByte(offset++), (byte) 's');
checkByte(in.getByte(offset++), (byte) 'N');
checkByte(in.getByte(offset++), (byte) 'a');
checkByte(in.getByte(offset++), (byte) 'P');
checkByte(in.getByte(offset++), (byte) 'p');
checkByte(in.getByte(offset), (byte) 'Y');
started = true;
break;
case RESERVED_SKIPPABLE:
if (!started) {
throw new DecompressionException("Received RESERVED_SKIPPABLE tag before STREAM_IDENTIFIER");
}
in.skipBytes(4);
int skipBytes = Math.min(chunkLength, in.readableBytes());
in.skipBytes(skipBytes);
if (skipBytes != chunkLength) {
// We could skip all bytes, let's store the remaining so we can do so once we receive more
// data.
numBytesToSkip = chunkLength - skipBytes;
}
break;
case RESERVED_UNSKIPPABLE:
// The spec mandates that reserved unskippable chunks must immediately
// return an error, as we must assume that we cannot decode the stream
// correctly
throw new DecompressionException(
"Found reserved unskippable chunk type: 0x" + Integer.toHexString(chunkTypeVal));
case UNCOMPRESSED_DATA:
if (!started) {
throw new DecompressionException("Received UNCOMPRESSED_DATA tag before STREAM_IDENTIFIER");
}
if (chunkLength > MAX_UNCOMPRESSED_DATA_SIZE) {
throw new DecompressionException("Received UNCOMPRESSED_DATA larger than " +
MAX_UNCOMPRESSED_DATA_SIZE + " bytes");
Domain
Subdomains
Defined In
Calls
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/SnappyFrameDecoder.java.
Where is decode() defined?
decode() is defined in codec-compression/src/main/java/io/netty/handler/codec/compression/SnappyFrameDecoder.java at line 84.
What does decode() call?
decode() calls 1 function(s): checkByte.
Analyze Your Own Codebase
Get architecture documentation, dependency graphs, and domain analysis for your codebase in minutes.
Try Supermodel Free