in crumb-compiler/src/main/kotlin/com/uber/crumb/internal/wire/ProtoReader.kt [332:350]
fun readVarint64(): Long {
if (state != STATE_VARINT && state != STATE_LENGTH_DELIMITED) {
throw ProtocolException("Expected VARINT or LENGTH_DELIMITED but was $state")
}
var shift = 0
var result: Long = 0
while (shift < 64) {
source.require(1) // Throws EOFException if insufficient bytes are available.
pos++
val b = source.readByte()
result = result or ((b and 0x7F).toLong() shl shift)
if (b and 0x80 == 0) {
afterPackableScalar(STATE_VARINT)
return result
}
shift += 7
}
throw ProtocolException("WireInput encountered a malformed varint")
}