raydac/java-binary-block-parser

Support for float in JBBPNumericField

sebastienmegnin opened this issue · 5 comments

Hello,
JBBPNumericField does not to implement float Type ( getAsfloat() ).
This seems to be mandatory before writing custom type processor for float values ?

is this analysis correct ?

thks

Hi
I didn't implement float and double because in java they can be represented as integer (float) and long (double) and just can be converted with Float#intBitsToFloat and Double#longBitsToDouble

Hi understood ! But in my use case ( online binary decoder as a service ), I want my user to inject via APIs the grammar DSL, and the decoder will be available online to generate a decoded Json. My system can't guess the output format if int and float share the same grammar.
this maybe explains the use case : http://blog.xebia.fr/wp-content/uploads/2016/03/Screen-Shot-2016-02-28-at-15.02.28.png

as I see you have implemented your own JBBPCustomFieldTypeProcessor for float values, it returns JBBPAbstractField object for parsed one (and implements parsing logic)
you can make your own copies of JBBPFieldInt and JBBPFieldLong (they are final ones for speed and you have just to make copy paste), make something like JBBPFieldFloat and JBBPFieldDouble (and also their array variants) and implement getAsFloat and getAsDouble methods which you need, then just return your objects from JBBPCustomFieldTypeProcessor and type of object can be recognized with 'instanceof'

Thanks. I have written my own processor, it works fine, I will have a look at your code.
We have also implemented Json result generator on top of GSON.
regards