Beispiel #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);
        }
Beispiel #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);
        }
Beispiel #3
0
 public static ulong ReadUInt64(SpanReader stream)
 {
     return(ReadRawVarInt64(stream, 10));
 }
Beispiel #4
0
 public static long ReadSInt64(SpanReader stream)
 {
     return(DecodeZigZag64(ReadRawVarInt64(stream, 10)));
 }
Beispiel #5
0
 public static long ReadInt64(SpanReader stream, bool printBytes = false)
 {
     return((long)ReadRawVarInt64(stream, 10, printBytes));
 }
Beispiel #6
0
 public static uint ReadUInt32(SpanReader stream)
 {
     return(ReadRawVarInt32(stream, 5));
 }
Beispiel #7
0
 public static int ReadSInt32(SpanReader stream)
 {
     return(DecodeZigZag32(ReadRawVarInt32(stream, 5)));
 }
Beispiel #8
0
 public static int ReadInt32(SpanReader stream)
 {
     return((int)ReadRawVarInt32(stream, 5));
 }