示例#1
0
        public void ReadString_NotAscii()
        {
            var ms     = new MemoryStream(new byte[] { 1, 0xFF });
            var reader = new WireReader(ms);

            reader.ReadString();
        }
示例#2
0
        public void BufferOverflow_String()
        {
            var ms     = new MemoryStream(new byte[] { 10, 1 });
            var reader = new WireReader(ms);

            ExceptionAssert.Throws <EndOfStreamException>(() => reader.ReadString());
        }
示例#3
0
 /// <inheritdoc />
 public override void ReadData(WireReader reader, int length)
 {
     while (length > 0)
     {
         var s = reader.ReadString();
         Strings.Add(s);
         length -= Encoding.UTF8.GetByteCount(s) + 1;
     }
 }
示例#4
0
        public void NullDomainName_Class()
        {
            var ms     = new MemoryStream();
            var writer = new WireWriter(ms);

            writer.WriteDomainName((DomainName)null);
            writer.WriteString("abc");

            ms.Position = 0;
            var reader = new WireReader(ms);

            Assert.AreEqual("", reader.ReadDomainName());
            Assert.AreEqual("abc", reader.ReadString());
        }
示例#5
0
        public void LengthPrefixedScope()
        {
            var ms     = new MemoryStream();
            var writer = new WireWriter(ms);

            writer.WriteString("abc");
            writer.PushLengthPrefixedScope();
            writer.WriteDomainName("a");
            writer.WriteDomainName("a");
            writer.PopLengthPrefixedScope();

            ms.Position = 0;
            var reader = new WireReader(ms);

            Assert.AreEqual("abc", reader.ReadString());
            Assert.AreEqual(5, reader.ReadUInt16());
            Assert.AreEqual("a", reader.ReadDomainName());
            Assert.AreEqual("a", reader.ReadDomainName());
        }
示例#6
0
        public void Roundtrip()
        {
            var someBytes = new byte[] { 1, 2, 3 };
            var someDate  = new DateTime(1997, 1, 21, 3, 4, 5, DateTimeKind.Utc);

            var ms     = new MemoryStream();
            var writer = new WireWriter(ms);

            writer.WriteDomainName("emanon.org");
            writer.WriteString("alpha");
            writer.WriteTimeSpan32(TimeSpan.FromHours(3));
            writer.WriteUInt16(ushort.MaxValue);
            writer.WriteUInt32(uint.MaxValue);
            writer.WriteUInt48(0XFFFFFFFFFFFFul);
            writer.WriteBytes(someBytes);
            writer.WriteByteLengthPrefixedBytes(someBytes);
            writer.WriteByteLengthPrefixedBytes(null);
            writer.WriteIPAddress(IPAddress.Parse("127.0.0.1"));
            writer.WriteIPAddress(IPAddress.Parse("2406:e001:13c7:1:7173:ef8:852f:25cb"));
            writer.WriteDateTime32(someDate);
            writer.WriteDateTime48(someDate);

            ms.Position = 0;
            var reader = new WireReader(ms);

            Assert.AreEqual("emanon.org", reader.ReadDomainName());
            Assert.AreEqual("alpha", reader.ReadString());
            Assert.AreEqual(TimeSpan.FromHours(3), reader.ReadTimeSpan32());
            Assert.AreEqual(ushort.MaxValue, reader.ReadUInt16());
            Assert.AreEqual(uint.MaxValue, reader.ReadUInt32());
            Assert.AreEqual(0XFFFFFFFFFFFFul, reader.ReadUInt48());
            CollectionAssert.AreEqual(someBytes, reader.ReadBytes(3));
            CollectionAssert.AreEqual(someBytes, reader.ReadByteLengthPrefixedBytes());
            CollectionAssert.AreEqual(new byte[0], reader.ReadByteLengthPrefixedBytes());
            Assert.AreEqual(IPAddress.Parse("127.0.0.1"), reader.ReadIPAddress());
            Assert.AreEqual(IPAddress.Parse("2406:e001:13c7:1:7173:ef8:852f:25cb"), reader.ReadIPAddress(16));
            Assert.AreEqual(someDate, reader.ReadDateTime32());
            Assert.AreEqual(someDate, reader.ReadDateTime48());
        }
示例#7
0
 /// <inheritdoc />
 public override void ReadData(WireReader reader, int length)
 {
     Cpu = reader.ReadString();
     OS  = reader.ReadString();
 }