public static MailHeader Decode(G2Header root) { MailHeader header = new MailHeader(); G2Header child = new G2Header(root.Data); while (G2Protocol.ReadNextChild(root, child) == G2ReadResult.PACKET_GOOD) { if (!G2Protocol.ReadPayload(child)) { continue; } switch (child.Name) { case Packet_Source: header.Source = Utilities.ExtractBytes(child.Data, child.PayloadPos, child.PayloadSize); header.SourceID = Utilities.KeytoID(header.Source); break; case Packet_Target: header.Target = Utilities.ExtractBytes(child.Data, child.PayloadPos, child.PayloadSize); header.TargetID = Utilities.KeytoID(header.Target); break; case Packet_FileKey: header.FileKey = Utilities.ExtractBytes(child.Data, child.PayloadPos, child.PayloadSize); break; case Packet_FileHash: header.FileHash = Utilities.ExtractBytes(child.Data, child.PayloadPos, child.PayloadSize); break; case Packet_FileSize: header.FileSize = BitConverter.ToInt64(child.Data, child.PayloadPos); break; case Packet_SourceVersion: header.SourceVersion = BitConverter.ToUInt32(child.Data, child.PayloadPos); break; case Packet_TargetVersion: header.TargetVersion = BitConverter.ToUInt32(child.Data, child.PayloadPos); break; case Packet_MailID: header.MailID = Utilities.ExtractBytes(child.Data, child.PayloadPos, child.PayloadSize); break; case Packet_ThreadID: header.ThreadID = BitConverter.ToInt32(child.Data, child.PayloadPos); break; case Packet_LocalKey: header.LocalKey = Utilities.ExtractBytes(child.Data, child.PayloadPos, child.PayloadSize); break; case Packet_FileStart: header.FileStart = BitConverter.ToInt64(child.Data, child.PayloadPos); break; case Packet_Read: header.Read = BitConverter.ToBoolean(child.Data, child.PayloadPos); break; case Packet_Received: header.Received = DateTime.FromBinary(BitConverter.ToInt64(child.Data, child.PayloadPos)); break; } } return(header); }
public static MailHeader Decode(G2Header root) { MailHeader header = new MailHeader(); G2Header child = new G2Header(root.Data); while (G2Protocol.ReadNextChild(root, child) == G2ReadResult.PACKET_GOOD) { if (!G2Protocol.ReadPayload(child)) continue; switch (child.Name) { case Packet_Source: header.Source = Utilities.ExtractBytes(child.Data, child.PayloadPos, child.PayloadSize); header.SourceID = Utilities.KeytoID(header.Source); break; case Packet_Target: header.Target = Utilities.ExtractBytes(child.Data, child.PayloadPos, child.PayloadSize); header.TargetID = Utilities.KeytoID(header.Target); break; case Packet_FileKey: header.FileKey = Utilities.ExtractBytes(child.Data, child.PayloadPos, child.PayloadSize); break; case Packet_FileHash: header.FileHash = Utilities.ExtractBytes(child.Data, child.PayloadPos, child.PayloadSize); break; case Packet_FileSize: header.FileSize = BitConverter.ToInt64(child.Data, child.PayloadPos); break; case Packet_SourceVersion: header.SourceVersion = BitConverter.ToUInt32(child.Data, child.PayloadPos); break; case Packet_TargetVersion: header.TargetVersion = BitConverter.ToUInt32(child.Data, child.PayloadPos); break; case Packet_MailID: header.MailID = Utilities.ExtractBytes(child.Data, child.PayloadPos, child.PayloadSize); break; case Packet_ThreadID: header.ThreadID = BitConverter.ToInt32(child.Data, child.PayloadPos); break; case Packet_LocalKey: header.LocalKey = Utilities.ExtractBytes(child.Data, child.PayloadPos, child.PayloadSize); break; case Packet_FileStart: header.FileStart = BitConverter.ToInt64(child.Data, child.PayloadPos); break; case Packet_Read: header.Read = BitConverter.ToBoolean(child.Data, child.PayloadPos); break; case Packet_Received: header.Received = DateTime.FromBinary(BitConverter.ToInt64(child.Data, child.PayloadPos)); break; } } return header; }