Top Description Fields Constructors Methods
io.netty.handler.codec.compression

public Class SnappyFrameEncoder

extends MessageToByteEncoder<ByteBuf>
Class Inheritance
Known Direct Subclasses
io.netty.handler.codec.compression.SnappyFramedEncoder
Imports
io.netty.buffer.ByteBuf, io.netty.channel.ChannelHandlerContext, io.netty.handler.codec.MessageToByteEncoder

Compresses a ByteBuf using the Snappy framing format. See Snappy framing format.

Field Summary

Modifier and TypeField and Description
private static final int
MIN_COMPRESSIBLE_LENGTH

The minimum amount that we'll consider actually attempting to compress.

private final int
private final Snappy
private static final int
SNAPPY_SLICE_JUMBO_SIZE

Both 32767 and 65535 are valid lengths for the Snappy framing format

private static final short
private boolean
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.

Constructor Summary

AccessConstructor and Description
public
private
SnappyFrameEncoder(int sliceSize)

Method Summary

Modifier and TypeMethod and Description
private static void
calculateAndWriteChecksum(ByteBuf
The data to calculate the checksum for
slice
,
ByteBuf
The output buffer to write the checksum to
out
)

Calculates and writes the 4-byte checksum to the output buffer

protected void
encode(ChannelHandlerContext ctx, ByteBuf
the message to encode
in
,
ByteBuf
the ByteBuf into which the encoded message will be written
out
)

Implements abstract io.netty.handler.codec.MessageToByteEncoder.encode.

Encode a message into a ByteBuf.
private static void
setChunkLength(ByteBuf out, int lengthIdx)

public static SnappyFrameEncoder
snappyEncoderWithJumboFrames()

Create a new instance with a 65535 chunk size.

private static void
writeChunkLength(ByteBuf
The buffer to write to
out
,
int
The length to write
chunkLength
)

Writes the 2-byte chunk length to the output buffer.

private static void
writeUnencodedChunk(ByteBuf in, ByteBuf out, int dataLength)

Inherited from io.netty.handler.codec.MessageToByteEncoder:
acceptOutboundMessageallocateBufferisPreferDirectwrite

Field Detail

MIN_COMPRESSIBLE_LENGTHback to summary
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).

sliceSizeback to summary
private final int sliceSize
snappyback to summary
private final Snappy snappy
SNAPPY_SLICE_JUMBO_SIZEback to summary
private static final int SNAPPY_SLICE_JUMBO_SIZE

Both 32767 and 65535 are valid lengths for the Snappy framing format

SNAPPY_SLICE_SIZEback to summary
private static final short SNAPPY_SLICE_SIZE
startedback to summary
private boolean started
STREAM_STARTback to summary
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.

Constructor Detail

SnappyFrameEncoderback to summary
public SnappyFrameEncoder()
SnappyFrameEncoderback to summary
private SnappyFrameEncoder(int sliceSize)

Method Detail

calculateAndWriteChecksumback to summary
private static void calculateAndWriteChecksum(ByteBuf slice, ByteBuf out)

Calculates and writes the 4-byte checksum to the output buffer

Parameters
slice:ByteBuf

The data to calculate the checksum for

out:ByteBuf

The output buffer to write the checksum to

encodeback to summary
protected void encode(ChannelHandlerContext ctx, ByteBuf in, ByteBuf out) throws Exception

Implements abstract io.netty.handler.codec.MessageToByteEncoder.encode.

Doc from io.netty.handler.codec.MessageToByteEncoder.encode.

Encode a message into a ByteBuf. This method will be called for each written message that can be handled by this encoder.

Parameters
ctx:ChannelHandlerContext

the ChannelHandlerContext which this MessageToByteEncoder belongs to

in:ByteBuf

the message to encode

out:ByteBuf

the ByteBuf into which the encoded message will be written

Annotations
@Override
Exceptions
Exception:
is thrown if an error occurs
setChunkLengthback to summary
private static void setChunkLength(ByteBuf out, int lengthIdx)
snappyEncoderWithJumboFramesback to summary
public static SnappyFrameEncoder snappyEncoderWithJumboFrames()

Create a new instance with a 65535 chunk size.

writeChunkLengthback to summary
private static void writeChunkLength(ByteBuf out, int chunkLength)

Writes the 2-byte chunk length to the output buffer.

Parameters
out:ByteBuf

The buffer to write to

chunkLength:int

The length to write

writeUnencodedChunkback to summary
private static void writeUnencodedChunk(ByteBuf in, ByteBuf out, int dataLength)