Encode.
@param  ?string $data
@return ?string
160374
public function encode($data)
    {
        if ($data !== null) {
            $data = gzencode((string) $data, $this->options['level'], $this->options['mode']);
            if ($data === false) {
                $data = null;
                $this->error = error_get_last()['message'] ?? 'Unknown';
            }
        }

        return $data;
    }
152046
public static function encode($data)
    {
        $module = $data['module'];
        $interface = $data['interface'];
        $cost_time = $data['cost_time'];
        $success = $data['success'];
        $code = isset($data['code']) ? $data['code'] : 0;
        $msg = isset($data['msg']) ? $data['msg'] : '';
        
        // 防止模块名过长
        if(strlen($module) > self::MAX_CHAR_VALUE)
        {
            $module = substr($module, 0, self::MAX_CHAR_VALUE);
        }

        // 防止接口名过长
        if(strlen($interface) > self::MAX_CHAR_VALUE)
        {
            $interface = substr($interface, 0, self::MAX_CHAR_VALUE);
        }

        // 防止msg过长
        $module_name_length = strlen($module);
        $interface_name_length = strlen($interface);
        $avalible_size = self::MAX_UDP_PACKGE_SIZE - self::PACKAGE_FIXED_LENGTH - $module_name_length - $interface_name_length;
        if(strlen($msg) > $avalible_size)
        {
            $msg = substr($msg, 0, $avalible_size);
        }

        // 打包
        return pack('CCfCNnN', $module_name_length, $interface_name_length, $cost_time, $success ? 1 : 0, $code, strlen($msg), time()).$module.$interface.$msg;
    }
333983
private function encode($data)
    {
        $rdm = $this->random();
        $data = base64_encode($data);
        $startIndex = rand(1, strlen($rdm));
        $params = base64_encode($startIndex).self::ENC_SEPARATOR;
        $params .= base64_encode(strlen($data)).self::ENC_SEPARATOR;

        return $params.substr_replace($rdm, $data, $startIndex, 0);
    }
874439
public static function encode($data)
    {
        if (!is_string($data)) {
            throw new InvalidArgumentException('data must be string');
        }

        $encodedData = parent::encode($data);

        // URL safe replacement and remove padding
        return rtrim(strtr($encodedData, '+/', '-_'), '=');
    }
24034
public static function encode($data)
    {
        if (version_compare(PHP_VERSION, '5.4.0', '>=')) {
            $json = json_encode($data, JSON_UNESCAPED_SLASHES | JSON_UNESCAPED_UNICODE);
        } else {
            $json = json_encode($data);
        }

        self::handleError(json_last_error());

        return $json;
    }
1077849
public function decode($data)
    {
        $data = \preg_replace('/[^0-9A-Fa-f]/', '', \rtrim($data, '>'));
        if ((\strlen($data) % 2) === 1) {
            $data .= '0';
        }

        return \pack('H*', $data);
    }
766824
protected function jsonEncode($data)
    {
        $return = json_encode($data);

        if ($return === false) {
            throw new ConverterException(
                sprintf(
                    "Could not convert %s data to JSON. Driver returned '%s'.",
                    gettype($data),
                    json_last_error()
                )
            );
        }

        return $return;
    }
583750
private function getQSEncode($data)
    {
        $req = null;
        foreach ($data as $key => $value) {
            $req .= $key . '=' . urlencode(stripslashes($value)) . '&';
        }

        // cut the last '&'
        $req = substr($req, 0, strlen($req) - 1);

        return $req;
    }
80647
final private static function encodeString(string $data): string
    {
        $buf = '';
        self::encodeUnsigned($buf, strlen($data));
        return $buf . $data;
    }
715757
public static function encode($data, $pad = null) {
		$str = str_replace(array('+', '/'), array('-', '_'), base64_encode($data));
		if (!$pad) {
			$str = rtrim($str, '=');
		}
		return $str;
	}
1240560
public function encode($data) : string
    {
        $result = json_encode($data, $this->options, $this->maxDepth);

        $this->checkLastError();

        return $result;
    }
103798
public static function encodeUrlSafeWithoutPadding($data) {
		$encoded = self::encode($data);

		$encoded = \rtrim(
			$encoded,
			\substr(self::LAST_THREE_STANDARD, -1)
		);

		return \strtr(
			$encoded,
			\substr(self::LAST_THREE_STANDARD, 0, -1),
			\substr(self::LAST_THREE_URL_SAFE, 0, -1)
		);
	}
101338
public function encrypt($data): string
    {
        if (!$this->password)
        {
            return JSON::encode($data);
        }

        return $this->security()
            ->encrypt(JSON::encode($data));
    }
487834
protected function encodeMessage($data)
    {
        return $this->server->getBean(\Imi\Server\DataParser\DataParser::class)->encode($data);
    }
1007328
protected static function encode($data, array $context)
    {
        $result = base64_encode($data);

        if (false === $result) {
            static::throwEncodingException($data);
        }

        if ($context['base64_encode_url_safe']) {
            return str_replace('=', '', strtr($result, '+/', '-_'));
        }

        return $result;
    }
45560
function encode(data) {
  var encodedData = null;
  try {
    encodedData = JSON.stringify(data);
  } catch (err) {
    logger.warn('failed encoding data', data);
  }
  return encodedData;
}
1171957
private function encodeInteger($data = null)
    {
        $data = is_null($data) ? $this->data : $data;
        return sprintf("i%.0fe", $data);
    }