Skip to content

Commit

Permalink
Merge f9462cc into 9c2e77a
Browse files Browse the repository at this point in the history
  • Loading branch information
dmitrybugakov authored Sep 4, 2023
2 parents 9c2e77a + f9462cc commit e5800d5
Showing 1 changed file with 14 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -35,18 +35,23 @@ public BinaryDeserializer(BuffedReader buffedReader, boolean enableCompress) {
switcher = new Switcher<>(compressedReader, buffedReader);
}

/**
* Reads VarInt from binary stream; uses lower 7 bits for value, 8th bit as continuation flag.
*
* @return Parsed VarInt.
* @throws IOException On read error.
*/
public long readVarInt() throws IOException {
int number = 0;
for (int i = 0; i < 9; i++) {
int byt = switcher.get().readBinary();

number |= (byt & 0x7F) << (7 * i);

if ((byt & 0x80) == 0) {
break;
long result = 0;
for (int i = 0; i < 10; i++) {
int currentByte = switcher.get().readBinary();
long valueChunk = currentByte & 0x7F;
result |= (valueChunk << (7 * i));
if ((currentByte & 0x80) == 0) {
return result;
}
}
return number;
throw new IOException("Malformed VarInt: too long");

Check warning on line 54 in clickhouse-native-jdbc/src/main/java/com/github/housepower/serde/BinaryDeserializer.java

View check run for this annotation

Codecov / codecov/patch

clickhouse-native-jdbc/src/main/java/com/github/housepower/serde/BinaryDeserializer.java#L54

Added line #L54 was not covered by tests
}

@SuppressWarnings("PointlessBitwiseExpression")
Expand Down

0 comments on commit e5800d5

Please sign in to comment.