static function encode($data, $type = self::DECODE_PHP, $uid = 0, $serid = 0)
{
//启用压缩
if ($type & self::DECODE_GZIP) {
$_type = $type & ~self::DECODE_GZIP;
$gzip_compress = true;
} else {
$gzip_compress = false;
$_type = $type;
}
switch ($_type) {
case self::DECODE_JSON:
$body = json_encode($data);
break;
case self::DECODE_PHP:
default:
$body = serialize($data);
break;
}
if ($gzip_compress) {
$body = gzencode($body);
}
return pack(RPCServer::HEADER_PACK, strlen($body), $type, $uid, $serid) . $body;
}