Domanda

I am using Preon to encode enum fields in a byte array.

The fields of the first byte (example-byte: 0xf7=1111 01 11) are set up as this:

@BoundNumber(size="2") //Corresponds to 11
private byte b1_1_notUsed;

@BoundNumber(size="2") //Corresponds to 01
private ParkingBrakeSwitch parkingBrakeSwitch;

@BoundNumber(size="4")
private byte b1_3_notUsed; //Corresponds to 1111

Decoding works fine, thus I expect encoding the decoded object back to a byte array will yield the same byte array that I had from the beginning. This is not the case however. Instead the bits in the first byte are encoded like this:

0xdf=11 01 1111

That is, the segments are encoded in the reverse order! Why doesn't decode-encode return the same byte array? What do I have to do? Is there some kind of order annotation that I am missing?

Thankful for reply, because Preon documentation seems scarce!

È stato utile?

Soluzione

Question resolved.

The describing class did not take into account the byte order. Foolishly I did not consider the byte-order to be an issue within the bits in the byte itself. But this is obviously the case:

Example-byte: 0xf7=1111 01 11 (Big Endian: MSB first)

@BoundNumber(size="4", byteOrder=ByteOrder.BigEndian) //Corresponds to 1111
private byte b1_3_notUsed;

@BoundNumber(size="2", byteOrder=ByteOrder.BigEndian) //Corresponds to 01
private ParkingBrakeSwitch parkingBrakeSwitch;

@BoundNumber(size="2", byteOrder=ByteOrder.BigEndian) //Corresponds to 11
private byte b1_1_notUsed;

Now encoding returns 0xf7=1111 01 11 again when it has been re-encoded.

Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top