Class SnappyFrameEncoder
java.lang.Object
io.netty.channel.ChannelHandlerAdapter
io.netty.channel.ChannelOutboundHandlerAdapter
io.netty.handler.codec.MessageToByteEncoder<ByteBuf>
io.netty.handler.codec.compression.SnappyFrameEncoder
- All Implemented Interfaces:
ChannelHandler,ChannelOutboundHandler
- Direct Known Subclasses:
SnappyFramedEncoder
Compresses a
ByteBuf using the Snappy framing format.
See Snappy framing format.-
Nested Class Summary
Nested classes/interfaces inherited from interface io.netty.channel.ChannelHandler
ChannelHandler.Sharable -
Field Summary
FieldsModifier and TypeFieldDescriptionprivate static final intThe minimum amount that we'll consider actually attempting to compress.private final intprivate final Snappyprivate static final intBoth 32767 and 65535 are valid lengths for the Snappy framing formatprivate static final shortprivate booleanprivate static final byte[]All streams should start with the "Stream identifier", containing chunk type 0xff, a length field of 0x6, and 'sNaPpY' in ASCII. -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionprivate static voidcalculateAndWriteChecksum(ByteBuf slice, ByteBuf out) Calculates and writes the 4-byte checksum to the output bufferprotected voidencode(ChannelHandlerContext ctx, ByteBuf in, ByteBuf out) Encode a message into aByteBuf.private static voidsetChunkLength(ByteBuf out, int lengthIdx) static SnappyFrameEncoderCreate a new instance with a 65535 chunk size.private static voidwriteChunkLength(ByteBuf out, int chunkLength) Writes the 2-byte chunk length to the output buffer.private static voidwriteUnencodedChunk(ByteBuf in, ByteBuf out, int dataLength) Methods inherited from class io.netty.handler.codec.MessageToByteEncoder
acceptOutboundMessage, allocateBuffer, isPreferDirect, writeMethods inherited from class io.netty.channel.ChannelOutboundHandlerAdapter
bind, close, connect, deregister, disconnect, flush, readMethods inherited from class io.netty.channel.ChannelHandlerAdapter
ensureNotSharable, exceptionCaught, handlerAdded, handlerRemoved, isSharableMethods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface io.netty.channel.ChannelHandler
exceptionCaught, handlerAdded, handlerRemoved
-
Field Details
-
SNAPPY_SLICE_SIZE
private static final short SNAPPY_SLICE_SIZE- See Also:
-
SNAPPY_SLICE_JUMBO_SIZE
private static final int SNAPPY_SLICE_JUMBO_SIZEBoth 32767 and 65535 are valid lengths for the Snappy framing format- See Also:
-
MIN_COMPRESSIBLE_LENGTH
private static final int MIN_COMPRESSIBLE_LENGTHThe minimum amount that we'll consider actually attempting to compress. This value is preamble + the minimum length our Snappy service will compress (instead of just emitting a literal).- See Also:
-
STREAM_START
private static final byte[] STREAM_STARTAll streams should start with the "Stream identifier", containing chunk type 0xff, a length field of 0x6, and 'sNaPpY' in ASCII. -
snappy
-
started
private boolean started -
sliceSize
private final int sliceSize
-
-
Constructor Details
-
SnappyFrameEncoder
public SnappyFrameEncoder() -
SnappyFrameEncoder
private SnappyFrameEncoder(int sliceSize)
-
-
Method Details
-
snappyEncoderWithJumboFrames
Create a new instance with a 65535 chunk size. -
encode
Description copied from class:MessageToByteEncoderEncode a message into aByteBuf. This method will be called for each written message that can be handled by this encoder.- Specified by:
encodein classMessageToByteEncoder<ByteBuf>- Parameters:
ctx- theChannelHandlerContextwhich thisMessageToByteEncoderbelongs toin- the message to encodeout- theByteBufinto which the encoded message will be written- Throws:
Exception- is thrown if an error occurs
-
writeUnencodedChunk
-
setChunkLength
-
writeChunkLength
Writes the 2-byte chunk length to the output buffer.- Parameters:
out- The buffer to write tochunkLength- The length to write
-
calculateAndWriteChecksum
Calculates and writes the 4-byte checksum to the output buffer- Parameters:
slice- The data to calculate the checksum forout- The output buffer to write the checksum to
-