in Aliyun/Log/protocolbuffers.inc.php [117:148]
public static function read_varint($fp, &$limit = null) {
$value = '';
$len = 0;
do { // Keep reading until we find the last byte
$b = fread($fp, 1);
if ($b === false)
throw new Exception("read_varint(): Error reading byte");
if (strlen($b) < 1)
break;
$value .= $b;
$len++;
} while ($b >= "\x80");
if ($len == 0) {
if (feof($fp))
return false;
throw new Exception("read_varint(): Error reading byte");
}
if ($limit !== null)
$limit -= $len;
$i = 0;
$shift = 0;
for ($j = 0; $j < $len; $j++) {
$i |= ((ord($value[$j]) & 0x7F) << $shift);
$shift += 7;
}
return $i;
}