Пример #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);
        }