Added byte support to BinaryStruct
This commit is contained in:
parent
59097efcdb
commit
fc1e650002
3 changed files with 55 additions and 16 deletions
|
|
@ -93,6 +93,27 @@ public class BinaryStructInputStreamTest {
|
|||
struct.assertObj();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void basicByteTest(){
|
||||
BinaryTestStruct struct = new BinaryTestStruct() {
|
||||
@BinaryField(index=1, length=1)
|
||||
public byte b1;
|
||||
@BinaryField(index=2, length=4)
|
||||
public byte b2;
|
||||
@BinaryField(index=3, length=3)
|
||||
public byte b3;
|
||||
|
||||
public void assertObj(){
|
||||
assertEquals(0, b1);
|
||||
assertEquals(6, b2);
|
||||
assertEquals(6, b3);
|
||||
}
|
||||
};
|
||||
|
||||
BinaryStructInputStream.read(struct, new byte[]{0b0011_0110});
|
||||
struct.assertObj();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void nonLinedLength(){
|
||||
BinaryTestStruct struct = new BinaryTestStruct() {
|
||||
|
|
|
|||
|
|
@ -38,6 +38,32 @@ import static org.junit.Assert.assertArrayEquals;
|
|||
*/
|
||||
public class BinaryStructOutputStreamTest {
|
||||
|
||||
@Test
|
||||
public void basicBooleanTest() throws IOException {
|
||||
BinaryStruct struct = new BinaryStruct() {
|
||||
@BinaryField(index=1, length=1)
|
||||
public boolean b1 = false;
|
||||
@BinaryField(index=2, length=1)
|
||||
public boolean b2 = true;
|
||||
};
|
||||
|
||||
byte[] data = BinaryStructOutputStream.serialize(struct);
|
||||
assertArrayEquals(new byte[]{(byte)0b0100_0000}, data);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void basicByteTest() throws IOException {
|
||||
BinaryStruct struct = new BinaryStruct() {
|
||||
@BinaryField(index=1, length=3)
|
||||
public byte b1 = 3;
|
||||
@BinaryField(index=2, length=5)
|
||||
public byte b2 = Byte.MAX_VALUE;
|
||||
};
|
||||
|
||||
byte[] data = BinaryStructOutputStream.serialize(struct);
|
||||
assertArrayEquals(new byte[]{(byte)0b0111_1111}, data);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void basicIntTest() throws IOException {
|
||||
BinaryStruct struct = new BinaryStruct() {
|
||||
|
|
@ -64,20 +90,6 @@ public class BinaryStructOutputStreamTest {
|
|||
assertArrayEquals(new byte[]{0,1, 0,2}, data);
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
public void basicBooleanTest() throws IOException {
|
||||
BinaryStruct struct = new BinaryStruct() {
|
||||
@BinaryField(index=1, length=1)
|
||||
public boolean b1 = false;
|
||||
@BinaryField(index=2, length=1)
|
||||
public boolean b2 = true;
|
||||
};
|
||||
|
||||
byte[] data = BinaryStructOutputStream.serialize(struct);
|
||||
assertArrayEquals(new byte[]{(byte)0b0100_0000}, data);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void basicStringTest() throws IOException {
|
||||
BinaryStruct struct = new BinaryStruct() {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue