当前位置: 首页>>代码示例>>PHP>>正文


PHP msgpack_unpack函数代码示例

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


在下文中一共展示了msgpack_unpack函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: decode

 /**
  * Decodes given value into the on-memory instance in accordance with
  * the predefined codec.
  *
  * @param  mixed $value value to be decoded.
  * @return mixed instance which is decoded.
  */
 public function decode($value)
 {
     if (function_exists('msgpack_unpack')) {
         return msgpack_unpack($value);
     }
     return unserialize($value);
 }
开发者ID:shingoOKAWA,项目名称:yacache-l5-php,代码行数:14,代码来源:MessagePack.php

示例2: 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

示例3: parse

 /**
  * Parse Payload Data
  *
  * @param string $payload
  *
  * @throws ParserException
  *
  * @return array
  */
 public function parse($payload)
 {
     if (function_exists('msgpack_unpack')) {
         if ($payload) {
             $prevHandler = set_error_handler(function ($errno, $errstr, $errfile, $errline, $errcontext) {
                 throw new \Exception($errstr);
                 // @codeCoverageIgnore
             });
             try {
                 $msg = msgpack_unpack(trim($payload));
                 if (!$msg) {
                     throw new \Exception('Unknown error');
                     // @codeCoverageIgnore
                 }
             } catch (\Exception $e) {
                 set_error_handler($prevHandler);
                 throw new ParserException('Failed To Parse MSGPack - ' . $e->getMessage());
             }
             set_error_handler($prevHandler);
             return $msg;
         }
         return [];
     }
     throw new ParserException('Failed To Parse MSGPack - Supporting Library Not Available');
     // @codeCoverageIgnore
 }
开发者ID:nathanmac,项目名称:parser,代码行数:35,代码来源:MSGPack.php

示例4: decode

 /**
  * @param string $encoded
  * @return mixed
  * @throws \Exception
  */
 public function decode($encoded)
 {
     if (function_exists('msgpack_unpack')) {
         return msgpack_unpack(substr($encoded, 1));
     }
     throw new \Exception('msgpack not installed');
 }
开发者ID:groupcash,项目名称:php,代码行数:12,代码来源:MsgPackTranscoder.php

示例5: unserialize

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

示例6: get

 /**
  * Function pretreatment
  * @param $_get
  * @param $_post
  * @param $_version
  * @param $_scope
  * @param $_interface
  * @return array
  */
 public static function get()
 {
     $_tmp_request = [];
     //MAKE URL REQUEST
     //MAKE HTTP HEADER REQUEST
     $_tmp_header_request = [];
     $_tmp_http_accept = explode(';', str_replace(' ', '', strtolower($_SERVER['HTTP_ACCEPT'])));
     $_tmp_request['content-type'] = $_tmp_http_accept[0] == TYPE_JSON || $_tmp_http_accept[0] == TYPE_MSGPACK ? $_tmp_http_accept[0] : TYPE_NULL;
     if (isset($_tmp_http_accept[1]) && !empty($_tmp_http_accept[1])) {
         $_tmp = explode('=', $_tmp_http_accept[1]);
         isset($_tmp[1]) && !empty($_tmp[1]) ? $_tmp_request['version'] = $_tmp[1] : FALSE;
     }
     //@todo Ranges
     //MAKE CONTENT REQUEST
     $_tmp_request['content'] = file_get_contents('php://input');
     switch ($_tmp_request['content-type']) {
         case TYPE_MSGPACK:
             $_tmp_request['content'] = msgpack_unpack($_tmp_request['content']);
             break;
         case TYPE_JSON:
             $_tmp_request['content'] = json_decode($_tmp_request['content']);
             break;
         case TYPE_NULL:
         default:
             $_tmp_request['content'] = NULL;
             break;
     }
     return $_tmp_request;
 }
开发者ID:randy-ran,项目名称:open-api-for-vopi,代码行数:38,代码来源:Request.php

示例7: 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

示例8: unpack

 /**
  * 解包工具
  *
  * @param string $raw
  *
  * @return mixed
  */
 public static function unpack($raw, $prefix = true)
 {
     if ($prefix) {
         return msgpack_unpack(substr($raw, 4));
     } else {
         return msgpack_unpack($raw);
     }
 }
开发者ID:lanma121,项目名称:superPrize,代码行数:15,代码来源:Pack.php

示例9: unserialize

 /**
  * Unserializes the data
  *
  * @param array $data data to be unserialized
  *
  * @return array unserialized message
  */
 public function unserialize($data)
 {
     $mssg = msgpack_unpack($data);
     //lets just make UUIDs readable incase we need to debug
     $mssg[0] = Helper::binToUuid($mssg[0]);
     $mssg[1] = Helper::binToUuid($mssg[1]);
     return $mssg;
 }
开发者ID:chekun,项目名称:gremlin-php,代码行数:15,代码来源:Msgpack.php

示例10: onData

 public function onData($data, Stream $conn)
 {
     $message = msgpack_unpack($data);
     printf("Request method: %s\n", $message['method']);
     printf("Request params: %s\n", print_r($message['params'], true));
     $result = $this->handler->process($message);
     $conn->write($result);
     $conn->end();
 }
开发者ID:mcocaro,项目名称:trevor,代码行数:9,代码来源:Server.php

示例11: testSend

 public function testSend()
 {
     $io = m::mock(Io::class);
     $io->shouldReceive('write')->andReturnUsing(function ($data) {
         self::assertEquals(array(1, 2, 3), msgpack_unpack($data));
     });
     $messenger = new MsgpackMessenger($io);
     $messenger->send(array(1, 2, 3));
 }
开发者ID:lvht,项目名称:msgpack-rpc,代码行数:9,代码来源:MsgpackMessengerTest.php

示例12: unpack

 /**
  */
 public function unpack($data)
 {
     ini_set('track_errors', 1);
     $out = @msgpack_unpack($data);
     ini_restore('track_errors');
     if (!isset($php_errormsg)) {
         return $out;
     }
     throw new Horde_Pack_Exception('Error when unpacking Msgpack data.');
 }
开发者ID:horde,项目名称:horde,代码行数:12,代码来源:Msgpack.php

示例13: parse

 public function parse($rawBody, $contentType)
 {
     if (!extension_loaded('msgpack')) {
         throw new BadRequestHttpException('Msgpack is not supported in this app server');
     }
     $unpacked = @msgpack_unpack($rawBody);
     if ($unpacked === null && $rawBody !== chr(0xc0)) {
         throw new BadRequestHttpException('Invalid MsgPack data in request body');
     }
     return $unpacked;
 }
开发者ID:Bochozkar,项目名称:stat.ink,代码行数:11,代码来源:MessagePackParser.php

示例14: 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

示例15: 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


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