Beispiel #1
0
        public void Serialize(Stream stream, BinarySerialization.Endianness endianness, BinarySerializationContext context)
        {
            var writer = new BinaryWriter(stream);

            var value = Value;

            do
            {
                var lower7Bits = (byte)(value & 0x7f);
                value >>= 7;
                if (value > 0)
                {
                    lower7Bits |= 128;
                }
                writer.Write(lower7Bits);
            } while (value > 0);
        }
Beispiel #2
0
        public void Deserialize(Stream stream, BinarySerialization.Endianness endianness, BinarySerializationContext context)
        {
            var reader = new BinaryReader(stream);

            bool more  = true;
            int  shift = 0;

            Value = 0;

            while (more)
            {
                int b = reader.ReadByte();

                if (b == -1)
                {
                    throw new InvalidOperationException("Reached end of stream before end of varuint.");
                }

                var lower7Bits = (byte)b;
                more   = (lower7Bits & 128) != 0;
                Value |= (uint)((lower7Bits & 0x7f) << shift);
                shift += 7;
            }
        }
Beispiel #3
0
 public void Deserialize(Stream stream, BinarySerialization.Endianness endianness, BinarySerializationContext serializationContext)
 {
 }