@Test public void shouldUnmarshalParsedArray() throws Exception { ByteArrayBitStreamWriter writer = new ByteArrayBitStreamWriter(); writer.writeInt(16); writer.writeInt(25); writer.writeInt(36); writer.writeInt(49); writer.close(); byte[] bytes = writer.toByteArray(); assertThat(bytes.length, is(16)); Unmarshaller unmarshaller = dadlContext.createUnmarshaller(); ParsedNumberList numberList = unmarshaller.unmarshal(writer.toByteArray(), ParsedNumberList.class); assertThat(numberList.getItems(), contains(16, 25, 36, 49)); }
@Test public void shouldParseAllNumbers() throws IOException { ByteArrayBitStreamWriter writer = new ByteArrayBitStreamWriter(); writer.writeBits(5, 8); writer.writeBits(200, 8); writer.writeBits(1000, 16); writer.writeBits(50000, 16); writer.writeBits(5_000_000L, 24); writer.writeBits(10_000_000L, 24); writer.writeInt(-100000); writer.writeUnsignedInt(3_000_000_000L); writer.close(); byte[] bytes = writer.toByteArray(); assertThat(bytes.length, is(20)); Unmarshaller parser = dadlContext.createUnmarshaller(); AllNumbers an = parser.unmarshal(bytes, AllNumbers.class); assertThat(an, is(notNullValue())); ShortNumbers sn = an.getShortNumbers(); assertThat(sn, is(notNullValue())); assertThat(sn.getI8(), is(5)); assertThat(sn.getU8(), is(200)); assertThat(sn.getI16(), is(1000)); assertThat(sn.getU16(), is(50000)); LongNumbers ln = an.getLongNumbers(); assertThat(ln, is(notNullValue())); assertThat(ln.getI24(), is(5_000_000)); assertThat(ln.getU24(), is(10_000_000)); assertThat(ln.getI32(), is(-100_000)); assertThat(ln.getU32(), is(3_000_000_000L)); }
@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)); }
@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)); }
@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)); }