Example #1
0
  public void testEncodeInt64() throws IOException {
    final long[] input = new long[] {0L, 9223372036854775807L, -9223372036854775808L, -1L};
    final byte[] expected =
        new byte[] {
          (byte) 0x00,
          (byte) 0xff,
          (byte) 0xff,
          (byte) 0xff,
          (byte) 0xff,
          (byte) 0xff,
          (byte) 0xff,
          (byte) 0xff,
          (byte) 0xff,
          (byte) 0xfe,
          (byte) 0xff,
          (byte) 0xff,
          (byte) 0xff,
          (byte) 0xff,
          (byte) 0xff,
          (byte) 0xff,
          (byte) 0xff,
          (byte) 0xff,
          (byte) 0xff,
          (byte) 0x01
        };

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

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