Пример #1
0
  @Test
  public void shouldMarshalNumberWithColour() throws Exception {
    NumberWithColour nwc = new NumberWithColour();
    nwc.setI1(99);
    nwc.setC(Colour.GREEN);
    Marshaller marshaller = dadlContext.createMarshaller();
    ByteArrayOutputStream os = new ByteArrayOutputStream();
    marshaller.marshal(nwc, os);
    assertThat(os.toByteArray().length, is(2));

    ByteArrayBitStreamReader reader = new ByteArrayBitStreamReader(os.toByteArray());
    assertThat(reader.readByte(), is((byte) 99));
    assertThat(reader.readByte(), is((byte) 17));
    reader.close();
  }
Пример #2
0
  @Test
  public void shouldMarshalTaggedString() throws Exception {
    NumberWithColour nwc = new NumberWithColour();
    nwc.setI1(22);
    nwc.setC(Colour.GREEN);
    String text = "Hello DADL!";
    TaggedString taggedString = new TaggedString();
    taggedString.setNwc(nwc);
    taggedString.setText(text);

    Marshaller marshaller = dadlContext.createMarshaller();
    ByteArrayOutputStream os = new ByteArrayOutputStream();
    marshaller.marshal(taggedString, os);

    ByteArrayBitStreamReader reader = new ByteArrayBitStreamReader(os.toByteArray());
    assertThat(reader.readByte(), is((byte) 0x0A));
    assertThat(reader.readByte(), is((byte) (2 + text.length())));
    assertThat(reader.readByte(), is((byte) 22));
    assertThat(reader.readByte(), is((byte) 17));
    byte[] bytes = new byte[11];
    reader.read(bytes);
    assertThat(new String(bytes, StandardCharsets.UTF_8), is(text));
    reader.close();
  }