public class SnappyFramedEncoder extends MessageToByteEncoder<ByteBuf>
ByteBuf
using the Snappy framing format.
See http://code.google.com/p/snappy/source/browse/trunk/framing_format.txtChannelHandler.Sharable
Modifier and Type | Field and 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 and Description |
---|
SnappyFramedEncoder() |
Modifier and Type | Method and Description |
---|---|
private static void |
calculateAndWriteChecksum(ByteBuf slice,
ByteBuf out)
Calculates and writes the 4-byte checksum to the output buffer
|
protected void |
encode(ChannelHandlerContext ctx,
ByteBuf in,
ByteBuf out)
Encode a message into a
ByteBuf . |
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) |
acceptOutboundMessage, allocateBuffer, write
bind, close, connect, deregister, disconnect, flush, read
exceptionCaught, handlerAdded, handlerRemoved, isSharable
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
exceptionCaught, handlerAdded, handlerRemoved
private static final int MIN_COMPRESSIBLE_LENGTH
private static final byte[] STREAM_START
private final Snappy snappy
private boolean started
protected void encode(ChannelHandlerContext ctx, ByteBuf in, ByteBuf out) throws java.lang.Exception
MessageToByteEncoder
ByteBuf
. This method will be called for each written message that can be handled
by this encoder.encode
in class MessageToByteEncoder<ByteBuf>
ctx
- the ChannelHandlerContext
which this MessageToByteEncoder
belongs toin
- the message to encodeout
- the ByteBuf
into which the encoded message will be writtenjava.lang.Exception
- is thrown if an error accourprivate static void writeUnencodedChunk(ByteBuf in, ByteBuf out, int dataLength)
private static void setChunkLength(ByteBuf out, int lengthIdx)
private static void writeChunkLength(ByteBuf out, int chunkLength)
out
- The buffer to write tochunkLength
- The length to write