Exemplo n.º 1
0
  @Test
  public void shouldMarshalOpaqueContainer() throws Exception {
    OpaqueContainer oc = new OpaqueContainer();
    oc.setContent("DADL".getBytes());
    oc.setLength(oc.getContent().length);

    Marshaller marshaller = dadlContext.createMarshaller();
    ByteArrayOutputStream os = new ByteArrayOutputStream();
    marshaller.marshal(oc, os);
    ByteArrayBitStreamReader reader = new ByteArrayBitStreamReader(os.toByteArray());
    assertThat(reader.readInt(), is(4));
    assertThat(reader.readByte(), is((byte) 'D'));
    assertThat(reader.readByte(), is((byte) 'A'));
    assertThat(reader.readByte(), is((byte) 'D'));
    assertThat(reader.readByte(), is((byte) 'L'));
    reader.close();
  }
Exemplo n.º 2
0
  @Test
  public void shouldUnmarshalOpaqueContainer() throws Exception {
    ByteArrayBitStreamWriter writer = new ByteArrayBitStreamWriter();
    writer.writeInt(4);
    writer.writeByte(20);
    writer.writeByte(22);
    writer.writeByte(24);
    writer.writeByte(26);
    writer.close();
    byte[] bytes = writer.toByteArray();
    assertThat(bytes.length, is(8));

    Unmarshaller parser = dadlContext.createUnmarshaller();
    OpaqueContainer oc = parser.unmarshal(bytes, OpaqueContainer.class);
    assertThat(oc, is(notNullValue()));
    assertThat(oc.getLength(), is(4));
    assertThat(oc.getContent().length, is(oc.getLength()));
    assertThat(oc.getContent()[0], is((byte) 20));
    assertThat(oc.getContent()[1], is((byte) 22));
    assertThat(oc.getContent()[2], is((byte) 24));
    assertThat(oc.getContent()[3], is((byte) 26));
  }