Preon解码然后编码不会返回相同的字节数组 [英] Preon decode and then encode doesn't return the same byte array

查看:165
本文介绍了Preon解码然后编码不会返回相同的字节数组的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用Preon对字节数组中的枚举字段进行编码。

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

第一个字节的字段(示例字节:0xf7 = 1111 01 11)已设置就像这样:

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

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?

感谢您的答复,因为Preon文档似乎很稀缺!

Thankful for reply, because Preon documentation seems scarce!

推荐答案

问题已解决。

描述类未考虑字节顺序。愚蠢地,我不认为字节顺序是字节本身中的位的问题。但这显然是这种情况:

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:

示例字节:0xf7 = 1111 01 11(Big Endian:首先是MSB)

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;

现在编码在重新编码后会再次返回0xf7 = 1111 01 11。

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

这篇关于Preon解码然后编码不会返回相同的字节数组的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆