Ejemplo n.º 1
0
        /// <summary>
        /// 将数据序列化成Byte[]数组
        /// </summary>
        /// <returns></returns>
        public byte[] ToBuffer()
        {
            byte[] data = SerHelper.Serialize(_data);
            byte[] id   = BitConverter.GetBytes(MessageId);

            byte[] buffer = new byte[data.Length + id.Length];
            Buffer.BlockCopy(id, 0, buffer, 0, id.Length);
            Buffer.BlockCopy(data, 0, buffer, id.Length, data.Length);
            return(buffer);
        }
Ejemplo n.º 2
0
 /// <summary>
 /// 将Byte[]数组反序列化成数据结构
 /// </summary>
 /// <param name="buffer"></param>
 public void FromBuffer(byte[] buffer)
 {
     _messageId = BitConverter.ToInt32(buffer, 0);
     _data      = SerHelper.Deserialize(buffer, 4);
 }