LongCodec implements BlockCodec<Long> { @Override public Long decode(byte[] data, int bitLength) throws BlockCodecException { try { return new Long(ByteUtils.longValue(data, bitLength)); } catch (Exception ex) { throw new BlockCodecException("long decode failure. " + ex.getMessage(), ex); } }  @Override Long zeroValue(); @Override Long decode(byte[] data, int bitLength); @Override byte[] encode(Long data, int bitLength); @Override void reset(); @Override String getValueType();  }
@Test public void testDecode() throws Exception { LongCodec codec = new LongCodec(); Assert.assertEquals(-2, codec.decode(new byte[] { (byte) 0xfe }, 8), 0); Assert.assertEquals(-1, codec.decode(new byte[] { (byte) 0xfe }, 7), 0); Assert.assertEquals(-2, codec.decode(new byte[] { (byte) 0xff, (byte) 0xfe }, 16), 0); Assert.assertEquals(-2, codec.decode(new byte[] { (byte) 0xff, (byte) 0xfd }, 15), 0); Assert.assertEquals(-4, codec.decode(new byte[] { (byte) 0xff, (byte) 0xff, (byte) 0xfc }, 24), 0); Assert.assertEquals(-1024, codec.decode(new byte[] { (byte) 0xff, (byte) 0xff, (byte) 0xfc, (byte) 0x00 }, 32), 0); }