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