自动化立体仓库 - WCS系统
#
vincent
2020-06-03 5d4402a4928a24d7fbb698f7f4f6640967570bff
#
1个文件已修改
9 ■■■■ 已修改文件
src/main/java/com/zy/common/utils/Struct.java 9 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/main/java/com/zy/common/utils/Struct.java
@@ -24,6 +24,7 @@
    
    private transient Map<String,byte[]> decodeByteMapping = new HashMap<>();
    private transient Map<String,byte[]> encodeByteMapping = new HashMap<>();
    // 解码前的原生字节数组
    private transient byte[] dataBytes = null;
    private transient byte[] decodeBytes = null;
    private transient byte[] encodeBytes = null;
@@ -247,6 +248,9 @@
        return instance.decode(bytes);
    }
    /**
     * 解码: 字节数组 ====>> java对象
     */
    @SuppressWarnings({ "unchecked", "rawtypes" })
    public <T extends Struct> T decode(byte[] bytes) throws Exception{
        this.dataBytes = bytes;
@@ -254,6 +258,7 @@
        Class<? extends Struct> cls = this.getClass();
        Field[] fields = cls.getFields();
        if(this.decodeByteMapping==null)instance.decodeByteMapping=new HashMap();
        // spring el表达式
        EvaluationContext context = new StandardEvaluationContext();
        context.setVariable("_", bytes.length);
        int bited = 0;//已读位数
@@ -262,9 +267,9 @@
            bit bit = field.getAnnotation(bit.class);
            expr expr = field.getAnnotation(expr.class);
            flag flag = field.getAnnotation(flag.class);
            // 没有size、bit、expr注解的变量不进行解析
            if(size==null && bit==null && expr==null){
                continue;
                //throw new RuntimeException(cls.getSimpleName()+"字段"+field.getName()+"未标记@size|@bit|@expr");
            }
            String name = field.getName();
            Class<?> type = field.getType();
@@ -368,7 +373,7 @@
    public static String toHex(byte[] bytes) {
        StringBuilder buf = new StringBuilder(bytes.length * 2);
        for(byte b : bytes) { // 使用String的format方法进行转换
            buf.append(String.format("%02x", new Integer(b & 0xff)));
            buf.append(String.format("%02x", b & 0xff));
        }
        return buf.toString().toUpperCase();
    }