public static IEnumerable <G2Header> EnumerateChildren(G2Header root) { G2Header child = new G2Header(root.Data); while (G2Protocol.ReadNextChild(root, child) == G2ReadResult.PACKET_GOOD) { // set payload pos vars G2Protocol.ReadPayload(child); yield return(child); } }
public static GenericPacket Decode(G2Header root) { var generic = new GenericPacket(); if (G2Protocol.ReadPayload(root)) { generic.Name = UTF8Encoding.UTF8.GetString(root.Data, root.PayloadPos, root.PayloadSize); } foreach (var child in G2Protocol.EnumerateChildren(root)) { if (generic.Data == null) { generic.Data = new Dictionary <string, string>(); } string key = null; string value = null; foreach (var sub in G2Protocol.EnumerateChildren(child)) { if (sub.Name == Packet_Key) { key = UTF8Encoding.UTF8.GetString(sub.Data, sub.PayloadPos, sub.PayloadSize); } else if (sub.Name == Packet_Value) { value = UTF8Encoding.UTF8.GetString(sub.Data, sub.PayloadPos, sub.PayloadSize); } } generic.Data[key] = value; } return(generic); }