예제 #1
0
  @Test
  public void shouldMarshalAllNumbers() throws IOException {
    ShortNumbers sn = new ShortNumbers();
    sn.setI8((byte) 5);
    sn.setU8((short) 200);
    sn.setI16((short) 1000);
    sn.setU16(50000);

    LongNumbers ln = new LongNumbers();
    ln.setI32(-100000);
    ln.setU32(3_000_000_000L);
    ln.setI24(5_000_000);
    ln.setU24(10_000_000);

    AllNumbers an = new AllNumbers();
    an.setShortNumbers(sn);
    an.setLongNumbers(ln);

    ByteArrayOutputStream os = new ByteArrayOutputStream();
    Marshaller marshaller = dadlContext.createMarshaller();
    marshaller.marshal(an, os);
    byte[] bytes = os.toByteArray();
    assertThat(bytes.length, is(20));

    ByteArrayBitStreamReader reader = new ByteArrayBitStreamReader(bytes);
    assertThat(reader.readByte(), is((byte) 5));
    assertThat(reader.readUnsignedByte(), is(200));
    assertThat(reader.readShort(), is((short) 1000));
    assertThat(reader.readUnsignedShort(), is(50000));
    assertThat(reader.readBits(24), is(5_000_000L));
    assertThat(reader.readBits(24), is(10_000_000L));
    assertThat(reader.readInt(), is(-100000));
    assertThat(reader.readUnsignedInt(), is(3_000_000_000L));
    reader.close();
  }
예제 #2
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();
  }
예제 #3
0
 @Test
 public void shouldMarshalBcdSequence() throws Exception {
   BcdSequence bcdSequence = new BcdSequence();
   bcdSequence.setI16(9999);
   bcdSequence.setBcd(2011);
   Marshaller marshaller = dadlContext.createMarshaller();
   ByteArrayOutputStream os = new ByteArrayOutputStream();
   marshaller.marshal(bcdSequence, os);
   assertThat(os.toByteArray().length, is(4));
   ByteArrayBitStreamReader reader = new ByteArrayBitStreamReader(os.toByteArray());
   assertThat(reader.readShort(), is((short) 9999));
   assertThat(reader.readByte(), is((byte) 0x20));
   assertThat(reader.readByte(), is((byte) 0x11));
   reader.close();
 }
예제 #4
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();
  }
예제 #5
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();
  }
예제 #6
0
 @Test
 public void shouldMarshalSeqMinLength() throws Exception {
   SeqMinLength sml = new SeqMinLength();
   NumberList list = new NumberList();
   list.getItems().add(17);
   list.getItems().add(39);
   sml.setNumberList(list);
   Marshaller marshaller = dadlContext.createMarshaller();
   ByteArrayOutputStream os = new ByteArrayOutputStream();
   marshaller.marshal(sml, os);
   assertThat(os.toByteArray().length, is(20));
   ByteArrayBitStreamReader reader = new ByteArrayBitStreamReader(os.toByteArray());
   assertThat(reader.readByte(), is((byte) 2));
   assertThat(reader.readInt(), is(17));
   assertThat(reader.readInt(), is(39));
   reader.close();
 }