From fc08466bbe495a363ac840f93511d970715c504e Mon Sep 17 00:00:00 2001
From: whycq <whycq>
Date: 星期一, 21 二月 2022 13:17:23 +0800
Subject: [PATCH] #css 修改176
---
src/main/java/com/zy/common/utils/Struct.java | 12 +++++++++---
1 files changed, 9 insertions(+), 3 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..0ee0939 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();
@@ -365,10 +370,12 @@
instance.unusedBytes = unusedBytes;
return (T) instance;
}
+
+ // 瀛楄妭鏁扮粍 ===>> 杞负鍗佸叚杩涘埗瀛楃涓�
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();
}
@@ -439,7 +446,6 @@
}
return bbt;
}
-
public static class TestMessage {
public @size(1) byte begin = 0x7e;//璧峰绗�
--
Gitblit v1.9.1