posted 20 years ago
Here is the example:
let me populate bytearray;
byte bytebuffer[] = new byte[3];
bytebuffer[0]=0x11;
bytebuffer[1]=0xA3;
bytebuffer[2]=0x11;
bytebuffer[3]=0xF3;
This byte array is populated in such a way that first byte and first 4 bits in the 2nd byte contain "id1". lower 4 bits in 2nd byte contain "id2" and third byte contains "id3" and fourth byte contains "id4".
The Java object that should be mapped is like this
// The ExampleObject is like a java bean and byte array should map to this java bean.
ExampleObject {
private short id1;
private byte id2;
private byte id3;
private byte id4;
public setId1(short id1) { this.id1=id1}
...
public short getId1( return id1; }
...
}
I know the byte array and I know the name of the fields and I know the java object, need to figure out the best way to map. Some fields as you can see id1 could not be byte aligned. I can walk through the byte array but is there any other way.
In c++ you can cast struct to the byte stream and you have access to the data fields of structs. Does java offer any convinient way?
Thanks,
Basheer