public byte[] SerializeWithHeader(APINetworkPacket packet)
        {
            using (var ms = new MemoryStream())
                using (var writer = new BinaryWriter(ms))
                {
                    writer.Write(0);
                    writer.Write((int)packet.Type);
                    Serializer.Serialize(ms, packet);

                    ms.Position = 0;
                    writer.Write((int)ms.Length);

                    ms.Position = ms.Length;
                    return(ms.ToArray());
                }
        }
Esempio n. 2
0
        public byte[] SerializeWithHeader(APINetworkPacket packet)
        {
            using (var ms = new MemoryStream())
            using (var writer = new BinaryWriter(ms))
            {
                writer.Write(0);
                writer.Write((int)packet.Type);
                Serializer.Serialize(ms, packet);
                
                ms.Position = 0;
                writer.Write((int)ms.Length);

                ms.Position = ms.Length;
                return ms.ToArray();
            }
        }
Esempio n. 3
0
 public void SendPacket(APINetworkPacket packet)
 {                        
     SendPacket(serializer.SerializeWithHeader(packet));         
 }
Esempio n. 4
0
 private void OnPacketReceived(APINetworkPacket packet)
 {
     var h = PacketReceived;
     if (h != null)
         EventHandler.RiseSafely(() => h(packet));
 }