From 5d4402a4928a24d7fbb698f7f4f6640967570bff Mon Sep 17 00:00:00 2001 From: vincent <1341870251@qq.com> Date: 星期三, 03 六月 2020 17:04:53 +0800 Subject: [PATCH] # --- src/main/java/com/zy/common/utils/Struct.java | 9 +++++++-- 1 files changed, 7 insertions(+), 2 deletions(-) diff --git a/src/main/java/com/zy/common/utils/Struct.java b/src/main/java/com/zy/common/utils/Struct.java index 9f960a0..1f5adad 100644 --- a/src/main/java/com/zy/common/utils/Struct.java +++ b/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<>(); + // 瑙g爜鍓嶇殑鍘熺敓瀛楄妭鏁扮粍 private transient byte[] dataBytes = null; private transient byte[] decodeBytes = null; private transient byte[] encodeBytes = null; @@ -247,6 +248,9 @@ return instance.decode(bytes); } + /** + * 瑙g爜锛� 瀛楄妭鏁扮粍 ====>> 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銆乥it銆乪xpr娉ㄨВ鐨勫彉閲忎笉杩涜瑙f瀽 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鐨刦ormat鏂规硶杩涜杞崲 - buf.append(String.format("%02x", new Integer(b & 0xff))); + buf.append(String.format("%02x", b & 0xff)); } return buf.toString().toUpperCase(); } -- Gitblit v1.9.1