Home / Function/ ByteBuf() — netty Function Reference

ByteBuf() — netty Function Reference

Architecture documentation for the ByteBuf() function in ZstdEncoder.java from the netty codebase.

Entity Profile

Dependency Diagram

graph TD
  2a7b7296_a9e1_ce90_5abd_aa5b5e3c8b67["ByteBuf()"]
  c54867ac_e573_180e_1e85_7abab9317cc8["ZstdEncoder"]
  2a7b7296_a9e1_ce90_5abd_aa5b5e3c8b67 -->|defined in| c54867ac_e573_180e_1e85_7abab9317cc8
  style 2a7b7296_a9e1_ce90_5abd_aa5b5e3c8b67 fill:#6366f1,stroke:#818cf8,color:#fff

Relationship Graph

Source Code

codec-compression/src/main/java/io/netty/handler/codec/compression/ZstdEncoder.java lines 98–127

    @Override
    protected ByteBuf allocateBuffer(ChannelHandlerContext ctx, ByteBuf msg, boolean preferDirect) {
        if (buffer == null) {
            throw new IllegalStateException("not added to a pipeline," +
                    "or has been removed,buffer is null");
        }

        int remaining = msg.readableBytes() + buffer.readableBytes();

        // quick overflow check
        if (remaining < 0) {
            throw new EncoderException("too much data to allocate a buffer for compression");
        }

        long bufferSize = 0;
        while (remaining > 0) {
            int curSize = Math.min(blockSize, remaining);
            remaining -= curSize;
            // calculate the max compressed size with Zstd.compressBound since
            // it returns the maximum size of the compressed data
            bufferSize = Math.max(bufferSize, Zstd.compressBound(curSize));
        }

        if (bufferSize > maxEncodeSize || 0 > bufferSize) {
            throw new EncoderException("requested encode buffer size (" + bufferSize + " bytes) exceeds " +
                    "the maximum allowable size (" + maxEncodeSize + " bytes)");
        }

        return ctx.alloc().directBuffer((int) bufferSize);
    }

Domain

Subdomains

Frequently Asked Questions

What does ByteBuf() do?
ByteBuf() is a function in the netty codebase, defined in codec-compression/src/main/java/io/netty/handler/codec/compression/ZstdEncoder.java.
Where is ByteBuf() defined?
ByteBuf() is defined in codec-compression/src/main/java/io/netty/handler/codec/compression/ZstdEncoder.java at line 98.

Analyze Your Own Codebase

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

Try Supermodel Free