/// <summary>
        /// 消息体反序列化
        /// </summary>
        /// <param name="value"></param>
        /// <returns></returns>
        public static object decode(byte[] value)
        {
            ByteArray   ba    = new ByteArray(value);
            SocketModel model = new SocketModel();
            byte        type;
            int         area;
            int         command;

            //从数据中读取 三层协议  读取数据顺序必须和写入顺序保持一致
            ba.read(out type);
            ba.read(out area);
            ba.read(out command);
            model.type    = type;
            model.area    = area;
            model.command = command;
            //判断读取完协议后 是否还有数据需要读取 是则说明有消息体 进行消息体读取
            if (ba.Readnable)
            {
                byte[] message;
                //将剩余数据全部读取出来
                ba.read(out message, ba.Length - ba.Position);
                //反序列化剩余数据为消息体
                model.message = SerializeUtil.decode(message);
            }
            ba.Close();
            return(model);
        }
示例#2
0
        /// <summary>
        /// 消息体反序列化
        /// </summary>
        /// <param name="value"></param>
        /// <returns></returns>
        public static object Decode(byte[] value)
        {
            ByteArray   ba    = new ByteArray(value);
            SocketModel model = new SocketModel();
            byte        type;
            int         area;
            int         command;

            //从流数据中读取三层协议 读取顺序和写入顺序一致
            ba.read(out type);
            ba.read(out area);
            ba.read(out command);
            model.type    = type;
            model.area    = area;
            model.command = command;
            //判断读完 协议后,是否还有数据需要读取 有则说明有消息体
            if (ba.Readable)
            {
                byte[] message;
                //将剩余数据读出
                ba.read(out message, ba.Length - ba.Position);
                //反序列化数据
                model.message = SerializeUtil.decode(message);
            }
            ba.Close();
            return(model);
        }