Implementation of Variable length BinaryStruct fields, one TC is failing
This commit is contained in:
parent
e41fe70951
commit
dd1b55106b
8 changed files with 139 additions and 21 deletions
|
|
@ -154,4 +154,25 @@ public class BinaryStructInputStreamTest {
|
|||
}
|
||||
public void write(OutputStream out, String obj, BinaryFieldData field) throws IOException {}
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
public void variableLengthField(){
|
||||
BinaryTestStruct struct = new BinaryTestStruct() {
|
||||
@BinaryField(index=1, length=8)
|
||||
public int i1;
|
||||
@VariableLengthBinaryField(index=2, lengthField="i1")
|
||||
public String s2;
|
||||
|
||||
public void assertObj(){
|
||||
assertEquals(3, i1);
|
||||
assertEquals("123", s2);
|
||||
}
|
||||
};
|
||||
|
||||
byte[] data = "0123456".getBytes();
|
||||
data[0] = 3;
|
||||
BinaryStructInputStream.read(struct, data);
|
||||
struct.assertObj();
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -80,7 +80,7 @@ public class BinaryStructOutputStreamTest {
|
|||
|
||||
|
||||
@Test
|
||||
public void customBinaryField() throws IOException {
|
||||
public void customBinaryFieldTest() throws IOException {
|
||||
BinaryStruct struct = new BinaryStruct() {
|
||||
@BinaryStruct.CustomBinaryField(index=1, serializer=ByteStringSerializer.class)
|
||||
public String s1 = "1234";
|
||||
|
|
@ -98,4 +98,20 @@ public class BinaryStructOutputStreamTest {
|
|||
out.write(Integer.parseInt(""+c));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
public void variableLengthFieldTest() throws IOException {
|
||||
BinaryStruct struct = new BinaryStruct() {
|
||||
@BinaryField(index=1, length=1)
|
||||
private int s1 = 2;
|
||||
@VariableLengthBinaryField(index=2, lengthField="s1")
|
||||
private String s2 = "12345";
|
||||
};
|
||||
|
||||
byte[] data = BinaryStructOutputStream.serialize(struct);
|
||||
byte[] expected = "012".getBytes();
|
||||
expected[0] = 2;
|
||||
assertArrayEquals(expected, data);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue