Beispiel #1
0
 private void ParsePacketData(byte[] data)
 {
     try
     {
         using (MemoryStream stream = new MemoryStream(data))
         {
             using (BinaryReader reader = new BinaryReader(stream))
             {
                 Header = new PacketHeader(reader);
                 if (Header.Size > data.Length - reader.BaseStream.Position)
                 {
                     IsValid = false;
                     return;
                 }
                 Data           = new MemoryStream(reader.ReadBytes(Header.Size), 0, Header.Size, false, true);
                 Payload        = new BinaryReader(Data);
                 HeaderOptional = new PacketHeaderOptional(Payload, Header);
                 if (!HeaderOptional.IsValid)
                 {
                     IsValid = false;
                     return;
                 }
             }
         }
         IsValid = true;
     }
     catch (Exception ex)
     {
         IsValid = false;
         packetLog.Error("Invalid packet data", ex);
     }
 }
Beispiel #2
0
 private void ParsePacketData(byte[] data)
 {
     try
     {
         using (var stream = new MemoryStream(data))
         {
             using (var reader = new BinaryReader(stream))
             {
                 Header         = new PacketHeader(reader);
                 Data           = new MemoryStream(reader.ReadBytes(Header.Size), 0, Header.Size, false, true);
                 Payload        = new BinaryReader(Data);
                 HeaderOptional = new PacketHeaderOptional(Payload, Header);
             }
         }
         IsValid = true;
     }
     catch (Exception ex)
     {
         log.Error("Invalid packet data", ex);
     }
 }