ZstdEncoder Class — netty Architecture
Architecture documentation for the ZstdEncoder class in ZstdEncoder.java from the netty codebase.
Entity Profile
Dependency Diagram
graph TD c54867ac_e573_180e_1e85_7abab9317cc8["ZstdEncoder"] d0bd72ce_fae3_db82_ce4d_79c33347a20a["ZstdEncoder.java"] c54867ac_e573_180e_1e85_7abab9317cc8 -->|defined in| d0bd72ce_fae3_db82_ce4d_79c33347a20a f5ab2c1a_c144_ccea_4b3a_7187803571cd["ZstdEncoder()"] c54867ac_e573_180e_1e85_7abab9317cc8 -->|method| f5ab2c1a_c144_ccea_4b3a_7187803571cd 2a7b7296_a9e1_ce90_5abd_aa5b5e3c8b67["ByteBuf()"] c54867ac_e573_180e_1e85_7abab9317cc8 -->|method| 2a7b7296_a9e1_ce90_5abd_aa5b5e3c8b67 a1ecf6dc_a2a8_b4cd_6687_b85c0ec6b659["encode()"] c54867ac_e573_180e_1e85_7abab9317cc8 -->|method| a1ecf6dc_a2a8_b4cd_6687_b85c0ec6b659 0c4095c4_5e2f_0027_e81b_119c77332d8c["flushBufferedData()"] c54867ac_e573_180e_1e85_7abab9317cc8 -->|method| 0c4095c4_5e2f_0027_e81b_119c77332d8c 6e883530_883f_bb07_d186_02fc43f44199["flush()"] c54867ac_e573_180e_1e85_7abab9317cc8 -->|method| 6e883530_883f_bb07_d186_02fc43f44199 34a1f9a1_344c_5905_cb8c_c001690bf4b8["handlerAdded()"] c54867ac_e573_180e_1e85_7abab9317cc8 -->|method| 34a1f9a1_344c_5905_cb8c_c001690bf4b8 5a563f9e_a2ba_1f2f_298c_25a53bb8c117["handlerRemoved()"] c54867ac_e573_180e_1e85_7abab9317cc8 -->|method| 5a563f9e_a2ba_1f2f_298c_25a53bb8c117
Relationship Graph
Source Code
codec-compression/src/main/java/io/netty/handler/codec/compression/ZstdEncoder.java lines 37–201
public final class ZstdEncoder extends MessageToByteEncoder<ByteBuf> {
// Don't use static here as we want to still allow to load the classes.
{
try {
io.netty.handler.codec.compression.Zstd.ensureAvailability();
} catch (Throwable throwable) {
throw new ExceptionInInitializerError(throwable);
}
}
private final int blockSize;
private final int compressionLevel;
private final int maxEncodeSize;
private ByteBuf buffer;
/**
* Creates a new Zstd encoder.
*
* Please note that if you use the default constructor, the default BLOCK_SIZE and MAX_BLOCK_SIZE
* will be used. If you want to specify BLOCK_SIZE and MAX_BLOCK_SIZE yourself,
* please use {@link ZstdEncoder(int,int)} constructor
*/
public ZstdEncoder() {
this(DEFAULT_COMPRESSION_LEVEL, DEFAULT_BLOCK_SIZE, DEFAULT_MAX_ENCODE_SIZE);
}
/**
* Creates a new Zstd encoder.
* @param compressionLevel
* specifies the level of the compression
*/
public ZstdEncoder(int compressionLevel) {
this(compressionLevel, DEFAULT_BLOCK_SIZE, DEFAULT_MAX_ENCODE_SIZE);
}
/**
* Creates a new Zstd encoder.
* @param blockSize
* is used to calculate the compressionLevel
* @param maxEncodeSize
* specifies the size of the largest compressed object
*/
public ZstdEncoder(int blockSize, int maxEncodeSize) {
this(DEFAULT_COMPRESSION_LEVEL, blockSize, maxEncodeSize);
}
/**
* @param blockSize
* is used to calculate the compressionLevel
* @param maxEncodeSize
* specifies the size of the largest compressed object
* @param compressionLevel
* specifies the level of the compression
*/
public ZstdEncoder(int compressionLevel, int blockSize, int maxEncodeSize) {
super(ByteBuf.class, true);
this.compressionLevel = ObjectUtil.checkInRange(compressionLevel,
MIN_COMPRESSION_LEVEL, MAX_COMPRESSION_LEVEL, "compressionLevel");
this.blockSize = ObjectUtil.checkPositive(blockSize, "blockSize");
this.maxEncodeSize = ObjectUtil.checkPositive(maxEncodeSize, "maxEncodeSize");
}
@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
Source
Frequently Asked Questions
What is the ZstdEncoder class?
ZstdEncoder is a class in the netty codebase, defined in codec-compression/src/main/java/io/netty/handler/codec/compression/ZstdEncoder.java.
Where is ZstdEncoder defined?
ZstdEncoder is defined in codec-compression/src/main/java/io/netty/handler/codec/compression/ZstdEncoder.java at line 37.
Analyze Your Own Codebase
Get architecture documentation, dependency graphs, and domain analysis for your codebase in minutes.
Try Supermodel Free