Class SnappyFrameEncoder

All Implemented Interfaces:
ChannelHandler, ChannelOutboundHandler
Direct Known Subclasses:
SnappyFramedEncoder

public class SnappyFrameEncoder extends MessageToByteEncoder<ByteBuf>
Compresses a ByteBuf using the Snappy framing format. See Snappy framing format.
  • 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_SIZE
      Both 32767 and 65535 are valid lengths for the Snappy framing format
      See Also:
    • 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:
    • 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
  • Constructor Details

    • SnappyFrameEncoder

      public SnappyFrameEncoder()
    • SnappyFrameEncoder

      private SnappyFrameEncoder(int sliceSize)
  • Method Details

    • 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 Exception
      Description copied from class: MessageToByteEncoder
      Encode a message into a ByteBuf. This method will be called for each written message that can be handled by this encoder.
      Specified by:
      encode in class MessageToByteEncoder<ByteBuf>
      Parameters:
      ctx - the ChannelHandlerContext which this MessageToByteEncoder belongs to
      in - the message to encode
      out - the ByteBuf into which the encoded message will be written
      Throws:
      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 to
      chunkLength - The length to write
    • calculateAndWriteChecksum

      private static void calculateAndWriteChecksum(ByteBuf slice, ByteBuf out)
      Calculates and writes the 4-byte checksum to the output buffer
      Parameters:
      slice - The data to calculate the checksum for
      out - The output buffer to write the checksum to