From 57d97bbcdac3fab70569fa67ac9b01694af3c302 Mon Sep 17 00:00:00 2001
From: lizhanwei <Dana_Lee1016@126.com>
Date: 星期一, 17 二月 2020 13:34:28 +0800
Subject: [PATCH] 修改NettyTcp;1.增加ByteUtil方法;2,增加服务端通用消息应答;3.增加客户端通用消息应答;4.服务器端消息封装;5,所有平台消息重构放入专用包下;6.所有消息打印TAG为PlatFormMessage 7.增加客户端获取学员信息、鉴权消息 8.MessageProcessor增加解析转义、验证之后的服务消息
---
im_lib/src/main/java/com/anyun/im_lib/util/ByteUtil.java | 33 ++++++++++++++++++++++++++++++++-
1 files changed, 32 insertions(+), 1 deletions(-)
diff --git a/im_lib/src/main/java/com/anyun/im_lib/util/ByteUtil.java b/im_lib/src/main/java/com/anyun/im_lib/util/ByteUtil.java
index 5761069..d871bef 100644
--- a/im_lib/src/main/java/com/anyun/im_lib/util/ByteUtil.java
+++ b/im_lib/src/main/java/com/anyun/im_lib/util/ByteUtil.java
@@ -107,6 +107,7 @@
*/
public static byte[] hexStr2Bytes(String src)
{
+ src = src.replace(" ","");
int m=0,n=0;
int l=src.length()/2;
System.out.println(l);
@@ -184,7 +185,7 @@
}
/**
- * short杞负瀛楄妭鏁扮粍
+ * short杞负瀛楄妭鏁扮粍 澶х
* @param data
* @return 鍖呭惈2涓瓧鑺傜殑瀛楄妭鏁扮粍
*/
@@ -192,6 +193,20 @@
byte[] bytes = new byte[2];
bytes[1] = (byte) (data & 0xff);
bytes[0] = (byte) ((data & 0xff00) >> 8);
+ return bytes;
+ }
+
+ /**
+ * 澶х int 杞垚 4涓瓧鑺傜殑byte鏁扮粍
+ * @param data
+ * @return
+ */
+ public static byte[] intGetBytes(int data) {
+ byte[] bytes = new byte[4];
+ bytes[3] = (byte) ((data & 0xff));
+ bytes[2] = (byte) ((data & 0xff00) >> 8);
+ bytes[1] = (byte) ((data & 0xff0000) >> 16);
+ bytes[0] = (byte) ((data & 0xff000000) >> 24);
return bytes;
}
@@ -217,6 +232,11 @@
System.arraycopy(shortGetBytes((short)3),0,messageBody,22,2);
System.out.println(byte2HexStr(messageBody));
+
+ byte[] bytes =new byte[]{(byte) 0x80};
+ short aShort= getShort(bytes);
+ System.out.println(aShort);
+
}
public static byte[] subArray(byte[] srcBytes, int begin, int length) {
@@ -225,4 +245,15 @@
Log.i(TAG, "subArray: "+byte2HexStr(bytes));
return bytes;
}
+
+ public static short getShort(byte[] bytes) {
+ short s =0;
+ if (bytes.length==1){
+ s|=(bytes[0]&0xff);
+ return s;
+ }
+ s =(short) ((0xff & bytes[1]) | (0xff00 & (bytes[0] << 8)));
+ Log.i(TAG, "getShort: "+s);
+ return s ;
+ }
}
--
Gitblit v1.8.0