本文整理汇总了PHP中msgpack_pack函数的典型用法代码示例。如果您正苦于以下问题:PHP msgpack_pack函数的具体用法?PHP msgpack_pack怎么用?PHP msgpack_pack使用的例子?那么, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了msgpack_pack函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: bench
function bench($value, $n = 1000000)
{
$benchmark = new Benchmark();
$benchmark->add('serialize', function () use(&$value) {
serialize($value);
});
$benchmark->add('json_encode', function () use(&$value) {
json_encode($value);
});
if (function_exists('bin_encode')) {
$benchmark->add('bin_encode', function () use(&$value) {
bin_encode($value);
});
}
if (function_exists('bson_encode')) {
$benchmark->add('bson_encode', function () use(&$value) {
bson_encode($value);
});
}
if (function_exists('msgpack_pack')) {
$benchmark->add('msgpack_pack', function () use(&$value) {
msgpack_pack($value);
});
}
if (function_exists('igbinary_serialize')) {
$benchmark->add('igbinary_serialize', function () use(&$value) {
igbinary_serialize($value);
});
}
$benchmark->add('var_export', function () use(&$value) {
var_export($value, true);
});
$benchmark->setCount($n);
$benchmark->run();
}
示例2: encode
/**
* Encodes given value into the serialized codes in accordance with
* the predefined codec.
*
* @param mixed $value value to be encoded.
* @return array array of the encoded strings.
*/
public function encode($value)
{
if (function_exists('msgpack_pack')) {
return msgpack_pack($value);
}
return serialize($value);
}
示例3: serialize
public function serialize()
{
$payload = array($this->header, $this->name, $this->args);
$message = $this->envelope ? $this->envelope : array(null);
array_push($message, msgpack_pack($payload));
return $message;
}
示例4: toString
public static function toString($json_array, $status = self::JSONRESULT_OK, $start_time = NULL)
{
if ($start_time == NULL) {
$start_time = \SYSTEM\time::getStartTime();
}
$json = array();
$json['querytime'] = round(microtime(true) - $start_time, 5);
$json['status'] = $status;
$json['result'] = $json_array;
if (\SYSTEM\CONFIG\config::get(\SYSTEM\CONFIG\config_ids::SYS_CONFIG_DEFAULT_RESULT) == \SYSTEM\CONFIG\config_ids::SYS_CONFIG_DEFAULT_RESULT_MSGPACK) {
//send Header
\SYSTEM\HEADER::JSON();
if ($json = msgpack_pack($json)) {
return $json;
}
throw new \SYSTEM\LOG\ERROR('MSGPack could not be encoded');
} else {
//send Header
\SYSTEM\HEADER::JSON();
if ($json = json_encode($json)) {
return $json;
}
throw new \SYSTEM\LOG\ERROR('JSON could not be encoded');
}
}
示例5: serialize
/**
* Serializes the data
*
* @param array &$data data to be serialized
*
* @return int length of generated string
*/
public function serialize(&$data)
{
$data[0] = Helper::uuidToBin($data[0]);
$data[1] = Helper::uuidToBin($data[1]);
$data = msgpack_pack($data);
return mb_strlen($data, 'ISO-8859-1');
}
示例6: encode
/**
* @param mixed $input
* @return string
* @throws \Exception
*/
public function encode($input)
{
if (function_exists('msgpack_pack')) {
return self::MARKER . msgpack_pack($input);
}
throw new \Exception('msgpack not installed');
}
示例7: serialize
public function serialize($data)
{
if (!function_exists('msgpack_pack')) {
throw new \Exception('msgpack extension must be installed!');
}
return msgpack_pack($data);
}
示例8: oneway_request
public function oneway_request($method, $params = null, $expiry = null, $extras = null)
{
$ref = ++self::$sequence % 1073741824;
$frames[] = '';
$frames[] = self::VERSION;
$frames[] = msgpack_pack(array($ref, microtime(true), $expiry));
$frames[] = $this->spID ? ":{$this->spID}:{$method}" : $method;
$frames[] = msgpack_pack($params);
if ($this->sender) {
$frames[] = msgpack_pack(array('Sender', $this->sender));
}
if ($this->spVer) {
$frames[] = msgpack_pack(array('Version', $this->spVer));
}
if (is_array($extras)) {
foreach ($extras as $extra) {
$frames[] = msgpack_pack($extra);
}
}
if ($this->socket->sendmulti($frames, ZMQ::MODE_DONTWAIT) == false) {
APF::get_instance()->get_logger()->error('APS[send]:error');
return false;
}
return $ref;
}
示例9: handleRequest
public function handleRequest()
{
$args = func_get_args();
$data = $args[0];
//TODO 简单实用 msgpack
//FIXME 数据传输协议依赖swoole 底层组包功能,此处不在检查数据完整
$datastr = substr($data, 4);
$params = (object) msgpack_unpack($datastr);
if (empty($params->op)) {
$params->op = 'main.main';
}
//TODO 这里的处理应该完善点
list($ctrl, $method) = explode('.', $params->op);
$className = $this->getCtrlNamespace() . '\\' . ucfirst($ctrl) . 'Ctrl';
$ctrl = new $className();
$ctrl->setParams($params);
//发送msgpack编码数据,头部为数据长度
$result = $ctrl->{$method}();
if (Ping::$server->debug) {
echo "swoole handle request:\n";
echo "\tctrl: {$ctrl} method: {$method}\n";
echo "\tparams:\n\t\t" . json_encode($params) . "\n";
echo "\tresponse:\n\t\t" . json_encode($result) . "\n";
echo "\n\n";
}
$rawResult = msgpack_pack($result);
$rawResult = pack('N1', strlen($rawResult));
return $rawResult;
}
示例10: packData
public function packData($var, $bool = true, $option = array())
{
$option += array('packer' => $this->option['packer']);
switch ($option['packer']) {
case BoxConstants::ENCODER_JSON:
if ($bool == true) {
return json_encode($var);
} else {
return json_decode($var, true);
}
break;
case BoxConstants::ENCODER_MSGPACK:
if ($bool == true) {
return msgpack_pack($var);
} else {
return msgpack_unpack($var);
}
break;
case BoxConstants::ENCODER_SERIALIZE:
default:
if ($bool == true) {
return serialize($var);
} else {
return unserialize($var);
}
break;
}
}
示例11: pack
/**
* pack entity with msgpack protocol.
* {@link https://github.com/msgpack/msgpack-php}
* @param Entity $entity
* @return string
*/
public function pack(Entity $entity)
{
if (function_exists('msgpack_pack')) {
return msgpack_pack(array($entity->getTag(), $entity->getTime(), $entity->getData()));
} else {
return json_encode(array($entity->getTag(), $entity->getTime(), $entity->getData()));
}
}
示例12: mk_serial_package
/**
* File libraries\Function\parse_config.func.php
* Desc 生成随机字符串
* Manual svn://svn.vop.com/api/manual/Function/parse_config
* version 1.0.0
* User duanchi <http://weibo.com/shijingye>
* Date 2013-12-09
* Time 16:32
*/
function mk_serial_package($_api, $_mvno, $_request_serial)
{
$_push_url = \DB\KV::get($_mvno['mvnokey'] . ':PUSHURL', MEM_DB_SERIAL);
empty($_push_url) || $_push_url == FALSE ? $_push_url = 'no://url' : FALSE;
//组装 push_url;
//$_push_url = (isset($_mvno['push.'.$_api['apikey']]) && !empty($_mvno['push.'.$_api['apikey']]) ? $_mvno['push.'.$_api['apikey']] : FALSE);
return msgpack_pack(['mvno' => [$_mvno['mvnokey'], $_push_url], 'api' => $_api['apikey'], 'serial' => $_request_serial]);
}
示例13: testNext
public function testNext()
{
$io = m::mock(Io::class);
$io->shouldReceive('read')->andReturn(msgpack_pack(array(1, 2, 3)) . msgpack_pack(array('a' => 1)));
$messenger = new MsgpackMessenger($io);
$msg = $messenger->next();
self::assertEquals(array(1, 2, 3), $msg);
$msg = $messenger->next();
self::assertEquals(array('a' => 1), $msg);
}
示例14: make_token
function make_token($xid)
{
// make access token
date_default_timezone_set('Asia/Seoul');
$config = config_get();
$extra_data = array('service_key' => $config['service_key'], 'version' => $config['version']);
$expire_date = date(strtotime('+7 day'));
$access_token_data = array('xid' => $xid, 'expire' => $expire_date, 'data' => $extra_data);
return base64_encode(msgpack_pack($access_token_data));
}
示例15: pack
/**
* {@inheritdoc}
*/
public function pack(Request $request, $sync = null)
{
// @see https://github.com/msgpack/msgpack-php/issues/45
$content = pack('C*', 0x82, IProto::CODE, $request->getType(), IProto::SYNC);
$content .= msgpack_pack((int) $sync);
if (null !== ($body = $request->getBody())) {
$content .= msgpack_pack($body);
}
return PackUtils::packLength(strlen($content)) . $content;
}