コード例 #1
0
  @Test
  public void shouldMarshalSequenceWithPresentOptionalElement() throws IOException {
    Option1 opt1 = new Option1();
    opt1.setI11(17);
    opt1.setI12(22);
    Option2 opt2 = new Option2();
    opt2.setI21(42);
    opt2.setI22(12345678);
    SequenceWithOptional seq = new SequenceWithOptional();
    seq.setOpt1(opt1);
    seq.setOpt2(opt2);

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

    ByteArrayBitStreamReader reader = new ByteArrayBitStreamReader(os.toByteArray());
    assertThat(reader.readUnsignedByte(), is(0x0A));
    assertThat(reader.readUnsignedByte(), is(3));
    assertThat(reader.readBits(16), is(17L));
    assertThat(reader.readBits(8), is(22L));
    assertThat(reader.readUnsignedByte(), is(0x0B));
    assertThat(reader.readUnsignedByte(), is(7));
    assertThat(reader.readBits(24), is(42L));
    assertThat(reader.readBits(32), is(12345678L));
    reader.close();
  }
コード例 #2
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();
  }
コード例 #3
0
  @Test
  public void shouldIgnoreMemberWhenOutputValueCalc() throws Exception {
    NumberList numberList = new NumberList();
    numberList.getItems().addAll(Arrays.asList(16, 25, 36));

    Marshaller marshaller = dadlContext.createMarshaller();
    ByteArrayOutputStream os = new ByteArrayOutputStream();
    marshaller.marshal(numberList, os);
    assertThat(os.toByteArray().length, is(13));

    ByteArrayBitStreamReader reader = new ByteArrayBitStreamReader(os.toByteArray());
    assertThat(reader.readUnsignedByte(), is(3));
    assertThat(reader.readInt(), is(16));
    assertThat(reader.readInt(), is(25));
    assertThat(reader.readInt(), is(36));
    reader.close();
  }
コード例 #4
0
  @Test
  public void shouldMarshalChoice() throws Exception {
    Option2 opt2 = new Option2();
    opt2.setI21(42);
    opt2.setI22(12345678);
    MyChoice myChoice = new MyChoice();
    myChoice.setOpt2(opt2);

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

    ByteArrayBitStreamReader reader = new ByteArrayBitStreamReader(os.toByteArray());
    assertThat(reader.readUnsignedByte(), is(0x0B));
    assertThat(reader.readUnsignedByte(), is(7));
    assertThat(reader.readBits(24), is(42L));
    assertThat(reader.readBits(32), is(12345678L));
    reader.close();
  }