• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

PHP msgpack_pack函数代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了PHP中msgpack_pack函数的典型用法代码示例。如果您正苦于以下问题:PHP msgpack_pack函数的具体用法?PHP msgpack_pack怎么用?PHP msgpack_pack使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。



在下文中一共展示了msgpack_pack函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的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();
}
开发者ID:ovr,项目名称:php-web-benchmarks,代码行数:35,代码来源:serialize.php


示例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);
 }
开发者ID:shingoOKAWA,项目名称:yacache-l5-php,代码行数:14,代码来源:MessagePack.php


示例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;
 }
开发者ID:0rpc,项目名称:zerorpc-php,代码行数:7,代码来源:Event.php


示例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');
     }
 }
开发者ID:webcraftmedia,项目名称:system,代码行数:25,代码来源:JsonResult.php


示例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');
 }
开发者ID:chekun,项目名称:gremlin-php,代码行数:14,代码来源:Msgpack.php


示例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');
 }
开发者ID:groupcash,项目名称:php,代码行数:12,代码来源:MsgPackTranscoder.php


示例7: serialize

 public function serialize($data)
 {
     if (!function_exists('msgpack_pack')) {
         throw new \Exception('msgpack extension must be installed!');
     }
     return msgpack_pack($data);
 }
开发者ID:mmolle-nelo,项目名称:flow-resttools,代码行数:7,代码来源:MsgpackSerializer.php


示例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;
 }
开发者ID:emilymwang8,项目名称:cms,代码行数:25,代码来源:Client12.php


示例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;
 }
开发者ID:imdaqian,项目名称:PingFramework,代码行数:29,代码来源:Server.php


示例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;
     }
 }
开发者ID:nickfan,项目名称:appbox,代码行数:28,代码来源:BoxDictionary.php


示例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()));
     }
 }
开发者ID:sfrek,项目名称:yii-fluentd-logroute,代码行数:14,代码来源:MsgpackOrJsonPacker.php


示例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]);
}
开发者ID:randy-ran,项目名称:open-api-for-vopi,代码行数:17,代码来源:mk_serial_package.php


示例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);
 }
开发者ID:lvht,项目名称:msgpack-rpc,代码行数:10,代码来源:MsgpackMessengerTest.php


示例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));
}
开发者ID:rinno83,项目名称:blinggling,代码行数:10,代码来源:token_helper.php


示例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;
 }
开发者ID:agolomazov,项目名称:client,代码行数:13,代码来源:PeclLitePacker.php


示例16: test

function test($type, $variable, $test = null)
{
    $serialized = msgpack_pack($variable);
    $unserialized = msgpack_unpack($serialized);
    var_dump($unserialized);
    if (!is_bool($test)) {
        echo $unserialized === $variable ? 'OK' : 'ERROR', PHP_EOL;
    } else {
        echo $test || $unserialized == $variable ? 'OK' : 'ERROR', PHP_EOL;
    }
}
开发者ID:chenyongze,项目名称:msgpack-hhvm,代码行数:11,代码来源:080.php


示例17: test

function test($type, $variable, $object, $result = null)
{
    $serialized = msgpack_pack($variable);
    $unserialized = msgpack_unpack($serialized, $object);
    var_dump($unserialized);
    if ($result) {
        echo $unserialized == $result ? 'OK' : 'ERROR', PHP_EOL;
    } else {
        echo 'SKIP', PHP_EOL;
    }
}
开发者ID:chenyongze,项目名称:msgpack-hhvm,代码行数:11,代码来源:092b.php


示例18: test

function test($type, $var)
{
    echo "================\n" . $type . "\n";
    $e = msgpack_pack($var);
    $d = msgpack_unpack($e);
    echo "\t" . bin2hex($e) . "\t" . $e . "\n\t";
    echo str_replace("\n", "\n\t", var_export($d, true)) . "\n";
    if ($var === $d) {
        echo "PASS\n";
    } else {
        echo "FAIL\n";
    }
}
开发者ID:client9,项目名称:msgpack-php,代码行数:13,代码来源:test.php


示例19: serializeData

 /**
  * 序列化PHP的数据结构(如果是序列化对象,请不要使用json序列).
  * 
  * @param array  $data 需要序列化的数据.
  * @param string $type 序列化方式.
  *
  * @return string
  */
 protected function serializeData(array $data = array(), $type = self::SERIALIZE_BY_MSGPACK)
 {
     if (!$data) {
         $data = array();
     }
     $dataString = '';
     if ($type == self::SERIALIZE_BY_JSON) {
         $dataString = json_encode($data);
     } elseif ($type == self::SERIALIZE_BY_PHP) {
         $dataString = serialize($data);
     } else {
         $dataString = msgpack_pack($data);
     }
     return $dataString;
 }
开发者ID:nangong92t,项目名称:go_src,代码行数:23,代码来源:ModuleBase.php


示例20: set

 /**
  * Sets a cache item to the given data, tags, and lifetime.
  *
  * @param   string   cache id to set
  * @param   string   data in the cache
  * @param   array    cache tags
  * @param   integer  lifetime
  * @return  bool
  */
 public function set($id, $data, array $tags = NULL, $lifetime)
 {
     // Remove old cache files
     $this->delete($id);
     // Cache File driver expects unix timestamp
     if ($lifetime !== 0) {
         $lifetime += time();
     }
     if (!empty($tags)) {
         // Convert the tags into a string list
         $tags = implode('+', $tags);
     }
     // Write out a serialized cache
     return (bool) file_put_contents($this->directory . $id . '~' . $tags . '~' . $lifetime . '.msgpack', msgpack_pack($data));
 }
开发者ID:paramonovav,项目名称:kohana2-modules,代码行数:24,代码来源:Msgpackfile.php



注:本文中的msgpack_pack函数示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
PHP msgpack_serialize函数代码示例发布时间:2022-05-15
下一篇:
PHP msgbox函数代码示例发布时间:2022-05-15
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap