我使用Preon Binding来读取传入的二进制数据流。
我们遇到的问题是,某些字段值需要一些简单的算法才能正确表示,因为我们的数据文档"表示:
Preon能否在绑定时支持这样的算法,或者我必须在解码后专门执行此操作(这会使解码的DTO值不一致)?
其他字段(latPositive和lngPositive)为其对应的值(lat和lng字段)提供数学符号(负数或正数),我认为这也可以通过在负数情况下乘以-1来支持,但是只有在Preon实际支持某种算术的情况下才有可能。
映射基本如下:
// ok
@BoundString(size = "1")
private String start;
// ??
@BoundNumber(size = "8")
private short size;
// ok
@BoundNumber(size = "8")
private short header;
// ok
@BoundNumber(size = "56", byteOrder = ByteOrder.BigEndian)
private long imei;
// ok
@BoundNumber(size = "8")
private short mask;
// ok
@BoundNumber(size = "5", byteOrder = ByteOrder.BigEndian)
private short day;
// ok
@BoundNumber(size = "4", byteOrder = ByteOrder.BigEndian)
private short month;
// ok
@BoundNumber(size = "5", byteOrder = ByteOrder.BigEndian)
private short year;
// ok
@BoundNumber(size = "5", byteOrder = ByteOrder.BigEndian)
private short hour;
// ok
@BoundNumber(size = "6", byteOrder = ByteOrder.BigEndian)
private short minute;
// ok
@BoundNumber(size = "6", byteOrder = ByteOrder.BigEndian)
private short second;
@Bound
private boolean latPositive;
@BoundNumber(size = "27", byteOrder = ByteOrder.BigEndian)
private int lat;
@Bound
private boolean lngPositive;
@BoundNumber(size = "28", byteOrder = ByteOrder.BigEndian)
private int lng;
// ok
@BoundNumber(size = "8", byteOrder = ByteOrder.BigEndian)
private int speed;
@BoundNumber(size = "7", byteOrder = ByteOrder.BigEndian)
private int direction;
// ok
@Bound
private boolean gpsFix;
// ok
@BoundNumber(size = "13", byteOrder = ByteOrder.BigEndian)
private int altitude;
// ok
@BoundNumber(size = "20", byteOrder = ByteOrder.BigEndian)
private int odometer;
// ok
@BoundNumber(size = "8", byteOrder = ByteOrder.BigEndian)
private int batteryLevel;
PS:是否有可用的Preon用户邮件列表?
答案 0 :(得分:1)
这可能为时已晚,但我最近一直在挖掘preon,所以我在preon中看到了两种可能性:
a)使用@Init注释指定要在代码中完成的转换,例如
public static class Blah {
@BoundNumber(size="32", byteOrder = ByteOrder.BigEndian)
private int size;
@Init
public void go() {
size = size * 3;
}
}
b)创建一个CodecDecorator(我会复制像InitCodecDecorator一样的东西),它理解如何执行算术,添加正确的注释并将其添加到解码器中,如下所示:http://technofovea.com/blog/archives/850
或者只是添加了解二元合约的getter和setter;