unpack() public method

public unpack ( string $str, mixed $object = null ) : mixed
$str string
$object mixed
return mixed
示例#1
0
function test($type, $variable, $object, $result = null)
{
    $msgpack = new MessagePack();
    $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;
    }
}
示例#2
0
function test($type, $variable, $test = null)
{
    $msgpack = new MessagePack();
    $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;
    }
}
示例#3
0
function test($type, $variable, $object, $result = null)
{
    $msgpack = new MessagePack();
    if (version_compare(PHP_VERSION, '5.1.0') <= 0) {
        $msgpack->setOption(MESSAGEPACK_OPT_PHPONLY, false);
    } else {
        $msgpack->setOption(MessagePack::OPT_PHPONLY, false);
    }
    $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;
    }
}
示例#4
0
function test($type, $variable, $test = null)
{
    $msgpack = new MessagePack();
    if (version_compare(PHP_VERSION, '5.1.0') < 0) {
        $msgpack->setOption(MESSAGEPACK_OPT_PHPONLY, false);
    } else {
        $msgpack->setOption(MessagePack::OPT_PHPONLY, false);
    }
    $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;
    }
}
示例#5
0
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
    $msgpack = new MessagePack();
    if (($unserialized = $msgpack->unpack($serialized)) === null) {
        return true;
    }
    // whole data is read?
    if ($serialized !== msgpack_serialize($unserialized)) {
        return true;
    }
    echo bin2hex($serialized), "\n";
    var_dump($unserialized);
    return false;
}