Example #1
0
  public void testEncodeUint64() throws IOException {
    final long[] input = new long[] {0L, 0x0123456789abcdefL, 0xfedcba9876543210L};
    final byte[] expected =
        new byte[] {
          (byte) 0x00,
          (byte) 0xff,
          (byte) 0x01,
          (byte) 0x23,
          (byte) 0x45,
          (byte) 0x67,
          (byte) 0x89,
          (byte) 0xab,
          (byte) 0xcd,
          (byte) 0xef,
          (byte) 0xff,
          (byte) 0xfe,
          (byte) 0xdc,
          (byte) 0xba,
          (byte) 0x98,
          (byte) 0x76,
          (byte) 0x54,
          (byte) 0x32,
          (byte) 0x10
        };

    ByteArrayOutputStream output = new ByteArrayOutputStream(expected.length);
    Encoder e = new Encoder(output);

    for (long u64 : input) {
      e.uint64(u64);
    }
    Assert.assertArrayEquals(expected, output.toByteArray());
  }