示例#1
0
 /// <summary>
 /// 构造消息包
 /// </summary>
 /// <param name="head">消息头</param>
 /// <param name="body">消息体</param>
 public Packet(Packet_Head head, Packet_Body body)
 {
     this.m_Head = head;
     this.m_Body = body;
     byte[] headbuffer = this.m_Head.ToByteArray();
     byte[] bodybuffer = this.m_Body.ToByteArray();
     this.m_PacketBuffer = new byte[headbuffer.Length + bodybuffer.Length];
     headbuffer.CopyTo(this.m_PacketBuffer, 0);
     bodybuffer.CopyTo(this.m_PacketBuffer, headbuffer.Length);
     this.IsValidPacket = true;
 }
示例#2
0
        /// <summary>
        /// 构造消息包
        /// </summary>
        /// <param name="packet">消息包</param>
        /// <param name="packet_size">消息包长度</param>
        public Packet(byte[] packet, uint packet_size)
        {
            if (packet == null || packet.Length < 16 || packet.Length != packet_size)
            {
                return;
            }
            this.m_PacketBuffer = packet;
            this.m_uiPacketLen  = packet_size;
            uint headlen = Packet_Head.HEAD_LENGTH, bodylen = this.m_uiPacketLen - Packet_Head.HEAD_LENGTH;

            byte[] head = new byte[headlen];
            System.Array.Copy(this.m_PacketBuffer, 0, head, 0, headlen);
            this.m_Head = new Packet_Head(head, headlen);

            byte[] body = new byte[bodylen];
            if (this.m_uiPacketLen > headlen)
            {
                System.Array.Copy(this.m_PacketBuffer, headlen, body, 0, bodylen);
            }
            this.m_Body        = new Packet_Body(body, bodylen);
            this.IsValidPacket = true;
        }
示例#3
0
        public void parseMsg(byte[] mesPacket)
        {
            Message     msg     = null;
            Packet      packet  = null;
            Packet_Head mesHead = null;
            Packet_Body mesBody = null;

            try
            {
                //Message.Common_ACCOUNT_AUTHOR_RESP(
                msg = new Message(mesPacket, Convert.ToUInt32(mesPacket.Length));
                msg.GetMessageID();
                packet  = msg.m_packet;
                mesHead = new Packet_Head(packet.m_Head.m_bHeadBuffer, packet.m_Head.m_uiHeadBufferLen);
                mesBody = new Packet_Body(packet.m_Body.m_bBodyBuffer, packet.m_Body.m_uiBodyLen);
                string wiriter = System.Text.Encoding.Default.GetString(mesBody.getTLVByTag(TagName.MAC).m_bValueBuffer);
                Console.WriteLine(wiriter);
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.GMMsg_ErrMessage);
            }
        }