in java/KinesisAggregator/src/main/java/com/amazonaws/kinesis/agg/AggRecord.java [277:302]
private int calculateVarintSize(long value) {
if (value < 0) {
throw new IllegalArgumentException("Size values should not be negative.");
}
int numBitsNeeded = 0;
if (value == 0) {
numBitsNeeded = 1;
} else {
// shift the value right one bit at a time until
// there are no more '1' bits left...this counts
// how many bits we need to represent the number
while (value > 0) {
numBitsNeeded++;
value = value >> 1;
}
}
// varints only use 7 bits of the byte for the actual value
int numVarintBytes = numBitsNeeded / 7;
if (numBitsNeeded % 7 > 0) {
numVarintBytes += 1;
}
return numVarintBytes;
}