Example #1
0
  public void testEncodeString() throws IOException {
    final String[] input = new String[] {null, "Hello", "", "World", "こんにちは世界"};
    final byte[] expected =
        new byte[] {
          0x00, // null string
          0x05,
          'H',
          'e',
          'l',
          'l',
          'o',
          0x00, // empty string
          0x05,
          'W',
          'o',
          'r',
          'l',
          'd',
          0x15,
          (byte) 0xe3,
          (byte) 0x81,
          (byte) 0x93,
          (byte) 0xe3,
          (byte) 0x82,
          (byte) 0x93,
          (byte) 0xe3,
          (byte) 0x81,
          (byte) 0xab,
          (byte) 0xe3,
          (byte) 0x81,
          (byte) 0xa1,
          (byte) 0xe3,
          (byte) 0x81,
          (byte) 0xaf,
          (byte) 0xe4,
          (byte) 0xb8,
          (byte) 0x96,
          (byte) 0xe7,
          (byte) 0x95,
          (byte) 0x8c
        };

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

    for (String str : input) {
      e.string(str);
    }
    Assert.assertArrayEquals(expected, output.toByteArray());
  }
Example #2
0
 @Override
 public void encode(@NotNull Encoder e) throws IOException {
   e.string(dummy);
 }