decode() — netty Function Reference
Architecture documentation for the decode() function in JsonObjectDecoder.java from the netty codebase.
Entity Profile
Dependency Diagram
graph TD e065d464_9fe4_dd94_1292_774ad1b9001b["decode()"] cc9d6d69_638d_e1e7_aa08_bd1cacf4f8cc["JsonObjectDecoder"] e065d464_9fe4_dd94_1292_774ad1b9001b -->|defined in| cc9d6d69_638d_e1e7_aa08_bd1cacf4f8cc b07845ff_606f_b96b_ccd4_54fa788281c7["reset()"] e065d464_9fe4_dd94_1292_774ad1b9001b -->|calls| b07845ff_606f_b96b_ccd4_54fa788281c7 82cd9175_c986_585e_8ea2_00d1538388bd["decodeByte()"] e065d464_9fe4_dd94_1292_774ad1b9001b -->|calls| 82cd9175_c986_585e_8ea2_00d1538388bd df843581_4533_d2cc_abd1_ec20eb52805c["initDecoding()"] e065d464_9fe4_dd94_1292_774ad1b9001b -->|calls| df843581_4533_d2cc_abd1_ec20eb52805c style e065d464_9fe4_dd94_1292_774ad1b9001b fill:#6366f1,stroke:#818cf8,color:#fff
Relationship Graph
Source Code
codec-base/src/main/java/io/netty/handler/codec/json/JsonObjectDecoder.java lines 89–183
@Override
protected void decode(ChannelHandlerContext ctx, ByteBuf in, List<Object> out) throws Exception {
if (state == ST_CORRUPTED) {
in.skipBytes(in.readableBytes());
return;
}
if (this.idx > in.readerIndex() && lastReaderIndex != in.readerIndex()) {
this.idx = in.readerIndex() + (idx - lastReaderIndex);
}
// index of next byte to process.
int idx = this.idx;
int wrtIdx = in.writerIndex();
if (wrtIdx > maxObjectLength) {
// buffer size exceeded maxObjectLength; discarding the complete buffer.
in.skipBytes(in.readableBytes());
reset();
throw new TooLongFrameException(
"object length exceeds " + maxObjectLength + ": " + wrtIdx + " bytes discarded");
}
for (/* use current idx */; idx < wrtIdx; idx++) {
byte c = in.getByte(idx);
if (state == ST_DECODING_NORMAL) {
decodeByte(c, in, idx);
// All opening braces/brackets have been closed. That's enough to conclude
// that the JSON object/array is complete.
if (openBraces == 0) {
ByteBuf json = extractObject(ctx, in, in.readerIndex(), idx + 1 - in.readerIndex());
if (json != null) {
out.add(json);
}
// The JSON object/array was extracted => discard the bytes from
// the input buffer.
in.readerIndex(idx + 1);
// Reset the object state to get ready for the next JSON object/text
// coming along the byte stream.
reset();
}
} else if (state == ST_DECODING_ARRAY_STREAM) {
decodeByte(c, in, idx);
if (!insideString && (openBraces == 1 && c == ',' || openBraces == 0 && c == ']')) {
// skip leading spaces. No range check is needed and the loop will terminate
// because the byte at position idx is not a whitespace.
for (int i = in.readerIndex(); Character.isWhitespace(in.getByte(i)); i++) {
in.skipBytes(1);
}
// skip trailing spaces.
int idxNoSpaces = idx - 1;
while (idxNoSpaces >= in.readerIndex() && Character.isWhitespace(in.getByte(idxNoSpaces))) {
idxNoSpaces--;
}
ByteBuf json = extractObject(ctx, in, in.readerIndex(), idxNoSpaces + 1 - in.readerIndex());
if (json != null) {
out.add(json);
}
in.readerIndex(idx + 1);
if (c == ']') {
reset();
}
}
// JSON object/array detected. Accumulate bytes until all braces/brackets are closed.
} else if (c == '{' || c == '[') {
initDecoding(c);
if (state == ST_DECODING_ARRAY_STREAM) {
// Discard the array bracket
in.skipBytes(1);
}
// Discard leading spaces in front of a JSON object/array.
} else if (Character.isWhitespace(c)) {
in.skipBytes(1);
Domain
Subdomains
Source
Frequently Asked Questions
What does decode() do?
decode() is a function in the netty codebase, defined in codec-base/src/main/java/io/netty/handler/codec/json/JsonObjectDecoder.java.
Where is decode() defined?
decode() is defined in codec-base/src/main/java/io/netty/handler/codec/json/JsonObjectDecoder.java at line 89.
What does decode() call?
decode() calls 3 function(s): decodeByte, initDecoding, reset.
Analyze Your Own Codebase
Get architecture documentation, dependency graphs, and domain analysis for your codebase in minutes.
Try Supermodel Free