private void Execute(Pmd.ForwardNullUserPmd_CS cmd) { var raw = VarlenProtobufCommandSerializer.Instance().Deserialize(cmd); msgIndex = cmd.seq; PushCmd(raw); }
// 网络包解析 在网络接收线程中调用,注意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(); }
private void OnPackage(Pmd.ForwardNullUserPmd_CS package) { if (package == null) { return; } // 网络解析包 PushCmd(package); }
// 包解析 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); }
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); }
public void OnReceive(Engine.PackageIn msg) { Pmd.ForwardNullUserPmd_CS package = Pmd.ForwardNullUserPmd_CS.DeserializeLengthDelimited(msg); OnPackage(package); DispatchMessage(); }