示例#1
0
        public void Roundtrip()
        {
            var opt1     = new OPTRecord();
            var expected = new UnknownEdnsOption
            {
                Type = EdnsOptionType.ExperimentalMin,
                Data = new byte[] { 10, 11, 12 }
            };

            opt1.Options.Add(expected);

            var opt2   = (OPTRecord) new ResourceRecord().Read(opt1.ToByteArray());
            var actual = (UnknownEdnsOption)opt2.Options[0];

            Assert.AreEqual(expected.Type, actual.Type);
            CollectionAssert.AreEqual(expected.Data, actual.Data);
        }
示例#2
0
        /// <inheritdoc />
        public override void ReadData(WireReader reader, int length)
        {
            var end = reader.Position + length;

            while (reader.Position < end)
            {
                var type    = (EdnsOptionType)reader.ReadUInt16();
                int olength = reader.ReadUInt16();

                EdnsOption option;
                if (EdnsOptionRegistry.Options.TryGetValue(type, out Func <EdnsOption> maker))
                {
                    option = maker();
                }
                else
                {
                    option = new UnknownEdnsOption {
                        Type = type
                    };
                }
                Options.Add(option);
                option.ReadData(reader, olength);
            }
        }