@Test public void testDecodeLiteral() throws Exception { ByteBuf in = Unpooled.wrappedBuffer(new byte[] { 0x05, 0x04 << 2, 0x6e, 0x65, 0x74, 0x74, 0x79 }); ByteBuf out = Unpooled.buffer(5); snappy.decode(in, out); ByteBuf expected = Unpooled.wrappedBuffer(new byte[] { 0x6e, 0x65, 0x74, 0x74, 0x79 }); assertEquals("Literal was not decoded correctly", expected, out); in.release(); out.release(); expected.release(); }
static int decodeLiteral(byte tag, ByteBuf in, ByteBuf out) { in.markReaderIndex(); int length; switch(tag >> 2 & 0x3F) { case 60: if (!in.isReadable()) { return NOT_ENOUGH_INPUT; } length = in.readUnsignedByte(); break; case 61: if (in.readableBytes() < 2) { return NOT_ENOUGH_INPUT; } length = in.readUnsignedShortLE(); break; case 62: if (in.readableBytes() < 3) { return NOT_ENOUGH_INPUT; } length = in.readUnsignedMediumLE(); break; case 63: if (in.readableBytes() < 4) { return NOT_ENOUGH_INPUT; } length = in.readIntLE(); break; default: length = tag >> 2 & 0x3F; } length += 1; if (in.readableBytes() < length) { in.resetReaderIndex(); return NOT_ENOUGH_INPUT; } out.writeBytes(in, length); return length; }
Snappy { static int decodeLiteral(byte tag, ByteBuf in, ByteBuf out) { in.markReaderIndex(); int length; switch(tag >> 2 & 0x3F) { case 60: if (!in.isReadable()) { return NOT_ENOUGH_INPUT; } length = in.readUnsignedByte(); break; case 61: if (in.readableBytes() < 2) { return NOT_ENOUGH_INPUT; } length = in.readUnsignedShortLE(); break; case 62: if (in.readableBytes() < 3) { return NOT_ENOUGH_INPUT; } length = in.readUnsignedMediumLE(); break; case 63: if (in.readableBytes() < 4) { return NOT_ENOUGH_INPUT; } length = in.readIntLE(); break; default: length = tag >> 2 & 0x3F; } length += 1; if (in.readableBytes() < length) { in.resetReaderIndex(); return NOT_ENOUGH_INPUT; } out.writeBytes(in, length); return length; } }
Snappy { static int decodeLiteral(byte tag, ByteBuf in, ByteBuf out) { in.markReaderIndex(); int length; switch(tag >> 2 & 0x3F) { case 60: if (!in.isReadable()) { return NOT_ENOUGH_INPUT; } length = in.readUnsignedByte(); break; case 61: if (in.readableBytes() < 2) { return NOT_ENOUGH_INPUT; } length = in.readUnsignedShortLE(); break; case 62: if (in.readableBytes() < 3) { return NOT_ENOUGH_INPUT; } length = in.readUnsignedMediumLE(); break; case 63: if (in.readableBytes() < 4) { return NOT_ENOUGH_INPUT; } length = in.readIntLE(); break; default: length = tag >> 2 & 0x3F; } length += 1; if (in.readableBytes() < length) { in.resetReaderIndex(); return NOT_ENOUGH_INPUT; } out.writeBytes(in, length); return length; }  }
Snappy { static int decodeLiteral(byte tag, ByteBuf in, ByteBuf out) { in.markReaderIndex(); int length; switch(tag >> 2 & 0x3F) { case 60: if (!in.isReadable()) { return NOT_ENOUGH_INPUT; } length = in.readUnsignedByte(); break; case 61: if (in.readableBytes() < 2) { return NOT_ENOUGH_INPUT; } length = in.readUnsignedShortLE(); break; case 62: if (in.readableBytes() < 3) { return NOT_ENOUGH_INPUT; } length = in.readUnsignedMediumLE(); break; case 63: if (in.readableBytes() < 4) { return NOT_ENOUGH_INPUT; } length = in.readIntLE(); break; default: length = tag >> 2 & 0x3F; } length += 1; if (in.readableBytes() < length) { in.resetReaderIndex(); return NOT_ENOUGH_INPUT; } out.writeBytes(in, length); return length; }  void reset(); void encode(final ByteBuf in, final ByteBuf out, final int length); void decode(ByteBuf in, ByteBuf out); }
Snappy { static int decodeLiteral(byte tag, ByteBuf in, ByteBuf out) { in.markReaderIndex(); int length; switch(tag >> 2 & 0x3F) { case 60: if (!in.isReadable()) { return NOT_ENOUGH_INPUT; } length = in.readUnsignedByte(); break; case 61: if (in.readableBytes() < 2) { return NOT_ENOUGH_INPUT; } length = in.readUnsignedShortLE(); break; case 62: if (in.readableBytes() < 3) { return NOT_ENOUGH_INPUT; } length = in.readUnsignedMediumLE(); break; case 63: if (in.readableBytes() < 4) { return NOT_ENOUGH_INPUT; } length = in.readIntLE(); break; default: length = tag >> 2 & 0x3F; } length += 1; if (in.readableBytes() < length) { in.resetReaderIndex(); return NOT_ENOUGH_INPUT; } out.writeBytes(in, length); return length; }  void reset(); void encode(final ByteBuf in, final ByteBuf out, final int length); void decode(ByteBuf in, ByteBuf out);  }