コード例 #1
0
        private static ulong ReadRawVarInt64(ref MemorySpan span, int maxSize)
        {
            List <byte> bytes = new List <byte>();

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

            do
            {
                b0 = span.ReadByte();
                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(ref MemorySpan span, int maxSize)
        {
            uint result = 0;
            int  j      = 0;
            int  b0;

            do
            {
                b0 = span.ReadByte();
                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 sbyte ReadSByte(ref MemorySpan span)
 {
     return((sbyte)span.ReadByte());
 }
コード例 #4
0
 public static byte ReadByte(ref MemorySpan span)
 {
     return(span.ReadByte());
 }