Пример #1
0
        private static ulong ReadRawVarInt64(SpanReader buf, int maxSize, bool printBytes = false)
        {
            List <byte> bytes = new List <byte>();

            ulong result = 0;
            int   j      = 0;
            int   b0;

            do
            {
                b0 = buf.ReadByte();                 // -1 if EOS
                bytes.Add((byte)b0);
                if (b0 < 0)
                {
                    throw new EndOfStreamException("Not enough bytes for VarInt");
                }

                result |= (ulong)(b0 & 0x7f) << j++ *7;

                if (j > maxSize)
                {
                    throw new OverflowException("VarInt too big");
                }
            } while ((b0 & 0x80) == 0x80);

            //byte[] byteArray = bytes.ToArray();

            return(result);
        }
Пример #2
0
        private static uint ReadRawVarInt32(SpanReader buf, int maxSize)
        {
            uint result = 0;
            int  j      = 0;
            int  b0;

            do
            {
                b0 = buf.ReadByte();                 // -1 if EOS
                if (b0 < 0)
                {
                    throw new EndOfStreamException("Not enough bytes for VarInt");
                }

                result |= (uint)(b0 & 0x7f) << j++ *7;

                if (j > maxSize)
                {
                    throw new OverflowException("VarInt too big");
                }
            } while ((b0 & 0x80) == 0x80);

            return(result);
        }
Пример #3
0
 public static ulong ReadUInt64(SpanReader stream)
 {
     return(ReadRawVarInt64(stream, 10));
 }
Пример #4
0
 public static long ReadSInt64(SpanReader stream)
 {
     return(DecodeZigZag64(ReadRawVarInt64(stream, 10)));
 }
Пример #5
0
 public static long ReadInt64(SpanReader stream, bool printBytes = false)
 {
     return((long)ReadRawVarInt64(stream, 10, printBytes));
 }
Пример #6
0
 public static uint ReadUInt32(SpanReader stream)
 {
     return(ReadRawVarInt32(stream, 5));
 }
Пример #7
0
 public static int ReadSInt32(SpanReader stream)
 {
     return(DecodeZigZag32(ReadRawVarInt32(stream, 5)));
 }
Пример #8
0
 public static int ReadInt32(SpanReader stream)
 {
     return((int)ReadRawVarInt32(stream, 5));
 }