public static SocketModel mDecode(byte[] value) { ByteArray ba = new ByteArray(value); SocketModel sm = new SocketModel(); int type; int area; int command; ba.read(out type); ba.read(out area); ba.read(out command); sm.type = type; sm.area = area; sm.command = command; if (ba.Readnable) { byte[] message; ba.read(out message, ba.Length - ba.Position); sm.message = SerializeUtil.decoder(message); } ba.Close(); return(sm); }
private void onData() { //消息体长度为一个4字节数值 长度不足的时候 说明消息未接收完成 或者是废弃消息 if (cache.Count < 4) { isRead = false; return; } byte[] result = ldecode(ref cache); if (result == null) { isRead = false; return; } //转换为传输模型用于使用 SocketModel model = mDecode(result); //将消息存储进消息列表 等待读取 messageList.Add(model); FinRecvEvent(); onData(); }