Home / Function/ decode() — netty Function Reference

decode() — netty Function Reference

Architecture documentation for the decode() function in JdkZlibDecoder.java from the netty codebase.

Function java Buffer Allocators calls 3 called by 1

Entity Profile

Dependency Diagram

graph TD
  f055bb74_306f_40f9_d9c1_85083f9dc74b["decode()"]
  bba68af7_04c2_8ee6_82f0_73e08fa3f9cd["JdkZlibDecoder"]
  f055bb74_306f_40f9_d9c1_85083f9dc74b -->|defined in| bba68af7_04c2_8ee6_82f0_73e08fa3f9cd
  ca861de0_2fde_a83c_66b8_29814a4e99d9["JdkZlibDecoder()"]
  ca861de0_2fde_a83c_66b8_29814a4e99d9 -->|calls| f055bb74_306f_40f9_d9c1_85083f9dc74b
  fabc18b6_34b9_4520_1323_3857f8a35bb4["looksLikeZlib()"]
  f055bb74_306f_40f9_d9c1_85083f9dc74b -->|calls| fabc18b6_34b9_4520_1323_3857f8a35bb4
  9205ab31_1c96_0d6b_c04c_5f510827b2ac["handleGzipFooter()"]
  f055bb74_306f_40f9_d9c1_85083f9dc74b -->|calls| 9205ab31_1c96_0d6b_c04c_5f510827b2ac
  146f8d9e_03da_37c7_3683_c470a8d21243["readGZIPHeader()"]
  f055bb74_306f_40f9_d9c1_85083f9dc74b -->|calls| 146f8d9e_03da_37c7_3683_c470a8d21243
  style f055bb74_306f_40f9_d9c1_85083f9dc74b fill:#6366f1,stroke:#818cf8,color:#fff

Relationship Graph

Source Code

codec-compression/src/main/java/io/netty/handler/codec/compression/JdkZlibDecoder.java lines 197–314

    @Override
    protected void decode(ChannelHandlerContext ctx, ByteBuf in, List<Object> out) throws Exception {
        needsRead = true;
        if (finished) {
            // Skip data received after finished.
            in.skipBytes(in.readableBytes());
            return;
        }

        int readableBytes = in.readableBytes();
        if (readableBytes == 0) {
            return;
        }

        if (decideZlibOrNone) {
            // First two bytes are needed to decide if it's a ZLIB stream.
            if (readableBytes < 2) {
                return;
            }

            boolean nowrap = !looksLikeZlib(in.getShort(in.readerIndex()));
            inflater = new Inflater(nowrap);
            decideZlibOrNone = false;
        }

        if (crc != null) {
            if (gzipState != GzipState.HEADER_END) {
                if (gzipState == GzipState.FOOTER_START) {
                    if (!handleGzipFooter(in)) {
                        // Either there was not enough data or the input is finished.
                        return;
                    }
                    // If we consumed the footer we will start with the header again.
                    assert gzipState == GzipState.HEADER_START;
                }
                if (!readGZIPHeader(in)) {
                    // There was not enough data readable to read the GZIP header.
                    return;
                }
                // Some bytes may have been consumed, and so we must re-set the number of readable bytes.
                readableBytes = in.readableBytes();
                if (readableBytes == 0) {
                    return;
                }
            }
        }

        if (inflater.needsInput()) {
            if (in.hasArray()) {
                inflater.setInput(in.array(), in.arrayOffset() + in.readerIndex(), readableBytes);
            } else {
                byte[] array = new byte[readableBytes];
                in.getBytes(in.readerIndex(), array);
                inflater.setInput(array);
            }
        }

        ByteBuf decompressed = prepareDecompressBuffer(ctx, null, inflater.getRemaining() << 1);
        try {
            boolean readFooter = false;
            while (!inflater.needsInput()) {
                byte[] outArray = decompressed.array();
                int writerIndex = decompressed.writerIndex();
                int outIndex = decompressed.arrayOffset() + writerIndex;
                int writable = decompressed.writableBytes();
                int outputLength = inflater.inflate(outArray, outIndex, writable);
                if (outputLength > 0) {
                    decompressed.writerIndex(writerIndex + outputLength);
                    if (crc != null) {
                        crc.update(outArray, outIndex, outputLength);
                    }
                    if (maxAllocation == 0) {
                        // If we don't limit the maximum allocations we should just
                        // forward the buffer directly.
                        ByteBuf buffer = decompressed;
                        decompressed = null;
                        needsRead = false;
                        ctx.fireChannelRead(buffer);
                    }
                } else if (inflater.needsDictionary()) {
                    if (dictionary == null) {

Domain

Subdomains

Called By

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/JdkZlibDecoder.java.
Where is decode() defined?
decode() is defined in codec-compression/src/main/java/io/netty/handler/codec/compression/JdkZlibDecoder.java at line 197.
What does decode() call?
decode() calls 3 function(s): handleGzipFooter, looksLikeZlib, readGZIPHeader.
What calls decode()?
decode() is called by 1 function(s): JdkZlibDecoder.

Analyze Your Own Codebase

Get architecture documentation, dependency graphs, and domain analysis for your codebase in minutes.

Try Supermodel Free