當前位置: 首頁>>代碼示例>>PHP>>正文


PHP msgpack_pack函數代碼示例

本文整理匯總了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();
}
開發者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


注:本文中的msgpack_pack函數示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。