use of org.codice.ddf.libs.klv.data.numerical.KlvInt in project ddf by codice.
the class KlvDecoderTest method testIntValue.
@Test
public void testIntValue() throws KlvDecodingException {
final byte[] klvBytes = { -8, 4, (byte) 0xAF, 0x69, 0x1E, 0x0F };
final KlvInt klvInt = new KlvInt(new byte[] { -8 }, "test");
final KlvContext decodedKlvContext = decodeKLV(KeyLength.ONE_BYTE, LengthEncoding.ONE_BYTE, klvInt, klvBytes);
final int value = ((KlvInt) decodedKlvContext.getDataElementByName("test")).getValue();
assertThat(value, is(-1352065521));
}
use of org.codice.ddf.libs.klv.data.numerical.KlvInt in project ddf by codice.
the class KlvDecoderTest method testFloatingPointEncodedAsInt.
@Test
public // Example value taken from ST0601.8 Tag 19.
void testFloatingPointEncodedAsInt() throws KlvDecodingException {
final byte[] klvBytes = { -8, 4, (byte) 0x87, (byte) 0xF8, 0x4B, (byte) 0x86 };
final KlvInt klvInt = new KlvInt(new byte[] { -8 }, "test");
final KlvIntegerEncodedFloatingPoint sensorRelativeElevationAngle = new KlvIntegerEncodedFloatingPoint(klvInt, // Short.MIN_VALUE is an "out of range" indicator, so it is not included in the range.
Integer.MIN_VALUE + 1, Integer.MAX_VALUE, -180, 180);
final KlvContext decodedKlvContext = decodeKLV(KeyLength.ONE_BYTE, LengthEncoding.ONE_BYTE, sensorRelativeElevationAngle, klvBytes);
final double value = ((KlvIntegerEncodedFloatingPoint) decodedKlvContext.getDataElementByName("test")).getValue();
assertThat(value, is(closeTo(-168.792324833941, 1e-12)));
}
use of org.codice.ddf.libs.klv.data.numerical.KlvInt in project ddf by codice.
the class KlvDecoderTest method isErrorIndicatedInt.
private boolean isErrorIndicatedInt(int value, Optional<Integer> errorValue) throws KlvDecodingException {
KlvInt klvInt = new KlvInt(new byte[] { 0 }, "test", errorValue);
byte[] dataBytes = new byte[6];
dataBytes[0] = 0;
dataBytes[1] = 4;
arraycopy(intToBytes(value), 0, dataBytes, 2, 4);
return isErrorIndicatedDecode(klvInt, dataBytes);
}
use of org.codice.ddf.libs.klv.data.numerical.KlvInt in project ddf by codice.
the class KlvContextTest method testAddDataElementCollection.
@Test
public void testAddDataElementCollection() {
final KlvContext klvContext = new KlvContext(KeyLength.ONE_BYTE, LengthEncoding.ONE_BYTE);
final Collection<KlvDataElement> dataElements = new HashSet<>();
final KlvInt klvInt = new KlvInt(new byte[] { 1 }, "first");
dataElements.add(klvInt);
final KlvDouble klvDouble = new KlvDouble(new byte[] { 2 }, "second");
dataElements.add(klvDouble);
klvContext.addDataElements(dataElements);
verifyKLVContextDataElements(klvContext, klvInt, klvDouble);
}
use of org.codice.ddf.libs.klv.data.numerical.KlvInt in project ddf by codice.
the class KlvContextTest method testAddSingleDataElement.
@Test
public void testAddSingleDataElement() {
final KlvContext klvContext = new KlvContext(KeyLength.ONE_BYTE, LengthEncoding.ONE_BYTE);
final KlvInt klvInt = new KlvInt(new byte[] { 1 }, "first");
klvContext.addDataElement(klvInt);
verifyKLVContextDataElements(klvContext, klvInt);
}
Aggregations