ByteCodec implements BlockCodec<Byte> { @Override public Byte decode(byte[] data, int bitLength) throws BlockCodecException { int _bitLength = Math.min(8, bitLength); byte result = ByteUtils.valueLeft(data[0], _bitLength); result = (byte) (result >> (8 - _bitLength)); return result; }  @Override Byte zeroValue(); @Override Byte decode(byte[] data, int bitLength); @Override byte[] encode(Byte data, int bitLength); @Override void reset(); @Override String getValueType();  }
@Test public void testDecode() throws Exception { ByteCodec codec = new ByteCodec(); Assert.assertEquals((byte) 0x7f, codec.decode(new byte[] { (byte) 0x7f }, 8), 0); Assert.assertEquals((byte) 0x3f, codec.decode(new byte[] { (byte) 0x7f }, 7), 0); Assert.assertEquals((byte) 0x1f, codec.decode(new byte[] { (byte) 0x7f }, 6), 0); Assert.assertEquals((byte) 0x0f, codec.decode(new byte[] { (byte) 0x7f }, 5), 0); Assert.assertEquals((byte) 0x07, codec.decode(new byte[] { (byte) 0x7f }, 4), 0); Assert.assertEquals((byte) 0x03, codec.decode(new byte[] { (byte) 0x7f }, 3), 0); Assert.assertEquals((byte) 0x01, codec.decode(new byte[] { (byte) 0x7f }, 2), 0); Assert.assertEquals((byte) 0x00, codec.decode(new byte[] { (byte) 0x7f }, 1), 0); }