Skip to content

Instantly share code, notes, and snippets.

@swankjesse
Last active November 28, 2020 20:07
Show Gist options
  • Save swankjesse/d2766040612459c4e4b54917cb34c0e2 to your computer and use it in GitHub Desktop.
Save swankjesse/d2766040612459c4e4b54917cb34c0e2 to your computer and use it in GitHub Desktop.
public final long readVarint64() throws IOException {
if (this.state != 0 && this.state != 2) {
throw (Throwable)(new ProtocolException("Expected VARINT or LENGTH_DELIMITED but was " + this.state));
} else {
int shift = 0;
for(long result = 0L; shift < 64; shift += 7) {
this.source.require(1L);
int var10001 = this.pos++;
byte b = this.source.readByte();
BlockingSample.Companion var5 = Companion;
int other$iv = 127;
int $i$f$and$wire_grpc_tests = false;
result |= (long)(b & other$iv) << shift;
var5 = Companion;
int other$iv = 128;
$i$f$and$wire_grpc_tests = false;
if ((b & other$iv) == 0) {
this.afterPackableScalar(0);
return result;
}
}
throw (Throwable)(new ProtocolException("WireInput encountered a malformed varint"));
}
}
@Nullable
public final Object readVarint64(@NotNull Continuation $completion) {
Object $continuation;
label71: {
if ($completion instanceof <undefinedtype>) {
$continuation = (<undefinedtype>)$completion;
if ((((<undefinedtype>)$continuation).label & Integer.MIN_VALUE) != 0) {
((<undefinedtype>)$continuation).label -= Integer.MIN_VALUE;
break label71;
}
}
$continuation = new ContinuationImpl($completion) {
// $FF: synthetic field
Object result;
int label;
Object L$0;
int I$0;
long J$0;
@Nullable
public final Object invokeSuspend(@NotNull Object $result) {
this.result = $result;
this.label |= Integer.MIN_VALUE;
return NonBlockingSample.this.readVarint64(this);
}
};
}
Object $result = ((<undefinedtype>)$continuation).result;
Object var12 = IntrinsicsKt.getCOROUTINE_SUSPENDED();
int shift;
long result;
BufferedSource2 var14;
Object var10000;
int var10001;
switch(((<undefinedtype>)$continuation).label) {
case 0:
ResultKt.throwOnFailure($result);
if (this.state != 0 && this.state != 2) {
throw (Throwable)(new ProtocolException("Expected VARINT or LENGTH_DELIMITED but was " + this.state));
}
shift = 0;
result = 0L;
if (shift >= 64) {
throw (Throwable)(new ProtocolException("WireInput encountered a malformed varint"));
}
var14 = this.source;
((<undefinedtype>)$continuation).L$0 = this;
((<undefinedtype>)$continuation).I$0 = shift;
((<undefinedtype>)$continuation).J$0 = result;
((<undefinedtype>)$continuation).label = 1;
if (var14.require(1L, (Continuation)$continuation) == var12) {
return var12;
}
var10001 = this.pos++;
var14 = this.source;
((<undefinedtype>)$continuation).L$0 = this;
((<undefinedtype>)$continuation).I$0 = shift;
((<undefinedtype>)$continuation).J$0 = result;
((<undefinedtype>)$continuation).label = 2;
var10000 = var14.readByte((Continuation)$continuation);
if (var10000 == var12) {
return var12;
}
break;
case 1:
result = ((<undefinedtype>)$continuation).J$0;
shift = ((<undefinedtype>)$continuation).I$0;
this = (NonBlockingSample)((<undefinedtype>)$continuation).L$0;
ResultKt.throwOnFailure($result);
var10001 = this.pos++;
var14 = this.source;
((<undefinedtype>)$continuation).L$0 = this;
((<undefinedtype>)$continuation).I$0 = shift;
((<undefinedtype>)$continuation).J$0 = result;
((<undefinedtype>)$continuation).label = 2;
var10000 = var14.readByte((Continuation)$continuation);
if (var10000 == var12) {
return var12;
}
break;
case 2:
result = ((<undefinedtype>)$continuation).J$0;
shift = ((<undefinedtype>)$continuation).I$0;
this = (NonBlockingSample)((<undefinedtype>)$continuation).L$0;
ResultKt.throwOnFailure($result);
var10000 = $result;
break;
default:
throw new IllegalStateException("call to 'resume' before 'invoke' with coroutine");
}
do {
byte b = ((Number)var10000).byteValue();
NonBlockingSample.Companion var6 = Companion;
int other$iv = 127;
int $i$f$and$wire_grpc_tests = false;
result |= (long)(b & other$iv) << shift;
var6 = Companion;
int other$iv = 128;
$i$f$and$wire_grpc_tests = false;
if ((b & other$iv) == 0) {
this.afterPackableScalar(0);
return Boxing.boxLong(result);
}
shift += 7;
if (shift >= 64) {
throw (Throwable)(new ProtocolException("WireInput encountered a malformed varint"));
}
var14 = this.source;
((<undefinedtype>)$continuation).L$0 = this;
((<undefinedtype>)$continuation).I$0 = shift;
((<undefinedtype>)$continuation).J$0 = result;
((<undefinedtype>)$continuation).label = 1;
if (var14.require(1L, (Continuation)$continuation) == var12) {
return var12;
}
var10001 = this.pos++;
var14 = this.source;
((<undefinedtype>)$continuation).L$0 = this;
((<undefinedtype>)$continuation).I$0 = shift;
((<undefinedtype>)$continuation).J$0 = result;
((<undefinedtype>)$continuation).label = 2;
var10000 = var14.readByte((Continuation)$continuation);
} while(var10000 != var12);
return var12;
}
/** Reads a raw varint up to 64 bits in length from the stream. */
@Throws(IOException::class)
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")
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment