Beispiel #1
0
        public void TestCustomVarInt()
        {
            {
                var stream = new MemoryStream();
                var bytes  = GetBytes("ff ff ff ff 0f");
                stream.Write(bytes, 0, bytes.Length);
                stream.Position = 0;
                int result = VarInt.ReadInt32(stream);
                Assert.AreEqual(-1, result);

                int t = (int)0x7fffffff;
                t |= 0xff << 1;
                Assert.AreEqual(t | 0x0f << 4 * 7, result);
                Assert.AreEqual(-1, result);

                MemoryStream outstream = new MemoryStream();
                VarInt.WriteInt32(outstream, -1);
                Assert.AreEqual(bytes, outstream.ToArray());
            }
            {
                var stream = new MemoryStream();
                var bytes  = GetBytes("ff ff ff ff ff ff ff ff ff 01");
                stream.Write(bytes, 0, bytes.Length);
                stream.Position = 0;
                long result = VarInt.ReadInt64(stream);
                Assert.AreEqual(-1, result);

                MemoryStream outstream = new MemoryStream();
                VarInt.WriteInt64(outstream, -1);
                Assert.AreEqual(bytes, outstream.ToArray());
            }
        }
Beispiel #2
0
 public long ReadVarLong()
 {
     return(VarInt.ReadInt64(_buffer));
 }