Exemplo n.º 1
0
    /// <summary>
    /// 添加数据到发送队列
    /// </summary>
    /// <param name="c2g">消息主体</param>
    /// <param name="isPrevent">是否显示loading</param>
    public void AddSendMessageQueue(C2GMessage c2g, bool isPrevent = false)
    {
        if (!PageManager.Instance.isCanSend)
        {
            return;
        }

        if (isPrevent && mSocket.Connected)
        {
            LoadingNode.OpenLoadingNode(LoadingType.Common);
        }
        c2g.testLogicId = testLogicId;
        byte[] bytes = BuildPackage(c2g);
        if (sendList.Count > 0)
        {
            if (!sendList.Contains(bytes))
            {
                sendList.Add(bytes);
            }
            else
            {
                UIUtils.Log("消息重复");
            }
        }
        else
        {
            sendList.Add(bytes);
        }
        if (c2g.msgid != MessageId.C2G_HeartBeat)
        {
            UIUtils.Log("发送消息:" + c2g.msgid.ToString());
        }
    }
Exemplo n.º 2
0
    /// <summary>
    /// 构建消息数据包
    /// </summary>
    /// <param name="protobufModel"></param>
    /// <param name="messageId"></param>
    byte[] BuildPackage(C2GMessage c2g)
    {
        byte[]     b   = ProtobufSerilizer.Serialize(c2g);
        ByteBuffer buf = ByteBuffer.Allocate(b.Length + 3);

        buf.WriteShort((short)(b.Length));
        //TODO 对预留字节的处理
        buf.WriteByte(new byte());
        buf.WriteBytes(b);
        return(buf.GetBytes());
    }