public static function decodeUnsigned(string $buf, int &$x): int
    {
        $x = 0;
        $s = 0;
        for ($i = 0; $i < strlen($buf); $i++) {
            $b = ord($buf[$i]);
            if ($b < 0x80) {
                if ($i > 9 || $i == 9 && $b > 1) {
                    // overflow
                    $x = 0;
                    return -($i + 1);
                }
                $x = $x | $b << $s;
                return $i + 1;
            }
            $x |= ($b & 0x7f) << $s;
            $s += 7;
        }
        $x = 0;
        return 0;
    }
public static function decodeUnsigned(string $buf, int &$x): int
    {
        $x = 0;
        $s = 0;
        for ($i = 0; $i < strlen($buf); $i++) {
            $b = ord($buf[$i]);
            if ($b < 0x80) {
                if ($i > 9 || $i == 9 && $b > 1) {
                    // overflow
                    $x = 0;
                    return -($i + 1);
                }
                $x = $x | $b << $s;
                return $i + 1;
            }
            $x |= ($b & 0x7f) << $s;
            $s += 7;
        }
        $x = 0;
        return 0;
    }
public static function decodeUnsigned ( string $ buf , int & $ x ) : int { $ x = 0 ; $ s = 0 ; for ( $ i = 0 ; $ i < strlen ( $ buf ) ; $ i ++ ) { $ b = ord ( $ buf [ $ i ] ) ; if ( $ b < 0x80 ) { if ( $ i > 9 || $ i == 9 && $ b > 1 ) { // overflow $ x = 0 ; return - ( $ i + 1 ) ; } $ x = $ x | $ b << $ s ; return $ i + 1 ; } $ x |= ( $ b & 0x7f ) << $ s ; $ s += 7 ; } $ x = 0 ; return 0 ; }
Varint decode an unsigned integer.

@param string $buf bytestring holding varint encoding.
@param int $x integer to receive the decoded value.
@return int number of bytes read from buf.
Varint decode an unsigned integer .