Exemplo n.º 1
0
        public override WunderPacket CreateFromBytes(byte[] bytes, ref int offset)
        {
            //if (bytes.Length - offset >= this.PacketSize)
            //Because the size of this packet is variable.. checking the size doesn't work
            try
            {
                int tempoffset             = offset + DATAOFFSET;
                WunderPacketVariable newwp = this.CreateNew() as WunderPacketVariable;

                //First field is the count of fields that were sent
                tempoffset = newwp.OrderdedFields[0].SetBytes(bytes, tempoffset);
                byte count = (byte)newwp.Get("VariableCount");

                //Byte - FieldID
                //Bytes=>TheField;
                for (int f = 0; f < count; ++f)
                {
                    int fieldID = (bytes[tempoffset++] + 1) * 2;
                    if (fieldID < OrderdedFields.Count)
                    {
                        tempoffset = newwp.OrderdedFields[fieldID].SetBytes(bytes, tempoffset);
                    }
                }
                offset = tempoffset;
                return(newwp);
            }
            catch
            {
                //Couldn't set the bytes
            }

            return(null);
        }
Exemplo n.º 2
0
        public override WunderPacket CreateNew()
        {
            var clone = new WunderPacketVariable
            {
                Name    = this.Name,
                ID      = this.ID,
                Version = this.Version
            };

            //Skip VariableCount
            for (int k = 1; k < this.OrderdedFields.Count; ++k)
            {
                clone.AddField(this.OrderdedFields[k].Name, this.OrderdedFields[k].CreateNew());
            }
            return(clone);
        }
Exemplo n.º 3
0
        public WunderLayer(string xmldescription)
        {
            Packets packets = GenericXMLTools.ReadXML <Packets>(xmldescription);

            Console.WriteLine("VERSION: " + packets.Version);
            if (packets.PacketList != null)
            {
                Int16 ids = 0;
                foreach (var p in packets.PacketList)
                {
                    //Console.WriteLine(p.ToString() +"\n");
                    WunderPacket wp;
                    bool         isVariable = p.PacketType == "Variable";
                    if (isVariable)
                    {
                        wp = new WunderPacketVariable()
                        {
                            Name = p.Name, PacketType = p.PacketType, ID = ids++, Version = Convert.ToInt32(packets.Version)
                        };
                    }
                    else
                    {
                        wp = new WunderPacket()
                        {
                            Name = p.Name, PacketType = p.PacketType, ID = ids++, Version = Convert.ToInt32(packets.Version)
                        };
                    }

                    foreach (var f in p.FieldList)
                    {
                        wp.AddFieldDefinition(f.Name, f.Type, f.Size);
                    }
                    PacketDefinitions.Add(p.Name, wp);
                    OrderedDefinitions.Add(wp);
                }
            }
        }