use of org.codice.ddf.libs.klv.KlvDataElement in project alliance by codice.
the class MetadataPacketTest method testThatPesHeadersWithOptionalFieldsAreHandled.
/**
* The binary data in this test was captured from a data stream where the PES header contains an
* optional timestamp.
*/
@Test
public void testThatPesHeadersWithOptionalFieldsAreHandled() throws KlvDecodingException {
byte[] packet = new byte[] { 0x00, 0x00, 0x01, (byte) 0xbd, 0x01, 0x08, (byte) 0x84, (byte) 0x80, 0x05, 0x21, 0x00, 0x09, 0x41, (byte) 0xd9, 0x06, 0x0e, 0x2b, 0x34, 0x02, 0x0b, 0x01, 0x01, 0x0e, 0x01, 0x03, 0x01, 0x01, 0x00, 0x00, 0x00, (byte) 0x82, 0x00, (byte) 0xed, 0x02, 0x08, 0x00, 0x04, (byte) 0xe4, (byte) 0xea, (byte) 0xad, 0x53, (byte) 0xfb, 0x48, 0x03, 0x05, 0x30, 0x30, 0x30, 0x30, 0x31, 0x04, 0x03, 0x30, 0x30, 0x31, 0x05, 0x02, 0x5a, (byte) 0xb6, 0x06, 0x02, 0x00, 0x00, 0x07, 0x02, 0x00, 0x00, 0x0a, 0x08, 0x56, 0x52, 0x53, 0x47, 0x20, 0x35, 0x2e, 0x36, 0x0b, 0x18, 0x56, 0x52, 0x53, 0x47, 0x20, 0x56, 0x35, 0x2e, 0x36, 0x2e, 0x37, 0x32, 0x20, 0x41, 0x70, 0x72, 0x20, 0x20, 0x37, 0x20, 0x32, 0x30, 0x31, 0x31, 0x0c, 0x0e, 0x47, 0x65, 0x6f, 0x64, 0x65, 0x74, 0x69, 0x63, 0x20, 0x57, 0x47, 0x53, 0x38, 0x34, 0x0d, 0x04, 0x30, (byte) 0xf7, 0x04, (byte) 0xea, 0x0e, 0x04, 0x31, 0x2d, (byte) 0xb4, 0x76, 0x0f, 0x02, 0x3f, 0x08, 0x10, 0x02, 0x03, (byte) 0x89, 0x11, 0x02, 0x02, (byte) 0xa7, 0x12, 0x04, 0x06, (byte) 0xfd, 0x6b, (byte) 0xff, 0x13, 0x04, (byte) 0xd7, (byte) 0xc3, 0x3c, (byte) 0xce, 0x14, 0x04, 0x00, 0x00, 0x00, 0x00, 0x15, 0x04, 0x00, 0x21, (byte) 0xac, 0x7e, 0x16, 0x02, 0x02, (byte) 0xdb, 0x17, 0x04, 0x30, (byte) 0xf3, (byte) 0x98, 0x3a, 0x18, 0x04, 0x31, 0x2f, (byte) 0x99, 0x59, 0x19, 0x02, 0x23, 0x72, 0x1a, 0x02, (byte) 0xff, (byte) 0xfe, 0x1b, 0x02, 0x01, 0x6e, 0x1c, 0x02, (byte) 0xfe, (byte) 0xc7, 0x1d, 0x02, (byte) 0xff, (byte) 0xee, 0x1e, 0x02, (byte) 0xff, (byte) 0xf8, 0x1f, 0x02, (byte) 0xfe, (byte) 0xa6, 0x20, 0x02, 0x01, 0x22, 0x21, 0x02, 0x00, 0x22, 0x30, 0x20, 0x01, 0x01, 0x01, 0x02, 0x01, 0x01, 0x03, 0x04, 0x2f, 0x2f, 0x55, 0x53, 0x06, 0x05, 0x43, 0x41, 0x20, 0x55, 0x53, 0x0c, 0x01, 0x01, 0x0d, 0x04, 0x2f, 0x2f, 0x55, 0x53, 0x16, 0x02, 0x00, 0x07, 0x41, 0x01, 0x01, 0x48, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x02, (byte) 0xb7, (byte) 0x8d };
final MPSDemuxer.PESPacket pesHeader = MPSUtils.readPESHeader(ByteBuffer.wrap(packet), 0);
AsynchronousMetadataPacket asynchronousMetadataPacket = new AsynchronousMetadataPacket(packet, pesHeader, new KlvDecoder(Stanag4609TransportStreamParser.UAS_DATALINK_LOCAL_SET_CONTEXT));
DecodedKLVMetadataPacket p = asynchronousMetadataPacket.decodeKLV();
assertThat(p, notNullValue());
KlvLocalSet e = (KlvLocalSet) p.getDecodedKLV().getDataElementByName(Stanag4609TransportStreamParser.UAS_DATALINK_LOCAL_SET);
KlvDataElement timestamp = e.getValue().getDataElementByName(Stanag4609TransportStreamParser.TIMESTAMP);
assertThat(timestamp.getValue(), is(1377596488285000L));
}
use of org.codice.ddf.libs.klv.KlvDataElement in project alliance by codice.
the class Stanag4609ProcessorImplTest method testHandleWithKlvLocalSet.
@Test
public void testHandleWithKlvLocalSet() throws KlvDecodingException {
KlvContext klvContext = new KlvContext(Klv.KeyLength.OneByte, Klv.LengthEncoding.OneByte, Collections.singleton(klvIntegerEncodedFloatingPoint));
KlvDataElement klvLocalSet = mock(KlvLocalSet.class);
when(klvLocalSet.getValue()).thenReturn(klvContext);
stanag4609Processor.handle(Collections.singletonMap(FIELD_NAME, klvHandler), defaultKlvHandler, klvLocalSet, dataElements);
verify(klvHandler, atLeastOnce()).accept(klvIntegerEncodedFloatingPoint);
}
use of org.codice.ddf.libs.klv.KlvDataElement in project alliance by codice.
the class Stanag4609TransportStreamParserTest method verifyDecodedMetadataPacket.
private void verifyDecodedMetadataPacket(final DecodedKLVMetadataPacket packet) {
final KlvContext outerContext = packet.getDecodedKLV();
assertThat(outerContext.getDataElements().size(), is(1));
assertThat(outerContext.hasDataElement(Stanag4609TransportStreamParser.UAS_DATALINK_LOCAL_SET), is(true));
final KlvContext localSetContext = ((KlvLocalSet) outerContext.getDataElementByName(Stanag4609TransportStreamParser.UAS_DATALINK_LOCAL_SET)).getValue();
final Map<String, KlvDataElement> localSetDataElements = localSetContext.getDataElements();
assertThat(localSetDataElements.size(), is(EXPECTED_VALUES.size()));
localSetDataElements.forEach((name, dataElement) -> {
final Object expectedValue = EXPECTED_VALUES.get(name);
final Object actualValue = dataElement.getValue();
if (actualValue instanceof Double) {
assertThat(String.format("%s is not close to %s", name, expectedValue), (Double) actualValue, is(closeTo((Double) expectedValue, 1e-6)));
} else {
assertThat(String.format("%s is not %s", name, expectedValue), actualValue, is(expectedValue));
}
});
}
Aggregations