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


PHP msgpack_serialize函数代码示例

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


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

示例1: test

function test($type, $variable, $test)
{
    $serialized = msgpack_serialize($variable);
    $unserialized = msgpack_unserialize($serialized);
    var_dump($variable);
    var_dump($unserialized);
}
开发者ID:chenyongze,项目名称:msgpack-hhvm,代码行数:7,代码来源:025.php

示例2: test

function test()
{
    $serialized = msgpack_serialize(null);
    $serialized = substr($serialized, 0, -1);
    $length = mt_rand(1, 255);
    for ($i = 0; $i < $length; ++$i) {
        $serialized .= chr(mt_rand(0, 255));
    }
    // if returned null everything is OK
    $unpacker = new MessagePackUnpacker();
    $unpacker->feed($serialized);
    if ($unpacker->execute()) {
        if (($unserialized = $unpacker->data()) === null) {
            return true;
        }
        $unpacker->reset();
    } else {
        return true;
    }
    // whole data is read?
    if ($serialized !== msgpack_serialize($unserialized)) {
        return true;
    }
    echo bin2hex($serialized), "\n";
    var_dump($unserialized);
    return false;
}
开发者ID:chenyongze,项目名称:msgpack-hhvm,代码行数:27,代码来源:040c.php

示例3: test

function test($type, $variable, $test = null)
{
    $serialized = msgpack_serialize($variable);
    $unpacker = new MessagePackUnpacker();
    $length = strlen($serialized);
    $str = "";
    $offset = 0;
    for ($i = 0; $i < $length;) {
        $len = rand(1, 10);
        $str .= substr($serialized, $i, $len);
        if ($unpacker->execute($str, $offset)) {
            $unserialized = $unpacker->data();
            var_dump($unserialized);
            $unpacker->reset();
            $str = "";
            $offset = 0;
        }
        $i += $len;
    }
    if (!is_bool($test)) {
        echo $unserialized === $variable ? 'OK' : 'ERROR', PHP_EOL;
    } else {
        echo $test || $unserialized == $variable ? 'OK' : 'ERROR', PHP_EOL;
    }
}
开发者ID:chenyongze,项目名称:msgpack-hhvm,代码行数:25,代码来源:061c.php

示例4: test

function test($type, $variable)
{
    $serialized = msgpack_serialize($variable);
    $unserialized = msgpack_unserialize($serialized);
    echo $type, PHP_EOL;
    echo bin2hex($serialized), PHP_EOL;
    var_dump($unserialized);
    echo $unserialized === $variable ? 'OK' : 'ERROR', PHP_EOL;
}
开发者ID:chenyongze,项目名称:msgpack-hhvm,代码行数:9,代码来源:006.php

示例5: test

function test($type, $variable, $test)
{
    $serialized = msgpack_serialize($variable);
    $unserialized = msgpack_unserialize($serialized);
    echo $type, PHP_EOL;
    echo bin2hex($serialized), PHP_EOL;
    var_dump($unserialized);
    echo $test || $unserialized === null ? 'OK' : 'FAIL', PHP_EOL;
}
开发者ID:chenyongze,项目名称:msgpack-hhvm,代码行数:9,代码来源:023.php

示例6: read

function read($id)
{
    global $output;
    $output .= "read" . PHP_EOL;
    $a = new Bar();
    $b = new Foo($a);
    $a->set($b);
    $session = array('old' => $b);
    return msgpack_serialize($session);
}
开发者ID:chenyongze,项目名称:msgpack-hhvm,代码行数:10,代码来源:028d.php

示例7: serialize

 /**
  * Serialize PHP value to msgpack
  *
  * @param  mixed $value
  * @return string
  * @throws Exception\RuntimeException on msgpack error
  */
 public function serialize($value)
 {
     ErrorHandler::start();
     $ret = msgpack_serialize($value);
     $err = ErrorHandler::stop();
     if ($ret === false) {
         throw new Exception\RuntimeException('Serialization failed', 0, $err);
     }
     return $ret;
 }
开发者ID:idwsdta,项目名称:INIT-frame,代码行数:17,代码来源:MsgPack.php

示例8: encode

 /**
  * 数据编码。
  * 
  * @param array $data  指定数据对象。
  * @param int $format  指定编码格式。(默认值: 1 | JSON, 其它可用值: Encoder::MSGPACK, Encoder::XML)
  * @param int $options 指定参数选项。(注: 此参数仅对 JSON 编码有效.)
  * @return string
  * @throws NotImplementedException
  */
 static function encode($data, $format = self::JSON, $options = 320)
 {
     $s = false;
     switch ($format) {
         case self::JSON:
             $s = json_encode($data, $options);
             break;
         case self::MSGPACK:
             $s = msgpack_serialize($data);
             break;
         case self::IGBINARY:
             $s = igbinary_serialize($data);
             break;
         case self::XML:
             throw new NotImplementedException('尚未实现此接口。', -1);
             break;
     }
     return $s;
 }
开发者ID:heesey,项目名称:LeePHP-Socket,代码行数:28,代码来源:Encoder.php

示例9: test

function test()
{
    $serialized = msgpack_serialize(null);
    $serialized = substr($serialized, 0, -1);
    $length = mt_rand(1, 255);
    for ($i = 0; $i < $length; ++$i) {
        $serialized .= chr(mt_rand(0, 255));
    }
    // if returned null everything is OK
    if (($unserialized = msgpack_unserialize($serialized)) === null) {
        return true;
    }
    // whole data is read?
    if ($serialized !== msgpack_serialize($unserialized)) {
        return true;
    }
    echo bin2hex($serialized), "\n";
    var_dump($unserialized);
    return false;
}
开发者ID:chenyongze,项目名称:msgpack-hhvm,代码行数:20,代码来源:040.php

示例10: test

function test($type, $variable, $test = null)
{
    $serialized = msgpack_serialize($variable);
    global $unpacker;
    $length = strlen($serialized);
    for ($i = 0; $i < $length;) {
        $len = rand(1, 10);
        $str = substr($serialized, $i, $len);
        $unpacker->feed($str);
        if ($unpacker->execute()) {
            $unserialized = $unpacker->data();
            var_dump($unserialized);
            $unpacker->reset();
        }
        $i += $len;
    }
    if (!is_bool($test)) {
        echo $unserialized === $variable ? 'OK' : 'ERROR', PHP_EOL;
    } else {
        echo $test || $unserialized == $variable ? 'OK' : 'ERROR', PHP_EOL;
    }
}
开发者ID:chenyongze,项目名称:msgpack-hhvm,代码行数:22,代码来源:064b.php

示例11: dl

<?php

if (!extension_loaded('msgpack')) {
    dl('msgpack.' . PHP_SHLIB_SUFFIX);
}
$datas = array(87817, -1, array(1, 2, 3, "testing" => 10, "foo"), true, false, 0.187182, "dakjdh98389", null, (object) array(1, 2, 3));
error_reporting(0);
foreach ($datas as $data) {
    $str = msgpack_serialize($data);
    $len = strlen($str);
    for ($j = 0; $j < 200; $j++) {
        for ($i = 0; $i < $len - 1; $i++) {
            $sub = substr($str, 0, $i);
            $sub .= mcrypt_create_iv(30, MCRYPT_DEV_URANDOM);
            $php_errormsg = null;
            $v = msgpack_unserialize($sub);
        }
    }
}
开发者ID:chenyongze,项目名称:msgpack-hhvm,代码行数:19,代码来源:034.php

示例12: dl

<?php

if (!extension_loaded('msgpack')) {
    dl('msgpack.' . PHP_SHLIB_SUFFIX);
}
$closure = function ($x) {
    return $x + 1;
};
class Foo implements Serializable
{
    public function serialize()
    {
        echo "Should not be run.\n";
    }
    public function unserialize($str)
    {
        echo "Should not be run.\n";
    }
}
$array = array($closure, new Foo());
try {
    $ser = msgpack_serialize($array);
    echo "Serialized closure.\n";
    $unser = msgpack_unserialize($ser);
    echo "Unserialized closure.\n";
    var_dump($unser);
} catch (Exception $e) {
    echo "Got exception.\n";
}
开发者ID:chenyongze,项目名称:msgpack-hhvm,代码行数:29,代码来源:042.php

示例13: pack

 /**
  */
 public function pack($data)
 {
     return msgpack_serialize($data);
 }
开发者ID:jubinpatel,项目名称:horde,代码行数:6,代码来源:Msgpackserialize.php

示例14: print_r

<?php

class test
{
}
print_r(msgpack_unserialize(msgpack_serialize(new test())));
开发者ID:chenyongze,项目名称:msgpack-hhvm,代码行数:6,代码来源:issue023.php

示例15: __construct

}
class Foo
{
    public $parent;
    public $children;
    public function __construct()
    {
        $this->parent = null;
        $this->children = array();
    }
    public function addChild(Foo $obj)
    {
        $this->children[] = $obj;
        $obj->setParent($this);
    }
    public function setParent(Foo $obj)
    {
        $this->parent = $obj;
    }
}
$obj1 = new Foo();
for ($i = 0; $i < 10; $i++) {
    $obj = new Foo();
    $obj1->addChild($obj);
}
$o = msgpack_unserialize(msgpack_serialize($obj1->children));
foreach ($obj1->children as $k => $v) {
    $obj_v = $v;
    $o_v = $o[$k];
    echo gettype($obj_v), "  ", gettype($o_v), PHP_EOL;
}
开发者ID:chenyongze,项目名称:msgpack-hhvm,代码行数:31,代码来源:033.php


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