コード例 #1
0
    private void Execute(Pmd.ForwardNullUserPmd_CS cmd)
    {
        var raw = VarlenProtobufCommandSerializer.Instance().Deserialize(cmd);

        msgIndex = cmd.seq;
        PushCmd(raw);
    }
コード例 #2
0
 // 网络包解析 在网络接收线程中调用,注意API的使用
 public void ParsePackage(byte[] buff, out List <PackageIn> lstPackage)
 {
     lstPackage = m_lstPackageIn;
     Engine.PackageIn          msg     = new Engine.PackageIn(buff);
     Pmd.ForwardNullUserPmd_CS package = Pmd.ForwardNullUserPmd_CS.Deserialize(msg);
     ParsePackage(package, buff.Length);
     msg.Close();
 }
コード例 #3
0
    private void OnPackage(Pmd.ForwardNullUserPmd_CS package)
    {
        if (package == null)
        {
            return;
        }

        // 网络解析包
        PushCmd(package);
    }
コード例 #4
0
    // 包解析
    private void ParsePackage(Pmd.ForwardNullUserPmd_CS package, int buffLen = 0)
    {
        if (package == null)
        {
            return;
        }

        // 消息解压
        if ((package.bitmask & (uint)Pmd.FrameHeader.Bitmask_Compress) != 0)
        {
            package.bitmask &= ~(uint)Pmd.FrameHeader.Bitmask_Compress; // 去掉压缩标记
            package.data     = Common.ZlibCodec.Decode(package.data);
        }

        // 嵌套打包
        if ((package.bitmask & (uint)Pmd.FrameHeader.Bitmask_Header) != 0)
        {
            package.bitmask &= ~(uint)Pmd.FrameHeader.Bitmask_Header; // 去掉嵌套打包标记

            using (var mem = new MemoryStream(package.data))
            {
                while (mem.Position < mem.Length)
                {
                    var embed = Pmd.ForwardNullUserPmd_CS.DeserializeLengthDelimited(mem);
                    ParsePackage(embed);
                }
                if (mem.Position >= mem.Length)
                {
                    return;
                }
            }
        }

        Engine.PackageIn pack = PackageInPool.Alloc();
        pack.buffLen = buffLen;
        try
        {
            package.SerializeLengthDelimited(pack);
        }
        catch (System.Exception ex)
        {
            //Engine.Utility.Log.Error("");
            //string str = ex.ToString();
        }

        m_lstPackageIn.Add(pack);
    }
コード例 #5
0
    public override void SerializeTo(Stream stream, ProtoBuf.IExtensible message)
    {
        var messageType = this[message.GetType()];
        var package     = new Pmd.ForwardNullUserPmd_CS()
        {
            byCmd   = messageType.Cmd,
            byParam = messageType.Param,
            time    = DateTime.Now.ToUnixTime(),
        };

        using (var buf = new MemoryStream())
        {
            ProtoBuf.Serializer.NonGeneric.SerializeWithLengthPrefix(buf, message, ProtoBuf.PrefixStyle.Base128, 0);
            package.data = buf.ToArray();
        }

        ProtoBuf.Serializer.NonGeneric.SerializeWithLengthPrefix(stream, package, ProtoBuf.PrefixStyle.Base128, 0);
    }
コード例 #6
0
 public void OnReceive(Engine.PackageIn msg)
 {
     Pmd.ForwardNullUserPmd_CS package = Pmd.ForwardNullUserPmd_CS.DeserializeLengthDelimited(msg);
     OnPackage(package);
     DispatchMessage();
 }