Search in sources :

Example 6 with KlvInt

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));
}
Also used : KlvInt(org.codice.ddf.libs.klv.data.numerical.KlvInt) KlvIntegerEncodedFloatingPoint(org.codice.ddf.libs.klv.data.numerical.KlvIntegerEncodedFloatingPoint) Test(org.junit.Test)

Example 7 with KlvInt

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)));
}
Also used : KlvIntegerEncodedFloatingPoint(org.codice.ddf.libs.klv.data.numerical.KlvIntegerEncodedFloatingPoint) KlvInt(org.codice.ddf.libs.klv.data.numerical.KlvInt) Test(org.junit.Test)

Example 8 with KlvInt

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);
}
Also used : KlvInt(org.codice.ddf.libs.klv.data.numerical.KlvInt)

Example 9 with KlvInt

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);
}
Also used : KlvDouble(org.codice.ddf.libs.klv.data.numerical.KlvDouble) KlvInt(org.codice.ddf.libs.klv.data.numerical.KlvInt) HashSet(java.util.HashSet) Test(org.junit.Test)

Example 10 with KlvInt

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);
}
Also used : KlvInt(org.codice.ddf.libs.klv.data.numerical.KlvInt) Test(org.junit.Test)

Aggregations

KlvInt (org.codice.ddf.libs.klv.data.numerical.KlvInt)13 Test (org.junit.Test)9 KlvIntegerEncodedFloatingPoint (org.codice.ddf.libs.klv.data.numerical.KlvIntegerEncodedFloatingPoint)4 HashSet (java.util.HashSet)1 KlvContext (org.codice.ddf.libs.klv.KlvContext)1 KlvByte (org.codice.ddf.libs.klv.data.numerical.KlvByte)1 KlvDouble (org.codice.ddf.libs.klv.data.numerical.KlvDouble)1 KlvLong (org.codice.ddf.libs.klv.data.numerical.KlvLong)1 KlvShort (org.codice.ddf.libs.klv.data.numerical.KlvShort)1 KlvUnsignedByte (org.codice.ddf.libs.klv.data.numerical.KlvUnsignedByte)1 KlvUnsignedShort (org.codice.ddf.libs.klv.data.numerical.KlvUnsignedShort)1 KlvString (org.codice.ddf.libs.klv.data.text.KlvString)1 BeforeClass (org.junit.BeforeClass)1