Esempio n. 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());
            }
        }
Esempio n. 2
0
        public override void WriteTo(BinaryWriter stream)
        {
            byte[] bytes = Encoding.UTF8.GetBytes(Value);
            VarInt.WriteInt32(stream.BaseStream, bytes.Length);

            stream.Write(bytes);
        }
Esempio n. 3
0
        public void WriteTo(BinaryWriter writer)
        {
            Stream stream = writer.BaseStream;

            VarInt.WriteInt32(stream, _entries.Count);
            foreach (var entry in _entries)
            {
                VarInt.WriteInt32(stream, entry.Key);
                VarInt.WriteInt32(stream, entry.Value.Identifier);
                entry.Value.WriteTo(writer);
            }
        }
Esempio n. 4
0
 public void WriteVarInt(int value)
 {
     VarInt.WriteInt32(_buffer, value);
 }