@Test
public void testEncode() throws Exception {

    LongCodec codec = new LongCodec();
    // 01111111
    Assert.assertArrayEquals(new byte[] { (byte) 0x7f }, codec.encode(127L, 8));
    // _1111111 >> 11111110
    Assert.assertArrayEquals(new byte[] { (byte) 0xfe }, codec.encode(127L, 7));
    Assert.assertArrayEquals(new byte[] { 0x00, (byte) 0x7f }, codec.encode(127L, 16));
    // 10000000
    Assert.assertArrayEquals(new byte[] { (byte) 0x80 }, codec.encode(-128L, 8));
    // _1111111 10000000 >> 11111111 00000000
    Assert.assertArrayEquals(new byte[] { (byte) 0xff, (byte) 0x00 }, codec.encode(-128L, 15));
    // 11111111 10000000
    Assert.assertArrayEquals(new byte[] { (byte) 0xff, (byte) 0x80 }, codec.encode(-128L, 16));
}