Impl variable length binary struct. Data will now be shifted to the correct possitions

This commit is contained in:
Ziver Koc 2016-05-11 17:11:18 +02:00
parent bae988e8dd
commit 3f21caa35b
7 changed files with 77 additions and 45 deletions

View file

@ -99,4 +99,21 @@ public class ByteUtilTest {
"024 00 00 00 00 00 00 00 00 '........'",
ByteUtil.toFormattedString(data3));
}
@Test
public void shiftLeft(){
assertArrayEquals( new byte[]{},
ByteUtil.shiftLeft(new byte[]{}, 4));
assertArrayEquals( new byte[]{0b0000_0001},
ByteUtil.shiftLeft(new byte[]{0b0000_0001}, 0));
assertArrayEquals( new byte[]{0b0000_0001},
ByteUtil.shiftLeft(new byte[]{0b0001_0000}, 4));
assertArrayEquals( new byte[]{0b0001_0001, 0b0000_0000},
ByteUtil.shiftLeft(new byte[]{0b0001_0000, 0b0000_0001}, 4));
assertArrayEquals( new byte[]{0b0100_1001, 0b0000_0001},
ByteUtil.shiftLeft(new byte[]{0b0111_1111, 0b0101_0010}, 6));
assertArrayEquals( new byte[]{0b0000_0001,0b0000_0001,0b0000_0001,0b0000_0001},
ByteUtil.shiftLeft(new byte[]{0b0001_0000,0b0001_0000,0b0001_0000,0b0001_0000}, 4));
}
}

View file

@ -84,11 +84,11 @@ public class ConverterTest {
public void byteArrayToInt(){
assertEquals(0, Converter.toInt(new byte[]{}));
assertEquals(1, Converter.toInt(new byte[]{0b0000_0001}));
assertEquals(1, Converter.toInt(new byte[]{0x00,0x01}));
assertEquals(1, Converter.toInt(new byte[]{0x01,0x00}));
assertEquals(256, Converter.toInt(new byte[]{0x00,0x01,0x00}));
assertEquals(-1, Converter.toInt(new byte[]{(byte)0xFF,(byte)0xFF,(byte)0xFF,(byte)0xFF}));
assertEquals(Integer.MAX_VALUE, Converter.toInt(new byte[]{(byte)0x7F,(byte)0xFF,(byte)0xFF,(byte)0xFF}));
assertEquals(Integer.MAX_VALUE, Converter.toInt(new byte[]{(byte)0x7F,(byte)0xFF,(byte)0xFF,(byte)0xFF,(byte)0xFF,(byte)0xFF}));
assertEquals(Integer.MAX_VALUE, Converter.toInt(new byte[]{(byte)0xFF,(byte)0xFF,(byte)0xFF,(byte)0x7F}));
assertEquals(Integer.MAX_VALUE, Converter.toInt(new byte[]{(byte)0xFF,(byte)0xFF,(byte)0xFF,(byte)0x7F, (byte)0xFF,(byte)0xFF}));
}
@Test

View file

@ -112,7 +112,7 @@ public class BinaryStructInputStreamTest {
}
// TODO: add full non lined length support
// @Test
@Test
public void nonLinedLength2(){
BinaryTestStruct struct = new BinaryTestStruct() {
@BinaryField(index=1, length=12)