decode() — netty Function Reference
Architecture documentation for the decode() function in WebSocket08FrameDecoder.java from the netty codebase.
Entity Profile
Dependency Diagram
graph TD 0cc1f80d_2de8_eba7_1c1b_044be6cac6ba["decode()"] c9b44ce3_48da_97b4_c171_21f4f8367ad8["WebSocket08FrameDecoder"] 0cc1f80d_2de8_eba7_1c1b_044be6cac6ba -->|defined in| c9b44ce3_48da_97b4_c171_21f4f8367ad8 052c117e_18bc_0a73_ffad_e40824a99630["protocolViolation()"] 0cc1f80d_2de8_eba7_1c1b_044be6cac6ba -->|calls| 052c117e_18bc_0a73_ffad_e40824a99630 1cbe5772_a8f4_98b0_b431_993c17d078a7["toFrameLength()"] 0cc1f80d_2de8_eba7_1c1b_044be6cac6ba -->|calls| 1cbe5772_a8f4_98b0_b431_993c17d078a7 eae6aaf4_a2cd_080e_53f7_5c3107c8c81a["unmask()"] 0cc1f80d_2de8_eba7_1c1b_044be6cac6ba -->|calls| eae6aaf4_a2cd_080e_53f7_5c3107c8c81a f1364653_ca1d_d1d2_a507_8c02eba374f5["checkCloseFrameBody()"] 0cc1f80d_2de8_eba7_1c1b_044be6cac6ba -->|calls| f1364653_ca1d_d1d2_a507_8c02eba374f5 style 0cc1f80d_2de8_eba7_1c1b_044be6cac6ba fill:#6366f1,stroke:#818cf8,color:#fff
Relationship Graph
Source Code
codec-http/src/main/java/io/netty/handler/codec/http/websocketx/WebSocket08FrameDecoder.java lines 160–390
@Override
protected void decode(ChannelHandlerContext ctx, ByteBuf in, List<Object> out) throws Exception {
// Discard all data received if closing handshake was received before.
if (receivedClosingHandshake) {
in.skipBytes(actualReadableBytes());
return;
}
switch (state) {
case READING_FIRST:
if (!in.isReadable()) {
return;
}
framePayloadLength = 0;
// FIN, RSV, OPCODE
byte b = in.readByte();
frameFinalFlag = (b & 0x80) != 0;
frameRsv = (b & 0x70) >> 4;
frameOpcode = b & 0x0F;
if (logger.isTraceEnabled()) {
logger.trace("Decoding WebSocket Frame opCode={}", frameOpcode);
}
state = State.READING_SECOND;
case READING_SECOND:
if (!in.isReadable()) {
return;
}
// MASK, PAYLOAD LEN 1
b = in.readByte();
frameMasked = (b & 0x80) != 0;
framePayloadLen1 = b & 0x7F;
if (frameRsv != 0 && !config.allowExtensions()) {
protocolViolation(ctx, in, "RSV != 0 and no extension negotiated, RSV:" + frameRsv);
return;
}
if (!config.allowMaskMismatch() && config.expectMaskedFrames() != frameMasked) {
protocolViolation(ctx, in, "received a frame that is not masked as expected");
return;
}
if (frameOpcode > 7) { // control frame (have MSB in opcode set)
// control frames MUST NOT be fragmented
if (!frameFinalFlag) {
protocolViolation(ctx, in, "fragmented control frame");
return;
}
// control frames MUST have payload 125 octets or less
if (framePayloadLen1 > 125) {
protocolViolation(ctx, in, "control frame with payload length > 125 octets");
return;
}
// check for reserved control frame opcodes
if (!(frameOpcode == OPCODE_CLOSE || frameOpcode == OPCODE_PING
|| frameOpcode == OPCODE_PONG)) {
protocolViolation(ctx, in, "control frame using reserved opcode " + frameOpcode);
return;
}
// close frame : if there is a body, the first two bytes of the
// body MUST be a 2-byte unsigned integer (in network byte
// order) representing a getStatus code
if (frameOpcode == 8 && framePayloadLen1 == 1) {
protocolViolation(ctx, in, "received close control frame with payload len 1");
return;
}
} else { // data frame
// check for reserved data frame opcodes
if (!(frameOpcode == OPCODE_CONT || frameOpcode == OPCODE_TEXT
|| frameOpcode == OPCODE_BINARY)) {
protocolViolation(ctx, in, "data frame using reserved opcode " + frameOpcode);
return;
}
Domain
Subdomains
Defined In
Source
Frequently Asked Questions
What does decode() do?
decode() is a function in the netty codebase, defined in codec-http/src/main/java/io/netty/handler/codec/http/websocketx/WebSocket08FrameDecoder.java.
Where is decode() defined?
decode() is defined in codec-http/src/main/java/io/netty/handler/codec/http/websocketx/WebSocket08FrameDecoder.java at line 160.
What does decode() call?
decode() calls 4 function(s): checkCloseFrameBody, protocolViolation, toFrameLength, unmask.
Analyze Your Own Codebase
Get architecture documentation, dependency graphs, and domain analysis for your codebase in minutes.
Try Supermodel Free