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
public class SnappyFrameEncoder extends MessageToByteEncoder<ByteBuf>
Compresses aByteBufusing 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
Fields Modifier and Type Field Description private static intMIN_COMPRESSIBLE_LENGTHThe minimum amount that we'll consider actually attempting to compress.private intsliceSizeprivate Snappysnappyprivate static intSNAPPY_SLICE_JUMBO_SIZEBoth 32767 and 65535 are valid lengths for the Snappy framing formatprivate static shortSNAPPY_SLICE_SIZEprivate booleanstartedprivate static byte[]STREAM_STARTAll streams should start with the "Stream identifier", containing chunk type 0xff, a length field of 0x6, and 'sNaPpY' in ASCII.
-
Constructor Summary
Constructors Modifier Constructor Description SnappyFrameEncoder()privateSnappyFrameEncoder(int sliceSize)
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description private 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 SnappyFrameEncodersnappyEncoderWithJumboFrames()Create 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, 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 Detail
-
SNAPPY_SLICE_SIZE
private static final short SNAPPY_SLICE_SIZE
- See Also:
- Constant Field Values
-
SNAPPY_SLICE_JUMBO_SIZE
private static final int SNAPPY_SLICE_JUMBO_SIZE
Both 32767 and 65535 are valid lengths for the Snappy framing format- See Also:
- Constant Field Values
-
MIN_COMPRESSIBLE_LENGTH
private static final int MIN_COMPRESSIBLE_LENGTH
The 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:
- Constant Field Values
-
STREAM_START
private static final byte[] STREAM_START
All streams should start with the "Stream identifier", containing chunk type 0xff, a length field of 0x6, and 'sNaPpY' in ASCII.
-
snappy
private final Snappy snappy
-
started
private boolean started
-
sliceSize
private final int sliceSize
-
-
Method Detail
-
snappyEncoderWithJumboFrames
public static SnappyFrameEncoder snappyEncoderWithJumboFrames()
Create a new instance with a 65535 chunk size.
-
encode
protected void encode(ChannelHandlerContext ctx, ByteBuf in, ByteBuf out) throws java.lang.Exception
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:
java.lang.Exception- is thrown if an error occurs
-
writeUnencodedChunk
private static void writeUnencodedChunk(ByteBuf in, ByteBuf out, int dataLength)
-
setChunkLength
private static void setChunkLength(ByteBuf out, int lengthIdx)
-
writeChunkLength
private static void writeChunkLength(ByteBuf out, int chunkLength)
Writes the 2-byte chunk length to the output buffer.- Parameters:
out- The buffer to write tochunkLength- The length to write
-
-