Fix chunk type for stream identifier
Motivation: The problem with the current snappy implementation is that it does not comply with framing format definition found on https://code.google.com/p/snappy/source/browse/trunk/framing_format.txt The document describes that chunk type of the stream identifier is defined as 0xff. The current implentation uses 0x80. Modifications: This patch replaces the first byte of the chunk type of the stream identifier with 0xff. Result: After this modification the snappy implementation is compliant to the framing format described at https://code.google.com/p/snappy/source/browse/trunk/framing_format.txt. This results in a better compatibility with other implementations.
This commit is contained in:
parent
4d279155f8
commit
104faba509
@ -198,7 +198,7 @@ public class SnappyFramedDecoder extends ByteToMessageDecoder {
|
||||
return ChunkType.COMPRESSED_DATA;
|
||||
} else if (type == 1) {
|
||||
return ChunkType.UNCOMPRESSED_DATA;
|
||||
} else if (type == -0x80) {
|
||||
} else if (type == (byte) 0xff) {
|
||||
return ChunkType.STREAM_IDENTIFIER;
|
||||
} else if ((type & 0x80) == 0x80) {
|
||||
return ChunkType.RESERVED_SKIPPABLE;
|
||||
|
@ -40,7 +40,7 @@ public class SnappyFramedEncoder extends MessageToByteEncoder<ByteBuf> {
|
||||
* type 0xff, a length field of 0x6, and 'sNaPpY' in ASCII.
|
||||
*/
|
||||
private static final byte[] STREAM_START = {
|
||||
-0x80, 0x06, 0x00, 0x00, 0x73, 0x4e, 0x61, 0x50, 0x70, 0x59
|
||||
(byte) 0xff, 0x06, 0x00, 0x00, 0x73, 0x4e, 0x61, 0x50, 0x70, 0x59
|
||||
};
|
||||
|
||||
private final Snappy snappy = new Snappy();
|
||||
|
@ -53,7 +53,7 @@ public class SnappyFramedDecoderTest {
|
||||
@Test(expected = DecompressionException.class)
|
||||
public void testInvalidStreamIdentifierValue() throws Exception {
|
||||
ByteBuf in = Unpooled.wrappedBuffer(new byte[] {
|
||||
-0x80, 0x06, 0x00, 0x00, 's', 'n', 'e', 't', 't', 'y'
|
||||
(byte) 0xff, 0x06, 0x00, 0x00, 's', 'n', 'e', 't', 't', 'y'
|
||||
});
|
||||
|
||||
channel.writeInbound(in);
|
||||
@ -89,7 +89,7 @@ public class SnappyFramedDecoderTest {
|
||||
@Test
|
||||
public void testReservedSkippableSkipsInput() throws Exception {
|
||||
ByteBuf in = Unpooled.wrappedBuffer(new byte[] {
|
||||
-0x80, 0x06, 0x00, 0x00, 0x73, 0x4e, 0x61, 0x50, 0x70, 0x59,
|
||||
(byte) 0xff, 0x06, 0x00, 0x00, 0x73, 0x4e, 0x61, 0x50, 0x70, 0x59,
|
||||
-0x7f, 0x05, 0x00, 0x00, 'n', 'e', 't', 't', 'y'
|
||||
});
|
||||
|
||||
@ -102,7 +102,7 @@ public class SnappyFramedDecoderTest {
|
||||
@Test
|
||||
public void testUncompressedDataAppendsToOut() throws Exception {
|
||||
ByteBuf in = Unpooled.wrappedBuffer(new byte[] {
|
||||
-0x80, 0x06, 0x00, 0x00, 0x73, 0x4e, 0x61, 0x50, 0x70, 0x59,
|
||||
(byte) 0xff, 0x06, 0x00, 0x00, 0x73, 0x4e, 0x61, 0x50, 0x70, 0x59,
|
||||
0x01, 0x09, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 'n', 'e', 't', 't', 'y'
|
||||
});
|
||||
|
||||
@ -115,7 +115,7 @@ public class SnappyFramedDecoderTest {
|
||||
@Test
|
||||
public void testCompressedDataDecodesAndAppendsToOut() throws Exception {
|
||||
ByteBuf in = Unpooled.wrappedBuffer(new byte[] {
|
||||
-0x80, 0x06, 0x00, 0x00, 0x73, 0x4e, 0x61, 0x50, 0x70, 0x59,
|
||||
(byte) 0xff, 0x06, 0x00, 0x00, 0x73, 0x4e, 0x61, 0x50, 0x70, 0x59,
|
||||
0x00, 0x0B, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
||||
0x05, // preamble length
|
||||
0x04 << 2, // literal tag + length
|
||||
@ -137,7 +137,7 @@ public class SnappyFramedDecoderTest {
|
||||
|
||||
// checksum here is presented as 0
|
||||
ByteBuf in = Unpooled.wrappedBuffer(new byte[] {
|
||||
-0x80, 0x06, 0x00, 0x00, 0x73, 0x4e, 0x61, 0x50, 0x70, 0x59,
|
||||
(byte) 0xff, 0x06, 0x00, 0x00, 0x73, 0x4e, 0x61, 0x50, 0x70, 0x59,
|
||||
0x01, 0x09, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 'n', 'e', 't', 't', 'y'
|
||||
});
|
||||
|
||||
@ -150,7 +150,7 @@ public class SnappyFramedDecoderTest {
|
||||
|
||||
// checksum here is presented as a282986f (little endian)
|
||||
ByteBuf in = Unpooled.wrappedBuffer(new byte[] {
|
||||
-0x80, 0x06, 0x00, 0x00, 0x73, 0x4e, 0x61, 0x50, 0x70, 0x59,
|
||||
(byte) 0xff, 0x06, 0x00, 0x00, 0x73, 0x4e, 0x61, 0x50, 0x70, 0x59,
|
||||
0x01, 0x09, 0x00, 0x00, 0x6f, -0x68, -0x7e, -0x5e, 'n', 'e', 't', 't', 'y'
|
||||
});
|
||||
|
||||
|
@ -43,7 +43,7 @@ public class SnappyFramedEncoderTest {
|
||||
assertTrue(channel.finish());
|
||||
|
||||
ByteBuf expected = Unpooled.wrappedBuffer(new byte[] {
|
||||
-0x80, 0x06, 0x00, 0x00, 0x73, 0x4e, 0x61, 0x50, 0x70, 0x59,
|
||||
(byte) 0xff, 0x06, 0x00, 0x00, 0x73, 0x4e, 0x61, 0x50, 0x70, 0x59,
|
||||
0x01, 0x09, 0x00, 0x00, 0x6f, -0x68, -0x7e, -0x5e, 'n', 'e', 't', 't', 'y'
|
||||
});
|
||||
|
||||
@ -61,7 +61,7 @@ public class SnappyFramedEncoderTest {
|
||||
assertTrue(channel.finish());
|
||||
|
||||
ByteBuf expected = Unpooled.wrappedBuffer(new byte[] {
|
||||
-0x80, 0x06, 0x00, 0x00, 0x73, 0x4e, 0x61, 0x50, 0x70, 0x59,
|
||||
(byte) 0xff, 0x06, 0x00, 0x00, 0x73, 0x4e, 0x61, 0x50, 0x70, 0x59,
|
||||
0x00, 0x0E, 0x00, 0x00, 0x3b, 0x36, -0x7f, 0x37,
|
||||
0x14, 0x10,
|
||||
'n', 'e', 't', 't', 'y',
|
||||
@ -83,7 +83,7 @@ public class SnappyFramedEncoderTest {
|
||||
assertTrue(channel.finish());
|
||||
|
||||
ByteBuf expected = Unpooled.wrappedBuffer(new byte[] {
|
||||
-0x80, 0x06, 0x00, 0x00, 0x73, 0x4e, 0x61, 0x50, 0x70, 0x59,
|
||||
(byte) 0xff, 0x06, 0x00, 0x00, 0x73, 0x4e, 0x61, 0x50, 0x70, 0x59,
|
||||
0x01, 0x09, 0x00, 0x00, 0x6f, -0x68, -0x7e, -0x5e, 'n', 'e', 't', 't', 'y',
|
||||
0x01, 0x09, 0x00, 0x00, 0x6f, -0x68, -0x7e, -0x5e, 'n', 'e', 't', 't', 'y',
|
||||
});
|
||||
|
Loading…
Reference in New Issue
Block a user