コード例 #1
0
  @Test
  public void shouldUnmarshalNumberWithUndefinedColour() throws Exception {
    ByteArrayBitStreamWriter writer = new ByteArrayBitStreamWriter();
    writer.writeByte(22);
    // not a valid Colour value
    writer.writeByte(99);
    writer.close();
    byte[] bytes = writer.toByteArray();
    assertThat(bytes.length, is(2));

    Unmarshaller parser = dadlContext.createUnmarshaller();
    NumberWithColour nwc = parser.unmarshal(bytes, NumberWithColour.class);
    assertThat(nwc, is(notNullValue()));
    assertThat(nwc.getI1(), is(22));
    assertThat(nwc.getC(), is(nullValue()));
  }
コード例 #2
0
  @Test
  public void shouldUnmarshalTaggedString() throws Exception {
    ByteArrayBitStreamWriter writer = new ByteArrayBitStreamWriter();
    String text = "Hello DADL!";
    writer.writeByte(0x0A);
    writer.writeByte(2 + text.length());
    writer.writeByte(22);
    writer.writeByte(14);
    writer.writeBytes(text);
    writer.close();
    byte[] bytes = writer.toByteArray();
    assertThat(bytes.length, is(15));

    Unmarshaller unmarshaller = dadlContext.createUnmarshaller();
    TaggedString taggedString = unmarshaller.unmarshal(bytes, TaggedString.class);
    assertThat(taggedString.getText(), is(text));
  }
コード例 #3
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));
  }
コード例 #4
0
  @Test
  public void shouldUnmarshalSeqMinLengthSuffix() throws Exception {
    ByteArrayBitStreamWriter writer = new ByteArrayBitStreamWriter();
    writer.writeByte(2);
    writer.writeInt(17);
    writer.writeInt(39);
    for (int i = 0; i < 11; i++) {
      writer.write(0);
    }
    writer.writeByte(99);
    writer.close();

    byte[] bytes = writer.toByteArray();
    assertThat(bytes.length, is(21));

    Unmarshaller unmarshaller = dadlContext.createUnmarshaller();
    SeqMinLengthSuffix seqMinLength = unmarshaller.unmarshal(bytes, SeqMinLengthSuffix.class);
    NumberList list = seqMinLength.getSml().getNumberList();
    assertThat(list.getNumItems(), is(2));
    assertThat(list.getItems().get(0), is(17));
    assertThat(list.getItems().get(1), is(39));
    assertThat(seqMinLength.getSuffix(), is(99));
  }
コード例 #5
0
  @Test
  public void shouldUnmarshalTaggedListWithSuffix() throws IOException {
    ByteArrayBitStreamWriter writer = new ByteArrayBitStreamWriter();
    writer.writeByte(0x8C);
    writer.writeByte(8);
    writer.writeShort(500);
    writer.writeShort(600);
    writer.writeShort(700);
    writer.writeShort(800);
    writer.writeInt(999);
    writer.close();

    byte[] bytes = writer.toByteArray();
    assertThat(bytes.length, is(14));

    Unmarshaller unmarshaller = dadlContext.createUnmarshaller();
    TaggedListWithSuffix tlws = unmarshaller.unmarshal(bytes, TaggedListWithSuffix.class);

    assertThat(tlws, is(notNullValue()));
    TaggedList tl = tlws.getTaggedList();
    assertThat(tl.getIndexes().size(), is(4));
    assertThat(tl.getIndexes(), contains(500, 600, 700, 800));
    assertThat(tlws.getSuffix(), is(999));
  }
コード例 #6
0
  @Test
  public void shouldUnmarshalList() throws Exception {
    ByteArrayBitStreamWriter writer = new ByteArrayBitStreamWriter();
    writer.writeByte(3);
    writer.writeInt(16);
    writer.writeInt(25);
    writer.writeInt(36);
    writer.close();
    byte[] bytes = writer.toByteArray();
    assertThat(bytes.length, is(13));

    Unmarshaller unmarshaller = dadlContext.createUnmarshaller();
    NumberList numberList = unmarshaller.unmarshal(writer.toByteArray(), NumberList.class);
    assertThat(numberList.getNumItems(), is(3));
    assertThat(numberList.getItems(), contains(16, 25, 36));
  }