Exemple #1
0
        public void MaxLong()
        {
            var x = "ffffffffffffffff7f".ToHexBuffer();

            Assert.AreEqual(9, Varint.RequiredBytes(long.MaxValue));
            CollectionAssert.AreEqual(x, Varint.Encode(long.MaxValue));
            Assert.AreEqual(long.MaxValue, Varint.DecodeInt64(x));
        }
Exemple #2
0
        public void ThreeHundred()
        {
            var x = new byte[] { 0xAC, 0x02 };

            Assert.AreEqual(2, Varint.RequiredBytes(300));
            CollectionAssert.AreEqual(x, Varint.Encode(300));
            Assert.AreEqual(300, Varint.DecodeInt32(x));
        }
Exemple #3
0
        public void Zero()
        {
            var x = new byte[] { 0 };

            Assert.AreEqual(1, Varint.RequiredBytes(0));
            CollectionAssert.AreEqual(x, Varint.Encode(0));
            Assert.AreEqual(0, Varint.DecodeInt32(x));
        }
Exemple #4
0
 public void Example()
 {
     for (long v = 1; v <= 0xFFFFFFFL; v = v << 4)
     {
         Console.Write($"| {v} (0x{v.ToString("x")}) ");
         Console.WriteLine($"| {Varint.Encode(v).ToHexString()} |");
     }
 }
Exemple #5
0
        public void Empty()
        {
            var bytes = new byte[0];

            ExceptionAssert.Throws <EndOfStreamException>(() => Varint.DecodeInt64(bytes));
        }
Exemple #6
0
        public void Unterminated()
        {
            var bytes = "ff".ToHexBuffer();

            ExceptionAssert.Throws <InvalidDataException>(() => Varint.DecodeInt64(bytes));
        }
Exemple #7
0
        public void TooBig_Int64()
        {
            var bytes = "ffffffffffffffffff7f".ToHexBuffer();

            ExceptionAssert.Throws <InvalidDataException>(() => Varint.DecodeInt64(bytes));
        }
Exemple #8
0
        public void TooBig_Int32()
        {
            var bytes = Varint.Encode((long)Int32.MaxValue + 1);

            ExceptionAssert.Throws <InvalidDataException>(() => Varint.DecodeInt32(bytes));
        }
Exemple #9
0
 public void Encode_Negative()
 {
     ExceptionAssert.Throws <NotSupportedException>(() => Varint.Encode(-1));
 }
Exemple #10
0
        public void Decode_From_Offset()
        {
            var x = new byte[] { 0x00, 0xAC, 0x02 };

            Assert.AreEqual(300, Varint.DecodeInt32(x, 1));
        }
Exemple #11
0
        public void Empty()
        {
            var bytes = new byte[0];

            ExceptionAssert.Throws <InvalidDataException>(() => Varint.DecodeInt64(bytes));
        }