Пример #1
0
 public void Parse(byte[] buffer, int index, int count)
 {
     using (MemoryStream memory = new MemoryStream(buffer, index, count))
         using (STUNBinaryReader binary = new STUNBinaryReader(memory))
         {
             Parse(binary);
         }
 }
Пример #2
0
        public void Parse(STUNBinaryReader binary)
        {
            MessageType = (STUNMessageTypes)binary.ReadUInt16();
            int messageLength = binary.ReadUInt16();

            TransactionID = binary.ReadBytes(16);

            Attributes = new List <STUNAttribute>();

            int attrType;
            int attrLength;
            int paddingLength;

            while ((binary.BaseStream.Position - 20) < messageLength)
            {
                attrType   = binary.ReadUInt16();
                attrLength = binary.ReadUInt16();

                if (attrLength % 4 == 0)
                {
                    paddingLength = 0;
                }
                else
                {
                    paddingLength = 4 - attrLength % 4;
                }

                var type = STUNAttribute.GetAttribute(attrType);

                if (type != null)
                {
                    var attr = Activator.CreateInstance(type) as STUNAttribute;
                    attr.Parse(binary, attrLength);
                    Attributes.Add(attr);
                }
                else
                {
                    binary.BaseStream.Position += attrLength;
                }

                binary.BaseStream.Position += paddingLength;
            }
        }
Пример #3
0
 public abstract void Parse(STUNBinaryReader binary, int length);