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:
Martin Krüger 2014-04-18 21:48:07 +02:00 committed by Norman Maurer
parent d6ec44c871
commit d854d3a617
4 changed files with 11 additions and 11 deletions

View File

@ -198,7 +198,7 @@ public class SnappyFramedDecoder extends ByteToMessageDecoder {
return ChunkType.COMPRESSED_DATA; return ChunkType.COMPRESSED_DATA;
} else if (type == 1) { } else if (type == 1) {
return ChunkType.UNCOMPRESSED_DATA; return ChunkType.UNCOMPRESSED_DATA;
} else if (type == -0x80) { } else if (type == (byte) 0xff) {
return ChunkType.STREAM_IDENTIFIER; return ChunkType.STREAM_IDENTIFIER;
} else if ((type & 0x80) == 0x80) { } else if ((type & 0x80) == 0x80) {
return ChunkType.RESERVED_SKIPPABLE; return ChunkType.RESERVED_SKIPPABLE;

View File

@ -40,7 +40,7 @@ public class SnappyFramedEncoder extends MessageToByteEncoder<ByteBuf> {
* type 0xff, a length field of 0x6, and 'sNaPpY' in ASCII. * type 0xff, a length field of 0x6, and 'sNaPpY' in ASCII.
*/ */
private static final byte[] STREAM_START = { 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(); private final Snappy snappy = new Snappy();

View File

@ -53,7 +53,7 @@ public class SnappyFramedDecoderTest {
@Test(expected = DecompressionException.class) @Test(expected = DecompressionException.class)
public void testInvalidStreamIdentifierValue() throws Exception { public void testInvalidStreamIdentifierValue() throws Exception {
ByteBuf in = Unpooled.wrappedBuffer(new byte[] { 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); channel.writeInbound(in);
@ -89,7 +89,7 @@ public class SnappyFramedDecoderTest {
@Test @Test
public void testReservedSkippableSkipsInput() throws Exception { public void testReservedSkippableSkipsInput() throws Exception {
ByteBuf in = Unpooled.wrappedBuffer(new byte[] { 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' -0x7f, 0x05, 0x00, 0x00, 'n', 'e', 't', 't', 'y'
}); });
@ -102,7 +102,7 @@ public class SnappyFramedDecoderTest {
@Test @Test
public void testUncompressedDataAppendsToOut() throws Exception { public void testUncompressedDataAppendsToOut() throws Exception {
ByteBuf in = Unpooled.wrappedBuffer(new byte[] { 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' 0x01, 0x09, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 'n', 'e', 't', 't', 'y'
}); });
@ -115,7 +115,7 @@ public class SnappyFramedDecoderTest {
@Test @Test
public void testCompressedDataDecodesAndAppendsToOut() throws Exception { public void testCompressedDataDecodesAndAppendsToOut() throws Exception {
ByteBuf in = Unpooled.wrappedBuffer(new byte[] { 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, 0x00, 0x0B, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x05, // preamble length 0x05, // preamble length
0x04 << 2, // literal tag + length 0x04 << 2, // literal tag + length
@ -137,7 +137,7 @@ public class SnappyFramedDecoderTest {
// checksum here is presented as 0 // checksum here is presented as 0
ByteBuf in = Unpooled.wrappedBuffer(new byte[] { 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' 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) // checksum here is presented as a282986f (little endian)
ByteBuf in = Unpooled.wrappedBuffer(new byte[] { 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' 0x01, 0x09, 0x00, 0x00, 0x6f, -0x68, -0x7e, -0x5e, 'n', 'e', 't', 't', 'y'
}); });

View File

@ -43,7 +43,7 @@ public class SnappyFramedEncoderTest {
assertTrue(channel.finish()); assertTrue(channel.finish());
ByteBuf expected = Unpooled.wrappedBuffer(new byte[] { 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'
}); });
@ -61,7 +61,7 @@ public class SnappyFramedEncoderTest {
assertTrue(channel.finish()); assertTrue(channel.finish());
ByteBuf expected = Unpooled.wrappedBuffer(new byte[] { 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, 0x00, 0x0E, 0x00, 0x00, 0x3b, 0x36, -0x7f, 0x37,
0x14, 0x10, 0x14, 0x10,
'n', 'e', 't', 't', 'y', 'n', 'e', 't', 't', 'y',
@ -83,7 +83,7 @@ public class SnappyFramedEncoderTest {
assertTrue(channel.finish()); assertTrue(channel.finish());
ByteBuf expected = Unpooled.wrappedBuffer(new byte[] { 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',
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',
}); });