Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bug in parsing of stringj written in MSB0 #26

Closed
mcsezhj opened this issue Feb 3, 2020 · 5 comments
Closed

Bug in parsing of stringj written in MSB0 #26

mcsezhj opened this issue Feb 3, 2020 · 5 comments
Assignees
Labels

Comments

@mcsezhj
Copy link

mcsezhj commented Feb 3, 2020

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 !

@raydac
Copy link
Owner

raydac commented Feb 3, 2020

Hello
it's a bug, I will fix

@raydac raydac self-assigned this Feb 3, 2020
@raydac raydac added the bug label Feb 3, 2020
@raydac raydac changed the title Pls Help: How to parse String from MSB0 code correctly ? Bug in parsing of stringj written in MSB0 Feb 3, 2020
@raydac
Copy link
Owner

raydac commented Feb 3, 2020

I made fix, if all is ok then tomorrow will make maintenance release

@mcsezhj
Copy link
Author

mcsezhj commented Feb 4, 2020

thank you for your quickly fix
would you pls give me a temporay fixed jar file ?

@raydac
Copy link
Owner

raydac commented Feb 4, 2020

here is fixed jar (inside zip)
jbbp2.0.1-SNAPSHOT-fix26.zip

@mcsezhj
Copy link
Author

mcsezhj commented Feb 5, 2020

tested, good job. thank you very much .

@mcsezhj mcsezhj closed this as completed Feb 5, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants