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 aByteBuf
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
Fields Modifier and Type Field Description private static int
MIN_COMPRESSIBLE_LENGTH
The minimum amount that we'll consider actually attempting to compress.private Snappy
snappy
private boolean
started
private static byte[]
STREAM_START
All streams should start with the "Stream identifier", containing chunk type 0xff, a length field of 0x6, and 'sNaPpY' in ASCII.
-
Constructor Summary
Constructors Constructor Description SnappyFrameEncoder()
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description private 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)
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 Detail
-
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
-
-
Method Detail
-
encode
protected void encode(ChannelHandlerContext ctx, ByteBuf in, ByteBuf out) throws java.lang.Exception
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:
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
-
-