Ejemplo n.º 1
0
        private static void ReadPairListMap(ref Dictionary <int, PairList> map, SyncPacket sync, G2Header child)
        {
            if (map == null)
            {
                map = new Dictionary <int, PairList>();
            }

            int      id   = 0;
            PairList list = new PairList();

            foreach (var sub in G2Protocol.EnumerateChildren(child))
            {
                if (sub.Name == ChildPacket_ThreadID)
                {
                    id = BitConverter.ToInt32(sub.Data, sub.PayloadPos);
                }
                else if (sub.Name == ChildPacket_PairList)
                {
                    list = PairList.FromBytes(sub.Data, sub.PayloadPos, sub.PayloadSize);
                }
            }

            map[id] = list;
        }
Ejemplo n.º 2
0
        public static SyncPacket Decode(G2Header root)
        {
            var sync = new SyncPacket();

            foreach (var child in G2Protocol.EnumerateChildren(root))
            {
                switch (child.Name)
                {
                case Packet_FunctionHit:
                    sync.FunctionHits = PacketExts.HashSetFromBytes(child.Data, child.PayloadPos, child.PayloadSize);
                    break;

                case Packet_ExceptionHit:
                    sync.ExceptionHits = PacketExts.HashSetFromBytes(child.Data, child.PayloadPos, child.PayloadSize);
                    break;

                case Packet_ConstructedHit:
                    sync.ConstructedHits = PacketExts.HashSetFromBytes(child.Data, child.PayloadPos, child.PayloadSize);
                    break;

                case Packet_DisposedHit:
                    sync.DisposeHits = PacketExts.HashSetFromBytes(child.Data, child.PayloadPos, child.PayloadSize);
                    break;

                case Packet_NewCalls:
                    sync.NewCalls = PairList.FromBytes(child.Data, child.PayloadPos, child.PayloadSize);
                    break;

                case Packet_CallHits:
                    sync.CallHits = PacketExts.HashSetFromBytes(child.Data, child.PayloadPos, child.PayloadSize);
                    break;

                case Packet_CallStats:
                    sync.CallStats = PacketExts.StatsFromBytes(child.Data, child.PayloadPos, child.PayloadSize);
                    break;

                case Packet_Inits:
                    sync.Inits = PairList.FromBytes(child.Data, child.PayloadPos, child.PayloadSize);
                    break;

                case Packet_NewThreads:
                    if (sync.NewThreads == null)
                    {
                        sync.NewThreads = new Dictionary <int, Tuple <string, bool> >();
                    }

                    int    id    = 0;
                    string name  = null;
                    bool   alive = false;

                    foreach (var sub in G2Protocol.EnumerateChildren(child))
                    {
                        if (sub.Name == ChildPacket_ThreadID)
                        {
                            id = BitConverter.ToInt32(sub.Data, sub.PayloadPos);
                        }
                        else if (sub.Name == ChildPacket_ThreadName)
                        {
                            name = UTF8Encoding.UTF8.GetString(sub.Data, sub.PayloadPos, sub.PayloadSize);
                        }
                        else if (sub.Name == ChildPacket_ThreadAlive)
                        {
                            alive = BitConverter.ToBoolean(sub.Data, sub.PayloadPos);
                        }
                    }

                    sync.NewThreads[id] = new Tuple <string, bool>(name, alive);
                    break;

                case Packet_ThreadChanges:
                    if (sync.ThreadChanges == null)
                    {
                        sync.ThreadChanges = new Dictionary <int, bool>();
                    }

                    int  id2    = 0;
                    bool alive2 = false;

                    foreach (var sub in G2Protocol.EnumerateChildren(child))
                    {
                        if (sub.Name == ChildPacket_ThreadID)
                        {
                            id2 = BitConverter.ToInt32(sub.Data, sub.PayloadPos);
                        }
                        else if (sub.Name == ChildPacket_ThreadAlive)
                        {
                            alive2 = BitConverter.ToBoolean(sub.Data, sub.PayloadPos);
                        }
                    }

                    sync.ThreadChanges[id2] = alive2;
                    break;

                case Packet_NodeThreads:
                    sync.NodeThreads = PairList.FromBytes(child.Data, child.PayloadPos, child.PayloadSize);
                    break;

                case Packet_CallThreads:
                    sync.CallThreads = PairList.FromBytes(child.Data, child.PayloadPos, child.PayloadSize);
                    break;

                case Packet_Threadlines:
                    ReadPairListMap(ref sync.Threadlines, sync, child);
                    break;

                case Packet_ThreadStacks:
                    ReadPairListMap(ref sync.ThreadStacks, sync, child);
                    break;
                }
            }

            return(sync);
        }