Bug in parsing of stringj written in MSB0
mcsezhj opened this issue · 5 comments
Hi developer:
I use JBBP to parse the signals generated from IOT device , the device generate signal in BIG_ENDIAN and MSB0 bitorder:
but when I parse some string from the signal, I got Error result:
the test code is below:
public static void main(String[] args) {
// TODO Auto-generated method stub
long startTime = System.currentTimeMillis();
try {
JBBPOut joparam = JBBPOut.BeginBin(JBBPByteOrder.valueOf("BIG_ENDIAN"), JBBPBitOrder.valueOf("MSB0"));
joparam.String("zzzz").Align();
joparam.Int(10).Align();
byte[] joparamarray = joparam.End().toByteArray();
System.out.println("the generate byte str is : ");
System.out.println("--------------------------------");
System.out.println(JBBPUtils.bin2str(joparamarray, true));
System.out.println("--------------------------------");
final JBBPParser tcpParser = JBBPParser.prepare(
"stringj fin;"
+ "int cot;"
, JBBPBitOrder.valueOf("MSB0"));
final JBBPFieldStruct bitflds =tcpParser.parse(joparamarray);
String finstr=bitflds.findFieldForNameAndType("fin", JBBPFieldString.class).getAsString();
System.out.println("but the parsed str is : ");
System.out.println("--------------------------------");
System.out.println(finstr);
System.out.println(bitflds.findFieldForNameAndType("cot", JBBPFieldInt.class).getAsInt());
System.out.println("--------------------------------");
System.out.println("the parsed 'zzzz' binary code is :");
System.out.println("--------------------------------");
System.out.println(JBBPUtils.bin2str(finstr.getBytes(),true));
System.out.println("--------------------------------");
long endTime = System.currentTimeMillis();
System.out.println("Full running:" + (endTime - startTime) + "ms");
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
and the test result is below:
the generate byte str is :
00100000 01111010 01111010 01111010 01111010 00000000 00000000 00000000 01010000
but the parsed str is :
^^^^
10
the parsed 'zzzz' binary code is :
01011110 01011110 01011110 01011110
Full running:98ms
I noticed the binary code of "zzzz" is "01111010 01111010 01111010 01111010", but when I parse use MSB0 , it get the wrong result - '^^^^'.
if I use LSB0 in generater and parser , the result is correct.
but the real request is : the device generate signal in MSB0 bit order.
would you give me some advise to get the correct result ?
thanks a lot !
Hello
it's a bug, I will fix
I made fix, if all is ok then tomorrow will make maintenance release
thank you for your quickly fix
would you pls give me a temporay fixed jar file ?
here is fixed jar (inside zip)
jbbp2.0.1-SNAPSHOT-fix26.zip
tested, good job. thank you very much .