public static function encodeSigned(string &$buf, int $x): int
    {
        $ux = $x << 1;
        if ($x < 0) {
            $ux = ~$ux;
        }
        return self::encodeUnsigned($buf, $ux);
    }