Home / Function/ decode() — netty Function Reference

decode() — netty Function Reference

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

Entity Profile

Dependency Diagram

graph TD
  78a72dfa_575b_382e_4f57_622743a22188["decode()"]
  b9b9e638_302b_6a01_f1e0_a9d2ea3a2ab2["JZlibDecoder"]
  78a72dfa_575b_382e_4f57_622743a22188 -->|defined in| b9b9e638_302b_6a01_f1e0_a9d2ea3a2ab2
  style 78a72dfa_575b_382e_4f57_622743a22188 fill:#6366f1,stroke:#818cf8,color:#fff

Relationship Graph

Source Code

codec-compression/src/main/java/io/netty/handler/codec/compression/JZlibDecoder.java lines 133–232

    @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;
        }

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

        try {
            // Configure input.
            z.avail_in = inputLength;
            if (in.hasArray()) {
                z.next_in = in.array();
                z.next_in_index = in.arrayOffset() + in.readerIndex();
            } else {
                byte[] array = new byte[inputLength];
                in.getBytes(in.readerIndex(), array);
                z.next_in = array;
                z.next_in_index = 0;
            }
            final int oldNextInIndex = z.next_in_index;

            // Configure output.
            ByteBuf decompressed = prepareDecompressBuffer(ctx, null, inputLength << 1);

            try {
                loop: for (;;) {
                    decompressed = prepareDecompressBuffer(ctx, decompressed, z.avail_in << 1);
                    z.avail_out = decompressed.writableBytes();
                    z.next_out = decompressed.array();
                    z.next_out_index = decompressed.arrayOffset() + decompressed.writerIndex();
                    int oldNextOutIndex = z.next_out_index;

                    // Decompress 'in' into 'out'
                    int resultCode = z.inflate(JZlib.Z_SYNC_FLUSH);
                    int outputLength = z.next_out_index - oldNextOutIndex;
                    if (outputLength > 0) {
                        decompressed.writerIndex(decompressed.writerIndex() + 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);
                        }
                    }

                    switch (resultCode) {
                    case JZlib.Z_NEED_DICT:
                        if (dictionary == null) {
                            ZlibUtil.fail(z, "decompression failure", resultCode);
                        } else {
                            resultCode = z.inflateSetDictionary(dictionary, dictionary.length);
                            if (resultCode != JZlib.Z_OK) {
                                ZlibUtil.fail(z, "failed to set the dictionary", resultCode);
                            }
                        }
                        break;
                    case JZlib.Z_STREAM_END:
                        finished = true; // Do not decode anymore.
                        z.inflateEnd();
                        break loop;
                    case JZlib.Z_OK:
                        break;
                    case JZlib.Z_BUF_ERROR:
                        if (z.avail_in <= 0) {
                            break loop;
                        }
                        break;
                    default:
                        ZlibUtil.fail(z, "decompression failure", resultCode);
                    }
                }
            } finally {

Domain

Subdomains

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/JZlibDecoder.java.
Where is decode() defined?
decode() is defined in codec-compression/src/main/java/io/netty/handler/codec/compression/JZlibDecoder.java at line 133.

Analyze Your Own Codebase

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

Try Supermodel Free