public static function encodeUnsigned(string &$buf, int $x): int
    {
        $offset = $i = strlen($buf);
        while ($x >= 0x80) {
            $buf[$i++] = chr($x | 0x80);
            $x >>= 7;
        }
        $buf[$i++] = chr($x);
        return $i - $offset;
    }
public static function encodeUnsigned(string &$buf, int $x): int
    {
        $offset = $i = strlen($buf);
        while ($x >= 0x80) {
            $buf[$i++] = chr($x | 0x80);
            $x >>= 7;
        }
        $buf[$i++] = chr($x);
        return $i - $offset;
    }
public static function encodeUnsigned ( string & $ buf , int $ x ) : int { $ offset = $ i = strlen ( $ buf ) ; while ( $ x >= 0x80 ) { $ buf [ $ i ++ ] = chr ( $ x | 0x80 ) ; $ x >>= 7 ; } $ buf [ $ i ++ ] = chr ( $ x ) ; return $ i - $ offset ; }
Varint encode as unsigned integer.

@param string $buf bytestring to hold varint encoding of $x.
@param int $x the unsigned integer to varint encode.
@return int number of bytes written to buf.
Varint encode as unsigned integer .