ReadPayload() public static method

public static ReadPayload ( G2Header packet ) : bool
packet G2Header
return bool
示例#1
0
        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);
            }
        }
示例#2
0
        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);
        }