コード例 #1
0
        virtual public void respond(proto_header head, byte[] block)
        {
            if (type != null)
            {
                ProtobufSerializer serializer = new ProtobufSerializer();
                using (MemoryStream temp = new MemoryStream(block, 0, block.Length, true, true))
                {
                    m_rec = serializer.Deserialize(temp, null, type);
                }

                if (m_rec != null)
                {
                    DkRspMsg item = new DkRspMsg();
                    item.head = head;
                    item.body = m_rec;

                    if (isMsgPushQueue)
                    {
                        DkProtoQueue.Instance.push(item);
                    }
                    else
                    {
                        onRspHandler(item);
                    }
                }
                else
                {
                    Debug.LogError("cmd " + head.shMsgID + " deserialize failed, please check !");
                }
            }
            else
            {
                Debug.LogError("cmd " + head.shMsgID + " deserialize type is null !");
            }
        }
コード例 #2
0
 //发送消息主接口.
 public bool SendMessage(proto_header header, MemoryStream data)
 {
     if (m_Writer != null)
     {
         byte[] stream = m_Writer.MakeStream(header, data);
         lock (m_SendQueue)
         {
             if (m_SendQueue.Count == 0)
             {
                 return(Send(stream));
             }
             else
             {
                 m_SendQueue.Enqueue(stream);
                 return(true);
             }
         }
     }
     return(false);
 }