raydac/java-binary-block-parser

New feature: support for strings

mmindenhall opened this issue · 2 comments

Hi Igor,

Have you thought about how best to handle Strings within the binary data? I realize this could be done with a JBBPCustomFieldTypeProcessor implementation, but it seems like a common enough use case to warrant inclusion in the DSL. For example, in the binary data I'm currently working with, there are things like serial numbers or vehicle identification numbers encoded as ASCII strings within the binary message. Usually there's a length indicator (ubyte), followed by the ASCII encoded data. Of course, it would be good to include an option on the JBBPParser to specify the character set you want to use when parsing the string type (defaulting to UTF-8, which should work most of the time). The "extra data" could be used to indicate the length of the string. For example:

serial_number {
  ubyte length;
  str:(length);
}

As always, I'm willing to help in whatever way I can.

Hi Mark
JBBP works with strings on the level of data mapping to class fields (byte arrays and short arrays mapped to string will be converted in string ) and JBBPOut (string will be written as byte array or short array), I think that's enough for the present, thank you very much for your proposals, the best help for the project is to use it and notify me about possible use cases and ideas :)

Hi Igor,
I now have the key pieces I need working:

  • strings (str:(length)) via a custom type processor
  • packed decimal (bcd:(length) or sbcd:(length)) via a custom type processor
  • conversion to Map<String, Object> as intermediate step to JSON via a utility class

Thanks for the suggestions and additional tests you wrote to demonstrate how to do this.