Exemplo n.º 1
0
        private void Parse(TemplatesV10 templates)
        {
            FlowSet = new List <FlowSet>();

            int length = _bytes.Length - 16;

            byte[] header  = new byte[16];
            byte[] flowset = new byte[length];

            Array.Copy(_bytes, 0, header, 0, 16);
            Array.Copy(_bytes, 16, flowset, 0, length);

            Header = new V10Header(header);
            byte[] reverse = flowset.Reverse().ToArray();

            int templenght = 0;

            while ((templenght + 2) < flowset.Length)
            {
                ushort lengths   = BitConverter.ToUInt16(reverse, flowset.Length - sizeof(short) - (templenght + 2));
                byte[] bflowsets = new byte[lengths];
                if (lengths <= flowset.Count())
                {
                    Array.Copy(flowset, templenght, bflowsets, 0, lengths);

                    FlowSet flowsets = new FlowSet(bflowsets, templates, Header.DomainID);
                    FlowSet.Add(flowsets);
                }
                templenght += lengths;
            }
        }
Exemplo n.º 2
0
        private void Parse(TemplatesV10 templates, uint _domain_id)
        {
            byte[] reverse = _bytes.Reverse().ToArray();
            Template  = new SynchronizedCollection <Template>();
            ValueByte = new List <byte>();
            ID        = BitConverter.ToUInt16(reverse, _bytes.Length - sizeof(short) - 0);
            Length    = BitConverter.ToUInt16(reverse, _bytes.Length - sizeof(short) - 2);
            if (ID == 2)
            {
                int address = 6;
                while (address < _bytes.Length)
                {
                    Template template = new Template(_bytes, address, _domain_id);
                    Template.Add(template);
                    bool flag = false;
                    SynchronizedCollection <Template> templs = templates.Templates;
                    for (int i = 0; i < templs.Count; i++)
                    {
                        if (template.ID == templs[i].ID)
                        {
                            flag      = true;
                            templs[i] = template;
                        }
                    }

                    if (flag)
                    {
                        templates.Templates = templs;
                    }
                    else
                    {
                        templates.Templates.Add(template);
                    }

                    address += template.Length + 4;
                }
            }
            else if (ID > 255)
            {
                Template templs = null;

                Template _template = templates.Templates.FirstOrDefault(x => x.ID == ID && x.DomainID == _domain_id);
                if (_template != null)
                {
                    int j = 4, z;
                    templs = DeepClone(_template) as Template;
                    z      = (this.Length - 4) / templs.FieldLength;

                    for (int y = 0; y < z; y++)
                    {
                        foreach (Field fields in templs.Field)
                        {
                            for (int i = 0; i < fields.Length; i++, j++)
                            {
                                fields.Value.Add(this._bytes[j]);
                            }
                        }

                        this.Template.Add(DeepClone(templs) as Template);

                        foreach (Field filds in templs.Field)
                        {
                            filds.Value.Clear();
                        }
                    }
                }
                else
                {
                    for (int i = 4; i < _bytes.Length; i++)
                    {
                        ValueByte.Add(_bytes[i]);
                    }
                }

                foreach (Template templ in templates.Templates)
                {
                    if (templ.ID == ID)
                    {
                        templs = DeepClone(templ) as Template;
                    }
                }
            }
        }
Exemplo n.º 3
0
 public V10Packet(byte[] bytes, TemplatesV10 templates)
 {
     _bytes = bytes;
     Parse(templates);
 }
Exemplo n.º 4
0
 public FlowSet(byte[] bytes, TemplatesV10 templates, uint _domain_id)
 {
     _bytes = bytes;
     Parse(templates, _domain_id);
 }