Search code examples
javaframeworksbytenibblepreon

Preon framework gathering separated bits (nibbles actually)


A binary stream I'm trying to decode using Preon has a value that is made up of 5 non-consecutive nibbles, for example:

Hex data: 00A00000F200EE0000

Consider that the value has to be extracted from the non zero marked nibbles into AF2EE, is that possible using Preon? If so, can you please provide any hints on such?

PS: Zeroes are just for the example, they don't represent the criteria for choosing which nibbles to extract, as they are fixed position nibbles the ones needed.

Perhaps @wilfred-spinger could assist?


Solution

  • If the nibbles are fixed position, then yes, this is possible. The class fields could look something like this:

     @BoundList(size = "8")
     private byte[] reserved0;
    
     @BoundList(size = "4")
     private byte[] nibble1; // location of A
    
     @BoundList(size = "20")
     private byte[] reserved1;
    
     @BoundList(size = "4")
     private byte[] nibble2; // location of F
    
     @BoundList(size = "4")
     private byte[] nibble3; // location of 2
    
     // etc
    

    I think there might be a way to specify an offset in Preon so you don't have to have fields for the 0-bits, but I can't remember off the top of my head.

    Hope that helps.