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 int
The minimum amount that we'll consider actually attempting to compress.private final int
private final Snappy
private static final int
Both 32767 and 65535 are valid lengths for the Snappy framing formatprivate static final short
private boolean
private 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 void
calculateAndWriteChecksum
(ByteBuf slice, ByteBuf out) Calculates and writes the 4-byte checksum to the output bufferprotected void
encode
(ChannelHandlerContext ctx, ByteBuf in, ByteBuf out) Encode a message into aByteBuf
.private static void
setChunkLength
(ByteBuf out, int lengthIdx) static SnappyFrameEncoder
Create a new instance with a 65535 chunk size.private static void
writeChunkLength
(ByteBuf out, int chunkLength) Writes the 2-byte chunk length to the output buffer.private static void
writeUnencodedChunk
(ByteBuf in, ByteBuf out, int dataLength) Methods inherited from class io.netty.handler.codec.MessageToByteEncoder
acceptOutboundMessage, allocateBuffer, isPreferDirect, write
Methods inherited from class io.netty.channel.ChannelOutboundHandlerAdapter
bind, close, connect, deregister, disconnect, flush, read
Methods inherited from class io.netty.channel.ChannelHandlerAdapter
ensureNotSharable, exceptionCaught, handlerAdded, handlerRemoved, isSharable
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
Methods 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:MessageToByteEncoder
Encode a message into aByteBuf
. This method will be called for each written message that can be handled by this encoder.- Specified by:
encode
in classMessageToByteEncoder<ByteBuf>
- Parameters:
ctx
- theChannelHandlerContext
which thisMessageToByteEncoder
belongs toin
- the message to encodeout
- theByteBuf
into 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
-