package.xml0000644000175000001440000004735413577133502012062 0ustar mikeusers msgpack pecl.php.net PHP extension for interfacing with MessagePack This extension provide API for communicating with MessagePack serialization. Advect advect advect@gmail.com yes Xinchen Hui laruence laruence@php.net yes Michael Wallner mike mike@php.net yes 2019-12-20 2.1.0beta1 2.0.3 beta stable 3-Clause-BSD + Improved performance + Upgraded bundled msgpack headers to 3.2.0 * Merged PR #101: Update README in order to match compatibile PHP version * Merged PR #125: fix ce->name is a zend_string * Merged PR #106: Update README * Merged PR #126: add mising tests in archive * Merged PR #135: Add fixes for issue #81 This also includes tests. * Merged PR #143: Fixed build with PHP-7.4 * Fixed issue #139: Segmentation fault when using cloned unpacker * Fixed issue #132: Segfault on session php7.3 * Fixed issue #107: $unpacker->execute() bug * Fixed issue #83: Arrays and negative index * Fixed issue #137: DateTime(Immutable) serialization doesn't work with php 7.4 RC1 * Fixed issue #105: MessagePackUnpacker() bug * Fixed issue #90: msgpack_unpack is super slow (30x times igbinary) on big data sets * Fixed issue #91: Private property in base class * Fixed issue #67: Integer overflow on a 64-bit system * Fixed issue #33: int64 and uint64 decode is not supported in 32-bit php * Fixed issue #119: uint64 numbers are cast to uint on Windows * Fixed issue #134: msgpack-php msgpack_serialize/msgpack_pack not handling properly large int * Fixed issue #81: Serialize optimization * Fixed issue #108: tests/041.phpt failure * Fixed issue #142: Recursion encoded as NULL * Fixed issue #138: Serializers comparison for session like data 7.0.0 1.4.3 msgpack 2018-12-20 2.0.3 2.0.3 stable stable PHP License - Fixed PHP-7.3 Compatibility 2016-12-07 2.0.2 2.0.2 stable stable PHP License - Fixed issue #104 (PHP7.1 build:Use own definition of msgpack_unserialize_data_t) 2016-03-01 2.0.1 2.0.1 beta beta PHP License - Fixed issue #82 (Check hash protection flag to avoid memory corruption) - Fixed Issue #80 (Serialized failed on unseted value) - When packing/unpacking a zend_object don't call magic methods __set/__get 2015-10-27 2.0.0 2.0.0 beta beta PHP License - Release msgpack for PHP7 2015-04-27 0.5.6 0.5.6 beta beta PHP License - support str8 type (wudikua) - Fix a warning and a possible crash (Mike) - Fix crash with memcached (Mike) 2013-02-19 0.5.5 0.5.5 beta beta PHP License - Fix ZTS build - Fixed Bug #14 ("Invalid read" reported by valgrind) - Fixed FR #8 (Return on unserialization) 2013-02-18 0.5.4 0.5.4 beta beta PHP License - Fixed Bug #12 (msgpack_seriallize interfere with php serialize). - Fixed Bug #11 (unpacking empty array / segmentation fault). 2012-10-12 0.5.3 0.5.3 beta beta PHP License - Fixed Bug #6 (bug with incorrect packing of mixed arrays) 2012-09-14 0.5.2 0.5.2 beta beta PHP License - Initial release msgpack-2.1.0beta1/tests/001.phpt0000644000175000001440000000031313577133502015262 0ustar mikeusers--TEST-- Check for msgpack presence --SKIPIF-- --FILE-- --EXPECT-- msgpack extension is available msgpack-2.1.0beta1/tests/002.phpt0000644000175000001440000000075113577133502015271 0ustar mikeusers--TEST-- Check for null serialisation --SKIPIF-- --FILE-- --EXPECT-- null c0 NULL OK msgpack-2.1.0beta1/tests/003.phpt0000644000175000001440000000106213577133502015266 0ustar mikeusers--TEST-- Check for bool serialisation --SKIPIF-- --FILE-- --EXPECT-- bool true c3 bool(true) OK bool false c2 bool(false) OK msgpack-2.1.0beta1/tests/004.phpt0000644000175000001440000000153513577133502015274 0ustar mikeusers--TEST-- Check for integer serialisation --SKIPIF-- --FILE-- --EXPECT-- zero: 0 00 int(0) OK small: 1 01 int(1) OK small: -1 ff int(-1) OK medium: 1000 cd03e8 int(1000) OK medium: -1000 d1fc18 int(-1000) OK large: 100000 ce000186a0 int(100000) OK large: -100000 d2fffe7960 int(-100000) OK msgpack-2.1.0beta1/tests/005.phpt0000644000175000001440000000103613577133502015271 0ustar mikeusers--TEST-- Check for double serialisation --SKIPIF-- --FILE-- --EXPECT-- double: 123.456 cb405edd2f1a9fbe77 float(123.456) OK msgpack-2.1.0beta1/tests/006.phpt0000644000175000001440000000113413577133502015271 0ustar mikeusers--TEST-- Check for simple string serialization --SKIPIF-- --FILE-- --EXPECT-- empty: "" a0 string(0) "" OK string: "foobar" a6666f6f626172 string(6) "foobar" OK msgpack-2.1.0beta1/tests/007.phpt0000644000175000001440000000207313577133502015275 0ustar mikeusers--TEST-- Check for simple array serialization --SKIPIF-- --FILE-- --EXPECT-- empty array: 90 array(0) { } OK array(1, 2, 3) 93010203 array(3) { [0]=> int(1) [1]=> int(2) [2]=> int(3) } OK array(array(1, 2, 3), arr... 93930102039304050693070809 array(3) { [0]=> array(3) { [0]=> int(1) [1]=> int(2) [2]=> int(3) } [1]=> array(3) { [0]=> int(4) [1]=> int(5) [2]=> int(6) } [2]=> array(3) { [0]=> int(7) [1]=> int(8) [2]=> int(9) } } OK msgpack-2.1.0beta1/tests/008.phpt0000644000175000001440000000231213577133502015272 0ustar mikeusers--TEST-- Check for array+string serialization --SKIPIF-- --FILE-- 1, "two" => 2))', array("one" => 1, "two" => 2)); test('array("kek" => "lol", "lol" => "kek")', array("kek" => "lol", "lol" => "kek")); test('array("" => "empty")', array("" => "empty")); ?> --EXPECT-- array("foo", "foo", "foo") 93a3666f6fa3666f6fa3666f6f array(3) { [0]=> string(3) "foo" [1]=> string(3) "foo" [2]=> string(3) "foo" } OK array("one" => 1, "two" => 2)) 82a36f6e6501a374776f02 array(2) { ["one"]=> int(1) ["two"]=> int(2) } OK array("kek" => "lol", "lol" => "kek") 82a36b656ba36c6f6ca36c6f6ca36b656b array(2) { ["kek"]=> string(3) "lol" ["lol"]=> string(3) "kek" } OK array("" => "empty") 81a0a5656d707479 array(1) { [""]=> string(5) "empty" } OK msgpack-2.1.0beta1/tests/009.phpt0000644000175000001440000000312613577133502015277 0ustar mikeusers--TEST-- Check for reference serialization --SKIPIF-- = 0 && version_compare(PHP_VERSION, '5.3.2') <= 0)) { echo "skip tests in PHP 5.2.14/5.3.3 or newer"; } --FILE-- array(1) { [0]=> string(3) "foo" } [1]=> array(1) { [0]=> string(3) "foo" } } OK array(&$a, &$a) 9282c00100a3666f6f82c0020002 array(2) { [0]=> &array(1) { [0]=> string(3) "foo" } [1]=> &array(1) { [0]=> string(3) "foo" } } OK cyclic 9182c0010082c0010082c0020002 array(1) { [0]=> &array(1) { [0]=> array(1) { [0]=> *RECURSION* } } } OK array(1) { [0]=> &array(1) { [0]=> &array(1) { [0]=> *RECURSION* } } } array(1) { [0]=> &array(1) { [0]=> array(1) { [0]=> *RECURSION* } } } msgpack-2.1.0beta1/tests/010.phpt0000644000175000001440000000144413577133502015270 0ustar mikeusers--TEST-- Array test --SKIPIF-- --FILE-- array( 'b' => 'c', 'd' => 'e' ), 'f' => array( 'g' => 'h' ) ); test('array', $a, false); ?> --EXPECT-- array 82a16182a162a163a164a165a16681a167a168 array(2) { ["a"]=> array(2) { ["b"]=> string(1) "c" ["d"]=> string(1) "e" } ["f"]=> array(1) { ["g"]=> string(1) "h" } } OK msgpack-2.1.0beta1/tests/012.phpt0000644000175000001440000000170313577133502015270 0ustar mikeusers--TEST-- Object test --SKIPIF-- a = $a; $this->b = $b; $this->c = $c; } } $o = new Obj(1, 2, 3); test('object', $o, false); ?> --EXPECTF-- object 84c0a34f626aa16101a4002a006202a6004f626a006303 object(Obj)#%d (3) { ["a"]=> int(1) [%r"?b"?:protected"?%r]=> int(2) [%r"?c"?:("Obj":)?private"?%r]=> int(3) } OK msgpack-2.1.0beta1/tests/013.phpt0000644000175000001440000000157413577133502015277 0ustar mikeusers--TEST-- Object-Array test --SKIPIF-- --FILE-- a = $a; $this->b = $b; } } $o = array(new Obj(1, 2), new Obj(3, 4)); test('object', $o, false); ?> --EXPECTF-- object 9283c0a34f626aa16101a1620283c0a34f626aa16103a16204 array(2) { [0]=> object(Obj)#%d (2) { ["a"]=> int(1) ["b"]=> int(2) } [1]=> object(Obj)#%d (2) { ["a"]=> int(3) ["b"]=> int(4) } } OK msgpack-2.1.0beta1/tests/014.phpt0000644000175000001440000000156713577133502015302 0ustar mikeusers--TEST-- Object-Reference test --SKIPIF-- --FILE-- a = $a; $this->b = $b; } } $o = new Obj(1, 2); $a = array(&$o, &$o); test('object', $a, false); ?> --EXPECTF-- object 9284c001c0a34f626aa16101a1620282c0050002 array(2) { [0]=> &object(Obj)#%d (2) { ["a"]=> int(1) ["b"]=> int(2) } [1]=> &object(Obj)#%d (2) { ["a"]=> int(1) ["b"]=> int(2) } } OK msgpack-2.1.0beta1/tests/015.phpt0000644000175000001440000000176113577133502015277 0ustar mikeusers--TEST-- Check for serialization handler --SKIPIF-- --EXPECT-- 2 82c001a3666f6f02 array(1) { ["foo"]=> int(2) } msgpack-2.1.0beta1/tests/015b.phpt0000644000175000001440000000177013577133502015441 0ustar mikeusers--TEST-- Check for serialization handler, ini-directive --SKIPIF-- --EXPECT-- 2 82c001a3666f6f02 array(1) { ["foo"]=> int(2) } msgpack-2.1.0beta1/tests/015e.phpt0000644000175000001440000000203013577133502015432 0ustar mikeusers--TEST-- Check for serialization handler, broken --SKIPIF-- --EXPECT-- 1 82c001a3666f6f01 array(1) { ["foo"]=> int(1) } msgpack-2.1.0beta1/tests/016.phpt0000644000175000001440000000223713577133502015277 0ustar mikeusers--TEST-- Object test, __sleep --SKIPIF-- a = $a; $this->b = $b; $this->c = $c; $this->d = $d; } function __sleep() { return array('a', 'b', 'c'); } # function __wakeup() { # $this->d = $this->a + $this->b + $this->c; # } } $o = new Obj(1, 2, 3, 4); test('object', $o, true); ?> --EXPECTF-- object 84c0a34f626aa16101a4002a006202a6004f626a006303 object(Obj)#%d (4) { ["a"]=> int(1) [%r"?b"?:protected"?%r]=> int(2) [%r"?c"?:("Obj":)?private"?%r]=> int(3) ["d"]=> NULL } OK msgpack-2.1.0beta1/tests/017.phpt0000644000175000001440000000143313577133502015275 0ustar mikeusers--TEST-- Object test, __wakeup --SKIPIF-- --FILE-- b == 3 ? 'OK' : 'ERROR', PHP_EOL; } class Obj { var $a; var $b; function __construct($a, $b) { $this->a = $a; $this->b = $b; } function __wakeup() { $this->b = $this->a * 3; } } $o = new Obj(1, 2); test('object', $o, false); ?> --EXPECTF-- object 83c0a34f626aa16101a16202 object(Obj)#%d (2) { ["a"]=> int(1) ["b"]=> int(3) } OK msgpack-2.1.0beta1/tests/018.phpt0000644000175000001440000000305113577133502015274 0ustar mikeusers--TEST-- Object test, __sleep error cases --SKIPIF-- --FILE-- a = $a; $this->b = $b; } function __sleep() { return array('c'); } # function __wakeup() { # $this->b = $this->a * 3; # } } class Opj { var $a; var $b; function __construct($a, $b) { $this->a = $a; $this->b = $b; } function __sleep() { return array(1); } # function __wakeup() { # # } } $o = new Obj(1, 2); $p = new Opj(1, 2); test('nonexisting', $o, true); test('wrong', $p, true); ?> --EXPECTF-- Notice: [msgpack] (msgpack_serialize_class) "c" returned as member variable from __sleep() but does not exist in %s on line %d nonexisting 82c0a34f626aa163c0 object(Obj)#%d (3) { ["a"]=> NULL ["b"]=> NULL ["c"]=> NULL } OK Notice: [msgpack] (msgpack_serialize_class) __sleep should return an array only containing the names of instance-variables to serialize in %s018.php on line %d Warning: [msgpack] (php_msgpack_unserialize) Insufficient data for unserializing in %s018.php on line %d wrong 82c0a34f706a bool(false) OK msgpack-2.1.0beta1/tests/019.phpt0000644000175000001440000000151113577133502015274 0ustar mikeusers--TEST-- Object test, __autoload --SKIPIF-- --FILE-- b == 2 ? 'OK' : 'ERROR', PHP_EOL; } function test_autoload($classname) { class Obj { var $a; var $b; function __construct($a, $b) { $this->a = $a; $this->b = $b; } } } spl_autoload_register('test_autoload'); test('autoload', '83c0a34f626aa16101a16202', false); ?> --EXPECTF-- autoload 83c0a34f626aa16101a16202 object(Obj)#%d (2) { ["a"]=> int(1) ["b"]=> int(2) } OK msgpack-2.1.0beta1/tests/020.phpt0000644000175000001440000000113613577133502015267 0ustar mikeusers--TEST-- Object test, incomplete class --SKIPIF-- --FILE-- --EXPECTF-- incom 83c0a34f626aa16101a16202 object(__PHP_Incomplete_Class)#%d (3) { ["__PHP_Incomplete_Class_Name"]=> string(3) "Obj" ["a"]=> int(1) ["b"]=> int(2) } msgpack-2.1.0beta1/tests/021.phpt0000644000175000001440000000211713577133502015270 0ustar mikeusers--TEST-- Object Serializable interface --SKIPIF-- a = $a; $this->b = $b; } public function serialize() { return pack('NN', $this->a, $this->b); } public function unserialize($serialized) { $tmp = unpack('N*', $serialized); $this->__construct($tmp[1], $tmp[2]); } } $o = new Obj(1, 2); test('object', $o, false); ?> --EXPECTF-- object 82c003a34f626aa80000000100000002 object(Obj)#%d (2) { ["a"]=> int(1) ["b"]=> int(2) } OK msgpack-2.1.0beta1/tests/022.phpt0000644000175000001440000000152613577133502015274 0ustar mikeusers--TEST-- Object test, unserialize_callback_func --SKIPIF-- --INI-- unserialize_callback_func=autoload --FILE-- b == 2 ? 'OK' : 'ERROR', PHP_EOL; } function autoload($classname) { class Obj { var $a; var $b; function __construct($a, $b) { $this->a = $a; $this->b = $b; } } } test('autoload', '83c0a34f626aa16101a16202', false); ?> --EXPECTF-- autoload 83c0a34f626aa16101a16202 object(Obj)#%d (2) { ["a"]=> int(1) ["b"]=> int(2) } OK msgpack-2.1.0beta1/tests/023.phpt0000644000175000001440000000144113577133502015271 0ustar mikeusers--TEST-- Resource --SKIPIF-- --FILE-- --EXPECT-- resource c0 NULL OK msgpack-2.1.0beta1/tests/024.phpt0000644000175000001440000000645013577133502015277 0ustar mikeusers--TEST-- Recursive objects --SKIPIF-- = 0 && version_compare(PHP_VERSION, '5.3.2') <= 0)) { echo "skip tests in PHP 5.2.14/5.3.3 or newer"; } --FILE-- a = $a; $this->b = $b; $this->c = $c; } } class Obj2 { public $aa; protected $bb; private $cc; private $obj; function __construct($a, $b, $c) { $this->a = $a; $this->b = $b; $this->c = $c; $this->obj = new Obj($a, $b, $c); } } class Obj3 { private $objs; function __construct($a, $b, $c) { $this->objs = array(); for ($i = $a; $i < $c; $i += $b) { $this->objs[] = new Obj($a, $i, $c); } } } class Obj4 { private $a; private $obj; function __construct($a) { $this->a = $a; } public function set($obj) { $this->obj = $obj; } } $o2 = new Obj2(1, 2, 3); test('objectrec', $o2, false); $o3 = new Obj3(0, 1, 4); test('objectrecarr', $o3, false); $o4 = new Obj4(100); $o4->set($o4); test('objectselfrec', $o4, true); ?> --EXPECTF-- objectrec 88c0a44f626a32a26161c0a5002a006262c0a8004f626a32006363c0a9004f626a32006f626a84c0a34f626aa16101a4002a006202a6004f626a006303a16101a16202a16303 object(Obj2)#%d (7) { ["aa"]=> NULL [%r"?bb"?:protected"?%r]=> NULL [%r"?cc"?:("Obj2":)?private"?%r]=> NULL [%r"?obj"?:("Obj2":)?private"?%r]=> object(Obj)#%d (3) { ["a"]=> int(1) [%r"?b"?:protected"?%r]=> int(2) [%r"?c"?:("Obj":)?private"?%r]=> int(3) } ["a"]=> int(1) ["b"]=> int(2) ["c"]=> int(3) } OK objectrecarr 82c0a44f626a33aa004f626a33006f626a739484c0a34f626aa16100a4002a006200a6004f626a00630484c0a34f626aa16100a4002a006201a6004f626a00630484c0a34f626aa16100a4002a006202a6004f626a00630484c0a34f626aa16100a4002a006203a6004f626a006304 object(Obj3)#%d (1) { [%r"?objs"?:("Obj3":)?private"?%r]=> array(4) { [0]=> object(Obj)#%d (3) { ["a"]=> int(0) [%r"?b"?:protected"?%r]=> int(0) [%r"?c"?:("Obj":)?private"?%r]=> int(4) } [1]=> object(Obj)#%d (3) { ["a"]=> int(0) [%r"?b"?:protected"?%r]=> int(1) [%r"?c"?:("Obj":)?private"?%r]=> int(4) } [2]=> object(Obj)#%d (3) { ["a"]=> int(0) [%r"?b"?:protected"?%r]=> int(2) [%r"?c"?:("Obj":)?private"?%r]=> int(4) } [3]=> object(Obj)#%d (3) { ["a"]=> int(0) [%r"?b"?:protected"?%r]=> int(3) [%r"?c"?:("Obj":)?private"?%r]=> int(4) } } } OK objectselfrec 83c0a44f626a34a7004f626a34006164a9004f626a34006f626a82c0040001 object(Obj4)#%d (2) { [%r"?a"?:("Obj4":)?private"?%r]=> int(100) [%r"?obj"?:("Obj4":)?private"?%r]=> *RECURSION* } OK msgpack-2.1.0beta1/tests/025.phpt0000644000175000001440000000413113577133502015272 0ustar mikeusers--TEST-- Object test, array of objects with __sleep --SKIPIF-- a = $a; $this->b = $b; $this->c = $c; $this->d = $d; } function __sleep() { return array('a', 'b', 'c'); } # function __wakeup() { # $this->d = $this->a + $this->b + $this->c; # } } $array = array( new Obj("aa", "bb", "cc", "dd"), new Obj("ee", "ff", "gg", "hh"), new Obj(1, 2, 3, 4), ); test('array', $array, true); ?> --EXPECTF-- array(3) { [0]=> object(Obj)#1 (4) { ["a"]=> string(2) "aa" [%r"?b"?:protected"?%r]=> string(2) "bb" [%r"?c"?:("Obj":)?private"?%r]=> string(2) "cc" ["d"]=> string(2) "dd" } [1]=> object(Obj)#2 (4) { ["a"]=> string(2) "ee" [%r"?b"?:protected"?%r]=> string(2) "ff" [%r"?c"?:("Obj":)?private"?%r]=> string(2) "gg" ["d"]=> string(2) "hh" } [2]=> object(Obj)#3 (4) { ["a"]=> int(1) [%r"?b"?:protected"?%r]=> int(2) [%r"?c"?:("Obj":)?private"?%r]=> int(3) ["d"]=> int(4) } } array(3) { [0]=> object(Obj)#4 (4) { ["a"]=> string(2) "aa" [%r"?b"?:protected"?%r]=> string(2) "bb" [%r"?c"?:("Obj":)?private"?%r]=> string(2) "cc" ["d"]=> NULL } [1]=> object(Obj)#5 (4) { ["a"]=> string(2) "ee" [%r"?b"?:protected"?%r]=> string(2) "ff" [%r"?c"?:("Obj":)?private"?%r]=> string(2) "gg" ["d"]=> NULL } [2]=> object(Obj)#6 (4) { ["a"]=> int(1) [%r"?b"?:protected"?%r]=> int(2) [%r"?c"?:("Obj":)?private"?%r]=> int(3) ["d"]=> NULL } } msgpack-2.1.0beta1/tests/026.phpt0000644000175000001440000000333113577133502015274 0ustar mikeusers--TEST-- Cyclic array test --INI-- --SKIPIF-- = 0 && version_compare(PHP_VERSION, '5.3.2') <= 0)) { echo "skip tests in PHP 5.2.14/5.3.3 or newer"; } --FILE-- array( 'b' => 'c', 'd' => 'e' ), ); $a['f'] = &$a; test('array', $a, true); $a = array("foo" => &$b); $b = array(1, 2, $a); var_dump($a); var_dump($k = msgpack_unserialize(msgpack_serialize($a))); $k["foo"][1] = "b"; var_dump($k); ?> --EXPECT-- array 82a16182a162a163a164a165a16683c001a16182a162a163a164a165a16682c0020003 array(2) { ["a"]=> array(2) { ["b"]=> string(1) "c" ["d"]=> string(1) "e" } ["f"]=> &array(2) { ["a"]=> array(2) { ["b"]=> string(1) "c" ["d"]=> string(1) "e" } ["f"]=> *RECURSION* } } OK array(1) { ["foo"]=> &array(3) { [0]=> int(1) [1]=> int(2) [2]=> array(1) { ["foo"]=> *RECURSION* } } } array(1) { ["foo"]=> &array(3) { [0]=> int(1) [1]=> int(2) [2]=> array(1) { ["foo"]=> *RECURSION* } } } array(1) { ["foo"]=> &array(3) { [0]=> int(1) [1]=> string(1) "b" [2]=> array(1) { ["foo"]=> *RECURSION* } } } msgpack-2.1.0beta1/tests/027.phpt0000644000175000001440000000233513577133502015300 0ustar mikeusers--TEST-- Check for serialization handler --SKIPIF-- --EXPECT-- bool(true) read wrote: 83c001a3666f6f01a474657374a6666f6f626172 array(2) { ["foo"]=> int(1) ["test"]=> string(6) "foobar" } msgpack-2.1.0beta1/tests/028.phpt0000644000175000001440000000700613577133502015301 0ustar mikeusers--TEST-- Serialize object into session, full set --SKIPIF-- = 0 && version_compare(PHP_VERSION, '5.3.2') <= 0)) { echo "skip tests in PHP 5.2.14/5.3.3 or newer"; } if (!extension_loaded("session")) { echo "skip needs session enabled"; } --FILE-- d1 = $foo; $this->d2 = $foo; $this->d3 = $foo; } } class Bar { private static $s1 = array(); protected static $s2 = array(); public static $s3 = array(); public $d1; private $d2; protected $d3; public function __construct() { } public function set($foo) { $this->d1 = $foo; $this->d2 = $foo; $this->d3 = $foo; } } $output = ''; function open($path, $name) { return true; } function close() { return true; } 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); } function write($id, $data) { global $output; $output .= "write: "; $output .= bin2hex($data) . PHP_EOL; return true; } function destroy($id) { return true; } function gc($time) { return true; } ini_set('session.serialize_handler', 'msgpack'); session_set_save_handler('open', 'close', 'read', 'write', 'destroy', 'gc'); session_start(); $_SESSION['test'] = "foobar"; $a = new Bar(); $b = new Foo($a); $a->set($b); $_SESSION['new'] = $a; session_write_close(); echo $output; var_dump($_SESSION); ?> --EXPECTF-- read write: 84c001a36f6c6484c0a3466f6fa700466f6f00643184c0a3426172a2643182c0040002a70042617200643282c0040002a5002a00643382c0040002a5002a00643282c0040003a2643382c0040003a474657374a6666f6f626172a36e657784c0a3426172a2643184c0a3466f6fa700466f6f00643182c0040009a5002a00643282c0040009a2643382c0040009a70042617200643282c004000aa5002a00643382c004000a array(3) { ["old"]=> object(Foo)#3 (3) { [%r"?d1"?:("Foo":)?private"?%r]=> object(Bar)#4 (3) { ["d1"]=> *RECURSION* [%r"?d2"?:("Bar":)?private"?%r]=> *RECURSION* [%r"?d3"?:protected"?%r]=> *RECURSION* } [%r"?d2"?:protected"?%r]=> object(Bar)#4 (3) { ["d1"]=> *RECURSION* [%r"?d2"?:("Bar":)?private"?%r]=> *RECURSION* [%r"?d3"?:protected"?%r]=> *RECURSION* } ["d3"]=> object(Bar)#4 (3) { ["d1"]=> *RECURSION* [%r"?d2"?:("Bar":)?private"?%r]=> *RECURSION* [%r"?d3"?:protected"?%r]=> *RECURSION* } } ["test"]=> string(6) "foobar" ["new"]=> object(Bar)#5 (3) { ["d1"]=> object(Foo)#6 (3) { [%r"?d1"?:("Foo":)?private"?%r]=> *RECURSION* [%r"?d2"?:protected"?%r]=> *RECURSION* ["d3"]=> *RECURSION* } [%r"?d2"?:("Bar":)?private"?%r]=> object(Foo)#6 (3) { [%r"?d1"?:("Foo":)?private"?%r]=> *RECURSION* [%r"?d2"?:protected"?%r]=> *RECURSION* ["d3"]=> *RECURSION* } [%r"?d3"?:protected"?%r]=> object(Foo)#6 (3) { [%r"?d1"?:("Foo":)?private"?%r]=> *RECURSION* [%r"?d2"?:protected"?%r]=> *RECURSION* ["d3"]=> *RECURSION* } } } msgpack-2.1.0beta1/tests/029.phpt0000644000175000001440000000164613577133502015306 0ustar mikeusers--TEST-- Msgpack module info --SKIPIF-- --FILE-- $val) { if (strcmp($val, 'msgpack') == 0 || $section) { $section = true; } else { continue; } if (empty($val)) { $blank++; if ($blank == 3) { $section = false; } } echo $val, PHP_EOL; } --EXPECTF-- msgpack MessagePack Support => enabled Session Support => enabled extension Version => %s header Version => %s Directive => Local Value => Master Value msgpack.error_display => %s => %s msgpack.illegal_key_insert => %s => %s msgpack.php_only => %s => %s msgpack.use_str8_serialization => %s => %s msgpack-2.1.0beta1/tests/030.phpt0000644000175000001440000000441013577133502015266 0ustar mikeusers--TEST-- Unserialize invalid data --SKIPIF-- --FILE-- 10, "foo"), true, false, 0.187182, "dakjdh98389\000", null, (object)array(1,2,3), ); error_reporting(0); foreach ($datas as $data) { $str = msgpack_serialize($data); $len = strlen($str); // truncated for ($i = 0; $i < $len - 1; $i++) { $v = msgpack_unserialize(substr($str, 0, $i)); if (is_object($data) || is_array($data)) { if ($v !== null && $v !== false && $v != $data) { echo "output at $i:\n"; var_dump($v); } } else if ($v !== null && $v == $data) { continue; } else if ($v !== null && $v !== $data) { echo "output at $i:\n"; var_dump($v); echo "vs.\n"; var_dump($data); } } // padded $str .= "98398afa\000y21_ "; $v = msgpack_unserialize($str); if ($v !== $data && !(is_object($data) && $v == $data)) { echo "padded should get original\n"; var_dump($v); echo "vs.\n"; var_dump($data); } } ?> --EXPECTF-- output at 1: bool(false) vs. int(87817) output at 2: bool(false) vs. int(87817) output at 3: bool(false) vs. int(87817) output at 1: bool(false) vs. float(0.187182) output at 2: bool(false) vs. float(0.187182) output at 3: bool(false) vs. float(0.187182) output at 4: bool(false) vs. float(0.187182) output at 5: bool(false) vs. float(0.187182) output at 6: bool(false) vs. float(0.187182) output at 7: bool(false) vs. float(0.187182) output at 1: bool(false) vs. string(12) "dakjdh98389" output at 2: bool(false) vs. string(12) "dakjdh98389" output at 3: bool(false) vs. string(12) "dakjdh98389" output at 4: bool(false) vs. string(12) "dakjdh98389" output at 5: bool(false) vs. string(12) "dakjdh98389" output at 6: bool(false) vs. string(12) "dakjdh98389" output at 7: bool(false) vs. string(12) "dakjdh98389" output at 8: bool(false) vs. string(12) "dakjdh98389" output at 9: bool(false) vs. string(12) "dakjdh98389" output at 10: bool(false) vs. string(12) "dakjdh98389" output at 11: bool(false) vs. string(12) "dakjdh98389" msgpack-2.1.0beta1/tests/031.phpt0000644000175000001440000000407113577133502015272 0ustar mikeusers--TEST-- Object Serializable interface throws exceptions --SKIPIF-- a = $a; $this->b = $b; } public function serialize() { $c = self::$count++; echo "call serialize, ", ($this->a ? "throw" : "no throw"), PHP_EOL; if ($this->a) { throw new Exception("exception in serialize $c"); } return pack('NN', $this->a, $this->b); } public function unserialize($serialized) { $tmp = unpack('N*', $serialized); $this->__construct($tmp[1], $tmp[2]); $c = self::$count++; echo "call unserialize, ", ($this->b ? "throw" : "no throw"), PHP_EOL; if ($this->b) { throw new Exception("exception in unserialize $c"); } } } $a = new Obj(1, 0); $a = new Obj(0, 0); $b = new Obj(0, 0); $c = new Obj(1, 0); $d = new Obj(0, 1); echo "a, a, c", PHP_EOL; try { test(array($a, $a, $c)); } catch (Exception $e) { if (version_compare(phpversion(), "5.3.0", ">=")) { if ($e->getPrevious()) { $e = $e->getPrevious(); } } echo $e->getMessage(), PHP_EOL; } echo "b, b, d", PHP_EOL; try { test(array($b, $b, $d)); } catch (Exception $e) { if (version_compare(phpversion(), "5.3.0", ">=")) { if ($e->getPrevious()) { $e = $e->getPrevious(); } } echo $e->getMessage(), PHP_EOL; } ?> --EXPECT-- a, a, c call serialize, no throw call serialize, throw exception in serialize 2 b, b, d call serialize, no throw call serialize, no throw call unserialize, no throw call unserialize, throw exception in unserialize 6 msgpack-2.1.0beta1/tests/032.phpt0000644000175000001440000000243613577133502015276 0ustar mikeusers--TEST-- Object test, __sleep and __wakeup exceptions --SKIPIF-- --FILE-- a = $a; $this->b = $b; } function __sleep() { $c = self::$count++; if ($this->a) { throw new Exception("exception in __sleep $c"); } return array('a', 'b'); } function __wakeup() { $c = self::$count++; if ($this->b) { throw new Exception("exception in __wakeup $c"); } $this->b = $this->a * 3; } } $a = new Obj(1, 0); $b = new Obj(0, 1); $c = new Obj(0, 0); try { test($a); } catch (Exception $e) { echo $e->getMessage(), PHP_EOL; } try { test($b); } catch (Exception $e) { echo $e->getMessage(), PHP_EOL; } try { test($c); } catch (Exception $e) { echo $e->getMessage(), PHP_EOL; } ?> --EXPECTF-- exception in __sleep 0 exception in __wakeup 2 object(Obj)#%d (2) { ["a"]=> int(0) ["b"]=> int(0) } msgpack-2.1.0beta1/tests/033.phpt0000644000175000001440000000170513577133502015275 0ustar mikeusers--TEST-- Object test, cyclic references --SKIPIF-- --FILE-- 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; } ?> --EXPECT-- object object object object object object object object object object object object object object object object object object object object msgpack-2.1.0beta1/tests/034.phpt0000644000175000001440000000132313577133502015272 0ustar mikeusers--TEST-- Unserialize invalid random data --SKIPIF-- --XFAIL-- REGRESSION --FILE-- 10, "foo"), true, false, 0.187182, "dakjdh98389\000", 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 .= random_bytes(30); $php_errormsg = null; $v = msgpack_unserialize($sub); } } } ?> OK --EXPECT-- OK msgpack-2.1.0beta1/tests/035.phpt0000644000175000001440000000156613577133502015304 0ustar mikeusers--TEST-- Profiling perf test. --SKIPIF-- --FILE-- 400 ? "GOOD" : "BAD")); } ?> --EXPECTF-- %d iterations took %f seconds: %d/s (GOOD) msgpack-2.1.0beta1/tests/040.phpt0000644000175000001440000000161213577133502015270 0ustar mikeusers--TEST-- broken random data test --SKIPIF-- =")) { die("skip PHP >= 7.1"); } ?> --FILE-- --EXPECT-- msgpack-2.1.0beta1/tests/040b.phpt0000644000175000001440000000167513577133502015443 0ustar mikeusers--TEST-- broken random data test : MessagePack class --SKIPIF-- =")) { die("skip PHP >= 7.1"); } ?> --FILE-- 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; } mt_srand(0x4c05b583); for ($i = 0; $i < 100; ++$i) { if (!test()) break; } ?> --EXPECT-- msgpack-2.1.0beta1/tests/040c.phpt0000644000175000001440000000214013577133502015430 0ustar mikeusers--TEST-- broken random data test : MessagePackUnpacker::feed --SKIPIF-- =")) { die("skip PHP >= 7.1"); } ?> --FILE-- 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; } mt_srand(0x4c05b583); for ($i = 0; $i < 100; ++$i) { if (!test()) break; } ?> --EXPECT-- msgpack-2.1.0beta1/tests/040d.phpt0000644000175000001440000000212513577133502015434 0ustar mikeusers--TEST-- broken random data test : MessagePackUnpacker::execute --SKIPIF-- =")) { die("skip PHP >= 7.1"); } ?> --FILE-- execute($serialized, $offset)) { 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; } mt_srand(0x4c05b583); for ($i = 0; $i < 100; ++$i) { if (!test()) break; } ?> --EXPECT-- msgpack-2.1.0beta1/tests/041.phpt0000644000175000001440000000207013577133502015270 0ustar mikeusers--TEST-- Check for double NaN, Inf, -Inf, 0, and -0 --FILE-- --EXPECT-- empty array: 90 array(0) { } array(1, 2, 3) 93010203 array(3) { [0]=> int(1) [1]=> int(2) [2]=> int(3) } array(array(1, 2, 3), arr... 93930102039304050693070809 array(3) { [0]=> array(3) { [0]=> int(1) [1]=> int(2) [2]=> int(3) } [1]=> array(3) { [0]=> int(4) [1]=> int(5) [2]=> int(6) } [2]=> array(3) { [0]=> int(7) [1]=> int(8) [2]=> int(9) } } array("foo", "FOO", "Foo") 93a3666f6fa3464f4fa3466f6f array(3) { [0]=> string(3) "foo" [1]=> string(3) "FOO" [2]=> string(3) "Foo" } array(1, 123.45, true, ... 9701cb405edccccccccccdc3c293010293090807c0a3666f6f array(7) { [0]=> int(1) [1]=> float(123.45) [2]=> bool(true) [3]=> bool(false) [4]=> array(3) { [0]=> int(1) [1]=> int(2) [2]=> array(3) { [0]=> int(9) [1]=> int(8) [2]=> int(7) } } [5]=> NULL [6]=> string(3) "foo" } msgpack-2.1.0beta1/tests/060.phpt0000644000175000001440000001117313577133502015275 0ustar mikeusers--TEST-- Check for buffered streaming unserialization --SKIPIF-- = 0 && version_compare(PHP_VERSION, '5.3.2') <= 0)) { echo "skip tests in PHP 5.2.14/5.3.3 or newer"; } --FILE-- 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; } } test('null', null); test('bool: true', true); test('bool: false', false); test('zero: 0', 0); test('small: 1', 1); test('small: -1', -1); test('medium: 1000', 1000); test('medium: -1000', -1000); test('large: 100000', 100000); test('large: -100000', -100000); test('double: 123.456', 123.456); test('empty: ""', ""); test('string: "foobar"', "foobar"); test('array', array(), false); test('array(1, 2, 3)', array(1, 2, 3), false); test('array(array(1, 2, 3), arr...', array(array(1, 2, 3), array(4, 5, 6), array(7, 8, 9)), false); test('array("foo", "foo", "foo")', array("foo", "foo", "foo"), false); test('array("one" => 1, "two" => 2))', array("one" => 1, "two" => 2), false); test('array("kek" => "lol", "lol" => "kek")', array("kek" => "lol", "lol" => "kek"), false); test('array("" => "empty")', array("" => "empty"), false); $a = array('foo'); test('array($a, $a)', array($a, $a), false); test('array(&$a, &$a)', array(&$a, &$a), false); $a = array(null); $b = array(&$a); $a[0] = &$b; test('cyclic', $a, true); $a = array( 'a' => array( 'b' => 'c', 'd' => 'e' ), 'f' => array( 'g' => 'h' ) ); test('array', $a, false); class Obj { public $a; protected $b; private $c; function __construct($a, $b, $c) { $this->a = $a; $this->b = $b; $this->c = $c; } } test('object', new Obj(1, 2, 3), false); test('object', array(new Obj(1, 2, 3), new Obj(4, 5, 6)), false); $o = new Obj(1, 2, 3); test('object', array(&$o, &$o), false); --EXPECTF-- NULL OK bool(true) OK bool(false) OK int(0) OK int(1) OK int(-1) OK int(1000) OK int(-1000) OK int(100000) OK int(-100000) OK float(123.456) OK string(0) "" OK string(6) "foobar" OK array(0) { } OK array(3) { [0]=> int(1) [1]=> int(2) [2]=> int(3) } OK array(3) { [0]=> array(3) { [0]=> int(1) [1]=> int(2) [2]=> int(3) } [1]=> array(3) { [0]=> int(4) [1]=> int(5) [2]=> int(6) } [2]=> array(3) { [0]=> int(7) [1]=> int(8) [2]=> int(9) } } OK array(3) { [0]=> string(3) "foo" [1]=> string(3) "foo" [2]=> string(3) "foo" } OK array(2) { ["one"]=> int(1) ["two"]=> int(2) } OK array(2) { ["kek"]=> string(3) "lol" ["lol"]=> string(3) "kek" } OK array(1) { [""]=> string(5) "empty" } OK array(2) { [0]=> array(1) { [0]=> string(3) "foo" } [1]=> array(1) { [0]=> string(3) "foo" } } OK array(2) { [0]=> &array(1) { [0]=> string(3) "foo" } [1]=> &array(1) { [0]=> string(3) "foo" } } OK array(1) { [0]=> &array(1) { [0]=> array(1) { [0]=> *RECURSION* } } } OK array(2) { ["a"]=> array(2) { ["b"]=> string(1) "c" ["d"]=> string(1) "e" } ["f"]=> array(1) { ["g"]=> string(1) "h" } } OK object(Obj)#%d (3) { ["a"]=> int(1) [%r"?b"?:protected"?%r]=> int(2) [%r"?c"?:("Obj":)?private"?%r]=> int(3) } OK array(2) { [0]=> object(Obj)#%d (3) { ["a"]=> int(1) [%r"?b"?:protected"?%r]=> int(2) [%r"?c"?:("Obj":)?private"?%r]=> int(3) } [1]=> object(Obj)#%d (3) { ["a"]=> int(4) [%r"?b"?:protected"?%r]=> int(5) [%r"?c"?:("Obj":)?private"?%r]=> int(6) } } OK array(2) { [0]=> &object(Obj)#%d (3) { ["a"]=> int(1) [%r"?b"?:protected"?%r]=> int(2) [%r"?c"?:("Obj":)?private"?%r]=> int(3) } [1]=> &object(Obj)#%d (3) { ["a"]=> int(1) [%r"?b"?:protected"?%r]=> int(2) [%r"?c"?:("Obj":)?private"?%r]=> int(3) } } OK msgpack-2.1.0beta1/tests/061.phpt0000644000175000001440000001130513577133502015273 0ustar mikeusers--TEST-- Check for unbuffered streaming unserialization --SKIPIF-- = 0 && version_compare(PHP_VERSION, '5.3.2') <= 0)) { echo "skip tests in PHP 5.2.14/5.3.3 or newer"; } --FILE-- 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; } } test('null', null); test('bool: true', true); test('bool: false', false); test('zero: 0', 0); test('small: 1', 1); test('small: -1', -1); test('medium: 1000', 1000); test('medium: -1000', -1000); test('large: 100000', 100000); test('large: -100000', -100000); test('double: 123.456', 123.456); test('empty: ""', ""); test('string: "foobar"', "foobar"); test('array: empty', array(), false); test('array(1, 2, 3)', array(1, 2, 3), false); test('array(array(1, 2, 3), arr...', array(array(1, 2, 3), array(4, 5, 6), array(7, 8, 9)), false); test('array("foo", "foo", "foo")', array("foo", "foo", "foo"), false); test('array("one" => 1, "two" => 2))', array("one" => 1, "two" => 2), false); test('array("kek" => "lol", "lol" => "kek")', array("kek" => "lol", "lol" => "kek"), false); test('array("" => "empty")', array("" => "empty"), false); $a = array('foo'); test('array($a, $a)', array($a, $a), false); test('array(&$a, &$a)', array(&$a, &$a), false); $a = array(null); $b = array(&$a); $a[0] = &$b; test('cyclic', $a, true); $a = array( 'a' => array( 'b' => 'c', 'd' => 'e' ), 'f' => array( 'g' => 'h' ) ); test('array', $a, false); class Obj { public $a; protected $b; private $c; function __construct($a, $b, $c) { $this->a = $a; $this->b = $b; $this->c = $c; } } test('object', new Obj(1, 2, 3), false); test('object', array(new Obj(1, 2, 3), new Obj(4, 5, 6)), false); $o = new Obj(1, 2, 3); test('object', array(&$o, &$o), false); --EXPECTF-- NULL OK bool(true) OK bool(false) OK int(0) OK int(1) OK int(-1) OK int(1000) OK int(-1000) OK int(100000) OK int(-100000) OK float(123.456) OK string(0) "" OK string(6) "foobar" OK array(0) { } OK array(3) { [0]=> int(1) [1]=> int(2) [2]=> int(3) } OK array(3) { [0]=> array(3) { [0]=> int(1) [1]=> int(2) [2]=> int(3) } [1]=> array(3) { [0]=> int(4) [1]=> int(5) [2]=> int(6) } [2]=> array(3) { [0]=> int(7) [1]=> int(8) [2]=> int(9) } } OK array(3) { [0]=> string(3) "foo" [1]=> string(3) "foo" [2]=> string(3) "foo" } OK array(2) { ["one"]=> int(1) ["two"]=> int(2) } OK array(2) { ["kek"]=> string(3) "lol" ["lol"]=> string(3) "kek" } OK array(1) { [""]=> string(5) "empty" } OK array(2) { [0]=> array(1) { [0]=> string(3) "foo" } [1]=> array(1) { [0]=> string(3) "foo" } } OK array(2) { [0]=> &array(1) { [0]=> string(3) "foo" } [1]=> &array(1) { [0]=> string(3) "foo" } } OK array(1) { [0]=> &array(1) { [0]=> array(1) { [0]=> *RECURSION* } } } OK array(2) { ["a"]=> array(2) { ["b"]=> string(1) "c" ["d"]=> string(1) "e" } ["f"]=> array(1) { ["g"]=> string(1) "h" } } OK object(Obj)#%d (3) { ["a"]=> int(1) [%r"?b"?:protected"?%r]=> int(2) [%r"?c"?:("Obj":)?private"?%r]=> int(3) } OK array(2) { [0]=> object(Obj)#%d (3) { ["a"]=> int(1) [%r"?b"?:protected"?%r]=> int(2) [%r"?c"?:("Obj":)?private"?%r]=> int(3) } [1]=> object(Obj)#%d (3) { ["a"]=> int(4) [%r"?b"?:protected"?%r]=> int(5) [%r"?c"?:("Obj":)?private"?%r]=> int(6) } } OK array(2) { [0]=> &object(Obj)#%d (3) { ["a"]=> int(1) [%r"?b"?:protected"?%r]=> int(2) [%r"?c"?:("Obj":)?private"?%r]=> int(3) } [1]=> &object(Obj)#%d (3) { ["a"]=> int(1) [%r"?b"?:protected"?%r]=> int(2) [%r"?c"?:("Obj":)?private"?%r]=> int(3) } } OK msgpack-2.1.0beta1/tests/062.phpt0000644000175000001440000000222713577133502015277 0ustar mikeusers--TEST-- Extra bytes buffered streaming unserialization --SKIPIF-- --FILE-- feed($str); while (true) { if ($unpacker->execute()) { $unserialized = $unpacker->data(); var_dump($unserialized); $unpacker->reset(); } else { break; } } $i += $len; } } } test('array(1, 2, 3)', array('9301020392')); test('array(1, 2, 3), array(3, 9), 4', array('9301020392', '030904')); --EXPECTF-- array(3) { [0]=> int(1) [1]=> int(2) [2]=> int(3) } array(3) { [0]=> int(1) [1]=> int(2) [2]=> int(3) } array(2) { [0]=> int(3) [1]=> int(9) } int(4) msgpack-2.1.0beta1/tests/063.phpt0000644000175000001440000000237013577133502015277 0ustar mikeusers--TEST-- Extra bytes unbuffered streaming unserialization --SKIPIF-- --FILE-- execute($str, $offset)) { $unserialized = $unpacker->data(); var_dump($unserialized); $unpacker->reset(); $str = substr($str, $offset); $offset = 0; } else { break; } } $i += $len; } } } test('array(1, 2, 3)', array('9301020392')); test('array(1, 2, 3), array(3, 9), 4', array('9301020392', '030904')); --EXPECTF-- array(3) { [0]=> int(1) [1]=> int(2) [2]=> int(3) } array(3) { [0]=> int(1) [1]=> int(2) [2]=> int(3) } array(2) { [0]=> int(3) [1]=> int(9) } int(4) msgpack-2.1.0beta1/tests/064.phpt0000644000175000001440000001122713577133502015301 0ustar mikeusers--TEST-- Check for buffered streaming unserialization (single) --SKIPIF-- = 0 && version_compare(PHP_VERSION, '5.3.2') <= 0)) { echo "skip tests in PHP 5.2.14/5.3.3 or newer"; } --FILE-- 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; } } test('null', null); test('bool: true', true); test('bool: false', false); test('zero: 0', 0); test('small: 1', 1); test('small: -1', -1); test('medium: 1000', 1000); test('medium: -1000', -1000); test('large: 100000', 100000); test('large: -100000', -100000); test('double: 123.456', 123.456); test('empty: ""', ""); test('string: "foobar"', "foobar"); test('array', array(), false); test('array(1, 2, 3)', array(1, 2, 3), false); test('array(array(1, 2, 3), arr...', array(array(1, 2, 3), array(4, 5, 6), array(7, 8, 9)), false); test('array("foo", "foo", "foo")', array("foo", "foo", "foo"), false); test('array("one" => 1, "two" => 2))', array("one" => 1, "two" => 2), false); test('array("kek" => "lol", "lol" => "kek")', array("kek" => "lol", "lol" => "kek"), false); test('array("" => "empty")', array("" => "empty"), false); $a = array('foo'); test('array($a, $a)', array($a, $a), false); test('array(&$a, &$a)', array(&$a, &$a), false); $a = array(null); $b = array(&$a); $a[0] = &$b; test('cyclic', $a, true); $a = array( 'a' => array( 'b' => 'c', 'd' => 'e' ), 'f' => array( 'g' => 'h' ) ); test('array', $a, false); class Obj { public $a; protected $b; private $c; function __construct($a, $b, $c) { $this->a = $a; $this->b = $b; $this->c = $c; } } test('object', new Obj(1, 2, 3), false); test('object', array(new Obj(1, 2, 3), new Obj(4, 5, 6)), false); $o = new Obj(1, 2, 3); test('object', array(&$o, &$o), false); --EXPECTF-- NULL OK bool(true) OK bool(false) OK int(0) OK int(1) OK int(-1) OK int(1000) OK int(-1000) OK int(100000) OK int(-100000) OK float(123.456) OK string(0) "" OK string(6) "foobar" OK array(0) { } OK array(3) { [0]=> int(1) [1]=> int(2) [2]=> int(3) } OK array(3) { [0]=> array(3) { [0]=> int(1) [1]=> int(2) [2]=> int(3) } [1]=> array(3) { [0]=> int(4) [1]=> int(5) [2]=> int(6) } [2]=> array(3) { [0]=> int(7) [1]=> int(8) [2]=> int(9) } } OK array(3) { [0]=> string(3) "foo" [1]=> string(3) "foo" [2]=> string(3) "foo" } OK array(2) { ["one"]=> int(1) ["two"]=> int(2) } OK array(2) { ["kek"]=> string(3) "lol" ["lol"]=> string(3) "kek" } OK array(1) { [""]=> string(5) "empty" } OK array(2) { [0]=> array(1) { [0]=> string(3) "foo" } [1]=> array(1) { [0]=> string(3) "foo" } } OK array(2) { [0]=> &array(1) { [0]=> string(3) "foo" } [1]=> &array(1) { [0]=> string(3) "foo" } } OK array(1) { [0]=> &array(1) { [0]=> array(1) { [0]=> *RECURSION* } } } OK array(2) { ["a"]=> array(2) { ["b"]=> string(1) "c" ["d"]=> string(1) "e" } ["f"]=> array(1) { ["g"]=> string(1) "h" } } OK object(Obj)#%d (3) { ["a"]=> int(1) [%r"?b"?:protected"?%r]=> int(2) [%r"?c"?:("Obj":)?private"?%r]=> int(3) } OK array(2) { [0]=> object(Obj)#%d (3) { ["a"]=> int(1) [%r"?b"?:protected"?%r]=> int(2) [%r"?c"?:("Obj":)?private"?%r]=> int(3) } [1]=> object(Obj)#%d (3) { ["a"]=> int(4) [%r"?b"?:protected"?%r]=> int(5) [%r"?c"?:("Obj":)?private"?%r]=> int(6) } } OK array(2) { [0]=> &object(Obj)#%d (3) { ["a"]=> int(1) [%r"?b"?:protected"?%r]=> int(2) [%r"?c"?:("Obj":)?private"?%r]=> int(3) } [1]=> &object(Obj)#%d (3) { ["a"]=> int(1) [%r"?b"?:protected"?%r]=> int(2) [%r"?c"?:("Obj":)?private"?%r]=> int(3) } } OK msgpack-2.1.0beta1/tests/065.phpt0000644000175000001440000001134113577133502015277 0ustar mikeusers--TEST-- Check for unbuffered streaming unserialization (single) --SKIPIF-- = 0 && version_compare(PHP_VERSION, '5.3.2') <= 0)) { echo "skip tests in PHP 5.2.14/5.3.3 or newer"; } --FILE-- 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; } } test('null', null); test('bool: true', true); test('bool: false', false); test('zero: 0', 0); test('small: 1', 1); test('small: -1', -1); test('medium: 1000', 1000); test('medium: -1000', -1000); test('large: 100000', 100000); test('large: -100000', -100000); test('double: 123.456', 123.456); test('empty: ""', ""); test('string: "foobar"', "foobar"); test('array: empty', array(), false); test('array(1, 2, 3)', array(1, 2, 3), false); test('array(array(1, 2, 3), arr...', array(array(1, 2, 3), array(4, 5, 6), array(7, 8, 9)), false); test('array("foo", "foo", "foo")', array("foo", "foo", "foo"), false); test('array("one" => 1, "two" => 2))', array("one" => 1, "two" => 2), false); test('array("kek" => "lol", "lol" => "kek")', array("kek" => "lol", "lol" => "kek"), false); test('array("" => "empty")', array("" => "empty"), false); $a = array('foo'); test('array($a, $a)', array($a, $a), false); test('array(&$a, &$a)', array(&$a, &$a), false); $a = array(null); $b = array(&$a); $a[0] = &$b; test('cyclic', $a, true); $a = array( 'a' => array( 'b' => 'c', 'd' => 'e' ), 'f' => array( 'g' => 'h' ) ); test('array', $a, false); class Obj { public $a; protected $b; private $c; function __construct($a, $b, $c) { $this->a = $a; $this->b = $b; $this->c = $c; } } test('object', new Obj(1, 2, 3), false); test('object', array(new Obj(1, 2, 3), new Obj(4, 5, 6)), false); $o = new Obj(1, 2, 3); test('object', array(&$o, &$o), false); --EXPECTF-- NULL OK bool(true) OK bool(false) OK int(0) OK int(1) OK int(-1) OK int(1000) OK int(-1000) OK int(100000) OK int(-100000) OK float(123.456) OK string(0) "" OK string(6) "foobar" OK array(0) { } OK array(3) { [0]=> int(1) [1]=> int(2) [2]=> int(3) } OK array(3) { [0]=> array(3) { [0]=> int(1) [1]=> int(2) [2]=> int(3) } [1]=> array(3) { [0]=> int(4) [1]=> int(5) [2]=> int(6) } [2]=> array(3) { [0]=> int(7) [1]=> int(8) [2]=> int(9) } } OK array(3) { [0]=> string(3) "foo" [1]=> string(3) "foo" [2]=> string(3) "foo" } OK array(2) { ["one"]=> int(1) ["two"]=> int(2) } OK array(2) { ["kek"]=> string(3) "lol" ["lol"]=> string(3) "kek" } OK array(1) { [""]=> string(5) "empty" } OK array(2) { [0]=> array(1) { [0]=> string(3) "foo" } [1]=> array(1) { [0]=> string(3) "foo" } } OK array(2) { [0]=> &array(1) { [0]=> string(3) "foo" } [1]=> &array(1) { [0]=> string(3) "foo" } } OK array(1) { [0]=> &array(1) { [0]=> array(1) { [0]=> *RECURSION* } } } OK array(2) { ["a"]=> array(2) { ["b"]=> string(1) "c" ["d"]=> string(1) "e" } ["f"]=> array(1) { ["g"]=> string(1) "h" } } OK object(Obj)#%d (3) { ["a"]=> int(1) [%r"?b"?:protected"?%r]=> int(2) [%r"?c"?:("Obj":)?private"?%r]=> int(3) } OK array(2) { [0]=> object(Obj)#%d (3) { ["a"]=> int(1) [%r"?b"?:protected"?%r]=> int(2) [%r"?c"?:("Obj":)?private"?%r]=> int(3) } [1]=> object(Obj)#%d (3) { ["a"]=> int(4) [%r"?b"?:protected"?%r]=> int(5) [%r"?c"?:("Obj":)?private"?%r]=> int(6) } } OK array(2) { [0]=> &object(Obj)#%d (3) { ["a"]=> int(1) [%r"?b"?:protected"?%r]=> int(2) [%r"?c"?:("Obj":)?private"?%r]=> int(3) } [1]=> &object(Obj)#%d (3) { ["a"]=> int(1) [%r"?b"?:protected"?%r]=> int(2) [%r"?c"?:("Obj":)?private"?%r]=> int(3) } } OK msgpack-2.1.0beta1/tests/066.phpt0000644000175000001440000000235413577133502015304 0ustar mikeusers--TEST-- Extra bytes buffered streaming unserialization (single) --SKIPIF-- --FILE-- feed($str); while (true) { if ($unpacker->execute()) { $unserialized = $unpacker->data(); var_dump($unserialized); $unpacker->reset(); } else { break; } } $i += $len; } } } test('array(1, 2, 3)', array('9301020392')); test('array(1, 2, 3), array(3, 9), 4', array('9301020392', '030904')); --EXPECTF-- array(3) { [0]=> int(1) [1]=> int(2) [2]=> int(3) } array(2) { [0]=> array(3) { [0]=> int(1) [1]=> int(2) [2]=> int(3) } [1]=> array(2) { [0]=> int(3) [1]=> int(9) } } int(4) msgpack-2.1.0beta1/tests/067.phpt0000644000175000001440000000251513577133502015304 0ustar mikeusers--TEST-- Extra bytes unbuffered streaming unserialization (single) --SKIPIF-- --FILE-- execute($str, $offset)) { $unserialized = $unpacker->data(); var_dump($unserialized); $unpacker->reset(); $str = substr($str, $offset); $offset = 0; } else { break; } } $i += $len; } } } test('array(1, 2, 3)', array('9301020392')); test('array(1, 2, 3), array(3, 9), 4', array('9301020392', '030904')); --EXPECTF-- array(3) { [0]=> int(1) [1]=> int(2) [2]=> int(3) } array(2) { [0]=> array(3) { [0]=> int(1) [1]=> int(2) [2]=> int(3) } [1]=> array(2) { [0]=> int(3) [1]=> int(9) } } int(4) msgpack-2.1.0beta1/tests/070.phpt0000644000175000001440000001042713577133502015277 0ustar mikeusers--TEST-- Check for alias functions --SKIPIF-- = 0 && version_compare(PHP_VERSION, '5.3.2') <= 0)) { echo "skip tests in PHP 5.2.14/5.3.3 or newer"; } --FILE-- 1, "two" => 2))', array("one" => 1, "two" => 2), false); test('array("kek" => "lol", "lol" => "kek")', array("kek" => "lol", "lol" => "kek"), false); test('array("" => "empty")', array("" => "empty"), false); $a = array('foo'); test('array($a, $a)', array($a, $a), false); test('array(&$a, &$a)', array(&$a, &$a), false); $a = array(null); $b = array(&$a); $a[0] = &$b; test('cyclic', $a, true); $a = array( 'a' => array( 'b' => 'c', 'd' => 'e' ), 'f' => array( 'g' => 'h' ) ); test('array', $a, false); class Obj { public $a; protected $b; private $c; function __construct($a, $b, $c) { $this->a = $a; $this->b = $b; $this->c = $c; } } test('object', new Obj(1, 2, 3), false); test('object', array(new Obj(1, 2, 3), new Obj(4, 5, 6)), false); $o = new Obj(1, 2, 3); test('object', array(&$o, &$o), false); --EXPECTF-- NULL OK bool(true) OK bool(false) OK int(0) OK int(1) OK int(-1) OK int(1000) OK int(-1000) OK int(100000) OK int(-100000) OK float(123.456) OK string(0) "" OK string(6) "foobar" OK array(0) { } OK array(3) { [0]=> int(1) [1]=> int(2) [2]=> int(3) } OK array(3) { [0]=> array(3) { [0]=> int(1) [1]=> int(2) [2]=> int(3) } [1]=> array(3) { [0]=> int(4) [1]=> int(5) [2]=> int(6) } [2]=> array(3) { [0]=> int(7) [1]=> int(8) [2]=> int(9) } } OK array(3) { [0]=> string(3) "foo" [1]=> string(3) "foo" [2]=> string(3) "foo" } OK array(2) { ["one"]=> int(1) ["two"]=> int(2) } OK array(2) { ["kek"]=> string(3) "lol" ["lol"]=> string(3) "kek" } OK array(1) { [""]=> string(5) "empty" } OK array(2) { [0]=> array(1) { [0]=> string(3) "foo" } [1]=> array(1) { [0]=> string(3) "foo" } } OK array(2) { [0]=> &array(1) { [0]=> string(3) "foo" } [1]=> &array(1) { [0]=> string(3) "foo" } } OK array(1) { [0]=> &array(1) { [0]=> array(1) { [0]=> *RECURSION* } } } OK array(2) { ["a"]=> array(2) { ["b"]=> string(1) "c" ["d"]=> string(1) "e" } ["f"]=> array(1) { ["g"]=> string(1) "h" } } OK object(Obj)#%d (3) { ["a"]=> int(1) [%r"?b"?:protected"?%r]=> int(2) [%r"?c"?:("Obj":)?private"?%r]=> int(3) } OK array(2) { [0]=> object(Obj)#%d (3) { ["a"]=> int(1) [%r"?b"?:protected"?%r]=> int(2) [%r"?c"?:("Obj":)?private"?%r]=> int(3) } [1]=> object(Obj)#%d (3) { ["a"]=> int(4) [%r"?b"?:protected"?%r]=> int(5) [%r"?c"?:("Obj":)?private"?%r]=> int(6) } } OK array(2) { [0]=> &object(Obj)#%d (3) { ["a"]=> int(1) [%r"?b"?:protected"?%r]=> int(2) [%r"?c"?:("Obj":)?private"?%r]=> int(3) } [1]=> &object(Obj)#%d (3) { ["a"]=> int(1) [%r"?b"?:protected"?%r]=> int(2) [%r"?c"?:("Obj":)?private"?%r]=> int(3) } } OK msgpack-2.1.0beta1/tests/071.phpt0000644000175000001440000001047413577133502015302 0ustar mikeusers--TEST-- Check for class methods --SKIPIF-- = 0 && version_compare(PHP_VERSION, '5.3.2') <= 0)) { echo "skip tests in PHP 5.2.14/5.3.3 or newer"; } --FILE-- 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; } } test('null', null); test('bool: true', true); test('bool: false', false); test('zero: 0', 0); test('small: 1', 1); test('small: -1', -1); test('medium: 1000', 1000); test('medium: -1000', -1000); test('large: 100000', 100000); test('large: -100000', -100000); test('double: 123.456', 123.456); test('empty: ""', ""); test('string: "foobar"', "foobar"); test('array: empty', array(), false); test('array(1, 2, 3)', array(1, 2, 3), false); test('array(array(1, 2, 3), arr...', array(array(1, 2, 3), array(4, 5, 6), array(7, 8, 9)), false); test('array("foo", "foo", "foo")', array("foo", "foo", "foo"), false); test('array("one" => 1, "two" => 2))', array("one" => 1, "two" => 2), false); test('array("kek" => "lol", "lol" => "kek")', array("kek" => "lol", "lol" => "kek"), false); test('array("" => "empty")', array("" => "empty"), false); $a = array('foo'); test('array($a, $a)', array($a, $a), false); test('array(&$a, &$a)', array(&$a, &$a), false); $a = array(null); $b = array(&$a); $a[0] = &$b; test('cyclic', $a, true); $a = array( 'a' => array( 'b' => 'c', 'd' => 'e' ), 'f' => array( 'g' => 'h' ) ); test('array', $a, false); class Obj { public $a; protected $b; private $c; function __construct($a, $b, $c) { $this->a = $a; $this->b = $b; $this->c = $c; } } test('object', new Obj(1, 2, 3), false); test('object', array(new Obj(1, 2, 3), new Obj(4, 5, 6)), false); $o = new Obj(1, 2, 3); test('object', array(&$o, &$o), false); --EXPECTF-- NULL OK bool(true) OK bool(false) OK int(0) OK int(1) OK int(-1) OK int(1000) OK int(-1000) OK int(100000) OK int(-100000) OK float(123.456) OK string(0) "" OK string(6) "foobar" OK array(0) { } OK array(3) { [0]=> int(1) [1]=> int(2) [2]=> int(3) } OK array(3) { [0]=> array(3) { [0]=> int(1) [1]=> int(2) [2]=> int(3) } [1]=> array(3) { [0]=> int(4) [1]=> int(5) [2]=> int(6) } [2]=> array(3) { [0]=> int(7) [1]=> int(8) [2]=> int(9) } } OK array(3) { [0]=> string(3) "foo" [1]=> string(3) "foo" [2]=> string(3) "foo" } OK array(2) { ["one"]=> int(1) ["two"]=> int(2) } OK array(2) { ["kek"]=> string(3) "lol" ["lol"]=> string(3) "kek" } OK array(1) { [""]=> string(5) "empty" } OK array(2) { [0]=> array(1) { [0]=> string(3) "foo" } [1]=> array(1) { [0]=> string(3) "foo" } } OK array(2) { [0]=> &array(1) { [0]=> string(3) "foo" } [1]=> &array(1) { [0]=> string(3) "foo" } } OK array(1) { [0]=> &array(1) { [0]=> array(1) { [0]=> *RECURSION* } } } OK array(2) { ["a"]=> array(2) { ["b"]=> string(1) "c" ["d"]=> string(1) "e" } ["f"]=> array(1) { ["g"]=> string(1) "h" } } OK object(Obj)#%d (3) { ["a"]=> int(1) [%r"?b"?:protected"?%r]=> int(2) [%r"?c"?:("Obj":)?private"?%r]=> int(3) } OK array(2) { [0]=> object(Obj)#%d (3) { ["a"]=> int(1) [%r"?b"?:protected"?%r]=> int(2) [%r"?c"?:("Obj":)?private"?%r]=> int(3) } [1]=> object(Obj)#%d (3) { ["a"]=> int(4) [%r"?b"?:protected"?%r]=> int(5) [%r"?c"?:("Obj":)?private"?%r]=> int(6) } } OK array(2) { [0]=> &object(Obj)#%d (3) { ["a"]=> int(1) [%r"?b"?:protected"?%r]=> int(2) [%r"?c"?:("Obj":)?private"?%r]=> int(3) } [1]=> &object(Obj)#%d (3) { ["a"]=> int(1) [%r"?b"?:protected"?%r]=> int(2) [%r"?c"?:("Obj":)?private"?%r]=> int(3) } } OK msgpack-2.1.0beta1/tests/072.phpt0000644000175000001440000001230313577133502015274 0ustar mikeusers--TEST-- Check for class methods unpacker --SKIPIF-- = 0 && version_compare(PHP_VERSION, '5.3.2') <= 0)) { echo "skip tests in PHP 5.2.14/5.3.3 or newer"; } --FILE-- pack($variable); $unpacker = $msgpack->unpacker(); $length = strlen($serialized); if (rand(0, 1)) { 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; } } else { $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; } } test('null', null); test('bool: true', true); test('bool: false', false); test('zero: 0', 0); test('small: 1', 1); test('small: -1', -1); test('medium: 1000', 1000); test('medium: -1000', -1000); test('large: 100000', 100000); test('large: -100000', -100000); test('double: 123.456', 123.456); test('empty: ""', ""); test('string: "foobar"', "foobar"); test('array: empty', array(), false); test('array(1, 2, 3)', array(1, 2, 3), false); test('array(array(1, 2, 3), arr...', array(array(1, 2, 3), array(4, 5, 6), array(7, 8, 9)), false); test('array("foo", "foo", "foo")', array("foo", "foo", "foo"), false); test('array("one" => 1, "two" => 2))', array("one" => 1, "two" => 2), false); test('array("kek" => "lol", "lol" => "kek")', array("kek" => "lol", "lol" => "kek"), false); test('array("" => "empty")', array("" => "empty"), false); $a = array('foo'); test('array($a, $a)', array($a, $a), false); test('array(&$a, &$a)', array(&$a, &$a), false); $a = array(null); $b = array(&$a); $a[0] = &$b; test('cyclic', $a, true); $a = array( 'a' => array( 'b' => 'c', 'd' => 'e' ), 'f' => array( 'g' => 'h' ) ); test('array', $a, false); class Obj { public $a; protected $b; private $c; function __construct($a, $b, $c) { $this->a = $a; $this->b = $b; $this->c = $c; } } test('object', new Obj(1, 2, 3), false); test('object', array(new Obj(1, 2, 3), new Obj(4, 5, 6)), false); $o = new Obj(1, 2, 3); test('object', array(&$o, &$o), false); --EXPECTF-- NULL OK bool(true) OK bool(false) OK int(0) OK int(1) OK int(-1) OK int(1000) OK int(-1000) OK int(100000) OK int(-100000) OK float(123.456) OK string(0) "" OK string(6) "foobar" OK array(0) { } OK array(3) { [0]=> int(1) [1]=> int(2) [2]=> int(3) } OK array(3) { [0]=> array(3) { [0]=> int(1) [1]=> int(2) [2]=> int(3) } [1]=> array(3) { [0]=> int(4) [1]=> int(5) [2]=> int(6) } [2]=> array(3) { [0]=> int(7) [1]=> int(8) [2]=> int(9) } } OK array(3) { [0]=> string(3) "foo" [1]=> string(3) "foo" [2]=> string(3) "foo" } OK array(2) { ["one"]=> int(1) ["two"]=> int(2) } OK array(2) { ["kek"]=> string(3) "lol" ["lol"]=> string(3) "kek" } OK array(1) { [""]=> string(5) "empty" } OK array(2) { [0]=> array(1) { [0]=> string(3) "foo" } [1]=> array(1) { [0]=> string(3) "foo" } } OK array(2) { [0]=> &array(1) { [0]=> string(3) "foo" } [1]=> &array(1) { [0]=> string(3) "foo" } } OK array(1) { [0]=> &array(1) { [0]=> array(1) { [0]=> *RECURSION* } } } OK array(2) { ["a"]=> array(2) { ["b"]=> string(1) "c" ["d"]=> string(1) "e" } ["f"]=> array(1) { ["g"]=> string(1) "h" } } OK object(Obj)#%d (3) { ["a"]=> int(1) [%r"?b"?:protected"?%r]=> int(2) [%r"?c"?:("Obj":)?private"?%r]=> int(3) } OK array(2) { [0]=> object(Obj)#%d (3) { ["a"]=> int(1) [%r"?b"?:protected"?%r]=> int(2) [%r"?c"?:("Obj":)?private"?%r]=> int(3) } [1]=> object(Obj)#%d (3) { ["a"]=> int(4) [%r"?b"?:protected"?%r]=> int(5) [%r"?c"?:("Obj":)?private"?%r]=> int(6) } } OK array(2) { [0]=> &object(Obj)#%d (3) { ["a"]=> int(1) [%r"?b"?:protected"?%r]=> int(2) [%r"?c"?:("Obj":)?private"?%r]=> int(3) } [1]=> &object(Obj)#%d (3) { ["a"]=> int(1) [%r"?b"?:protected"?%r]=> int(2) [%r"?c"?:("Obj":)?private"?%r]=> int(3) } } OK msgpack-2.1.0beta1/tests/073.phpt0000644000175000001440000001230113577133502015273 0ustar mikeusers--TEST-- Check for class unpacker --SKIPIF-- = 0 && version_compare(PHP_VERSION, '5.3.2') <= 0)) { echo "skip tests in PHP 5.2.14/5.3.3 or newer"; } --FILE-- pack($variable); $unpacker = new MessagePackUnpacker(); $length = strlen($serialized); if (rand(0, 1)) { 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; } } else { $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; } } test('null', null); test('bool: true', true); test('bool: false', false); test('zero: 0', 0); test('small: 1', 1); test('small: -1', -1); test('medium: 1000', 1000); test('medium: -1000', -1000); test('large: 100000', 100000); test('large: -100000', -100000); test('double: 123.456', 123.456); test('empty: ""', ""); test('string: "foobar"', "foobar"); test('array: empty', array(), false); test('array(1, 2, 3)', array(1, 2, 3), false); test('array(array(1, 2, 3), arr...', array(array(1, 2, 3), array(4, 5, 6), array(7, 8, 9)), false); test('array("foo", "foo", "foo")', array("foo", "foo", "foo"), false); test('array("one" => 1, "two" => 2))', array("one" => 1, "two" => 2), false); test('array("kek" => "lol", "lol" => "kek")', array("kek" => "lol", "lol" => "kek"), false); test('array("" => "empty")', array("" => "empty"), false); $a = array('foo'); test('array($a, $a)', array($a, $a), false); test('array(&$a, &$a)', array(&$a, &$a), false); $a = array(null); $b = array(&$a); $a[0] = &$b; test('cyclic', $a, true); $a = array( 'a' => array( 'b' => 'c', 'd' => 'e' ), 'f' => array( 'g' => 'h' ) ); test('array', $a, false); class Obj { public $a; protected $b; private $c; function __construct($a, $b, $c) { $this->a = $a; $this->b = $b; $this->c = $c; } } test('object', new Obj(1, 2, 3), false); test('object', array(new Obj(1, 2, 3), new Obj(4, 5, 6)), false); $o = new Obj(1, 2, 3); test('object', array(&$o, &$o), false); --EXPECTF-- NULL OK bool(true) OK bool(false) OK int(0) OK int(1) OK int(-1) OK int(1000) OK int(-1000) OK int(100000) OK int(-100000) OK float(123.456) OK string(0) "" OK string(6) "foobar" OK array(0) { } OK array(3) { [0]=> int(1) [1]=> int(2) [2]=> int(3) } OK array(3) { [0]=> array(3) { [0]=> int(1) [1]=> int(2) [2]=> int(3) } [1]=> array(3) { [0]=> int(4) [1]=> int(5) [2]=> int(6) } [2]=> array(3) { [0]=> int(7) [1]=> int(8) [2]=> int(9) } } OK array(3) { [0]=> string(3) "foo" [1]=> string(3) "foo" [2]=> string(3) "foo" } OK array(2) { ["one"]=> int(1) ["two"]=> int(2) } OK array(2) { ["kek"]=> string(3) "lol" ["lol"]=> string(3) "kek" } OK array(1) { [""]=> string(5) "empty" } OK array(2) { [0]=> array(1) { [0]=> string(3) "foo" } [1]=> array(1) { [0]=> string(3) "foo" } } OK array(2) { [0]=> &array(1) { [0]=> string(3) "foo" } [1]=> &array(1) { [0]=> string(3) "foo" } } OK array(1) { [0]=> &array(1) { [0]=> array(1) { [0]=> *RECURSION* } } } OK array(2) { ["a"]=> array(2) { ["b"]=> string(1) "c" ["d"]=> string(1) "e" } ["f"]=> array(1) { ["g"]=> string(1) "h" } } OK object(Obj)#%d (3) { ["a"]=> int(1) [%r"?b"?:protected"?%r]=> int(2) [%r"?c"?:("Obj":)?private"?%r]=> int(3) } OK array(2) { [0]=> object(Obj)#%d (3) { ["a"]=> int(1) [%r"?b"?:protected"?%r]=> int(2) [%r"?c"?:("Obj":)?private"?%r]=> int(3) } [1]=> object(Obj)#%d (3) { ["a"]=> int(4) [%r"?b"?:protected"?%r]=> int(5) [%r"?c"?:("Obj":)?private"?%r]=> int(6) } } OK array(2) { [0]=> &object(Obj)#%d (3) { ["a"]=> int(1) [%r"?b"?:protected"?%r]=> int(2) [%r"?c"?:("Obj":)?private"?%r]=> int(3) } [1]=> &object(Obj)#%d (3) { ["a"]=> int(1) [%r"?b"?:protected"?%r]=> int(2) [%r"?c"?:("Obj":)?private"?%r]=> int(3) } } OK msgpack-2.1.0beta1/tests/080.phpt0000644000175000001440000000745413577133502015306 0ustar mikeusers--TEST-- disabled php only (ini_set) --SKIPIF-- --FILE-- 1, "two" => 2))', array("one" => 1, "two" => 2), false); test('array("kek" => "lol", "lol" => "kek")', array("kek" => "lol", "lol" => "kek"), false); test('array("" => "empty")', array("" => "empty"), false); $a = array('foo'); test('array($a, $a)', array($a, $a), false); test('array(&$a, &$a)', array(&$a, &$a), false); $a = array(null); $b = array(&$a); $a[0] = &$b; test('cyclic', $a, true); $a = array( 'a' => array( 'b' => 'c', 'd' => 'e' ), 'f' => array( 'g' => 'h' ) ); test('array', $a, false); class Obj { public $a; protected $b; private $c; function __construct($a, $b, $c) { $this->a = $a; $this->b = $b; $this->c = $c; } } test('object', new Obj(1, 2, 3), true); test('object', array(new Obj(1, 2, 3), new Obj(4, 5, 6)), true); $o = new Obj(1, 2, 3); test('object', array(&$o, &$o), true); --EXPECTF-- NULL OK bool(true) OK bool(false) OK int(0) OK int(1) OK int(-1) OK int(1000) OK int(-1000) OK int(100000) OK int(-100000) OK float(123.456) OK string(0) "" OK string(6) "foobar" OK array(0) { } OK array(3) { [0]=> int(1) [1]=> int(2) [2]=> int(3) } OK array(3) { [0]=> array(3) { [0]=> int(1) [1]=> int(2) [2]=> int(3) } [1]=> array(3) { [0]=> int(4) [1]=> int(5) [2]=> int(6) } [2]=> array(3) { [0]=> int(7) [1]=> int(8) [2]=> int(9) } } OK array(3) { [0]=> string(3) "foo" [1]=> string(3) "foo" [2]=> string(3) "foo" } OK array(2) { ["one"]=> int(1) ["two"]=> int(2) } OK array(2) { ["kek"]=> string(3) "lol" ["lol"]=> string(3) "kek" } OK array(1) { [""]=> string(5) "empty" } OK array(2) { [0]=> array(1) { [0]=> string(3) "foo" } [1]=> array(1) { [0]=> string(3) "foo" } } OK array(2) { [0]=> array(1) { [0]=> string(3) "foo" } [1]=> array(1) { [0]=> string(3) "foo" } } OK array(1) { [0]=> array(1) { [0]=> array(1) { [0]=> NULL } } } OK array(2) { ["a"]=> array(2) { ["b"]=> string(1) "c" ["d"]=> string(1) "e" } ["f"]=> array(1) { ["g"]=> string(1) "h" } } OK array(3) { [0]=> int(1) [1]=> int(2) [2]=> int(3) } OK array(2) { [0]=> array(3) { [0]=> int(1) [1]=> int(2) [2]=> int(3) } [1]=> array(3) { [0]=> int(4) [1]=> int(5) [2]=> int(6) } } OK array(2) { [0]=> array(3) { [0]=> int(1) [1]=> int(2) [2]=> int(3) } [1]=> array(3) { [0]=> int(1) [1]=> int(2) [2]=> int(3) } } OK msgpack-2.1.0beta1/tests/081.phpt0000644000175000001440000000754513577133502015310 0ustar mikeusers--TEST-- disabled php only for class methods (ini_set) --SKIPIF-- --FILE-- 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; } } test('null', null); test('bool: true', true); test('bool: false', false); test('zero: 0', 0); test('small: 1', 1); test('small: -1', -1); test('medium: 1000', 1000); test('medium: -1000', -1000); test('large: 100000', 100000); test('large: -100000', -100000); test('double: 123.456', 123.456); test('empty: ""', ""); test('string: "foobar"', "foobar"); test('array: empty', array(), false); test('array(1, 2, 3)', array(1, 2, 3), false); test('array(array(1, 2, 3), arr...', array(array(1, 2, 3), array(4, 5, 6), array(7, 8, 9)), false); test('array("foo", "foo", "foo")', array("foo", "foo", "foo"), false); test('array("one" => 1, "two" => 2))', array("one" => 1, "two" => 2), false); test('array("kek" => "lol", "lol" => "kek")', array("kek" => "lol", "lol" => "kek"), false); test('array("" => "empty")', array("" => "empty"), false); $a = array('foo'); test('array($a, $a)', array($a, $a), false); test('array(&$a, &$a)', array(&$a, &$a), false); $a = array(null); $b = array(&$a); $a[0] = &$b; test('cyclic', $a, true); $a = array( 'a' => array( 'b' => 'c', 'd' => 'e' ), 'f' => array( 'g' => 'h' ) ); test('array', $a, false); class Obj { public $a; protected $b; private $c; function __construct($a, $b, $c) { $this->a = $a; $this->b = $b; $this->c = $c; } } test('object', new Obj(1, 2, 3), true); test('object', array(new Obj(1, 2, 3), new Obj(4, 5, 6)), true); $o = new Obj(1, 2, 3); test('object', array(&$o, &$o), true); --EXPECTF-- NULL OK bool(true) OK bool(false) OK int(0) OK int(1) OK int(-1) OK int(1000) OK int(-1000) OK int(100000) OK int(-100000) OK float(123.456) OK string(0) "" OK string(6) "foobar" OK array(0) { } OK array(3) { [0]=> int(1) [1]=> int(2) [2]=> int(3) } OK array(3) { [0]=> array(3) { [0]=> int(1) [1]=> int(2) [2]=> int(3) } [1]=> array(3) { [0]=> int(4) [1]=> int(5) [2]=> int(6) } [2]=> array(3) { [0]=> int(7) [1]=> int(8) [2]=> int(9) } } OK array(3) { [0]=> string(3) "foo" [1]=> string(3) "foo" [2]=> string(3) "foo" } OK array(2) { ["one"]=> int(1) ["two"]=> int(2) } OK array(2) { ["kek"]=> string(3) "lol" ["lol"]=> string(3) "kek" } OK array(1) { [""]=> string(5) "empty" } OK array(2) { [0]=> array(1) { [0]=> string(3) "foo" } [1]=> array(1) { [0]=> string(3) "foo" } } OK array(2) { [0]=> array(1) { [0]=> string(3) "foo" } [1]=> array(1) { [0]=> string(3) "foo" } } OK array(1) { [0]=> array(1) { [0]=> array(1) { [0]=> NULL } } } OK array(2) { ["a"]=> array(2) { ["b"]=> string(1) "c" ["d"]=> string(1) "e" } ["f"]=> array(1) { ["g"]=> string(1) "h" } } OK array(3) { [0]=> int(1) [1]=> int(2) [2]=> int(3) } OK array(2) { [0]=> array(3) { [0]=> int(1) [1]=> int(2) [2]=> int(3) } [1]=> array(3) { [0]=> int(4) [1]=> int(5) [2]=> int(6) } } OK array(2) { [0]=> array(3) { [0]=> int(1) [1]=> int(2) [2]=> int(3) } [1]=> array(3) { [0]=> int(1) [1]=> int(2) [2]=> int(3) } } OK msgpack-2.1.0beta1/tests/082.phpt0000644000175000001440000001137413577133502015304 0ustar mikeusers--TEST-- disabled php only for class methods unpacker (ini_set) --SKIPIF-- --FILE-- pack($variable); $unpacker = $msgpack->unpacker(); $length = strlen($serialized); if (rand(0, 1)) { 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; } } else { $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; } } test('null', null); test('bool: true', true); test('bool: false', false); test('zero: 0', 0); test('small: 1', 1); test('small: -1', -1); test('medium: 1000', 1000); test('medium: -1000', -1000); test('large: 100000', 100000); test('large: -100000', -100000); test('double: 123.456', 123.456); test('empty: ""', ""); test('string: "foobar"', "foobar"); test('array: empty', array(), false); test('array(1, 2, 3)', array(1, 2, 3), false); test('array(array(1, 2, 3), arr...', array(array(1, 2, 3), array(4, 5, 6), array(7, 8, 9)), false); test('array("foo", "foo", "foo")', array("foo", "foo", "foo"), false); test('array("one" => 1, "two" => 2))', array("one" => 1, "two" => 2), false); test('array("kek" => "lol", "lol" => "kek")', array("kek" => "lol", "lol" => "kek"), false); test('array("" => "empty")', array("" => "empty"), false); $a = array('foo'); test('array($a, $a)', array($a, $a), false); test('array(&$a, &$a)', array(&$a, &$a), false); $a = array(null); $b = array(&$a); $a[0] = &$b; test('cyclic', $a, true); $a = array( 'a' => array( 'b' => 'c', 'd' => 'e' ), 'f' => array( 'g' => 'h' ) ); test('array', $a, false); class Obj { public $a; protected $b; private $c; function __construct($a, $b, $c) { $this->a = $a; $this->b = $b; $this->c = $c; } } test('object', new Obj(1, 2, 3), true); test('object', array(new Obj(1, 2, 3), new Obj(4, 5, 6)), true); $o = new Obj(1, 2, 3); test('object', array(&$o, &$o), true); --EXPECTF-- NULL OK bool(true) OK bool(false) OK int(0) OK int(1) OK int(-1) OK int(1000) OK int(-1000) OK int(100000) OK int(-100000) OK float(123.456) OK string(0) "" OK string(6) "foobar" OK array(0) { } OK array(3) { [0]=> int(1) [1]=> int(2) [2]=> int(3) } OK array(3) { [0]=> array(3) { [0]=> int(1) [1]=> int(2) [2]=> int(3) } [1]=> array(3) { [0]=> int(4) [1]=> int(5) [2]=> int(6) } [2]=> array(3) { [0]=> int(7) [1]=> int(8) [2]=> int(9) } } OK array(3) { [0]=> string(3) "foo" [1]=> string(3) "foo" [2]=> string(3) "foo" } OK array(2) { ["one"]=> int(1) ["two"]=> int(2) } OK array(2) { ["kek"]=> string(3) "lol" ["lol"]=> string(3) "kek" } OK array(1) { [""]=> string(5) "empty" } OK array(2) { [0]=> array(1) { [0]=> string(3) "foo" } [1]=> array(1) { [0]=> string(3) "foo" } } OK array(2) { [0]=> array(1) { [0]=> string(3) "foo" } [1]=> array(1) { [0]=> string(3) "foo" } } OK array(1) { [0]=> array(1) { [0]=> array(1) { [0]=> NULL } } } OK array(2) { ["a"]=> array(2) { ["b"]=> string(1) "c" ["d"]=> string(1) "e" } ["f"]=> array(1) { ["g"]=> string(1) "h" } } OK array(3) { [0]=> int(1) [1]=> int(2) [2]=> int(3) } OK array(2) { [0]=> array(3) { [0]=> int(1) [1]=> int(2) [2]=> int(3) } [1]=> array(3) { [0]=> int(4) [1]=> int(5) [2]=> int(6) } } OK array(2) { [0]=> array(3) { [0]=> int(1) [1]=> int(2) [2]=> int(3) } [1]=> array(3) { [0]=> int(1) [1]=> int(2) [2]=> int(3) } } OK msgpack-2.1.0beta1/tests/083.phpt0000644000175000001440000001137213577133502015303 0ustar mikeusers--TEST-- disabled php only for class unpacker (ini_set) --SKIPIF-- --FILE-- pack($variable); $unpacker = new MessagePackUnpacker(); $length = strlen($serialized); if (rand(0, 1)) { 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; } } else { $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; } } test('null', null); test('bool: true', true); test('bool: false', false); test('zero: 0', 0); test('small: 1', 1); test('small: -1', -1); test('medium: 1000', 1000); test('medium: -1000', -1000); test('large: 100000', 100000); test('large: -100000', -100000); test('double: 123.456', 123.456); test('empty: ""', ""); test('string: "foobar"', "foobar"); test('array: empty', array(), false); test('array(1, 2, 3)', array(1, 2, 3), false); test('array(array(1, 2, 3), arr...', array(array(1, 2, 3), array(4, 5, 6), array(7, 8, 9)), false); test('array("foo", "foo", "foo")', array("foo", "foo", "foo"), false); test('array("one" => 1, "two" => 2))', array("one" => 1, "two" => 2), false); test('array("kek" => "lol", "lol" => "kek")', array("kek" => "lol", "lol" => "kek"), false); test('array("" => "empty")', array("" => "empty"), false); $a = array('foo'); test('array($a, $a)', array($a, $a), false); test('array(&$a, &$a)', array(&$a, &$a), false); $a = array(null); $b = array(&$a); $a[0] = &$b; test('cyclic', $a, true); $a = array( 'a' => array( 'b' => 'c', 'd' => 'e' ), 'f' => array( 'g' => 'h' ) ); test('array', $a, false); class Obj { public $a; protected $b; private $c; function __construct($a, $b, $c) { $this->a = $a; $this->b = $b; $this->c = $c; } } test('object', new Obj(1, 2, 3), true); test('object', array(new Obj(1, 2, 3), new Obj(4, 5, 6)), true); $o = new Obj(1, 2, 3); test('object', array(&$o, &$o), true); --EXPECTF-- NULL OK bool(true) OK bool(false) OK int(0) OK int(1) OK int(-1) OK int(1000) OK int(-1000) OK int(100000) OK int(-100000) OK float(123.456) OK string(0) "" OK string(6) "foobar" OK array(0) { } OK array(3) { [0]=> int(1) [1]=> int(2) [2]=> int(3) } OK array(3) { [0]=> array(3) { [0]=> int(1) [1]=> int(2) [2]=> int(3) } [1]=> array(3) { [0]=> int(4) [1]=> int(5) [2]=> int(6) } [2]=> array(3) { [0]=> int(7) [1]=> int(8) [2]=> int(9) } } OK array(3) { [0]=> string(3) "foo" [1]=> string(3) "foo" [2]=> string(3) "foo" } OK array(2) { ["one"]=> int(1) ["two"]=> int(2) } OK array(2) { ["kek"]=> string(3) "lol" ["lol"]=> string(3) "kek" } OK array(1) { [""]=> string(5) "empty" } OK array(2) { [0]=> array(1) { [0]=> string(3) "foo" } [1]=> array(1) { [0]=> string(3) "foo" } } OK array(2) { [0]=> array(1) { [0]=> string(3) "foo" } [1]=> array(1) { [0]=> string(3) "foo" } } OK array(1) { [0]=> array(1) { [0]=> array(1) { [0]=> NULL } } } OK array(2) { ["a"]=> array(2) { ["b"]=> string(1) "c" ["d"]=> string(1) "e" } ["f"]=> array(1) { ["g"]=> string(1) "h" } } OK array(3) { [0]=> int(1) [1]=> int(2) [2]=> int(3) } OK array(2) { [0]=> array(3) { [0]=> int(1) [1]=> int(2) [2]=> int(3) } [1]=> array(3) { [0]=> int(4) [1]=> int(5) [2]=> int(6) } } OK array(2) { [0]=> array(3) { [0]=> int(1) [1]=> int(2) [2]=> int(3) } [1]=> array(3) { [0]=> int(1) [1]=> int(2) [2]=> int(3) } } OK msgpack-2.1.0beta1/tests/084.phpt0000644000175000001440000000751313577133502015306 0ustar mikeusers--TEST-- disabled php only for class methods (constract) --SKIPIF-- --FILE-- 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; } } test('null', null); test('bool: true', true); test('bool: false', false); test('zero: 0', 0); test('small: 1', 1); test('small: -1', -1); test('medium: 1000', 1000); test('medium: -1000', -1000); test('large: 100000', 100000); test('large: -100000', -100000); test('double: 123.456', 123.456); test('empty: ""', ""); test('string: "foobar"', "foobar"); test('array: empty', array(), false); test('array(1, 2, 3)', array(1, 2, 3), false); test('array(array(1, 2, 3), arr...', array(array(1, 2, 3), array(4, 5, 6), array(7, 8, 9)), false); test('array("foo", "foo", "foo")', array("foo", "foo", "foo"), false); test('array("one" => 1, "two" => 2))', array("one" => 1, "two" => 2), false); test('array("kek" => "lol", "lol" => "kek")', array("kek" => "lol", "lol" => "kek"), false); test('array("" => "empty")', array("" => "empty"), false); $a = array('foo'); test('array($a, $a)', array($a, $a), false); test('array(&$a, &$a)', array(&$a, &$a), false); $a = array(null); $b = array(&$a); $a[0] = &$b; test('cyclic', $a, true); $a = array( 'a' => array( 'b' => 'c', 'd' => 'e' ), 'f' => array( 'g' => 'h' ) ); test('array', $a, false); class Obj { public $a; protected $b; private $c; function __construct($a, $b, $c) { $this->a = $a; $this->b = $b; $this->c = $c; } } test('object', new Obj(1, 2, 3), true); test('object', array(new Obj(1, 2, 3), new Obj(4, 5, 6)), true); $o = new Obj(1, 2, 3); test('object', array(&$o, &$o), true); --EXPECTF-- NULL OK bool(true) OK bool(false) OK int(0) OK int(1) OK int(-1) OK int(1000) OK int(-1000) OK int(100000) OK int(-100000) OK float(123.456) OK string(0) "" OK string(6) "foobar" OK array(0) { } OK array(3) { [0]=> int(1) [1]=> int(2) [2]=> int(3) } OK array(3) { [0]=> array(3) { [0]=> int(1) [1]=> int(2) [2]=> int(3) } [1]=> array(3) { [0]=> int(4) [1]=> int(5) [2]=> int(6) } [2]=> array(3) { [0]=> int(7) [1]=> int(8) [2]=> int(9) } } OK array(3) { [0]=> string(3) "foo" [1]=> string(3) "foo" [2]=> string(3) "foo" } OK array(2) { ["one"]=> int(1) ["two"]=> int(2) } OK array(2) { ["kek"]=> string(3) "lol" ["lol"]=> string(3) "kek" } OK array(1) { [""]=> string(5) "empty" } OK array(2) { [0]=> array(1) { [0]=> string(3) "foo" } [1]=> array(1) { [0]=> string(3) "foo" } } OK array(2) { [0]=> array(1) { [0]=> string(3) "foo" } [1]=> array(1) { [0]=> string(3) "foo" } } OK array(1) { [0]=> array(1) { [0]=> array(1) { [0]=> NULL } } } OK array(2) { ["a"]=> array(2) { ["b"]=> string(1) "c" ["d"]=> string(1) "e" } ["f"]=> array(1) { ["g"]=> string(1) "h" } } OK array(3) { [0]=> int(1) [1]=> int(2) [2]=> int(3) } OK array(2) { [0]=> array(3) { [0]=> int(1) [1]=> int(2) [2]=> int(3) } [1]=> array(3) { [0]=> int(4) [1]=> int(5) [2]=> int(6) } } OK array(2) { [0]=> array(3) { [0]=> int(1) [1]=> int(2) [2]=> int(3) } [1]=> array(3) { [0]=> int(1) [1]=> int(2) [2]=> int(3) } } OK msgpack-2.1.0beta1/tests/085.phpt0000644000175000001440000001134213577133502015302 0ustar mikeusers--TEST-- disabled php only for class methods unpacker (constract) --SKIPIF-- --FILE-- pack($variable); $unpacker = $msgpack->unpacker(); $length = strlen($serialized); if (rand(0, 1)) { 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; } } else { $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; } } test('null', null); test('bool: true', true); test('bool: false', false); test('zero: 0', 0); test('small: 1', 1); test('small: -1', -1); test('medium: 1000', 1000); test('medium: -1000', -1000); test('large: 100000', 100000); test('large: -100000', -100000); test('double: 123.456', 123.456); test('empty: ""', ""); test('string: "foobar"', "foobar"); test('array: empty', array(), false); test('array(1, 2, 3)', array(1, 2, 3), false); test('array(array(1, 2, 3), arr...', array(array(1, 2, 3), array(4, 5, 6), array(7, 8, 9)), false); test('array("foo", "foo", "foo")', array("foo", "foo", "foo"), false); test('array("one" => 1, "two" => 2))', array("one" => 1, "two" => 2), false); test('array("kek" => "lol", "lol" => "kek")', array("kek" => "lol", "lol" => "kek"), false); test('array("" => "empty")', array("" => "empty"), false); $a = array('foo'); test('array($a, $a)', array($a, $a), false); test('array(&$a, &$a)', array(&$a, &$a), false); $a = array(null); $b = array(&$a); $a[0] = &$b; test('cyclic', $a, true); $a = array( 'a' => array( 'b' => 'c', 'd' => 'e' ), 'f' => array( 'g' => 'h' ) ); test('array', $a, false); class Obj { public $a; protected $b; private $c; function __construct($a, $b, $c) { $this->a = $a; $this->b = $b; $this->c = $c; } } test('object', new Obj(1, 2, 3), true); test('object', array(new Obj(1, 2, 3), new Obj(4, 5, 6)), true); $o = new Obj(1, 2, 3); test('object', array(&$o, &$o), true); --EXPECTF-- NULL OK bool(true) OK bool(false) OK int(0) OK int(1) OK int(-1) OK int(1000) OK int(-1000) OK int(100000) OK int(-100000) OK float(123.456) OK string(0) "" OK string(6) "foobar" OK array(0) { } OK array(3) { [0]=> int(1) [1]=> int(2) [2]=> int(3) } OK array(3) { [0]=> array(3) { [0]=> int(1) [1]=> int(2) [2]=> int(3) } [1]=> array(3) { [0]=> int(4) [1]=> int(5) [2]=> int(6) } [2]=> array(3) { [0]=> int(7) [1]=> int(8) [2]=> int(9) } } OK array(3) { [0]=> string(3) "foo" [1]=> string(3) "foo" [2]=> string(3) "foo" } OK array(2) { ["one"]=> int(1) ["two"]=> int(2) } OK array(2) { ["kek"]=> string(3) "lol" ["lol"]=> string(3) "kek" } OK array(1) { [""]=> string(5) "empty" } OK array(2) { [0]=> array(1) { [0]=> string(3) "foo" } [1]=> array(1) { [0]=> string(3) "foo" } } OK array(2) { [0]=> array(1) { [0]=> string(3) "foo" } [1]=> array(1) { [0]=> string(3) "foo" } } OK array(1) { [0]=> array(1) { [0]=> array(1) { [0]=> NULL } } } OK array(2) { ["a"]=> array(2) { ["b"]=> string(1) "c" ["d"]=> string(1) "e" } ["f"]=> array(1) { ["g"]=> string(1) "h" } } OK array(3) { [0]=> int(1) [1]=> int(2) [2]=> int(3) } OK array(2) { [0]=> array(3) { [0]=> int(1) [1]=> int(2) [2]=> int(3) } [1]=> array(3) { [0]=> int(4) [1]=> int(5) [2]=> int(6) } } OK array(2) { [0]=> array(3) { [0]=> int(1) [1]=> int(2) [2]=> int(3) } [1]=> array(3) { [0]=> int(1) [1]=> int(2) [2]=> int(3) } } OK msgpack-2.1.0beta1/tests/086.phpt0000644000175000001440000001134513577133502015306 0ustar mikeusers--TEST-- disabled php only for class unpacker (constract) --SKIPIF-- --FILE-- pack($variable); $unpacker = new MessagePackUnpacker(false); $length = strlen($serialized); if (rand(0, 1)) { 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; } } else { $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; } } test('null', null); test('bool: true', true); test('bool: false', false); test('zero: 0', 0); test('small: 1', 1); test('small: -1', -1); test('medium: 1000', 1000); test('medium: -1000', -1000); test('large: 100000', 100000); test('large: -100000', -100000); test('double: 123.456', 123.456); test('empty: ""', ""); test('string: "foobar"', "foobar"); test('array: empty', array(), false); test('array(1, 2, 3)', array(1, 2, 3), false); test('array(array(1, 2, 3), arr...', array(array(1, 2, 3), array(4, 5, 6), array(7, 8, 9)), false); test('array("foo", "foo", "foo")', array("foo", "foo", "foo"), false); test('array("one" => 1, "two" => 2))', array("one" => 1, "two" => 2), false); test('array("kek" => "lol", "lol" => "kek")', array("kek" => "lol", "lol" => "kek"), false); test('array("" => "empty")', array("" => "empty"), false); $a = array('foo'); test('array($a, $a)', array($a, $a), false); test('array(&$a, &$a)', array(&$a, &$a), false); $a = array(null); $b = array(&$a); $a[0] = &$b; test('cyclic', $a, true); $a = array( 'a' => array( 'b' => 'c', 'd' => 'e' ), 'f' => array( 'g' => 'h' ) ); test('array', $a, false); class Obj { public $a; protected $b; private $c; function __construct($a, $b, $c) { $this->a = $a; $this->b = $b; $this->c = $c; } } test('object', new Obj(1, 2, 3), true); test('object', array(new Obj(1, 2, 3), new Obj(4, 5, 6)), true); $o = new Obj(1, 2, 3); test('object', array(&$o, &$o), true); --EXPECTF-- NULL OK bool(true) OK bool(false) OK int(0) OK int(1) OK int(-1) OK int(1000) OK int(-1000) OK int(100000) OK int(-100000) OK float(123.456) OK string(0) "" OK string(6) "foobar" OK array(0) { } OK array(3) { [0]=> int(1) [1]=> int(2) [2]=> int(3) } OK array(3) { [0]=> array(3) { [0]=> int(1) [1]=> int(2) [2]=> int(3) } [1]=> array(3) { [0]=> int(4) [1]=> int(5) [2]=> int(6) } [2]=> array(3) { [0]=> int(7) [1]=> int(8) [2]=> int(9) } } OK array(3) { [0]=> string(3) "foo" [1]=> string(3) "foo" [2]=> string(3) "foo" } OK array(2) { ["one"]=> int(1) ["two"]=> int(2) } OK array(2) { ["kek"]=> string(3) "lol" ["lol"]=> string(3) "kek" } OK array(1) { [""]=> string(5) "empty" } OK array(2) { [0]=> array(1) { [0]=> string(3) "foo" } [1]=> array(1) { [0]=> string(3) "foo" } } OK array(2) { [0]=> array(1) { [0]=> string(3) "foo" } [1]=> array(1) { [0]=> string(3) "foo" } } OK array(1) { [0]=> array(1) { [0]=> array(1) { [0]=> NULL } } } OK array(2) { ["a"]=> array(2) { ["b"]=> string(1) "c" ["d"]=> string(1) "e" } ["f"]=> array(1) { ["g"]=> string(1) "h" } } OK array(3) { [0]=> int(1) [1]=> int(2) [2]=> int(3) } OK array(2) { [0]=> array(3) { [0]=> int(1) [1]=> int(2) [2]=> int(3) } [1]=> array(3) { [0]=> int(4) [1]=> int(5) [2]=> int(6) } } OK array(2) { [0]=> array(3) { [0]=> int(1) [1]=> int(2) [2]=> int(3) } [1]=> array(3) { [0]=> int(1) [1]=> int(2) [2]=> int(3) } } OK msgpack-2.1.0beta1/tests/087.phpt0000644000175000001440000001002613577133502015302 0ustar mikeusers--TEST-- disabled php only for class methods (set option) --SKIPIF-- --FILE-- 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; } } test('null', null); test('bool: true', true); test('bool: false', false); test('zero: 0', 0); test('small: 1', 1); test('small: -1', -1); test('medium: 1000', 1000); test('medium: -1000', -1000); test('large: 100000', 100000); test('large: -100000', -100000); test('double: 123.456', 123.456); test('empty: ""', ""); test('string: "foobar"', "foobar"); test('array: empty', array(), false); test('array(1, 2, 3)', array(1, 2, 3), false); test('array(array(1, 2, 3), arr...', array(array(1, 2, 3), array(4, 5, 6), array(7, 8, 9)), false); test('array("foo", "foo", "foo")', array("foo", "foo", "foo"), false); test('array("one" => 1, "two" => 2))', array("one" => 1, "two" => 2), false); test('array("kek" => "lol", "lol" => "kek")', array("kek" => "lol", "lol" => "kek"), false); test('array("" => "empty")', array("" => "empty"), false); $a = array('foo'); test('array($a, $a)', array($a, $a), false); test('array(&$a, &$a)', array(&$a, &$a), false); $a = array(null); $b = array(&$a); $a[0] = &$b; test('cyclic', $a, true); $a = array( 'a' => array( 'b' => 'c', 'd' => 'e' ), 'f' => array( 'g' => 'h' ) ); test('array', $a, false); class Obj { public $a; protected $b; private $c; function __construct($a, $b, $c) { $this->a = $a; $this->b = $b; $this->c = $c; } } test('object', new Obj(1, 2, 3), true); test('object', array(new Obj(1, 2, 3), new Obj(4, 5, 6)), true); $o = new Obj(1, 2, 3); test('object', array(&$o, &$o), true); --EXPECTF-- NULL OK bool(true) OK bool(false) OK int(0) OK int(1) OK int(-1) OK int(1000) OK int(-1000) OK int(100000) OK int(-100000) OK float(123.456) OK string(0) "" OK string(6) "foobar" OK array(0) { } OK array(3) { [0]=> int(1) [1]=> int(2) [2]=> int(3) } OK array(3) { [0]=> array(3) { [0]=> int(1) [1]=> int(2) [2]=> int(3) } [1]=> array(3) { [0]=> int(4) [1]=> int(5) [2]=> int(6) } [2]=> array(3) { [0]=> int(7) [1]=> int(8) [2]=> int(9) } } OK array(3) { [0]=> string(3) "foo" [1]=> string(3) "foo" [2]=> string(3) "foo" } OK array(2) { ["one"]=> int(1) ["two"]=> int(2) } OK array(2) { ["kek"]=> string(3) "lol" ["lol"]=> string(3) "kek" } OK array(1) { [""]=> string(5) "empty" } OK array(2) { [0]=> array(1) { [0]=> string(3) "foo" } [1]=> array(1) { [0]=> string(3) "foo" } } OK array(2) { [0]=> array(1) { [0]=> string(3) "foo" } [1]=> array(1) { [0]=> string(3) "foo" } } OK array(1) { [0]=> array(1) { [0]=> array(1) { [0]=> NULL } } } OK array(2) { ["a"]=> array(2) { ["b"]=> string(1) "c" ["d"]=> string(1) "e" } ["f"]=> array(1) { ["g"]=> string(1) "h" } } OK array(3) { [0]=> int(1) [1]=> int(2) [2]=> int(3) } OK array(2) { [0]=> array(3) { [0]=> int(1) [1]=> int(2) [2]=> int(3) } [1]=> array(3) { [0]=> int(4) [1]=> int(5) [2]=> int(6) } } OK array(2) { [0]=> array(3) { [0]=> int(1) [1]=> int(2) [2]=> int(3) } [1]=> array(3) { [0]=> int(1) [1]=> int(2) [2]=> int(3) } } OK msgpack-2.1.0beta1/tests/088.phpt0000644000175000001440000001165513577133502015314 0ustar mikeusers--TEST-- disabled php only for class methods unpacker (set option) --SKIPIF-- --FILE-- setOption(MESSAGEPACK_OPT_PHPONLY, false); } else { $msgpack->setOption(MessagePack::OPT_PHPONLY, false); } $serialized = $msgpack->pack($variable); $unpacker = $msgpack->unpacker(); $length = strlen($serialized); if (rand(0, 1)) { 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; } } else { $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; } } test('null', null); test('bool: true', true); test('bool: false', false); test('zero: 0', 0); test('small: 1', 1); test('small: -1', -1); test('medium: 1000', 1000); test('medium: -1000', -1000); test('large: 100000', 100000); test('large: -100000', -100000); test('double: 123.456', 123.456); test('empty: ""', ""); test('string: "foobar"', "foobar"); test('array: empty', array(), false); test('array(1, 2, 3)', array(1, 2, 3), false); test('array(array(1, 2, 3), arr...', array(array(1, 2, 3), array(4, 5, 6), array(7, 8, 9)), false); test('array("foo", "foo", "foo")', array("foo", "foo", "foo"), false); test('array("one" => 1, "two" => 2))', array("one" => 1, "two" => 2), false); test('array("kek" => "lol", "lol" => "kek")', array("kek" => "lol", "lol" => "kek"), false); test('array("" => "empty")', array("" => "empty"), false); $a = array('foo'); test('array($a, $a)', array($a, $a), false); test('array(&$a, &$a)', array(&$a, &$a), false); $a = array(null); $b = array(&$a); $a[0] = &$b; test('cyclic', $a, true); $a = array( 'a' => array( 'b' => 'c', 'd' => 'e' ), 'f' => array( 'g' => 'h' ) ); test('array', $a, false); class Obj { public $a; protected $b; private $c; function __construct($a, $b, $c) { $this->a = $a; $this->b = $b; $this->c = $c; } } test('object', new Obj(1, 2, 3), true); test('object', array(new Obj(1, 2, 3), new Obj(4, 5, 6)), true); $o = new Obj(1, 2, 3); test('object', array(&$o, &$o), true); --EXPECTF-- NULL OK bool(true) OK bool(false) OK int(0) OK int(1) OK int(-1) OK int(1000) OK int(-1000) OK int(100000) OK int(-100000) OK float(123.456) OK string(0) "" OK string(6) "foobar" OK array(0) { } OK array(3) { [0]=> int(1) [1]=> int(2) [2]=> int(3) } OK array(3) { [0]=> array(3) { [0]=> int(1) [1]=> int(2) [2]=> int(3) } [1]=> array(3) { [0]=> int(4) [1]=> int(5) [2]=> int(6) } [2]=> array(3) { [0]=> int(7) [1]=> int(8) [2]=> int(9) } } OK array(3) { [0]=> string(3) "foo" [1]=> string(3) "foo" [2]=> string(3) "foo" } OK array(2) { ["one"]=> int(1) ["two"]=> int(2) } OK array(2) { ["kek"]=> string(3) "lol" ["lol"]=> string(3) "kek" } OK array(1) { [""]=> string(5) "empty" } OK array(2) { [0]=> array(1) { [0]=> string(3) "foo" } [1]=> array(1) { [0]=> string(3) "foo" } } OK array(2) { [0]=> array(1) { [0]=> string(3) "foo" } [1]=> array(1) { [0]=> string(3) "foo" } } OK array(1) { [0]=> array(1) { [0]=> array(1) { [0]=> NULL } } } OK array(2) { ["a"]=> array(2) { ["b"]=> string(1) "c" ["d"]=> string(1) "e" } ["f"]=> array(1) { ["g"]=> string(1) "h" } } OK array(3) { [0]=> int(1) [1]=> int(2) [2]=> int(3) } OK array(2) { [0]=> array(3) { [0]=> int(1) [1]=> int(2) [2]=> int(3) } [1]=> array(3) { [0]=> int(4) [1]=> int(5) [2]=> int(6) } } OK array(2) { [0]=> array(3) { [0]=> int(1) [1]=> int(2) [2]=> int(3) } [1]=> array(3) { [0]=> int(1) [1]=> int(2) [2]=> int(3) } } OK msgpack-2.1.0beta1/tests/089.phpt0000644000175000001440000001234013577133502015305 0ustar mikeusers--TEST-- disabled php only for class unpacker (set option) --SKIPIF-- setOption(MESSAGEPACK_OPT_PHPONLY, false); } else { $msgpack->setOption(MessagePack::OPT_PHPONLY, false); } $serialized = $msgpack->pack($variable); $unpacker = new MessagePackUnpacker(); if (version_compare(PHP_VERSION, '5.1.0') < 0) { $unpacker->setOption(MESSAGEPACK_OPT_PHPONLY, false); } else { $unpacker->setOption(MessagePack::OPT_PHPONLY, false); } $length = strlen($serialized); if (rand(0, 1)) { 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; } } else { $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; } } test('null', null); test('bool: true', true); test('bool: false', false); test('zero: 0', 0); test('small: 1', 1); test('small: -1', -1); test('medium: 1000', 1000); test('medium: -1000', -1000); test('large: 100000', 100000); test('large: -100000', -100000); test('double: 123.456', 123.456); test('empty: ""', ""); test('string: "foobar"', "foobar"); test('array: empty', array(), false); test('array(1, 2, 3)', array(1, 2, 3), false); test('array(array(1, 2, 3), arr...', array(array(1, 2, 3), array(4, 5, 6), array(7, 8, 9)), false); test('array("foo", "foo", "foo")', array("foo", "foo", "foo"), false); test('array("one" => 1, "two" => 2))', array("one" => 1, "two" => 2), false); test('array("kek" => "lol", "lol" => "kek")', array("kek" => "lol", "lol" => "kek"), false); test('array("" => "empty")', array("" => "empty"), false); $a = array('foo'); test('array($a, $a)', array($a, $a), false); test('array(&$a, &$a)', array(&$a, &$a), false); $a = array(null); $b = array(&$a); $a[0] = &$b; test('cyclic', $a, true); $a = array( 'a' => array( 'b' => 'c', 'd' => 'e' ), 'f' => array( 'g' => 'h' ) ); test('array', $a, false); class Obj { public $a; protected $b; private $c; function __construct($a, $b, $c) { $this->a = $a; $this->b = $b; $this->c = $c; } } test('object', new Obj(1, 2, 3), true); test('object', array(new Obj(1, 2, 3), new Obj(4, 5, 6)), true); $o = new Obj(1, 2, 3); test('object', array(&$o, &$o), true); --EXPECTF-- NULL OK bool(true) OK bool(false) OK int(0) OK int(1) OK int(-1) OK int(1000) OK int(-1000) OK int(100000) OK int(-100000) OK float(123.456) OK string(0) "" OK string(6) "foobar" OK array(0) { } OK array(3) { [0]=> int(1) [1]=> int(2) [2]=> int(3) } OK array(3) { [0]=> array(3) { [0]=> int(1) [1]=> int(2) [2]=> int(3) } [1]=> array(3) { [0]=> int(4) [1]=> int(5) [2]=> int(6) } [2]=> array(3) { [0]=> int(7) [1]=> int(8) [2]=> int(9) } } OK array(3) { [0]=> string(3) "foo" [1]=> string(3) "foo" [2]=> string(3) "foo" } OK array(2) { ["one"]=> int(1) ["two"]=> int(2) } OK array(2) { ["kek"]=> string(3) "lol" ["lol"]=> string(3) "kek" } OK array(1) { [""]=> string(5) "empty" } OK array(2) { [0]=> array(1) { [0]=> string(3) "foo" } [1]=> array(1) { [0]=> string(3) "foo" } } OK array(2) { [0]=> array(1) { [0]=> string(3) "foo" } [1]=> array(1) { [0]=> string(3) "foo" } } OK array(1) { [0]=> array(1) { [0]=> array(1) { [0]=> NULL } } } OK array(2) { ["a"]=> array(2) { ["b"]=> string(1) "c" ["d"]=> string(1) "e" } ["f"]=> array(1) { ["g"]=> string(1) "h" } } OK array(3) { [0]=> int(1) [1]=> int(2) [2]=> int(3) } OK array(2) { [0]=> array(3) { [0]=> int(1) [1]=> int(2) [2]=> int(3) } [1]=> array(3) { [0]=> int(4) [1]=> int(5) [2]=> int(6) } } OK array(2) { [0]=> array(3) { [0]=> int(1) [1]=> int(2) [2]=> int(3) } [1]=> array(3) { [0]=> int(1) [1]=> int(2) [2]=> int(3) } } OK msgpack-2.1.0beta1/tests/090.phpt0000644000175000001440000001730313577133502015301 0ustar mikeusers--TEST-- unpack of object converter (string) --SKIPIF-- a = $a; $this->b = $b; $this->c = $c; if (is_array($d)) { foreach ($d as $key => $val) { $this->{$key} = $val; } } } } test('null', null, 'Obj', new Obj(null, null, null)); test('bool: true', true, 'Obj', new Obj(true, null, null)); test('bool: false', false, 'Obj', new Obj(false, null, null)); test('zero: 0', 0, 'Obj', new Obj(0, null, null)); test('small: 1', 1, 'Obj', new Obj(1, null, null)); test('small: -1', -1, 'Obj', new Obj(-1, null, null)); test('medium: 1000', 1000, 'Obj', new Obj(1000, null, null)); test('medium: -1000', -1000, 'Obj', new Obj(-1000, null, null)); test('large: 100000', 100000, 'Obj', new Obj(100000, null, null)); test('large: -100000', -100000, 'Obj', new Obj(-100000, null, null)); test('double: 123.456', 123.456, 'Obj', new Obj(123.456, null, null)); test('empty: ""', "", 'Obj', new Obj("", null, null)); test('string: "foobar"', "foobar", 'Obj', new Obj("foobar", null, null)); test('array: empty', array(), 'Obj', new Obj(null, null, null)); test('array(1, 2, 3)', array(1, 2, 3), 'Obj', new Obj(1, 2, 3)); test('array(array(1, 2, 3), arr...', array(array(1, 2, 3), array(4, 5, 6), array(7, 8, 9)), 'Obj', new Obj(array(1, 2, 3), array(4, 5, 6), array(7, 8, 9))); test('array(1, 2, 3, 4)', array(1, 2, 3, 4), 'Obj'); test('array("foo", "foobar", "foohoge")', array("foo", "foobar", "hoge"), 'Obj', new Obj("foo", "foobar", "hoge")); test('array("a" => 1, "b" => 2))', array("a" => 1, "b" => 2), 'Obj', new Obj(1, 2, null)); test('array("one" => 1, "two" => 2))', array("one" => 1, "two" => 2), 'Obj', new Obj(null, null, null, array("one" => 1, "two" => 2))); test('array("a" => 1, "b" => 2, 3))', array("a" => 1, "b" => 2, 3), 'Obj', new Obj(1, 2, 3)); test('array(3, "a" => 1, "b" => 2))', array(3, "a" => 1, "b" => 2), 'Obj', new Obj(1, 2, 3)); test('array("a" => 1, 3, "b" => 2))', array("a" => 1, 3, "b" => 2), 'Obj', new Obj(1, 2, 3)); $a = array('foo'); test('array($a, $a)', array($a, $a), 'Obj', new Obj($a, $a, null)); $a = array( 'a' => array( 'b' => 'c', 'd' => 'e' ), 'f' => array( 'g' => 'h' ) ); test('array', $a, 'Obj', new Obj(null, null, null, $a)); $o = new Obj(1, 2, 3); test('object', $o, 'Obj', new Obj(1, 2, 3)); class Obj2 { public $A; protected $B; private $C; function __construct($a, $b, $c) { $this->A = $a; $this->B = $b; $this->C = $c; } } $o = new Obj2(1, 2, 3); test('object', $o, 'Obj', new Obj($o)); $o1 = new Obj2(1, 2, 3); $o2 = new Obj2(4, 5, 6); test('object', array($o1, $o2), 'Obj', new Obj($o1, $o2)); --EXPECTF-- object(Obj)#%d (3) { ["a"]=> NULL [%r"?b"?:protected"?%r]=> NULL [%r"?c"?:("Obj":)?private"?%r]=> NULL } OK object(Obj)#%d (3) { ["a"]=> bool(true) [%r"?b"?:protected"?%r]=> NULL [%r"?c"?:("Obj":)?private"?%r]=> NULL } OK object(Obj)#%d (3) { ["a"]=> bool(false) [%r"?b"?:protected"?%r]=> NULL [%r"?c"?:("Obj":)?private"?%r]=> NULL } OK object(Obj)#%d (3) { ["a"]=> int(0) [%r"?b"?:protected"?%r]=> NULL [%r"?c"?:("Obj":)?private"?%r]=> NULL } OK object(Obj)#%d (3) { ["a"]=> int(1) [%r"?b"?:protected"?%r]=> NULL [%r"?c"?:("Obj":)?private"?%r]=> NULL } OK object(Obj)#%d (3) { ["a"]=> int(-1) [%r"?b"?:protected"?%r]=> NULL [%r"?c"?:("Obj":)?private"?%r]=> NULL } OK object(Obj)#%d (3) { ["a"]=> int(1000) [%r"?b"?:protected"?%r]=> NULL [%r"?c"?:("Obj":)?private"?%r]=> NULL } OK object(Obj)#%d (3) { ["a"]=> int(-1000) [%r"?b"?:protected"?%r]=> NULL [%r"?c"?:("Obj":)?private"?%r]=> NULL } OK object(Obj)#%d (3) { ["a"]=> int(100000) [%r"?b"?:protected"?%r]=> NULL [%r"?c"?:("Obj":)?private"?%r]=> NULL } OK object(Obj)#%d (3) { ["a"]=> int(-100000) [%r"?b"?:protected"?%r]=> NULL [%r"?c"?:("Obj":)?private"?%r]=> NULL } OK object(Obj)#%d (3) { ["a"]=> float(123.456) [%r"?b"?:protected"?%r]=> NULL [%r"?c"?:("Obj":)?private"?%r]=> NULL } OK object(Obj)#%d (3) { ["a"]=> string(0) "" [%r"?b"?:protected"?%r]=> NULL [%r"?c"?:("Obj":)?private"?%r]=> NULL } OK object(Obj)#%d (3) { ["a"]=> string(6) "foobar" [%r"?b"?:protected"?%r]=> NULL [%r"?c"?:("Obj":)?private"?%r]=> NULL } OK object(Obj)#%d (3) { ["a"]=> NULL [%r"?b"?:protected"?%r]=> NULL [%r"?c"?:("Obj":)?private"?%r]=> NULL } OK object(Obj)#%d (3) { ["a"]=> int(1) [%r"?b"?:protected"?%r]=> int(2) [%r"?c"?:("Obj":)?private"?%r]=> int(3) } OK object(Obj)#%d (3) { ["a"]=> array(3) { [0]=> int(1) [1]=> int(2) [2]=> int(3) } [%r"?b"?:protected"?%r]=> array(3) { [0]=> int(4) [1]=> int(5) [2]=> int(6) } [%r"?c"?:("Obj":)?private"?%r]=> array(3) { [0]=> int(7) [1]=> int(8) [2]=> int(9) } } OK object(Obj)#%d (4) { ["a"]=> int(1) [%r"?b"?:protected"?%r]=> int(2) [%r"?c"?:("Obj":)?private"?%r]=> int(3) ["3"]=> int(4) } SKIP object(Obj)#%d (3) { ["a"]=> string(3) "foo" [%r"?b"?:protected"?%r]=> string(6) "foobar" [%r"?c"?:("Obj":)?private"?%r]=> string(4) "hoge" } OK object(Obj)#%d (3) { ["a"]=> int(1) [%r"?b"?:protected"?%r]=> int(2) [%r"?c"?:("Obj":)?private"?%r]=> NULL } OK object(Obj)#%d (5) { ["a"]=> NULL [%r"?b"?:protected"?%r]=> NULL [%r"?c"?:("Obj":)?private"?%r]=> NULL ["one"]=> int(1) ["two"]=> int(2) } OK object(Obj)#%d (3) { ["a"]=> int(1) [%r"?b"?:protected"?%r]=> int(2) [%r"?c"?:("Obj":)?private"?%r]=> int(3) } OK object(Obj)#%d (3) { ["a"]=> int(1) [%r"?b"?:protected"?%r]=> int(2) [%r"?c"?:("Obj":)?private"?%r]=> int(3) } OK object(Obj)#%d (3) { ["a"]=> int(1) [%r"?b"?:protected"?%r]=> int(2) [%r"?c"?:("Obj":)?private"?%r]=> int(3) } OK object(Obj)#%d (3) { ["a"]=> array(1) { [0]=> string(3) "foo" } [%r"?b"?:protected"?%r]=> array(1) { [0]=> string(3) "foo" } [%r"?c"?:("Obj":)?private"?%r]=> NULL } OK object(Obj)#%d (4) { ["a"]=> array(2) { ["b"]=> string(1) "c" ["d"]=> string(1) "e" } [%r"?b"?:protected"?%r]=> NULL [%r"?c"?:("Obj":)?private"?%r]=> NULL ["f"]=> array(1) { ["g"]=> string(1) "h" } } OK object(Obj)#%d (3) { ["a"]=> int(1) [%r"?b"?:protected"?%r]=> int(2) [%r"?c"?:("Obj":)?private"?%r]=> int(3) } OK object(Obj)#%d (3) { ["a"]=> object(Obj2)#%d (3) { ["A"]=> int(1) [%r"?B"?:protected"?%r]=> int(2) [%r"?C"?:("Obj2":)?private"?%r]=> int(3) } [%r"?b"?:protected"?%r]=> NULL [%r"?c"?:("Obj":)?private"?%r]=> NULL } OK object(Obj)#%d (3) { ["a"]=> object(Obj2)#%d (3) { ["A"]=> int(1) [%r"?B"?:protected"?%r]=> int(2) [%r"?C"?:("Obj2":)?private"?%r]=> int(3) } [%r"?b"?:protected"?%r]=> object(Obj2)#%d (3) { ["A"]=> int(4) [%r"?B"?:protected"?%r]=> int(5) [%r"?C"?:("Obj2":)?private"?%r]=> int(6) } [%r"?c"?:("Obj":)?private"?%r]=> NULL } OK msgpack-2.1.0beta1/tests/091.phpt0000644000175000001440000001751113577133502015303 0ustar mikeusers--TEST-- unpack of object converter (object) --SKIPIF-- a = $a; $this->b = $b; $this->c = $c; if (is_array($d)) { foreach ($d as $key => $val) { $this->{$key} = $val; } } } } $object = new Obj(); test('null', null, new Obj(), new Obj(null, null, null)); test('bool: true', true, new Obj(), new Obj(true, null, null)); test('bool: false', false, new Obj(), new Obj(false, null, null)); test('zero: 0', 0, new Obj(), new Obj(0, null, null)); test('small: 1', 1, new Obj(), new Obj(1, null, null)); test('small: -1', -1, new Obj(), new Obj(-1, null, null)); test('medium: 1000', 1000, new Obj(), new Obj(1000, null, null)); test('medium: -1000', -1000, new Obj(), new Obj(-1000, null, null)); test('large: 100000', 100000, new Obj(), new Obj(100000, null, null)); test('large: -100000', -100000, new Obj(), new Obj(-100000, null, null)); test('double: 123.456', 123.456, new Obj(), new Obj(123.456, null, null)); test('empty: ""', "", new Obj(), new Obj("", null, null)); test('string: "foobar"', "foobar", new Obj(), new Obj("foobar", null, null)); test('array: empty', array(), new Obj(), new Obj(null, null, null)); test('array(1, 2, 3)', array(1, 2, 3), new Obj(), new Obj(1, 2, 3)); test('array(array(1, 2, 3), arr...', array(array(1, 2, 3), array(4, 5, 6), array(7, 8, 9)), new Obj(), new Obj(array(1, 2, 3), array(4, 5, 6), array(7, 8, 9))); test('array(1, 2, 3, 4)', array(1, 2, 3, 4), new Obj()); test('array("foo", "foobar", "foohoge")', array("foo", "foobar", "hoge"), new Obj(), new Obj("foo", "foobar", "hoge")); test('array("a" => 1, "b" => 2))', array("a" => 1, "b" => 2), new Obj(), new Obj(1, 2, null)); test('array("one" => 1, "two" => 2))', array("one" => 1, "two" => 2), new Obj(), new Obj(null, null, null, array("one" => 1, "two" => 2))); test('array("a" => 1, "b" => 2, 3))', array("a" => 1, "b" => 2, 3), new Obj(), new Obj(1, 2, 3)); test('array(3, "a" => 1, "b" => 2))', array(3, "a" => 1, "b" => 2), new Obj(), new Obj(1, 2, 3)); test('array("a" => 1, 3, "b" => 2))', array("a" => 1, 3, "b" => 2), new Obj(), new Obj(1, 2, 3)); $a = array('foo'); test('array($a, $a)', array($a, $a), new Obj(), new Obj($a, $a, null)); $a = array( 'a' => array( 'b' => 'c', 'd' => 'e' ), 'f' => array( 'g' => 'h' ) ); test('array', $a, new Obj(), new Obj(null, null, null, $a)); $o = new Obj(1, 2, 3); test('object', $o, new Obj(), new Obj(1, 2, 3)); class Obj2 { public $A; protected $B; private $C; function __construct($a, $b, $c) { $this->A = $a; $this->B = $b; $this->C = $c; } } $o = new Obj2(1, 2, 3); test('object', $o, new Obj(), new Obj($o)); $o1 = new Obj2(1, 2, 3); $o2 = new Obj2(4, 5, 6); test('object', array($o1, $o2), new Obj(), new Obj($o1, $o2)); --EXPECTF-- object(Obj)#%d (3) { ["a"]=> NULL [%r"?b"?:protected"?%r]=> NULL [%r"?c"?:("Obj":)?private"?%r]=> NULL } OK object(Obj)#%d (3) { ["a"]=> bool(true) [%r"?b"?:protected"?%r]=> NULL [%r"?c"?:("Obj":)?private"?%r]=> NULL } OK object(Obj)#%d (3) { ["a"]=> bool(false) [%r"?b"?:protected"?%r]=> NULL [%r"?c"?:("Obj":)?private"?%r]=> NULL } OK object(Obj)#%d (3) { ["a"]=> int(0) [%r"?b"?:protected"?%r]=> NULL [%r"?c"?:("Obj":)?private"?%r]=> NULL } OK object(Obj)#%d (3) { ["a"]=> int(1) [%r"?b"?:protected"?%r]=> NULL [%r"?c"?:("Obj":)?private"?%r]=> NULL } OK object(Obj)#%d (3) { ["a"]=> int(-1) [%r"?b"?:protected"?%r]=> NULL [%r"?c"?:("Obj":)?private"?%r]=> NULL } OK object(Obj)#%d (3) { ["a"]=> int(1000) [%r"?b"?:protected"?%r]=> NULL [%r"?c"?:("Obj":)?private"?%r]=> NULL } OK object(Obj)#%d (3) { ["a"]=> int(-1000) [%r"?b"?:protected"?%r]=> NULL [%r"?c"?:("Obj":)?private"?%r]=> NULL } OK object(Obj)#%d (3) { ["a"]=> int(100000) [%r"?b"?:protected"?%r]=> NULL [%r"?c"?:("Obj":)?private"?%r]=> NULL } OK object(Obj)#%d (3) { ["a"]=> int(-100000) [%r"?b"?:protected"?%r]=> NULL [%r"?c"?:("Obj":)?private"?%r]=> NULL } OK object(Obj)#%d (3) { ["a"]=> float(123.456) [%r"?b"?:protected"?%r]=> NULL [%r"?c"?:("Obj":)?private"?%r]=> NULL } OK object(Obj)#%d (3) { ["a"]=> string(0) "" [%r"?b"?:protected"?%r]=> NULL [%r"?c"?:("Obj":)?private"?%r]=> NULL } OK object(Obj)#%d (3) { ["a"]=> string(6) "foobar" [%r"?b"?:protected"?%r]=> NULL [%r"?c"?:("Obj":)?private"?%r]=> NULL } OK object(Obj)#%d (3) { ["a"]=> NULL [%r"?b"?:protected"?%r]=> NULL [%r"?c"?:("Obj":)?private"?%r]=> NULL } OK object(Obj)#%d (3) { ["a"]=> int(1) [%r"?b"?:protected"?%r]=> int(2) [%r"?c"?:("Obj":)?private"?%r]=> int(3) } OK object(Obj)#%d (3) { ["a"]=> array(3) { [0]=> int(1) [1]=> int(2) [2]=> int(3) } [%r"?b"?:protected"?%r]=> array(3) { [0]=> int(4) [1]=> int(5) [2]=> int(6) } [%r"?c"?:("Obj":)?private"?%r]=> array(3) { [0]=> int(7) [1]=> int(8) [2]=> int(9) } } OK object(Obj)#%d (4) { ["a"]=> int(1) [%r"?b"?:protected"?%r]=> int(2) [%r"?c"?:("Obj":)?private"?%r]=> int(3) ["3"]=> int(4) } SKIP object(Obj)#%d (3) { ["a"]=> string(3) "foo" [%r"?b"?:protected"?%r]=> string(6) "foobar" [%r"?c"?:("Obj":)?private"?%r]=> string(4) "hoge" } OK object(Obj)#%d (3) { ["a"]=> int(1) [%r"?b"?:protected"?%r]=> int(2) [%r"?c"?:("Obj":)?private"?%r]=> NULL } OK object(Obj)#%d (5) { ["a"]=> NULL [%r"?b"?:protected"?%r]=> NULL [%r"?c"?:("Obj":)?private"?%r]=> NULL ["one"]=> int(1) ["two"]=> int(2) } OK object(Obj)#%d (3) { ["a"]=> int(1) [%r"?b"?:protected"?%r]=> int(2) [%r"?c"?:("Obj":)?private"?%r]=> int(3) } OK object(Obj)#%d (3) { ["a"]=> int(1) [%r"?b"?:protected"?%r]=> int(2) [%r"?c"?:("Obj":)?private"?%r]=> int(3) } OK object(Obj)#%d (3) { ["a"]=> int(1) [%r"?b"?:protected"?%r]=> int(2) [%r"?c"?:("Obj":)?private"?%r]=> int(3) } OK object(Obj)#%d (3) { ["a"]=> array(1) { [0]=> string(3) "foo" } [%r"?b"?:protected"?%r]=> array(1) { [0]=> string(3) "foo" } [%r"?c"?:("Obj":)?private"?%r]=> NULL } OK object(Obj)#%d (4) { ["a"]=> array(2) { ["b"]=> string(1) "c" ["d"]=> string(1) "e" } [%r"?b"?:protected"?%r]=> NULL [%r"?c"?:("Obj":)?private"?%r]=> NULL ["f"]=> array(1) { ["g"]=> string(1) "h" } } OK object(Obj)#%d (3) { ["a"]=> int(1) [%r"?b"?:protected"?%r]=> int(2) [%r"?c"?:("Obj":)?private"?%r]=> int(3) } OK object(Obj)#%d (3) { ["a"]=> object(Obj2)#%d (3) { ["A"]=> int(1) [%r"?B"?:protected"?%r]=> int(2) [%r"?C"?:("Obj2":)?private"?%r]=> int(3) } [%r"?b"?:protected"?%r]=> NULL [%r"?c"?:("Obj":)?private"?%r]=> NULL } OK object(Obj)#%d (3) { ["a"]=> object(Obj2)#%d (3) { ["A"]=> int(1) [%r"?B"?:protected"?%r]=> int(2) [%r"?C"?:("Obj2":)?private"?%r]=> int(3) } [%r"?b"?:protected"?%r]=> object(Obj2)#%d (3) { ["A"]=> int(4) [%r"?B"?:protected"?%r]=> int(5) [%r"?C"?:("Obj2":)?private"?%r]=> int(6) } [%r"?c"?:("Obj":)?private"?%r]=> NULL } OK msgpack-2.1.0beta1/tests/092.phpt0000644000175000001440000001702013577133502015277 0ustar mikeusers--TEST-- unpack of object converter (string: php_only=0) --SKIPIF-- a = $a; $this->b = $b; $this->c = $c; if (is_array($d)) { foreach ($d as $key => $val) { $this->{$key} = $val; } } } } test('null', null, 'Obj', new Obj(null, null, null)); test('bool: true', true, 'Obj', new Obj(true, null, null)); test('bool: false', false, 'Obj', new Obj(false, null, null)); test('zero: 0', 0, 'Obj', new Obj(0, null, null)); test('small: 1', 1, 'Obj', new Obj(1, null, null)); test('small: -1', -1, 'Obj', new Obj(-1, null, null)); test('medium: 1000', 1000, 'Obj', new Obj(1000, null, null)); test('medium: -1000', -1000, 'Obj', new Obj(-1000, null, null)); test('large: 100000', 100000, 'Obj', new Obj(100000, null, null)); test('large: -100000', -100000, 'Obj', new Obj(-100000, null, null)); test('double: 123.456', 123.456, 'Obj', new Obj(123.456, null, null)); test('empty: ""', "", 'Obj', new Obj("", null, null)); test('string: "foobar"', "foobar", 'Obj', new Obj("foobar", null, null)); test('array: empty', array(), 'Obj', new Obj(null, null, null)); test('array(1, 2, 3)', array(1, 2, 3), 'Obj', new Obj(1, 2, 3)); test('array(array(1, 2, 3), arr...', array(array(1, 2, 3), array(4, 5, 6), array(7, 8, 9)), 'Obj', new Obj(array(1, 2, 3), array(4, 5, 6), array(7, 8, 9))); test('array(1, 2, 3, 4)', array(1, 2, 3, 4), 'Obj'); test('array("foo", "foobar", "foohoge")', array("foo", "foobar", "hoge"), 'Obj', new Obj("foo", "foobar", "hoge")); test('array("a" => 1, "b" => 2))', array("a" => 1, "b" => 2), 'Obj', new Obj(1, 2, null)); test('array("one" => 1, "two" => 2))', array("one" => 1, "two" => 2), 'Obj', new Obj(null, null, null, array("one" => 1, "two" => 2))); test('array("a" => 1, "b" => 2, 3))', array("a" => 1, "b" => 2, 3), 'Obj', new Obj(1, 2, 3)); test('array(3, "a" => 1, "b" => 2))', array(3, "a" => 1, "b" => 2), 'Obj', new Obj(1, 2, 3)); test('array("a" => 1, 3, "b" => 2))', array("a" => 1, 3, "b" => 2), 'Obj', new Obj(1, 2, 3)); $a = array('foo'); test('array($a, $a)', array($a, $a), 'Obj', new Obj($a, $a, null)); $a = array( 'a' => array( 'b' => 'c', 'd' => 'e' ), 'f' => array( 'g' => 'h' ) ); test('array', $a, 'Obj', new Obj(null, null, null, $a)); $o = new Obj(1, 2, 3); test('object', $o, 'Obj', new Obj(1, 2, 3)); class Obj2 { public $A; protected $B; private $C; function __construct($a, $b, $c) { $this->A = $a; $this->B = $b; $this->C = $c; } } $o = new Obj2(1, 2, 3); test('object', $o, 'Obj', new Obj(1, 2, 3)); $o1 = new Obj2(1, 2, 3); $o2 = new Obj2(4, 5, 6); test('object', array($o1, $o2), 'Obj', new Obj(array(1, 2, 3), array(4, 5, 6))); --EXPECTF-- object(Obj)#%d (3) { ["a"]=> NULL [%r"?b"?:protected"?%r]=> NULL [%r"?c"?:("Obj":)?private"?%r]=> NULL } OK object(Obj)#%d (3) { ["a"]=> bool(true) [%r"?b"?:protected"?%r]=> NULL [%r"?c"?:("Obj":)?private"?%r]=> NULL } OK object(Obj)#%d (3) { ["a"]=> bool(false) [%r"?b"?:protected"?%r]=> NULL [%r"?c"?:("Obj":)?private"?%r]=> NULL } OK object(Obj)#%d (3) { ["a"]=> int(0) [%r"?b"?:protected"?%r]=> NULL [%r"?c"?:("Obj":)?private"?%r]=> NULL } OK object(Obj)#%d (3) { ["a"]=> int(1) [%r"?b"?:protected"?%r]=> NULL [%r"?c"?:("Obj":)?private"?%r]=> NULL } OK object(Obj)#%d (3) { ["a"]=> int(-1) [%r"?b"?:protected"?%r]=> NULL [%r"?c"?:("Obj":)?private"?%r]=> NULL } OK object(Obj)#%d (3) { ["a"]=> int(1000) [%r"?b"?:protected"?%r]=> NULL [%r"?c"?:("Obj":)?private"?%r]=> NULL } OK object(Obj)#%d (3) { ["a"]=> int(-1000) [%r"?b"?:protected"?%r]=> NULL [%r"?c"?:("Obj":)?private"?%r]=> NULL } OK object(Obj)#%d (3) { ["a"]=> int(100000) [%r"?b"?:protected"?%r]=> NULL [%r"?c"?:("Obj":)?private"?%r]=> NULL } OK object(Obj)#%d (3) { ["a"]=> int(-100000) [%r"?b"?:protected"?%r]=> NULL [%r"?c"?:("Obj":)?private"?%r]=> NULL } OK object(Obj)#%d (3) { ["a"]=> float(123.456) [%r"?b"?:protected"?%r]=> NULL [%r"?c"?:("Obj":)?private"?%r]=> NULL } OK object(Obj)#%d (3) { ["a"]=> string(0) "" [%r"?b"?:protected"?%r]=> NULL [%r"?c"?:("Obj":)?private"?%r]=> NULL } OK object(Obj)#%d (3) { ["a"]=> string(6) "foobar" [%r"?b"?:protected"?%r]=> NULL [%r"?c"?:("Obj":)?private"?%r]=> NULL } OK object(Obj)#%d (3) { ["a"]=> NULL [%r"?b"?:protected"?%r]=> NULL [%r"?c"?:("Obj":)?private"?%r]=> NULL } OK object(Obj)#%d (3) { ["a"]=> int(1) [%r"?b"?:protected"?%r]=> int(2) [%r"?c"?:("Obj":)?private"?%r]=> int(3) } OK object(Obj)#%d (3) { ["a"]=> array(3) { [0]=> int(1) [1]=> int(2) [2]=> int(3) } [%r"?b"?:protected"?%r]=> array(3) { [0]=> int(4) [1]=> int(5) [2]=> int(6) } [%r"?c"?:("Obj":)?private"?%r]=> array(3) { [0]=> int(7) [1]=> int(8) [2]=> int(9) } } OK object(Obj)#%d (4) { ["a"]=> int(1) [%r"?b"?:protected"?%r]=> int(2) [%r"?c"?:("Obj":)?private"?%r]=> int(3) ["3"]=> int(4) } SKIP object(Obj)#%d (3) { ["a"]=> string(3) "foo" [%r"?b"?:protected"?%r]=> string(6) "foobar" [%r"?c"?:("Obj":)?private"?%r]=> string(4) "hoge" } OK object(Obj)#%d (3) { ["a"]=> int(1) [%r"?b"?:protected"?%r]=> int(2) [%r"?c"?:("Obj":)?private"?%r]=> NULL } OK object(Obj)#%d (5) { ["a"]=> NULL [%r"?b"?:protected"?%r]=> NULL [%r"?c"?:("Obj":)?private"?%r]=> NULL ["one"]=> int(1) ["two"]=> int(2) } OK object(Obj)#%d (3) { ["a"]=> int(1) [%r"?b"?:protected"?%r]=> int(2) [%r"?c"?:("Obj":)?private"?%r]=> int(3) } OK object(Obj)#%d (3) { ["a"]=> int(1) [%r"?b"?:protected"?%r]=> int(2) [%r"?c"?:("Obj":)?private"?%r]=> int(3) } OK object(Obj)#%d (3) { ["a"]=> int(1) [%r"?b"?:protected"?%r]=> int(2) [%r"?c"?:("Obj":)?private"?%r]=> int(3) } OK object(Obj)#%d (3) { ["a"]=> array(1) { [0]=> string(3) "foo" } [%r"?b"?:protected"?%r]=> array(1) { [0]=> string(3) "foo" } [%r"?c"?:("Obj":)?private"?%r]=> NULL } OK object(Obj)#%d (4) { ["a"]=> array(2) { ["b"]=> string(1) "c" ["d"]=> string(1) "e" } [%r"?b"?:protected"?%r]=> NULL [%r"?c"?:("Obj":)?private"?%r]=> NULL ["f"]=> array(1) { ["g"]=> string(1) "h" } } OK object(Obj)#%d (3) { ["a"]=> int(1) [%r"?b"?:protected"?%r]=> int(2) [%r"?c"?:("Obj":)?private"?%r]=> int(3) } OK object(Obj)#%d (3) { ["a"]=> int(1) [%r"?b"?:protected"?%r]=> int(2) [%r"?c"?:("Obj":)?private"?%r]=> int(3) } OK object(Obj)#%d (3) { ["a"]=> array(3) { [0]=> int(1) [1]=> int(2) [2]=> int(3) } [%r"?b"?:protected"?%r]=> array(3) { [0]=> int(4) [1]=> int(5) [2]=> int(6) } [%r"?c"?:("Obj":)?private"?%r]=> NULL } OK msgpack-2.1.0beta1/tests/093.phpt0000644000175000001440000001722613577133502015310 0ustar mikeusers--TEST-- unpack of object converter (object: php_only=0) --SKIPIF-- a = $a; $this->b = $b; $this->c = $c; if (is_array($d)) { foreach ($d as $key => $val) { $this->{$key} = $val; } } } } $object = new Obj(); test('null', null, new Obj(), new Obj(null, null, null)); test('bool: true', true, new Obj(), new Obj(true, null, null)); test('bool: false', false, new Obj(), new Obj(false, null, null)); test('zero: 0', 0, new Obj(), new Obj(0, null, null)); test('small: 1', 1, new Obj(), new Obj(1, null, null)); test('small: -1', -1, new Obj(), new Obj(-1, null, null)); test('medium: 1000', 1000, new Obj(), new Obj(1000, null, null)); test('medium: -1000', -1000, new Obj(), new Obj(-1000, null, null)); test('large: 100000', 100000, new Obj(), new Obj(100000, null, null)); test('large: -100000', -100000, new Obj(), new Obj(-100000, null, null)); test('double: 123.456', 123.456, new Obj(), new Obj(123.456, null, null)); test('empty: ""', "", new Obj(), new Obj("", null, null)); test('string: "foobar"', "foobar", new Obj(), new Obj("foobar", null, null)); test('array: empty', array(), new Obj(), new Obj(null, null, null)); test('array(1, 2, 3)', array(1, 2, 3), new Obj(), new Obj(1, 2, 3)); test('array(array(1, 2, 3), arr...', array(array(1, 2, 3), array(4, 5, 6), array(7, 8, 9)), new Obj(), new Obj(array(1, 2, 3), array(4, 5, 6), array(7, 8, 9))); test('array(1, 2, 3, 4)', array(1, 2, 3, 4), new Obj()); test('array("foo", "foobar", "foohoge")', array("foo", "foobar", "hoge"), new Obj(), new Obj("foo", "foobar", "hoge")); test('array("a" => 1, "b" => 2))', array("a" => 1, "b" => 2), new Obj(), new Obj(1, 2, null)); test('array("one" => 1, "two" => 2))', array("one" => 1, "two" => 2), new Obj(), new Obj(null, null, null, array("one" => 1, "two" => 2))); test('array("a" => 1, "b" => 2, 3))', array("a" => 1, "b" => 2, 3), new Obj(), new Obj(1, 2, 3)); test('array(3, "a" => 1, "b" => 2))', array(3, "a" => 1, "b" => 2), new Obj(), new Obj(1, 2, 3)); test('array("a" => 1, 3, "b" => 2))', array("a" => 1, 3, "b" => 2), new Obj(), new Obj(1, 2, 3)); $a = array('foo'); test('array($a, $a)', array($a, $a), new Obj(), new Obj($a, $a, null)); $a = array( 'a' => array( 'b' => 'c', 'd' => 'e' ), 'f' => array( 'g' => 'h' ) ); test('array', $a, new Obj(), new Obj(null, null, null, $a)); $o = new Obj(1, 2, 3); test('object', $o, new Obj(), new Obj(1, 2, 3)); class Obj2 { public $A; protected $B; private $C; function __construct($a, $b, $c) { $this->A = $a; $this->B = $b; $this->C = $c; } } $o = new Obj2(1, 2, 3); test('object', $o, new Obj(), new Obj(1, 2, 3)); $o1 = new Obj2(1, 2, 3); $o2 = new Obj2(4, 5, 6); test('object', array($o1, $o2), new Obj(), new Obj(array(1, 2, 3), array(4, 5, 6))); --EXPECTF-- object(Obj)#%d (3) { ["a"]=> NULL [%r"?b"?:protected"?%r]=> NULL [%r"?c"?:("Obj":)?private"?%r]=> NULL } OK object(Obj)#%d (3) { ["a"]=> bool(true) [%r"?b"?:protected"?%r]=> NULL [%r"?c"?:("Obj":)?private"?%r]=> NULL } OK object(Obj)#%d (3) { ["a"]=> bool(false) [%r"?b"?:protected"?%r]=> NULL [%r"?c"?:("Obj":)?private"?%r]=> NULL } OK object(Obj)#%d (3) { ["a"]=> int(0) [%r"?b"?:protected"?%r]=> NULL [%r"?c"?:("Obj":)?private"?%r]=> NULL } OK object(Obj)#%d (3) { ["a"]=> int(1) [%r"?b"?:protected"?%r]=> NULL [%r"?c"?:("Obj":)?private"?%r]=> NULL } OK object(Obj)#%d (3) { ["a"]=> int(-1) [%r"?b"?:protected"?%r]=> NULL [%r"?c"?:("Obj":)?private"?%r]=> NULL } OK object(Obj)#%d (3) { ["a"]=> int(1000) [%r"?b"?:protected"?%r]=> NULL [%r"?c"?:("Obj":)?private"?%r]=> NULL } OK object(Obj)#%d (3) { ["a"]=> int(-1000) [%r"?b"?:protected"?%r]=> NULL [%r"?c"?:("Obj":)?private"?%r]=> NULL } OK object(Obj)#%d (3) { ["a"]=> int(100000) [%r"?b"?:protected"?%r]=> NULL [%r"?c"?:("Obj":)?private"?%r]=> NULL } OK object(Obj)#%d (3) { ["a"]=> int(-100000) [%r"?b"?:protected"?%r]=> NULL [%r"?c"?:("Obj":)?private"?%r]=> NULL } OK object(Obj)#%d (3) { ["a"]=> float(123.456) [%r"?b"?:protected"?%r]=> NULL [%r"?c"?:("Obj":)?private"?%r]=> NULL } OK object(Obj)#%d (3) { ["a"]=> string(0) "" [%r"?b"?:protected"?%r]=> NULL [%r"?c"?:("Obj":)?private"?%r]=> NULL } OK object(Obj)#%d (3) { ["a"]=> string(6) "foobar" [%r"?b"?:protected"?%r]=> NULL [%r"?c"?:("Obj":)?private"?%r]=> NULL } OK object(Obj)#%d (3) { ["a"]=> NULL [%r"?b"?:protected"?%r]=> NULL [%r"?c"?:("Obj":)?private"?%r]=> NULL } OK object(Obj)#%d (3) { ["a"]=> int(1) [%r"?b"?:protected"?%r]=> int(2) [%r"?c"?:("Obj":)?private"?%r]=> int(3) } OK object(Obj)#%d (3) { ["a"]=> array(3) { [0]=> int(1) [1]=> int(2) [2]=> int(3) } [%r"?b"?:protected"?%r]=> array(3) { [0]=> int(4) [1]=> int(5) [2]=> int(6) } [%r"?c"?:("Obj":)?private"?%r]=> array(3) { [0]=> int(7) [1]=> int(8) [2]=> int(9) } } OK object(Obj)#%d (4) { ["a"]=> int(1) [%r"?b"?:protected"?%r]=> int(2) [%r"?c"?:("Obj":)?private"?%r]=> int(3) ["3"]=> int(4) } SKIP object(Obj)#%d (3) { ["a"]=> string(3) "foo" [%r"?b"?:protected"?%r]=> string(6) "foobar" [%r"?c"?:("Obj":)?private"?%r]=> string(4) "hoge" } OK object(Obj)#%d (3) { ["a"]=> int(1) [%r"?b"?:protected"?%r]=> int(2) [%r"?c"?:("Obj":)?private"?%r]=> NULL } OK object(Obj)#%d (5) { ["a"]=> NULL [%r"?b"?:protected"?%r]=> NULL [%r"?c"?:("Obj":)?private"?%r]=> NULL ["one"]=> int(1) ["two"]=> int(2) } OK object(Obj)#%d (3) { ["a"]=> int(1) [%r"?b"?:protected"?%r]=> int(2) [%r"?c"?:("Obj":)?private"?%r]=> int(3) } OK object(Obj)#%d (3) { ["a"]=> int(1) [%r"?b"?:protected"?%r]=> int(2) [%r"?c"?:("Obj":)?private"?%r]=> int(3) } OK object(Obj)#%d (3) { ["a"]=> int(1) [%r"?b"?:protected"?%r]=> int(2) [%r"?c"?:("Obj":)?private"?%r]=> int(3) } OK object(Obj)#%d (3) { ["a"]=> array(1) { [0]=> string(3) "foo" } [%r"?b"?:protected"?%r]=> array(1) { [0]=> string(3) "foo" } [%r"?c"?:("Obj":)?private"?%r]=> NULL } OK object(Obj)#%d (4) { ["a"]=> array(2) { ["b"]=> string(1) "c" ["d"]=> string(1) "e" } [%r"?b"?:protected"?%r]=> NULL [%r"?c"?:("Obj":)?private"?%r]=> NULL ["f"]=> array(1) { ["g"]=> string(1) "h" } } OK object(Obj)#%d (3) { ["a"]=> int(1) [%r"?b"?:protected"?%r]=> int(2) [%r"?c"?:("Obj":)?private"?%r]=> int(3) } OK object(Obj)#%d (3) { ["a"]=> int(1) [%r"?b"?:protected"?%r]=> int(2) [%r"?c"?:("Obj":)?private"?%r]=> int(3) } OK object(Obj)#%d (3) { ["a"]=> array(3) { [0]=> int(1) [1]=> int(2) [2]=> int(3) } [%r"?b"?:protected"?%r]=> array(3) { [0]=> int(4) [1]=> int(5) [2]=> int(6) } [%r"?c"?:("Obj":)?private"?%r]=> NULL } OK msgpack-2.1.0beta1/tests/094.phpt0000644000175000001440000001737213577133502015313 0ustar mikeusers--TEST-- unpack of object converter : class unpack (string) --SKIPIF-- pack($variable); $unserialized = $msgpack->unpack($serialized, $object); var_dump($unserialized); if ($result) { echo $unserialized == $result ? 'OK' : 'ERROR', PHP_EOL; } else { echo 'SKIP', PHP_EOL; } } class Obj { public $a; protected $b; private $c; public function __construct($a = null, $b = null, $c = null, $d = null) { $this->a = $a; $this->b = $b; $this->c = $c; if (is_array($d)) { foreach ($d as $key => $val) { $this->{$key} = $val; } } } } test('null', null, 'Obj', new Obj(null, null, null)); test('bool: true', true, 'Obj', new Obj(true, null, null)); test('bool: false', false, 'Obj', new Obj(false, null, null)); test('zero: 0', 0, 'Obj', new Obj(0, null, null)); test('small: 1', 1, 'Obj', new Obj(1, null, null)); test('small: -1', -1, 'Obj', new Obj(-1, null, null)); test('medium: 1000', 1000, 'Obj', new Obj(1000, null, null)); test('medium: -1000', -1000, 'Obj', new Obj(-1000, null, null)); test('large: 100000', 100000, 'Obj', new Obj(100000, null, null)); test('large: -100000', -100000, 'Obj', new Obj(-100000, null, null)); test('double: 123.456', 123.456, 'Obj', new Obj(123.456, null, null)); test('empty: ""', "", 'Obj', new Obj("", null, null)); test('string: "foobar"', "foobar", 'Obj', new Obj("foobar", null, null)); test('array: empty', array(), 'Obj', new Obj(null, null, null)); test('array(1, 2, 3)', array(1, 2, 3), 'Obj', new Obj(1, 2, 3)); test('array(array(1, 2, 3), arr...', array(array(1, 2, 3), array(4, 5, 6), array(7, 8, 9)), 'Obj', new Obj(array(1, 2, 3), array(4, 5, 6), array(7, 8, 9))); test('array(1, 2, 3, 4)', array(1, 2, 3, 4), 'Obj'); test('array("foo", "foobar", "foohoge")', array("foo", "foobar", "hoge"), 'Obj', new Obj("foo", "foobar", "hoge")); test('array("a" => 1, "b" => 2))', array("a" => 1, "b" => 2), 'Obj', new Obj(1, 2, null)); test('array("one" => 1, "two" => 2))', array("one" => 1, "two" => 2), 'Obj', new Obj(null, null, null, array("one" => 1, "two" => 2))); test('array("a" => 1, "b" => 2, 3))', array("a" => 1, "b" => 2, 3), 'Obj', new Obj(1, 2, 3)); test('array(3, "a" => 1, "b" => 2))', array(3, "a" => 1, "b" => 2), 'Obj', new Obj(1, 2, 3)); test('array("a" => 1, 3, "b" => 2))', array("a" => 1, 3, "b" => 2), 'Obj', new Obj(1, 2, 3)); $a = array('foo'); test('array($a, $a)', array($a, $a), 'Obj', new Obj($a, $a, null)); $a = array( 'a' => array( 'b' => 'c', 'd' => 'e' ), 'f' => array( 'g' => 'h' ) ); test('array', $a, 'Obj', new Obj(null, null, null, $a)); $o = new Obj(1, 2, 3); test('object', $o, 'Obj', new Obj(1, 2, 3)); class Obj2 { public $A; protected $B; private $C; function __construct($a, $b, $c) { $this->A = $a; $this->B = $b; $this->C = $c; } } $o = new Obj2(1, 2, 3); test('object', $o, 'Obj', new Obj($o)); $o1 = new Obj2(1, 2, 3); $o2 = new Obj2(4, 5, 6); test('object', array($o1, $o2), 'Obj', new Obj($o1, $o2)); --EXPECTF-- object(Obj)#%d (3) { ["a"]=> NULL [%r"?b"?:protected"?%r]=> NULL [%r"?c"?:("Obj":)?private"?%r]=> NULL } OK object(Obj)#%d (3) { ["a"]=> bool(true) [%r"?b"?:protected"?%r]=> NULL [%r"?c"?:("Obj":)?private"?%r]=> NULL } OK object(Obj)#%d (3) { ["a"]=> bool(false) [%r"?b"?:protected"?%r]=> NULL [%r"?c"?:("Obj":)?private"?%r]=> NULL } OK object(Obj)#%d (3) { ["a"]=> int(0) [%r"?b"?:protected"?%r]=> NULL [%r"?c"?:("Obj":)?private"?%r]=> NULL } OK object(Obj)#%d (3) { ["a"]=> int(1) [%r"?b"?:protected"?%r]=> NULL [%r"?c"?:("Obj":)?private"?%r]=> NULL } OK object(Obj)#%d (3) { ["a"]=> int(-1) [%r"?b"?:protected"?%r]=> NULL [%r"?c"?:("Obj":)?private"?%r]=> NULL } OK object(Obj)#%d (3) { ["a"]=> int(1000) [%r"?b"?:protected"?%r]=> NULL [%r"?c"?:("Obj":)?private"?%r]=> NULL } OK object(Obj)#%d (3) { ["a"]=> int(-1000) [%r"?b"?:protected"?%r]=> NULL [%r"?c"?:("Obj":)?private"?%r]=> NULL } OK object(Obj)#%d (3) { ["a"]=> int(100000) [%r"?b"?:protected"?%r]=> NULL [%r"?c"?:("Obj":)?private"?%r]=> NULL } OK object(Obj)#%d (3) { ["a"]=> int(-100000) [%r"?b"?:protected"?%r]=> NULL [%r"?c"?:("Obj":)?private"?%r]=> NULL } OK object(Obj)#%d (3) { ["a"]=> float(123.456) [%r"?b"?:protected"?%r]=> NULL [%r"?c"?:("Obj":)?private"?%r]=> NULL } OK object(Obj)#%d (3) { ["a"]=> string(0) "" [%r"?b"?:protected"?%r]=> NULL [%r"?c"?:("Obj":)?private"?%r]=> NULL } OK object(Obj)#%d (3) { ["a"]=> string(6) "foobar" [%r"?b"?:protected"?%r]=> NULL [%r"?c"?:("Obj":)?private"?%r]=> NULL } OK object(Obj)#%d (3) { ["a"]=> NULL [%r"?b"?:protected"?%r]=> NULL [%r"?c"?:("Obj":)?private"?%r]=> NULL } OK object(Obj)#%d (3) { ["a"]=> int(1) [%r"?b"?:protected"?%r]=> int(2) [%r"?c"?:("Obj":)?private"?%r]=> int(3) } OK object(Obj)#%d (3) { ["a"]=> array(3) { [0]=> int(1) [1]=> int(2) [2]=> int(3) } [%r"?b"?:protected"?%r]=> array(3) { [0]=> int(4) [1]=> int(5) [2]=> int(6) } [%r"?c"?:("Obj":)?private"?%r]=> array(3) { [0]=> int(7) [1]=> int(8) [2]=> int(9) } } OK object(Obj)#%d (4) { ["a"]=> int(1) [%r"?b"?:protected"?%r]=> int(2) [%r"?c"?:("Obj":)?private"?%r]=> int(3) ["3"]=> int(4) } SKIP object(Obj)#%d (3) { ["a"]=> string(3) "foo" [%r"?b"?:protected"?%r]=> string(6) "foobar" [%r"?c"?:("Obj":)?private"?%r]=> string(4) "hoge" } OK object(Obj)#%d (3) { ["a"]=> int(1) [%r"?b"?:protected"?%r]=> int(2) [%r"?c"?:("Obj":)?private"?%r]=> NULL } OK object(Obj)#%d (5) { ["a"]=> NULL [%r"?b"?:protected"?%r]=> NULL [%r"?c"?:("Obj":)?private"?%r]=> NULL ["one"]=> int(1) ["two"]=> int(2) } OK object(Obj)#%d (3) { ["a"]=> int(1) [%r"?b"?:protected"?%r]=> int(2) [%r"?c"?:("Obj":)?private"?%r]=> int(3) } OK object(Obj)#%d (3) { ["a"]=> int(1) [%r"?b"?:protected"?%r]=> int(2) [%r"?c"?:("Obj":)?private"?%r]=> int(3) } OK object(Obj)#%d (3) { ["a"]=> int(1) [%r"?b"?:protected"?%r]=> int(2) [%r"?c"?:("Obj":)?private"?%r]=> int(3) } OK object(Obj)#%d (3) { ["a"]=> array(1) { [0]=> string(3) "foo" } [%r"?b"?:protected"?%r]=> array(1) { [0]=> string(3) "foo" } [%r"?c"?:("Obj":)?private"?%r]=> NULL } OK object(Obj)#%d (4) { ["a"]=> array(2) { ["b"]=> string(1) "c" ["d"]=> string(1) "e" } [%r"?b"?:protected"?%r]=> NULL [%r"?c"?:("Obj":)?private"?%r]=> NULL ["f"]=> array(1) { ["g"]=> string(1) "h" } } OK object(Obj)#%d (3) { ["a"]=> int(1) [%r"?b"?:protected"?%r]=> int(2) [%r"?c"?:("Obj":)?private"?%r]=> int(3) } OK object(Obj)#%d (3) { ["a"]=> object(Obj2)#%d (3) { ["A"]=> int(1) [%r"?B"?:protected"?%r]=> int(2) [%r"?C"?:("Obj2":)?private"?%r]=> int(3) } [%r"?b"?:protected"?%r]=> NULL [%r"?c"?:("Obj":)?private"?%r]=> NULL } OK object(Obj)#%d (3) { ["a"]=> object(Obj2)#%d (3) { ["A"]=> int(1) [%r"?B"?:protected"?%r]=> int(2) [%r"?C"?:("Obj2":)?private"?%r]=> int(3) } [%r"?b"?:protected"?%r]=> object(Obj2)#%d (3) { ["A"]=> int(4) [%r"?B"?:protected"?%r]=> int(5) [%r"?C"?:("Obj2":)?private"?%r]=> int(6) } [%r"?c"?:("Obj":)?private"?%r]=> NULL } OK msgpack-2.1.0beta1/tests/095.phpt0000644000175000001440000001760013577133502015306 0ustar mikeusers--TEST-- unpack of object converter : class unpack (object) --SKIPIF-- pack($variable); $unserialized = $msgpack->unpack($serialized, $object); var_dump($unserialized); if ($result) { echo $unserialized == $result ? 'OK' : 'ERROR', PHP_EOL; } else { echo 'SKIP', PHP_EOL; } } class Obj { public $a; protected $b; private $c; public function __construct($a = null, $b = null, $c = null, $d = null) { $this->a = $a; $this->b = $b; $this->c = $c; if (is_array($d)) { foreach ($d as $key => $val) { $this->{$key} = $val; } } } } $object = new Obj(); test('null', null, new Obj(), new Obj(null, null, null)); test('bool: true', true, new Obj(), new Obj(true, null, null)); test('bool: false', false, new Obj(), new Obj(false, null, null)); test('zero: 0', 0, new Obj(), new Obj(0, null, null)); test('small: 1', 1, new Obj(), new Obj(1, null, null)); test('small: -1', -1, new Obj(), new Obj(-1, null, null)); test('medium: 1000', 1000, new Obj(), new Obj(1000, null, null)); test('medium: -1000', -1000, new Obj(), new Obj(-1000, null, null)); test('large: 100000', 100000, new Obj(), new Obj(100000, null, null)); test('large: -100000', -100000, new Obj(), new Obj(-100000, null, null)); test('double: 123.456', 123.456, new Obj(), new Obj(123.456, null, null)); test('empty: ""', "", new Obj(), new Obj("", null, null)); test('string: "foobar"', "foobar", new Obj(), new Obj("foobar", null, null)); test('array: empty', array(), new Obj(), new Obj(null, null, null)); test('array(1, 2, 3)', array(1, 2, 3), new Obj(), new Obj(1, 2, 3)); test('array(array(1, 2, 3), arr...', array(array(1, 2, 3), array(4, 5, 6), array(7, 8, 9)), new Obj(), new Obj(array(1, 2, 3), array(4, 5, 6), array(7, 8, 9))); test('array(1, 2, 3, 4)', array(1, 2, 3, 4), new Obj()); test('array("foo", "foobar", "foohoge")', array("foo", "foobar", "hoge"), new Obj(), new Obj("foo", "foobar", "hoge")); test('array("a" => 1, "b" => 2))', array("a" => 1, "b" => 2), new Obj(), new Obj(1, 2, null)); test('array("one" => 1, "two" => 2))', array("one" => 1, "two" => 2), new Obj(), new Obj(null, null, null, array("one" => 1, "two" => 2))); test('array("a" => 1, "b" => 2, 3))', array("a" => 1, "b" => 2, 3), new Obj(), new Obj(1, 2, 3)); test('array(3, "a" => 1, "b" => 2))', array(3, "a" => 1, "b" => 2), new Obj(), new Obj(1, 2, 3)); test('array("a" => 1, 3, "b" => 2))', array("a" => 1, 3, "b" => 2), new Obj(), new Obj(1, 2, 3)); $a = array('foo'); test('array($a, $a)', array($a, $a), new Obj(), new Obj($a, $a, null)); $a = array( 'a' => array( 'b' => 'c', 'd' => 'e' ), 'f' => array( 'g' => 'h' ) ); test('array', $a, new Obj(), new Obj(null, null, null, $a)); $o = new Obj(1, 2, 3); test('object', $o, new Obj(), new Obj(1, 2, 3)); class Obj2 { public $A; protected $B; private $C; function __construct($a, $b, $c) { $this->A = $a; $this->B = $b; $this->C = $c; } } $o = new Obj2(1, 2, 3); test('object', $o, new Obj(), new Obj($o)); $o1 = new Obj2(1, 2, 3); $o2 = new Obj2(4, 5, 6); test('object', array($o1, $o2), new Obj(), new Obj($o1, $o2)); --EXPECTF-- object(Obj)#%d (3) { ["a"]=> NULL [%r"?b"?:protected"?%r]=> NULL [%r"?c"?:("Obj":)?private"?%r]=> NULL } OK object(Obj)#%d (3) { ["a"]=> bool(true) [%r"?b"?:protected"?%r]=> NULL [%r"?c"?:("Obj":)?private"?%r]=> NULL } OK object(Obj)#%d (3) { ["a"]=> bool(false) [%r"?b"?:protected"?%r]=> NULL [%r"?c"?:("Obj":)?private"?%r]=> NULL } OK object(Obj)#%d (3) { ["a"]=> int(0) [%r"?b"?:protected"?%r]=> NULL [%r"?c"?:("Obj":)?private"?%r]=> NULL } OK object(Obj)#%d (3) { ["a"]=> int(1) [%r"?b"?:protected"?%r]=> NULL [%r"?c"?:("Obj":)?private"?%r]=> NULL } OK object(Obj)#%d (3) { ["a"]=> int(-1) [%r"?b"?:protected"?%r]=> NULL [%r"?c"?:("Obj":)?private"?%r]=> NULL } OK object(Obj)#%d (3) { ["a"]=> int(1000) [%r"?b"?:protected"?%r]=> NULL [%r"?c"?:("Obj":)?private"?%r]=> NULL } OK object(Obj)#%d (3) { ["a"]=> int(-1000) [%r"?b"?:protected"?%r]=> NULL [%r"?c"?:("Obj":)?private"?%r]=> NULL } OK object(Obj)#%d (3) { ["a"]=> int(100000) [%r"?b"?:protected"?%r]=> NULL [%r"?c"?:("Obj":)?private"?%r]=> NULL } OK object(Obj)#%d (3) { ["a"]=> int(-100000) [%r"?b"?:protected"?%r]=> NULL [%r"?c"?:("Obj":)?private"?%r]=> NULL } OK object(Obj)#%d (3) { ["a"]=> float(123.456) [%r"?b"?:protected"?%r]=> NULL [%r"?c"?:("Obj":)?private"?%r]=> NULL } OK object(Obj)#%d (3) { ["a"]=> string(0) "" [%r"?b"?:protected"?%r]=> NULL [%r"?c"?:("Obj":)?private"?%r]=> NULL } OK object(Obj)#%d (3) { ["a"]=> string(6) "foobar" [%r"?b"?:protected"?%r]=> NULL [%r"?c"?:("Obj":)?private"?%r]=> NULL } OK object(Obj)#%d (3) { ["a"]=> NULL [%r"?b"?:protected"?%r]=> NULL [%r"?c"?:("Obj":)?private"?%r]=> NULL } OK object(Obj)#%d (3) { ["a"]=> int(1) [%r"?b"?:protected"?%r]=> int(2) [%r"?c"?:("Obj":)?private"?%r]=> int(3) } OK object(Obj)#%d (3) { ["a"]=> array(3) { [0]=> int(1) [1]=> int(2) [2]=> int(3) } [%r"?b"?:protected"?%r]=> array(3) { [0]=> int(4) [1]=> int(5) [2]=> int(6) } [%r"?c"?:("Obj":)?private"?%r]=> array(3) { [0]=> int(7) [1]=> int(8) [2]=> int(9) } } OK object(Obj)#%d (4) { ["a"]=> int(1) [%r"?b"?:protected"?%r]=> int(2) [%r"?c"?:("Obj":)?private"?%r]=> int(3) ["3"]=> int(4) } SKIP object(Obj)#%d (3) { ["a"]=> string(3) "foo" [%r"?b"?:protected"?%r]=> string(6) "foobar" [%r"?c"?:("Obj":)?private"?%r]=> string(4) "hoge" } OK object(Obj)#%d (3) { ["a"]=> int(1) [%r"?b"?:protected"?%r]=> int(2) [%r"?c"?:("Obj":)?private"?%r]=> NULL } OK object(Obj)#%d (5) { ["a"]=> NULL [%r"?b"?:protected"?%r]=> NULL [%r"?c"?:("Obj":)?private"?%r]=> NULL ["one"]=> int(1) ["two"]=> int(2) } OK object(Obj)#%d (3) { ["a"]=> int(1) [%r"?b"?:protected"?%r]=> int(2) [%r"?c"?:("Obj":)?private"?%r]=> int(3) } OK object(Obj)#%d (3) { ["a"]=> int(1) [%r"?b"?:protected"?%r]=> int(2) [%r"?c"?:("Obj":)?private"?%r]=> int(3) } OK object(Obj)#%d (3) { ["a"]=> int(1) [%r"?b"?:protected"?%r]=> int(2) [%r"?c"?:("Obj":)?private"?%r]=> int(3) } OK object(Obj)#%d (3) { ["a"]=> array(1) { [0]=> string(3) "foo" } [%r"?b"?:protected"?%r]=> array(1) { [0]=> string(3) "foo" } [%r"?c"?:("Obj":)?private"?%r]=> NULL } OK object(Obj)#%d (4) { ["a"]=> array(2) { ["b"]=> string(1) "c" ["d"]=> string(1) "e" } [%r"?b"?:protected"?%r]=> NULL [%r"?c"?:("Obj":)?private"?%r]=> NULL ["f"]=> array(1) { ["g"]=> string(1) "h" } } OK object(Obj)#%d (3) { ["a"]=> int(1) [%r"?b"?:protected"?%r]=> int(2) [%r"?c"?:("Obj":)?private"?%r]=> int(3) } OK object(Obj)#%d (3) { ["a"]=> object(Obj2)#%d (3) { ["A"]=> int(1) [%r"?B"?:protected"?%r]=> int(2) [%r"?C"?:("Obj2":)?private"?%r]=> int(3) } [%r"?b"?:protected"?%r]=> NULL [%r"?c"?:("Obj":)?private"?%r]=> NULL } OK object(Obj)#%d (3) { ["a"]=> object(Obj2)#%d (3) { ["A"]=> int(1) [%r"?B"?:protected"?%r]=> int(2) [%r"?C"?:("Obj2":)?private"?%r]=> int(3) } [%r"?b"?:protected"?%r]=> object(Obj2)#%d (3) { ["A"]=> int(4) [%r"?B"?:protected"?%r]=> int(5) [%r"?C"?:("Obj2":)?private"?%r]=> int(6) } [%r"?c"?:("Obj":)?private"?%r]=> NULL } OK msgpack-2.1.0beta1/tests/096.phpt0000644000175000001440000001710713577133502015311 0ustar mikeusers--TEST-- unpack of object converter : class unpack (string: php_only=0) --SKIPIF-- pack($variable); $unserialized = $msgpack->unpack($serialized, $object); var_dump($unserialized); if ($result) { echo $unserialized == $result ? 'OK' : 'ERROR', PHP_EOL; } else { echo 'SKIP', PHP_EOL; } } class Obj { public $a; protected $b; private $c; public function __construct($a = null, $b = null, $c = null, $d = null) { $this->a = $a; $this->b = $b; $this->c = $c; if (is_array($d)) { foreach ($d as $key => $val) { $this->{$key} = $val; } } } } test('null', null, 'Obj', new Obj(null, null, null)); test('bool: true', true, 'Obj', new Obj(true, null, null)); test('bool: false', false, 'Obj', new Obj(false, null, null)); test('zero: 0', 0, 'Obj', new Obj(0, null, null)); test('small: 1', 1, 'Obj', new Obj(1, null, null)); test('small: -1', -1, 'Obj', new Obj(-1, null, null)); test('medium: 1000', 1000, 'Obj', new Obj(1000, null, null)); test('medium: -1000', -1000, 'Obj', new Obj(-1000, null, null)); test('large: 100000', 100000, 'Obj', new Obj(100000, null, null)); test('large: -100000', -100000, 'Obj', new Obj(-100000, null, null)); test('double: 123.456', 123.456, 'Obj', new Obj(123.456, null, null)); test('empty: ""', "", 'Obj', new Obj("", null, null)); test('string: "foobar"', "foobar", 'Obj', new Obj("foobar", null, null)); test('array: empty', array(), 'Obj', new Obj(null, null, null)); test('array(1, 2, 3)', array(1, 2, 3), 'Obj', new Obj(1, 2, 3)); test('array(array(1, 2, 3), arr...', array(array(1, 2, 3), array(4, 5, 6), array(7, 8, 9)), 'Obj', new Obj(array(1, 2, 3), array(4, 5, 6), array(7, 8, 9))); test('array(1, 2, 3, 4)', array(1, 2, 3, 4), 'Obj'); test('array("foo", "foobar", "foohoge")', array("foo", "foobar", "hoge"), 'Obj', new Obj("foo", "foobar", "hoge")); test('array("a" => 1, "b" => 2))', array("a" => 1, "b" => 2), 'Obj', new Obj(1, 2, null)); test('array("one" => 1, "two" => 2))', array("one" => 1, "two" => 2), 'Obj', new Obj(null, null, null, array("one" => 1, "two" => 2))); test('array("a" => 1, "b" => 2, 3))', array("a" => 1, "b" => 2, 3), 'Obj', new Obj(1, 2, 3)); test('array(3, "a" => 1, "b" => 2))', array(3, "a" => 1, "b" => 2), 'Obj', new Obj(1, 2, 3)); test('array("a" => 1, 3, "b" => 2))', array("a" => 1, 3, "b" => 2), 'Obj', new Obj(1, 2, 3)); $a = array('foo'); test('array($a, $a)', array($a, $a), 'Obj', new Obj($a, $a, null)); $a = array( 'a' => array( 'b' => 'c', 'd' => 'e' ), 'f' => array( 'g' => 'h' ) ); test('array', $a, 'Obj', new Obj(null, null, null, $a)); $o = new Obj(1, 2, 3); test('object', $o, 'Obj', new Obj(1, 2, 3)); class Obj2 { public $A; protected $B; private $C; function __construct($a, $b, $c) { $this->A = $a; $this->B = $b; $this->C = $c; } } $o = new Obj2(1, 2, 3); test('object', $o, 'Obj', new Obj(1, 2, 3)); $o1 = new Obj2(1, 2, 3); $o2 = new Obj2(4, 5, 6); test('object', array($o1, $o2), 'Obj', new Obj(array(1, 2, 3), array(4, 5, 6))); --EXPECTF-- object(Obj)#%d (3) { ["a"]=> NULL [%r"?b"?:protected"?%r]=> NULL [%r"?c"?:("Obj":)?private"?%r]=> NULL } OK object(Obj)#%d (3) { ["a"]=> bool(true) [%r"?b"?:protected"?%r]=> NULL [%r"?c"?:("Obj":)?private"?%r]=> NULL } OK object(Obj)#%d (3) { ["a"]=> bool(false) [%r"?b"?:protected"?%r]=> NULL [%r"?c"?:("Obj":)?private"?%r]=> NULL } OK object(Obj)#%d (3) { ["a"]=> int(0) [%r"?b"?:protected"?%r]=> NULL [%r"?c"?:("Obj":)?private"?%r]=> NULL } OK object(Obj)#%d (3) { ["a"]=> int(1) [%r"?b"?:protected"?%r]=> NULL [%r"?c"?:("Obj":)?private"?%r]=> NULL } OK object(Obj)#%d (3) { ["a"]=> int(-1) [%r"?b"?:protected"?%r]=> NULL [%r"?c"?:("Obj":)?private"?%r]=> NULL } OK object(Obj)#%d (3) { ["a"]=> int(1000) [%r"?b"?:protected"?%r]=> NULL [%r"?c"?:("Obj":)?private"?%r]=> NULL } OK object(Obj)#%d (3) { ["a"]=> int(-1000) [%r"?b"?:protected"?%r]=> NULL [%r"?c"?:("Obj":)?private"?%r]=> NULL } OK object(Obj)#%d (3) { ["a"]=> int(100000) [%r"?b"?:protected"?%r]=> NULL [%r"?c"?:("Obj":)?private"?%r]=> NULL } OK object(Obj)#%d (3) { ["a"]=> int(-100000) [%r"?b"?:protected"?%r]=> NULL [%r"?c"?:("Obj":)?private"?%r]=> NULL } OK object(Obj)#%d (3) { ["a"]=> float(123.456) [%r"?b"?:protected"?%r]=> NULL [%r"?c"?:("Obj":)?private"?%r]=> NULL } OK object(Obj)#%d (3) { ["a"]=> string(0) "" [%r"?b"?:protected"?%r]=> NULL [%r"?c"?:("Obj":)?private"?%r]=> NULL } OK object(Obj)#%d (3) { ["a"]=> string(6) "foobar" [%r"?b"?:protected"?%r]=> NULL [%r"?c"?:("Obj":)?private"?%r]=> NULL } OK object(Obj)#%d (3) { ["a"]=> NULL [%r"?b"?:protected"?%r]=> NULL [%r"?c"?:("Obj":)?private"?%r]=> NULL } OK object(Obj)#%d (3) { ["a"]=> int(1) [%r"?b"?:protected"?%r]=> int(2) [%r"?c"?:("Obj":)?private"?%r]=> int(3) } OK object(Obj)#%d (3) { ["a"]=> array(3) { [0]=> int(1) [1]=> int(2) [2]=> int(3) } [%r"?b"?:protected"?%r]=> array(3) { [0]=> int(4) [1]=> int(5) [2]=> int(6) } [%r"?c"?:("Obj":)?private"?%r]=> array(3) { [0]=> int(7) [1]=> int(8) [2]=> int(9) } } OK object(Obj)#%d (4) { ["a"]=> int(1) [%r"?b"?:protected"?%r]=> int(2) [%r"?c"?:("Obj":)?private"?%r]=> int(3) ["3"]=> int(4) } SKIP object(Obj)#%d (3) { ["a"]=> string(3) "foo" [%r"?b"?:protected"?%r]=> string(6) "foobar" [%r"?c"?:("Obj":)?private"?%r]=> string(4) "hoge" } OK object(Obj)#%d (3) { ["a"]=> int(1) [%r"?b"?:protected"?%r]=> int(2) [%r"?c"?:("Obj":)?private"?%r]=> NULL } OK object(Obj)#%d (5) { ["a"]=> NULL [%r"?b"?:protected"?%r]=> NULL [%r"?c"?:("Obj":)?private"?%r]=> NULL ["one"]=> int(1) ["two"]=> int(2) } OK object(Obj)#%d (3) { ["a"]=> int(1) [%r"?b"?:protected"?%r]=> int(2) [%r"?c"?:("Obj":)?private"?%r]=> int(3) } OK object(Obj)#%d (3) { ["a"]=> int(1) [%r"?b"?:protected"?%r]=> int(2) [%r"?c"?:("Obj":)?private"?%r]=> int(3) } OK object(Obj)#%d (3) { ["a"]=> int(1) [%r"?b"?:protected"?%r]=> int(2) [%r"?c"?:("Obj":)?private"?%r]=> int(3) } OK object(Obj)#%d (3) { ["a"]=> array(1) { [0]=> string(3) "foo" } [%r"?b"?:protected"?%r]=> array(1) { [0]=> string(3) "foo" } [%r"?c"?:("Obj":)?private"?%r]=> NULL } OK object(Obj)#%d (4) { ["a"]=> array(2) { ["b"]=> string(1) "c" ["d"]=> string(1) "e" } [%r"?b"?:protected"?%r]=> NULL [%r"?c"?:("Obj":)?private"?%r]=> NULL ["f"]=> array(1) { ["g"]=> string(1) "h" } } OK object(Obj)#%d (3) { ["a"]=> int(1) [%r"?b"?:protected"?%r]=> int(2) [%r"?c"?:("Obj":)?private"?%r]=> int(3) } OK object(Obj)#%d (3) { ["a"]=> int(1) [%r"?b"?:protected"?%r]=> int(2) [%r"?c"?:("Obj":)?private"?%r]=> int(3) } OK object(Obj)#%d (3) { ["a"]=> array(3) { [0]=> int(1) [1]=> int(2) [2]=> int(3) } [%r"?b"?:protected"?%r]=> array(3) { [0]=> int(4) [1]=> int(5) [2]=> int(6) } [%r"?c"?:("Obj":)?private"?%r]=> NULL } OK msgpack-2.1.0beta1/tests/097.phpt0000644000175000001440000001731513577133502015313 0ustar mikeusers--TEST-- unpack of object converter : class unpack (object: php_only=0) --SKIPIF-- pack($variable); $unserialized = $msgpack->unpack($serialized, $object); var_dump($unserialized); if ($result) { echo $unserialized == $result ? 'OK' : 'ERROR', PHP_EOL; } else { echo 'SKIP', PHP_EOL; } } class Obj { public $a; protected $b; private $c; public function __construct($a = null, $b = null, $c = null, $d = null) { $this->a = $a; $this->b = $b; $this->c = $c; if (is_array($d)) { foreach ($d as $key => $val) { $this->{$key} = $val; } } } } $object = new Obj(); test('null', null, new Obj(), new Obj(null, null, null)); test('bool: true', true, new Obj(), new Obj(true, null, null)); test('bool: false', false, new Obj(), new Obj(false, null, null)); test('zero: 0', 0, new Obj(), new Obj(0, null, null)); test('small: 1', 1, new Obj(), new Obj(1, null, null)); test('small: -1', -1, new Obj(), new Obj(-1, null, null)); test('medium: 1000', 1000, new Obj(), new Obj(1000, null, null)); test('medium: -1000', -1000, new Obj(), new Obj(-1000, null, null)); test('large: 100000', 100000, new Obj(), new Obj(100000, null, null)); test('large: -100000', -100000, new Obj(), new Obj(-100000, null, null)); test('double: 123.456', 123.456, new Obj(), new Obj(123.456, null, null)); test('empty: ""', "", new Obj(), new Obj("", null, null)); test('string: "foobar"', "foobar", new Obj(), new Obj("foobar", null, null)); test('array: empty', array(), new Obj(), new Obj(null, null, null)); test('array(1, 2, 3)', array(1, 2, 3), new Obj(), new Obj(1, 2, 3)); test('array(array(1, 2, 3), arr...', array(array(1, 2, 3), array(4, 5, 6), array(7, 8, 9)), new Obj(), new Obj(array(1, 2, 3), array(4, 5, 6), array(7, 8, 9))); test('array(1, 2, 3, 4)', array(1, 2, 3, 4), new Obj()); test('array("foo", "foobar", "foohoge")', array("foo", "foobar", "hoge"), new Obj(), new Obj("foo", "foobar", "hoge")); test('array("a" => 1, "b" => 2))', array("a" => 1, "b" => 2), new Obj(), new Obj(1, 2, null)); test('array("one" => 1, "two" => 2))', array("one" => 1, "two" => 2), new Obj(), new Obj(null, null, null, array("one" => 1, "two" => 2))); test('array("a" => 1, "b" => 2, 3))', array("a" => 1, "b" => 2, 3), new Obj(), new Obj(1, 2, 3)); test('array(3, "a" => 1, "b" => 2))', array(3, "a" => 1, "b" => 2), new Obj(), new Obj(1, 2, 3)); test('array("a" => 1, 3, "b" => 2))', array("a" => 1, 3, "b" => 2), new Obj(), new Obj(1, 2, 3)); $a = array('foo'); test('array($a, $a)', array($a, $a), new Obj(), new Obj($a, $a, null)); $a = array( 'a' => array( 'b' => 'c', 'd' => 'e' ), 'f' => array( 'g' => 'h' ) ); test('array', $a, new Obj(), new Obj(null, null, null, $a)); $o = new Obj(1, 2, 3); test('object', $o, new Obj(), new Obj(1, 2, 3)); class Obj2 { public $A; protected $B; private $C; function __construct($a, $b, $c) { $this->A = $a; $this->B = $b; $this->C = $c; } } $o = new Obj2(1, 2, 3); test('object', $o, new Obj(), new Obj(1, 2, 3)); $o1 = new Obj2(1, 2, 3); $o2 = new Obj2(4, 5, 6); test('object', array($o1, $o2), new Obj(), new Obj(array(1, 2, 3), array(4, 5, 6))); --EXPECTF-- object(Obj)#%d (3) { ["a"]=> NULL [%r"?b"?:protected"?%r]=> NULL [%r"?c"?:("Obj":)?private"?%r]=> NULL } OK object(Obj)#%d (3) { ["a"]=> bool(true) [%r"?b"?:protected"?%r]=> NULL [%r"?c"?:("Obj":)?private"?%r]=> NULL } OK object(Obj)#%d (3) { ["a"]=> bool(false) [%r"?b"?:protected"?%r]=> NULL [%r"?c"?:("Obj":)?private"?%r]=> NULL } OK object(Obj)#%d (3) { ["a"]=> int(0) [%r"?b"?:protected"?%r]=> NULL [%r"?c"?:("Obj":)?private"?%r]=> NULL } OK object(Obj)#%d (3) { ["a"]=> int(1) [%r"?b"?:protected"?%r]=> NULL [%r"?c"?:("Obj":)?private"?%r]=> NULL } OK object(Obj)#%d (3) { ["a"]=> int(-1) [%r"?b"?:protected"?%r]=> NULL [%r"?c"?:("Obj":)?private"?%r]=> NULL } OK object(Obj)#%d (3) { ["a"]=> int(1000) [%r"?b"?:protected"?%r]=> NULL [%r"?c"?:("Obj":)?private"?%r]=> NULL } OK object(Obj)#%d (3) { ["a"]=> int(-1000) [%r"?b"?:protected"?%r]=> NULL [%r"?c"?:("Obj":)?private"?%r]=> NULL } OK object(Obj)#%d (3) { ["a"]=> int(100000) [%r"?b"?:protected"?%r]=> NULL [%r"?c"?:("Obj":)?private"?%r]=> NULL } OK object(Obj)#%d (3) { ["a"]=> int(-100000) [%r"?b"?:protected"?%r]=> NULL [%r"?c"?:("Obj":)?private"?%r]=> NULL } OK object(Obj)#%d (3) { ["a"]=> float(123.456) [%r"?b"?:protected"?%r]=> NULL [%r"?c"?:("Obj":)?private"?%r]=> NULL } OK object(Obj)#%d (3) { ["a"]=> string(0) "" [%r"?b"?:protected"?%r]=> NULL [%r"?c"?:("Obj":)?private"?%r]=> NULL } OK object(Obj)#%d (3) { ["a"]=> string(6) "foobar" [%r"?b"?:protected"?%r]=> NULL [%r"?c"?:("Obj":)?private"?%r]=> NULL } OK object(Obj)#%d (3) { ["a"]=> NULL [%r"?b"?:protected"?%r]=> NULL [%r"?c"?:("Obj":)?private"?%r]=> NULL } OK object(Obj)#%d (3) { ["a"]=> int(1) [%r"?b"?:protected"?%r]=> int(2) [%r"?c"?:("Obj":)?private"?%r]=> int(3) } OK object(Obj)#%d (3) { ["a"]=> array(3) { [0]=> int(1) [1]=> int(2) [2]=> int(3) } [%r"?b"?:protected"?%r]=> array(3) { [0]=> int(4) [1]=> int(5) [2]=> int(6) } [%r"?c"?:("Obj":)?private"?%r]=> array(3) { [0]=> int(7) [1]=> int(8) [2]=> int(9) } } OK object(Obj)#%d (4) { ["a"]=> int(1) [%r"?b"?:protected"?%r]=> int(2) [%r"?c"?:("Obj":)?private"?%r]=> int(3) ["3"]=> int(4) } SKIP object(Obj)#%d (3) { ["a"]=> string(3) "foo" [%r"?b"?:protected"?%r]=> string(6) "foobar" [%r"?c"?:("Obj":)?private"?%r]=> string(4) "hoge" } OK object(Obj)#%d (3) { ["a"]=> int(1) [%r"?b"?:protected"?%r]=> int(2) [%r"?c"?:("Obj":)?private"?%r]=> NULL } OK object(Obj)#%d (5) { ["a"]=> NULL [%r"?b"?:protected"?%r]=> NULL [%r"?c"?:("Obj":)?private"?%r]=> NULL ["one"]=> int(1) ["two"]=> int(2) } OK object(Obj)#%d (3) { ["a"]=> int(1) [%r"?b"?:protected"?%r]=> int(2) [%r"?c"?:("Obj":)?private"?%r]=> int(3) } OK object(Obj)#%d (3) { ["a"]=> int(1) [%r"?b"?:protected"?%r]=> int(2) [%r"?c"?:("Obj":)?private"?%r]=> int(3) } OK object(Obj)#%d (3) { ["a"]=> int(1) [%r"?b"?:protected"?%r]=> int(2) [%r"?c"?:("Obj":)?private"?%r]=> int(3) } OK object(Obj)#%d (3) { ["a"]=> array(1) { [0]=> string(3) "foo" } [%r"?b"?:protected"?%r]=> array(1) { [0]=> string(3) "foo" } [%r"?c"?:("Obj":)?private"?%r]=> NULL } OK object(Obj)#%d (4) { ["a"]=> array(2) { ["b"]=> string(1) "c" ["d"]=> string(1) "e" } [%r"?b"?:protected"?%r]=> NULL [%r"?c"?:("Obj":)?private"?%r]=> NULL ["f"]=> array(1) { ["g"]=> string(1) "h" } } OK object(Obj)#%d (3) { ["a"]=> int(1) [%r"?b"?:protected"?%r]=> int(2) [%r"?c"?:("Obj":)?private"?%r]=> int(3) } OK object(Obj)#%d (3) { ["a"]=> int(1) [%r"?b"?:protected"?%r]=> int(2) [%r"?c"?:("Obj":)?private"?%r]=> int(3) } OK object(Obj)#%d (3) { ["a"]=> array(3) { [0]=> int(1) [1]=> int(2) [2]=> int(3) } [%r"?b"?:protected"?%r]=> array(3) { [0]=> int(4) [1]=> int(5) [2]=> int(6) } [%r"?c"?:("Obj":)?private"?%r]=> NULL } OK msgpack-2.1.0beta1/tests/098.phpt0000644000175000001440000001714713577133502015317 0ustar mikeusers--TEST-- unpack of object converter: class unpack (string: OPT_PHPONLY=false) --SKIPIF-- 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; } } class Obj { public $a; protected $b; private $c; public function __construct($a = null, $b = null, $c = null, $d = null) { $this->a = $a; $this->b = $b; $this->c = $c; if (is_array($d)) { foreach ($d as $key => $val) { $this->{$key} = $val; } } } } test('null', null, 'Obj', new Obj(null, null, null)); test('bool: true', true, 'Obj', new Obj(true, null, null)); test('bool: false', false, 'Obj', new Obj(false, null, null)); test('zero: 0', 0, 'Obj', new Obj(0, null, null)); test('small: 1', 1, 'Obj', new Obj(1, null, null)); test('small: -1', -1, 'Obj', new Obj(-1, null, null)); test('medium: 1000', 1000, 'Obj', new Obj(1000, null, null)); test('medium: -1000', -1000, 'Obj', new Obj(-1000, null, null)); test('large: 100000', 100000, 'Obj', new Obj(100000, null, null)); test('large: -100000', -100000, 'Obj', new Obj(-100000, null, null)); test('double: 123.456', 123.456, 'Obj', new Obj(123.456, null, null)); test('empty: ""', "", 'Obj', new Obj("", null, null)); test('string: "foobar"', "foobar", 'Obj', new Obj("foobar", null, null)); test('array: empty', array(), 'Obj', new Obj(null, null, null)); test('array(1, 2, 3)', array(1, 2, 3), 'Obj', new Obj(1, 2, 3)); test('array(array(1, 2, 3), arr...', array(array(1, 2, 3), array(4, 5, 6), array(7, 8, 9)), 'Obj', new Obj(array(1, 2, 3), array(4, 5, 6), array(7, 8, 9))); test('array(1, 2, 3, 4)', array(1, 2, 3, 4), 'Obj'); test('array("foo", "foobar", "foohoge")', array("foo", "foobar", "hoge"), 'Obj', new Obj("foo", "foobar", "hoge")); test('array("a" => 1, "b" => 2))', array("a" => 1, "b" => 2), 'Obj', new Obj(1, 2, null)); test('array("one" => 1, "two" => 2))', array("one" => 1, "two" => 2), 'Obj', new Obj(null, null, null, array("one" => 1, "two" => 2))); test('array("a" => 1, "b" => 2, 3))', array("a" => 1, "b" => 2, 3), 'Obj', new Obj(1, 2, 3)); test('array(3, "a" => 1, "b" => 2))', array(3, "a" => 1, "b" => 2), 'Obj', new Obj(1, 2, 3)); test('array("a" => 1, 3, "b" => 2))', array("a" => 1, 3, "b" => 2), 'Obj', new Obj(1, 2, 3)); $a = array('foo'); test('array($a, $a)', array($a, $a), 'Obj', new Obj($a, $a, null)); $a = array( 'a' => array( 'b' => 'c', 'd' => 'e' ), 'f' => array( 'g' => 'h' ) ); test('array', $a, 'Obj', new Obj(null, null, null, $a)); $o = new Obj(1, 2, 3); test('object', $o, 'Obj', new Obj(1, 2, 3)); class Obj2 { public $A; protected $B; private $C; function __construct($a, $b, $c) { $this->A = $a; $this->B = $b; $this->C = $c; } } $o = new Obj2(1, 2, 3); test('object', $o, 'Obj', new Obj(1, 2, 3)); $o1 = new Obj2(1, 2, 3); $o2 = new Obj2(4, 5, 6); test('object', array($o1, $o2), 'Obj', new Obj(array(1, 2, 3), array(4, 5, 6))); --EXPECTF-- object(Obj)#%d (3) { ["a"]=> NULL [%r"?b"?:protected"?%r]=> NULL [%r"?c"?:("Obj":)?private"?%r]=> NULL } OK object(Obj)#%d (3) { ["a"]=> bool(true) [%r"?b"?:protected"?%r]=> NULL [%r"?c"?:("Obj":)?private"?%r]=> NULL } OK object(Obj)#%d (3) { ["a"]=> bool(false) [%r"?b"?:protected"?%r]=> NULL [%r"?c"?:("Obj":)?private"?%r]=> NULL } OK object(Obj)#%d (3) { ["a"]=> int(0) [%r"?b"?:protected"?%r]=> NULL [%r"?c"?:("Obj":)?private"?%r]=> NULL } OK object(Obj)#%d (3) { ["a"]=> int(1) [%r"?b"?:protected"?%r]=> NULL [%r"?c"?:("Obj":)?private"?%r]=> NULL } OK object(Obj)#%d (3) { ["a"]=> int(-1) [%r"?b"?:protected"?%r]=> NULL [%r"?c"?:("Obj":)?private"?%r]=> NULL } OK object(Obj)#%d (3) { ["a"]=> int(1000) [%r"?b"?:protected"?%r]=> NULL [%r"?c"?:("Obj":)?private"?%r]=> NULL } OK object(Obj)#%d (3) { ["a"]=> int(-1000) [%r"?b"?:protected"?%r]=> NULL [%r"?c"?:("Obj":)?private"?%r]=> NULL } OK object(Obj)#%d (3) { ["a"]=> int(100000) [%r"?b"?:protected"?%r]=> NULL [%r"?c"?:("Obj":)?private"?%r]=> NULL } OK object(Obj)#%d (3) { ["a"]=> int(-100000) [%r"?b"?:protected"?%r]=> NULL [%r"?c"?:("Obj":)?private"?%r]=> NULL } OK object(Obj)#%d (3) { ["a"]=> float(123.456) [%r"?b"?:protected"?%r]=> NULL [%r"?c"?:("Obj":)?private"?%r]=> NULL } OK object(Obj)#%d (3) { ["a"]=> string(0) "" [%r"?b"?:protected"?%r]=> NULL [%r"?c"?:("Obj":)?private"?%r]=> NULL } OK object(Obj)#%d (3) { ["a"]=> string(6) "foobar" [%r"?b"?:protected"?%r]=> NULL [%r"?c"?:("Obj":)?private"?%r]=> NULL } OK object(Obj)#%d (3) { ["a"]=> NULL [%r"?b"?:protected"?%r]=> NULL [%r"?c"?:("Obj":)?private"?%r]=> NULL } OK object(Obj)#%d (3) { ["a"]=> int(1) [%r"?b"?:protected"?%r]=> int(2) [%r"?c"?:("Obj":)?private"?%r]=> int(3) } OK object(Obj)#%d (3) { ["a"]=> array(3) { [0]=> int(1) [1]=> int(2) [2]=> int(3) } [%r"?b"?:protected"?%r]=> array(3) { [0]=> int(4) [1]=> int(5) [2]=> int(6) } [%r"?c"?:("Obj":)?private"?%r]=> array(3) { [0]=> int(7) [1]=> int(8) [2]=> int(9) } } OK object(Obj)#%d (4) { ["a"]=> int(1) [%r"?b"?:protected"?%r]=> int(2) [%r"?c"?:("Obj":)?private"?%r]=> int(3) ["3"]=> int(4) } SKIP object(Obj)#%d (3) { ["a"]=> string(3) "foo" [%r"?b"?:protected"?%r]=> string(6) "foobar" [%r"?c"?:("Obj":)?private"?%r]=> string(4) "hoge" } OK object(Obj)#%d (3) { ["a"]=> int(1) [%r"?b"?:protected"?%r]=> int(2) [%r"?c"?:("Obj":)?private"?%r]=> NULL } OK object(Obj)#%d (5) { ["a"]=> NULL [%r"?b"?:protected"?%r]=> NULL [%r"?c"?:("Obj":)?private"?%r]=> NULL ["one"]=> int(1) ["two"]=> int(2) } OK object(Obj)#%d (3) { ["a"]=> int(1) [%r"?b"?:protected"?%r]=> int(2) [%r"?c"?:("Obj":)?private"?%r]=> int(3) } OK object(Obj)#%d (3) { ["a"]=> int(1) [%r"?b"?:protected"?%r]=> int(2) [%r"?c"?:("Obj":)?private"?%r]=> int(3) } OK object(Obj)#%d (3) { ["a"]=> int(1) [%r"?b"?:protected"?%r]=> int(2) [%r"?c"?:("Obj":)?private"?%r]=> int(3) } OK object(Obj)#%d (3) { ["a"]=> array(1) { [0]=> string(3) "foo" } [%r"?b"?:protected"?%r]=> array(1) { [0]=> string(3) "foo" } [%r"?c"?:("Obj":)?private"?%r]=> NULL } OK object(Obj)#%d (4) { ["a"]=> array(2) { ["b"]=> string(1) "c" ["d"]=> string(1) "e" } [%r"?b"?:protected"?%r]=> NULL [%r"?c"?:("Obj":)?private"?%r]=> NULL ["f"]=> array(1) { ["g"]=> string(1) "h" } } OK object(Obj)#%d (3) { ["a"]=> int(1) [%r"?b"?:protected"?%r]=> int(2) [%r"?c"?:("Obj":)?private"?%r]=> int(3) } OK object(Obj)#%d (3) { ["a"]=> int(1) [%r"?b"?:protected"?%r]=> int(2) [%r"?c"?:("Obj":)?private"?%r]=> int(3) } OK object(Obj)#%d (3) { ["a"]=> array(3) { [0]=> int(1) [1]=> int(2) [2]=> int(3) } [%r"?b"?:protected"?%r]=> array(3) { [0]=> int(4) [1]=> int(5) [2]=> int(6) } [%r"?c"?:("Obj":)?private"?%r]=> NULL } OK msgpack-2.1.0beta1/tests/099.phpt0000644000175000001440000001755013577133502015316 0ustar mikeusers--TEST-- unpack of object converter : class unpacker (string) --SKIPIF-- pack($variable); $unserialized = null; $unpacker = $msgpack->unpacker(); if ($unpacker->execute($serialized)) { $unserialized = $unpacker->data($object); } var_dump($unserialized); if ($result) { echo $unserialized == $result ? 'OK' : 'ERROR', PHP_EOL; } else { echo 'SKIP', PHP_EOL; } } class Obj { public $a; protected $b; private $c; public function __construct($a = null, $b = null, $c = null, $d = null) { $this->a = $a; $this->b = $b; $this->c = $c; if (is_array($d)) { foreach ($d as $key => $val) { $this->{$key} = $val; } } } } test('null', null, 'Obj', new Obj(null, null, null)); test('bool: true', true, 'Obj', new Obj(true, null, null)); test('bool: false', false, 'Obj', new Obj(false, null, null)); test('zero: 0', 0, 'Obj', new Obj(0, null, null)); test('small: 1', 1, 'Obj', new Obj(1, null, null)); test('small: -1', -1, 'Obj', new Obj(-1, null, null)); test('medium: 1000', 1000, 'Obj', new Obj(1000, null, null)); test('medium: -1000', -1000, 'Obj', new Obj(-1000, null, null)); test('large: 100000', 100000, 'Obj', new Obj(100000, null, null)); test('large: -100000', -100000, 'Obj', new Obj(-100000, null, null)); test('double: 123.456', 123.456, 'Obj', new Obj(123.456, null, null)); test('empty: ""', "", 'Obj', new Obj("", null, null)); test('string: "foobar"', "foobar", 'Obj', new Obj("foobar", null, null)); test('array: empty', array(), 'Obj', new Obj(null, null, null)); test('array(1, 2, 3)', array(1, 2, 3), 'Obj', new Obj(1, 2, 3)); test('array(array(1, 2, 3), arr...', array(array(1, 2, 3), array(4, 5, 6), array(7, 8, 9)), 'Obj', new Obj(array(1, 2, 3), array(4, 5, 6), array(7, 8, 9))); test('array(1, 2, 3, 4)', array(1, 2, 3, 4), 'Obj'); test('array("foo", "foobar", "foohoge")', array("foo", "foobar", "hoge"), 'Obj', new Obj("foo", "foobar", "hoge")); test('array("a" => 1, "b" => 2))', array("a" => 1, "b" => 2), 'Obj', new Obj(1, 2, null)); test('array("one" => 1, "two" => 2))', array("one" => 1, "two" => 2), 'Obj', new Obj(null, null, null, array("one" => 1, "two" => 2))); test('array("a" => 1, "b" => 2, 3))', array("a" => 1, "b" => 2, 3), 'Obj', new Obj(1, 2, 3)); test('array(3, "a" => 1, "b" => 2))', array(3, "a" => 1, "b" => 2), 'Obj', new Obj(1, 2, 3)); test('array("a" => 1, 3, "b" => 2))', array("a" => 1, 3, "b" => 2), 'Obj', new Obj(1, 2, 3)); $a = array('foo'); test('array($a, $a)', array($a, $a), 'Obj', new Obj($a, $a, null)); $a = array( 'a' => array( 'b' => 'c', 'd' => 'e' ), 'f' => array( 'g' => 'h' ) ); test('array', $a, 'Obj', new Obj(null, null, null, $a)); $o = new Obj(1, 2, 3); test('object', $o, 'Obj', new Obj(1, 2, 3)); class Obj2 { public $A; protected $B; private $C; function __construct($a, $b, $c) { $this->A = $a; $this->B = $b; $this->C = $c; } } $o = new Obj2(1, 2, 3); test('object', $o, 'Obj', new Obj($o)); $o1 = new Obj2(1, 2, 3); $o2 = new Obj2(4, 5, 6); test('object', array($o1, $o2), 'Obj', new Obj($o1, $o2)); --EXPECTF-- object(Obj)#%d (3) { ["a"]=> NULL [%r"?b"?:protected"?%r]=> NULL [%r"?c"?:("Obj":)?private"?%r]=> NULL } OK object(Obj)#%d (3) { ["a"]=> bool(true) [%r"?b"?:protected"?%r]=> NULL [%r"?c"?:("Obj":)?private"?%r]=> NULL } OK object(Obj)#%d (3) { ["a"]=> bool(false) [%r"?b"?:protected"?%r]=> NULL [%r"?c"?:("Obj":)?private"?%r]=> NULL } OK object(Obj)#%d (3) { ["a"]=> int(0) [%r"?b"?:protected"?%r]=> NULL [%r"?c"?:("Obj":)?private"?%r]=> NULL } OK object(Obj)#%d (3) { ["a"]=> int(1) [%r"?b"?:protected"?%r]=> NULL [%r"?c"?:("Obj":)?private"?%r]=> NULL } OK object(Obj)#%d (3) { ["a"]=> int(-1) [%r"?b"?:protected"?%r]=> NULL [%r"?c"?:("Obj":)?private"?%r]=> NULL } OK object(Obj)#%d (3) { ["a"]=> int(1000) [%r"?b"?:protected"?%r]=> NULL [%r"?c"?:("Obj":)?private"?%r]=> NULL } OK object(Obj)#%d (3) { ["a"]=> int(-1000) [%r"?b"?:protected"?%r]=> NULL [%r"?c"?:("Obj":)?private"?%r]=> NULL } OK object(Obj)#%d (3) { ["a"]=> int(100000) [%r"?b"?:protected"?%r]=> NULL [%r"?c"?:("Obj":)?private"?%r]=> NULL } OK object(Obj)#%d (3) { ["a"]=> int(-100000) [%r"?b"?:protected"?%r]=> NULL [%r"?c"?:("Obj":)?private"?%r]=> NULL } OK object(Obj)#%d (3) { ["a"]=> float(123.456) [%r"?b"?:protected"?%r]=> NULL [%r"?c"?:("Obj":)?private"?%r]=> NULL } OK object(Obj)#%d (3) { ["a"]=> string(0) "" [%r"?b"?:protected"?%r]=> NULL [%r"?c"?:("Obj":)?private"?%r]=> NULL } OK object(Obj)#%d (3) { ["a"]=> string(6) "foobar" [%r"?b"?:protected"?%r]=> NULL [%r"?c"?:("Obj":)?private"?%r]=> NULL } OK object(Obj)#%d (3) { ["a"]=> NULL [%r"?b"?:protected"?%r]=> NULL [%r"?c"?:("Obj":)?private"?%r]=> NULL } OK object(Obj)#%d (3) { ["a"]=> int(1) [%r"?b"?:protected"?%r]=> int(2) [%r"?c"?:("Obj":)?private"?%r]=> int(3) } OK object(Obj)#%d (3) { ["a"]=> array(3) { [0]=> int(1) [1]=> int(2) [2]=> int(3) } [%r"?b"?:protected"?%r]=> array(3) { [0]=> int(4) [1]=> int(5) [2]=> int(6) } [%r"?c"?:("Obj":)?private"?%r]=> array(3) { [0]=> int(7) [1]=> int(8) [2]=> int(9) } } OK object(Obj)#%d (4) { ["a"]=> int(1) [%r"?b"?:protected"?%r]=> int(2) [%r"?c"?:("Obj":)?private"?%r]=> int(3) ["3"]=> int(4) } SKIP object(Obj)#%d (3) { ["a"]=> string(3) "foo" [%r"?b"?:protected"?%r]=> string(6) "foobar" [%r"?c"?:("Obj":)?private"?%r]=> string(4) "hoge" } OK object(Obj)#%d (3) { ["a"]=> int(1) [%r"?b"?:protected"?%r]=> int(2) [%r"?c"?:("Obj":)?private"?%r]=> NULL } OK object(Obj)#%d (5) { ["a"]=> NULL [%r"?b"?:protected"?%r]=> NULL [%r"?c"?:("Obj":)?private"?%r]=> NULL ["one"]=> int(1) ["two"]=> int(2) } OK object(Obj)#%d (3) { ["a"]=> int(1) [%r"?b"?:protected"?%r]=> int(2) [%r"?c"?:("Obj":)?private"?%r]=> int(3) } OK object(Obj)#%d (3) { ["a"]=> int(1) [%r"?b"?:protected"?%r]=> int(2) [%r"?c"?:("Obj":)?private"?%r]=> int(3) } OK object(Obj)#%d (3) { ["a"]=> int(1) [%r"?b"?:protected"?%r]=> int(2) [%r"?c"?:("Obj":)?private"?%r]=> int(3) } OK object(Obj)#%d (3) { ["a"]=> array(1) { [0]=> string(3) "foo" } [%r"?b"?:protected"?%r]=> array(1) { [0]=> string(3) "foo" } [%r"?c"?:("Obj":)?private"?%r]=> NULL } OK object(Obj)#%d (4) { ["a"]=> array(2) { ["b"]=> string(1) "c" ["d"]=> string(1) "e" } [%r"?b"?:protected"?%r]=> NULL [%r"?c"?:("Obj":)?private"?%r]=> NULL ["f"]=> array(1) { ["g"]=> string(1) "h" } } OK object(Obj)#%d (3) { ["a"]=> int(1) [%r"?b"?:protected"?%r]=> int(2) [%r"?c"?:("Obj":)?private"?%r]=> int(3) } OK object(Obj)#%d (3) { ["a"]=> object(Obj2)#%d (3) { ["A"]=> int(1) [%r"?B"?:protected"?%r]=> int(2) [%r"?C"?:("Obj2":)?private"?%r]=> int(3) } [%r"?b"?:protected"?%r]=> NULL [%r"?c"?:("Obj":)?private"?%r]=> NULL } OK object(Obj)#%d (3) { ["a"]=> object(Obj2)#%d (3) { ["A"]=> int(1) [%r"?B"?:protected"?%r]=> int(2) [%r"?C"?:("Obj2":)?private"?%r]=> int(3) } [%r"?b"?:protected"?%r]=> object(Obj2)#%d (3) { ["A"]=> int(4) [%r"?B"?:protected"?%r]=> int(5) [%r"?C"?:("Obj2":)?private"?%r]=> int(6) } [%r"?c"?:("Obj":)?private"?%r]=> NULL } OK msgpack-2.1.0beta1/tests/100.phpt0000644000175000001440000001775613577133502015305 0ustar mikeusers--TEST-- unpack of object converter : class unpacker (object) --SKIPIF-- pack($variable); $unserialized = null; $unpacker = $msgpack->unpacker(); if ($unpacker->execute($serialized)) { $unserialized = $unpacker->data($object); } var_dump($unserialized); if ($result) { echo $unserialized == $result ? 'OK' : 'ERROR', PHP_EOL; } else { echo 'SKIP', PHP_EOL; } } class Obj { public $a; protected $b; private $c; public function __construct($a = null, $b = null, $c = null, $d = null) { $this->a = $a; $this->b = $b; $this->c = $c; if (is_array($d)) { foreach ($d as $key => $val) { $this->{$key} = $val; } } } } $object = new Obj(); test('null', null, new Obj(), new Obj(null, null, null)); test('bool: true', true, new Obj(), new Obj(true, null, null)); test('bool: false', false, new Obj(), new Obj(false, null, null)); test('zero: 0', 0, new Obj(), new Obj(0, null, null)); test('small: 1', 1, new Obj(), new Obj(1, null, null)); test('small: -1', -1, new Obj(), new Obj(-1, null, null)); test('medium: 1000', 1000, new Obj(), new Obj(1000, null, null)); test('medium: -1000', -1000, new Obj(), new Obj(-1000, null, null)); test('large: 100000', 100000, new Obj(), new Obj(100000, null, null)); test('large: -100000', -100000, new Obj(), new Obj(-100000, null, null)); test('double: 123.456', 123.456, new Obj(), new Obj(123.456, null, null)); test('empty: ""', "", new Obj(), new Obj("", null, null)); test('string: "foobar"', "foobar", new Obj(), new Obj("foobar", null, null)); test('array: empty', array(), new Obj(), new Obj(null, null, null)); test('array(1, 2, 3)', array(1, 2, 3), new Obj(), new Obj(1, 2, 3)); test('array(array(1, 2, 3), arr...', array(array(1, 2, 3), array(4, 5, 6), array(7, 8, 9)), new Obj(), new Obj(array(1, 2, 3), array(4, 5, 6), array(7, 8, 9))); test('array(1, 2, 3, 4)', array(1, 2, 3, 4), new Obj()); test('array("foo", "foobar", "foohoge")', array("foo", "foobar", "hoge"), new Obj(), new Obj("foo", "foobar", "hoge")); test('array("a" => 1, "b" => 2))', array("a" => 1, "b" => 2), new Obj(), new Obj(1, 2, null)); test('array("one" => 1, "two" => 2))', array("one" => 1, "two" => 2), new Obj(), new Obj(null, null, null, array("one" => 1, "two" => 2))); test('array("a" => 1, "b" => 2, 3))', array("a" => 1, "b" => 2, 3), new Obj(), new Obj(1, 2, 3)); test('array(3, "a" => 1, "b" => 2))', array(3, "a" => 1, "b" => 2), new Obj(), new Obj(1, 2, 3)); test('array("a" => 1, 3, "b" => 2))', array("a" => 1, 3, "b" => 2), new Obj(), new Obj(1, 2, 3)); $a = array('foo'); test('array($a, $a)', array($a, $a), new Obj(), new Obj($a, $a, null)); $a = array( 'a' => array( 'b' => 'c', 'd' => 'e' ), 'f' => array( 'g' => 'h' ) ); test('array', $a, new Obj(), new Obj(null, null, null, $a)); $o = new Obj(1, 2, 3); test('object', $o, new Obj(), new Obj(1, 2, 3)); class Obj2 { public $A; protected $B; private $C; function __construct($a, $b, $c) { $this->A = $a; $this->B = $b; $this->C = $c; } } $o = new Obj2(1, 2, 3); test('object', $o, new Obj(), new Obj($o)); $o1 = new Obj2(1, 2, 3); $o2 = new Obj2(4, 5, 6); test('object', array($o1, $o2), new Obj(), new Obj($o1, $o2)); --EXPECTF-- object(Obj)#%d (3) { ["a"]=> NULL [%r"?b"?:protected"?%r]=> NULL [%r"?c"?:("Obj":)?private"?%r]=> NULL } OK object(Obj)#%d (3) { ["a"]=> bool(true) [%r"?b"?:protected"?%r]=> NULL [%r"?c"?:("Obj":)?private"?%r]=> NULL } OK object(Obj)#%d (3) { ["a"]=> bool(false) [%r"?b"?:protected"?%r]=> NULL [%r"?c"?:("Obj":)?private"?%r]=> NULL } OK object(Obj)#%d (3) { ["a"]=> int(0) [%r"?b"?:protected"?%r]=> NULL [%r"?c"?:("Obj":)?private"?%r]=> NULL } OK object(Obj)#%d (3) { ["a"]=> int(1) [%r"?b"?:protected"?%r]=> NULL [%r"?c"?:("Obj":)?private"?%r]=> NULL } OK object(Obj)#%d (3) { ["a"]=> int(-1) [%r"?b"?:protected"?%r]=> NULL [%r"?c"?:("Obj":)?private"?%r]=> NULL } OK object(Obj)#%d (3) { ["a"]=> int(1000) [%r"?b"?:protected"?%r]=> NULL [%r"?c"?:("Obj":)?private"?%r]=> NULL } OK object(Obj)#%d (3) { ["a"]=> int(-1000) [%r"?b"?:protected"?%r]=> NULL [%r"?c"?:("Obj":)?private"?%r]=> NULL } OK object(Obj)#%d (3) { ["a"]=> int(100000) [%r"?b"?:protected"?%r]=> NULL [%r"?c"?:("Obj":)?private"?%r]=> NULL } OK object(Obj)#%d (3) { ["a"]=> int(-100000) [%r"?b"?:protected"?%r]=> NULL [%r"?c"?:("Obj":)?private"?%r]=> NULL } OK object(Obj)#%d (3) { ["a"]=> float(123.456) [%r"?b"?:protected"?%r]=> NULL [%r"?c"?:("Obj":)?private"?%r]=> NULL } OK object(Obj)#%d (3) { ["a"]=> string(0) "" [%r"?b"?:protected"?%r]=> NULL [%r"?c"?:("Obj":)?private"?%r]=> NULL } OK object(Obj)#%d (3) { ["a"]=> string(6) "foobar" [%r"?b"?:protected"?%r]=> NULL [%r"?c"?:("Obj":)?private"?%r]=> NULL } OK object(Obj)#%d (3) { ["a"]=> NULL [%r"?b"?:protected"?%r]=> NULL [%r"?c"?:("Obj":)?private"?%r]=> NULL } OK object(Obj)#%d (3) { ["a"]=> int(1) [%r"?b"?:protected"?%r]=> int(2) [%r"?c"?:("Obj":)?private"?%r]=> int(3) } OK object(Obj)#%d (3) { ["a"]=> array(3) { [0]=> int(1) [1]=> int(2) [2]=> int(3) } [%r"?b"?:protected"?%r]=> array(3) { [0]=> int(4) [1]=> int(5) [2]=> int(6) } [%r"?c"?:("Obj":)?private"?%r]=> array(3) { [0]=> int(7) [1]=> int(8) [2]=> int(9) } } OK object(Obj)#%d (4) { ["a"]=> int(1) [%r"?b"?:protected"?%r]=> int(2) [%r"?c"?:("Obj":)?private"?%r]=> int(3) ["3"]=> int(4) } SKIP object(Obj)#%d (3) { ["a"]=> string(3) "foo" [%r"?b"?:protected"?%r]=> string(6) "foobar" [%r"?c"?:("Obj":)?private"?%r]=> string(4) "hoge" } OK object(Obj)#%d (3) { ["a"]=> int(1) [%r"?b"?:protected"?%r]=> int(2) [%r"?c"?:("Obj":)?private"?%r]=> NULL } OK object(Obj)#%d (5) { ["a"]=> NULL [%r"?b"?:protected"?%r]=> NULL [%r"?c"?:("Obj":)?private"?%r]=> NULL ["one"]=> int(1) ["two"]=> int(2) } OK object(Obj)#%d (3) { ["a"]=> int(1) [%r"?b"?:protected"?%r]=> int(2) [%r"?c"?:("Obj":)?private"?%r]=> int(3) } OK object(Obj)#%d (3) { ["a"]=> int(1) [%r"?b"?:protected"?%r]=> int(2) [%r"?c"?:("Obj":)?private"?%r]=> int(3) } OK object(Obj)#%d (3) { ["a"]=> int(1) [%r"?b"?:protected"?%r]=> int(2) [%r"?c"?:("Obj":)?private"?%r]=> int(3) } OK object(Obj)#%d (3) { ["a"]=> array(1) { [0]=> string(3) "foo" } [%r"?b"?:protected"?%r]=> array(1) { [0]=> string(3) "foo" } [%r"?c"?:("Obj":)?private"?%r]=> NULL } OK object(Obj)#%d (4) { ["a"]=> array(2) { ["b"]=> string(1) "c" ["d"]=> string(1) "e" } [%r"?b"?:protected"?%r]=> NULL [%r"?c"?:("Obj":)?private"?%r]=> NULL ["f"]=> array(1) { ["g"]=> string(1) "h" } } OK object(Obj)#%d (3) { ["a"]=> int(1) [%r"?b"?:protected"?%r]=> int(2) [%r"?c"?:("Obj":)?private"?%r]=> int(3) } OK object(Obj)#%d (3) { ["a"]=> object(Obj2)#%d (3) { ["A"]=> int(1) [%r"?B"?:protected"?%r]=> int(2) [%r"?C"?:("Obj2":)?private"?%r]=> int(3) } [%r"?b"?:protected"?%r]=> NULL [%r"?c"?:("Obj":)?private"?%r]=> NULL } OK object(Obj)#%d (3) { ["a"]=> object(Obj2)#%d (3) { ["A"]=> int(1) [%r"?B"?:protected"?%r]=> int(2) [%r"?C"?:("Obj2":)?private"?%r]=> int(3) } [%r"?b"?:protected"?%r]=> object(Obj2)#%d (3) { ["A"]=> int(4) [%r"?B"?:protected"?%r]=> int(5) [%r"?C"?:("Obj2":)?private"?%r]=> int(6) } [%r"?c"?:("Obj":)?private"?%r]=> NULL } OK msgpack-2.1.0beta1/tests/101.phpt0000644000175000001440000001726513577133502015301 0ustar mikeusers--TEST-- unpack of object converter : class unpacker (string: php_only=0) --SKIPIF-- pack($variable); $unserialized = null; $unpacker = $msgpack->unpacker(); if ($unpacker->execute($serialized)) { $unserialized = $unpacker->data($object); } var_dump($unserialized); if ($result) { echo $unserialized == $result ? 'OK' : 'ERROR', PHP_EOL; } else { echo 'SKIP', PHP_EOL; } } class Obj { public $a; protected $b; private $c; public function __construct($a = null, $b = null, $c = null, $d = null) { $this->a = $a; $this->b = $b; $this->c = $c; if (is_array($d)) { foreach ($d as $key => $val) { $this->{$key} = $val; } } } } test('null', null, 'Obj', new Obj(null, null, null)); test('bool: true', true, 'Obj', new Obj(true, null, null)); test('bool: false', false, 'Obj', new Obj(false, null, null)); test('zero: 0', 0, 'Obj', new Obj(0, null, null)); test('small: 1', 1, 'Obj', new Obj(1, null, null)); test('small: -1', -1, 'Obj', new Obj(-1, null, null)); test('medium: 1000', 1000, 'Obj', new Obj(1000, null, null)); test('medium: -1000', -1000, 'Obj', new Obj(-1000, null, null)); test('large: 100000', 100000, 'Obj', new Obj(100000, null, null)); test('large: -100000', -100000, 'Obj', new Obj(-100000, null, null)); test('double: 123.456', 123.456, 'Obj', new Obj(123.456, null, null)); test('empty: ""', "", 'Obj', new Obj("", null, null)); test('string: "foobar"', "foobar", 'Obj', new Obj("foobar", null, null)); test('array: empty', array(), 'Obj', new Obj(null, null, null)); test('array(1, 2, 3)', array(1, 2, 3), 'Obj', new Obj(1, 2, 3)); test('array(array(1, 2, 3), arr...', array(array(1, 2, 3), array(4, 5, 6), array(7, 8, 9)), 'Obj', new Obj(array(1, 2, 3), array(4, 5, 6), array(7, 8, 9))); test('array(1, 2, 3, 4)', array(1, 2, 3, 4), 'Obj'); test('array("foo", "foobar", "foohoge")', array("foo", "foobar", "hoge"), 'Obj', new Obj("foo", "foobar", "hoge")); test('array("a" => 1, "b" => 2))', array("a" => 1, "b" => 2), 'Obj', new Obj(1, 2, null)); test('array("one" => 1, "two" => 2))', array("one" => 1, "two" => 2), 'Obj', new Obj(null, null, null, array("one" => 1, "two" => 2))); test('array("a" => 1, "b" => 2, 3))', array("a" => 1, "b" => 2, 3), 'Obj', new Obj(1, 2, 3)); test('array(3, "a" => 1, "b" => 2))', array(3, "a" => 1, "b" => 2), 'Obj', new Obj(1, 2, 3)); test('array("a" => 1, 3, "b" => 2))', array("a" => 1, 3, "b" => 2), 'Obj', new Obj(1, 2, 3)); $a = array('foo'); test('array($a, $a)', array($a, $a), 'Obj', new Obj($a, $a, null)); $a = array( 'a' => array( 'b' => 'c', 'd' => 'e' ), 'f' => array( 'g' => 'h' ) ); test('array', $a, 'Obj', new Obj(null, null, null, $a)); $o = new Obj(1, 2, 3); test('object', $o, 'Obj', new Obj(1, 2, 3)); class Obj2 { public $A; protected $B; private $C; function __construct($a, $b, $c) { $this->A = $a; $this->B = $b; $this->C = $c; } } $o = new Obj2(1, 2, 3); test('object', $o, 'Obj', new Obj(1, 2, 3)); $o1 = new Obj2(1, 2, 3); $o2 = new Obj2(4, 5, 6); test('object', array($o1, $o2), 'Obj', new Obj(array(1, 2, 3), array(4, 5, 6))); --EXPECTF-- object(Obj)#%d (3) { ["a"]=> NULL [%r"?b"?:protected"?%r]=> NULL [%r"?c"?:("Obj":)?private"?%r]=> NULL } OK object(Obj)#%d (3) { ["a"]=> bool(true) [%r"?b"?:protected"?%r]=> NULL [%r"?c"?:("Obj":)?private"?%r]=> NULL } OK object(Obj)#%d (3) { ["a"]=> bool(false) [%r"?b"?:protected"?%r]=> NULL [%r"?c"?:("Obj":)?private"?%r]=> NULL } OK object(Obj)#%d (3) { ["a"]=> int(0) [%r"?b"?:protected"?%r]=> NULL [%r"?c"?:("Obj":)?private"?%r]=> NULL } OK object(Obj)#%d (3) { ["a"]=> int(1) [%r"?b"?:protected"?%r]=> NULL [%r"?c"?:("Obj":)?private"?%r]=> NULL } OK object(Obj)#%d (3) { ["a"]=> int(-1) [%r"?b"?:protected"?%r]=> NULL [%r"?c"?:("Obj":)?private"?%r]=> NULL } OK object(Obj)#%d (3) { ["a"]=> int(1000) [%r"?b"?:protected"?%r]=> NULL [%r"?c"?:("Obj":)?private"?%r]=> NULL } OK object(Obj)#%d (3) { ["a"]=> int(-1000) [%r"?b"?:protected"?%r]=> NULL [%r"?c"?:("Obj":)?private"?%r]=> NULL } OK object(Obj)#%d (3) { ["a"]=> int(100000) [%r"?b"?:protected"?%r]=> NULL [%r"?c"?:("Obj":)?private"?%r]=> NULL } OK object(Obj)#%d (3) { ["a"]=> int(-100000) [%r"?b"?:protected"?%r]=> NULL [%r"?c"?:("Obj":)?private"?%r]=> NULL } OK object(Obj)#%d (3) { ["a"]=> float(123.456) [%r"?b"?:protected"?%r]=> NULL [%r"?c"?:("Obj":)?private"?%r]=> NULL } OK object(Obj)#%d (3) { ["a"]=> string(0) "" [%r"?b"?:protected"?%r]=> NULL [%r"?c"?:("Obj":)?private"?%r]=> NULL } OK object(Obj)#%d (3) { ["a"]=> string(6) "foobar" [%r"?b"?:protected"?%r]=> NULL [%r"?c"?:("Obj":)?private"?%r]=> NULL } OK object(Obj)#%d (3) { ["a"]=> NULL [%r"?b"?:protected"?%r]=> NULL [%r"?c"?:("Obj":)?private"?%r]=> NULL } OK object(Obj)#%d (3) { ["a"]=> int(1) [%r"?b"?:protected"?%r]=> int(2) [%r"?c"?:("Obj":)?private"?%r]=> int(3) } OK object(Obj)#%d (3) { ["a"]=> array(3) { [0]=> int(1) [1]=> int(2) [2]=> int(3) } [%r"?b"?:protected"?%r]=> array(3) { [0]=> int(4) [1]=> int(5) [2]=> int(6) } [%r"?c"?:("Obj":)?private"?%r]=> array(3) { [0]=> int(7) [1]=> int(8) [2]=> int(9) } } OK object(Obj)#%d (4) { ["a"]=> int(1) [%r"?b"?:protected"?%r]=> int(2) [%r"?c"?:("Obj":)?private"?%r]=> int(3) ["3"]=> int(4) } SKIP object(Obj)#%d (3) { ["a"]=> string(3) "foo" [%r"?b"?:protected"?%r]=> string(6) "foobar" [%r"?c"?:("Obj":)?private"?%r]=> string(4) "hoge" } OK object(Obj)#%d (3) { ["a"]=> int(1) [%r"?b"?:protected"?%r]=> int(2) [%r"?c"?:("Obj":)?private"?%r]=> NULL } OK object(Obj)#%d (5) { ["a"]=> NULL [%r"?b"?:protected"?%r]=> NULL [%r"?c"?:("Obj":)?private"?%r]=> NULL ["one"]=> int(1) ["two"]=> int(2) } OK object(Obj)#%d (3) { ["a"]=> int(1) [%r"?b"?:protected"?%r]=> int(2) [%r"?c"?:("Obj":)?private"?%r]=> int(3) } OK object(Obj)#%d (3) { ["a"]=> int(1) [%r"?b"?:protected"?%r]=> int(2) [%r"?c"?:("Obj":)?private"?%r]=> int(3) } OK object(Obj)#%d (3) { ["a"]=> int(1) [%r"?b"?:protected"?%r]=> int(2) [%r"?c"?:("Obj":)?private"?%r]=> int(3) } OK object(Obj)#%d (3) { ["a"]=> array(1) { [0]=> string(3) "foo" } [%r"?b"?:protected"?%r]=> array(1) { [0]=> string(3) "foo" } [%r"?c"?:("Obj":)?private"?%r]=> NULL } OK object(Obj)#%d (4) { ["a"]=> array(2) { ["b"]=> string(1) "c" ["d"]=> string(1) "e" } [%r"?b"?:protected"?%r]=> NULL [%r"?c"?:("Obj":)?private"?%r]=> NULL ["f"]=> array(1) { ["g"]=> string(1) "h" } } OK object(Obj)#%d (3) { ["a"]=> int(1) [%r"?b"?:protected"?%r]=> int(2) [%r"?c"?:("Obj":)?private"?%r]=> int(3) } OK object(Obj)#%d (3) { ["a"]=> int(1) [%r"?b"?:protected"?%r]=> int(2) [%r"?c"?:("Obj":)?private"?%r]=> int(3) } OK object(Obj)#%d (3) { ["a"]=> array(3) { [0]=> int(1) [1]=> int(2) [2]=> int(3) } [%r"?b"?:protected"?%r]=> array(3) { [0]=> int(4) [1]=> int(5) [2]=> int(6) } [%r"?c"?:("Obj":)?private"?%r]=> NULL } OK msgpack-2.1.0beta1/tests/102.phpt0000644000175000001440000001747313577133502015303 0ustar mikeusers--TEST-- unpack of object converter : class unpacker (object: php_only=0) --SKIPIF-- pack($variable); $unserialized = null; $unpacker = $msgpack->unpacker(); if ($unpacker->execute($serialized)) { $unserialized = $unpacker->data($object); } var_dump($unserialized); if ($result) { echo $unserialized == $result ? 'OK' : 'ERROR', PHP_EOL; } else { echo 'SKIP', PHP_EOL; } } class Obj { public $a; protected $b; private $c; public function __construct($a = null, $b = null, $c = null, $d = null) { $this->a = $a; $this->b = $b; $this->c = $c; if (is_array($d)) { foreach ($d as $key => $val) { $this->{$key} = $val; } } } } $object = new Obj(); test('null', null, new Obj(), new Obj(null, null, null)); test('bool: true', true, new Obj(), new Obj(true, null, null)); test('bool: false', false, new Obj(), new Obj(false, null, null)); test('zero: 0', 0, new Obj(), new Obj(0, null, null)); test('small: 1', 1, new Obj(), new Obj(1, null, null)); test('small: -1', -1, new Obj(), new Obj(-1, null, null)); test('medium: 1000', 1000, new Obj(), new Obj(1000, null, null)); test('medium: -1000', -1000, new Obj(), new Obj(-1000, null, null)); test('large: 100000', 100000, new Obj(), new Obj(100000, null, null)); test('large: -100000', -100000, new Obj(), new Obj(-100000, null, null)); test('double: 123.456', 123.456, new Obj(), new Obj(123.456, null, null)); test('empty: ""', "", new Obj(), new Obj("", null, null)); test('string: "foobar"', "foobar", new Obj(), new Obj("foobar", null, null)); test('array: empty', array(), new Obj(), new Obj(null, null, null)); test('array(1, 2, 3)', array(1, 2, 3), new Obj(), new Obj(1, 2, 3)); test('array(array(1, 2, 3), arr...', array(array(1, 2, 3), array(4, 5, 6), array(7, 8, 9)), new Obj(), new Obj(array(1, 2, 3), array(4, 5, 6), array(7, 8, 9))); test('array(1, 2, 3, 4)', array(1, 2, 3, 4), new Obj()); test('array("foo", "foobar", "foohoge")', array("foo", "foobar", "hoge"), new Obj(), new Obj("foo", "foobar", "hoge")); test('array("a" => 1, "b" => 2))', array("a" => 1, "b" => 2), new Obj(), new Obj(1, 2, null)); test('array("one" => 1, "two" => 2))', array("one" => 1, "two" => 2), new Obj(), new Obj(null, null, null, array("one" => 1, "two" => 2))); test('array("a" => 1, "b" => 2, 3))', array("a" => 1, "b" => 2, 3), new Obj(), new Obj(1, 2, 3)); test('array(3, "a" => 1, "b" => 2))', array(3, "a" => 1, "b" => 2), new Obj(), new Obj(1, 2, 3)); test('array("a" => 1, 3, "b" => 2))', array("a" => 1, 3, "b" => 2), new Obj(), new Obj(1, 2, 3)); $a = array('foo'); test('array($a, $a)', array($a, $a), new Obj(), new Obj($a, $a, null)); $a = array( 'a' => array( 'b' => 'c', 'd' => 'e' ), 'f' => array( 'g' => 'h' ) ); test('array', $a, new Obj(), new Obj(null, null, null, $a)); $o = new Obj(1, 2, 3); test('object', $o, new Obj(), new Obj(1, 2, 3)); class Obj2 { public $A; protected $B; private $C; function __construct($a, $b, $c) { $this->A = $a; $this->B = $b; $this->C = $c; } } $o = new Obj2(1, 2, 3); test('object', $o, new Obj(), new Obj(1, 2, 3)); $o1 = new Obj2(1, 2, 3); $o2 = new Obj2(4, 5, 6); test('object', array($o1, $o2), new Obj(), new Obj(array(1, 2, 3), array(4, 5, 6))); --EXPECTF-- object(Obj)#%d (3) { ["a"]=> NULL [%r"?b"?:protected"?%r]=> NULL [%r"?c"?:("Obj":)?private"?%r]=> NULL } OK object(Obj)#%d (3) { ["a"]=> bool(true) [%r"?b"?:protected"?%r]=> NULL [%r"?c"?:("Obj":)?private"?%r]=> NULL } OK object(Obj)#%d (3) { ["a"]=> bool(false) [%r"?b"?:protected"?%r]=> NULL [%r"?c"?:("Obj":)?private"?%r]=> NULL } OK object(Obj)#%d (3) { ["a"]=> int(0) [%r"?b"?:protected"?%r]=> NULL [%r"?c"?:("Obj":)?private"?%r]=> NULL } OK object(Obj)#%d (3) { ["a"]=> int(1) [%r"?b"?:protected"?%r]=> NULL [%r"?c"?:("Obj":)?private"?%r]=> NULL } OK object(Obj)#%d (3) { ["a"]=> int(-1) [%r"?b"?:protected"?%r]=> NULL [%r"?c"?:("Obj":)?private"?%r]=> NULL } OK object(Obj)#%d (3) { ["a"]=> int(1000) [%r"?b"?:protected"?%r]=> NULL [%r"?c"?:("Obj":)?private"?%r]=> NULL } OK object(Obj)#%d (3) { ["a"]=> int(-1000) [%r"?b"?:protected"?%r]=> NULL [%r"?c"?:("Obj":)?private"?%r]=> NULL } OK object(Obj)#%d (3) { ["a"]=> int(100000) [%r"?b"?:protected"?%r]=> NULL [%r"?c"?:("Obj":)?private"?%r]=> NULL } OK object(Obj)#%d (3) { ["a"]=> int(-100000) [%r"?b"?:protected"?%r]=> NULL [%r"?c"?:("Obj":)?private"?%r]=> NULL } OK object(Obj)#%d (3) { ["a"]=> float(123.456) [%r"?b"?:protected"?%r]=> NULL [%r"?c"?:("Obj":)?private"?%r]=> NULL } OK object(Obj)#%d (3) { ["a"]=> string(0) "" [%r"?b"?:protected"?%r]=> NULL [%r"?c"?:("Obj":)?private"?%r]=> NULL } OK object(Obj)#%d (3) { ["a"]=> string(6) "foobar" [%r"?b"?:protected"?%r]=> NULL [%r"?c"?:("Obj":)?private"?%r]=> NULL } OK object(Obj)#%d (3) { ["a"]=> NULL [%r"?b"?:protected"?%r]=> NULL [%r"?c"?:("Obj":)?private"?%r]=> NULL } OK object(Obj)#%d (3) { ["a"]=> int(1) [%r"?b"?:protected"?%r]=> int(2) [%r"?c"?:("Obj":)?private"?%r]=> int(3) } OK object(Obj)#%d (3) { ["a"]=> array(3) { [0]=> int(1) [1]=> int(2) [2]=> int(3) } [%r"?b"?:protected"?%r]=> array(3) { [0]=> int(4) [1]=> int(5) [2]=> int(6) } [%r"?c"?:("Obj":)?private"?%r]=> array(3) { [0]=> int(7) [1]=> int(8) [2]=> int(9) } } OK object(Obj)#%d (4) { ["a"]=> int(1) [%r"?b"?:protected"?%r]=> int(2) [%r"?c"?:("Obj":)?private"?%r]=> int(3) ["3"]=> int(4) } SKIP object(Obj)#%d (3) { ["a"]=> string(3) "foo" [%r"?b"?:protected"?%r]=> string(6) "foobar" [%r"?c"?:("Obj":)?private"?%r]=> string(4) "hoge" } OK object(Obj)#%d (3) { ["a"]=> int(1) [%r"?b"?:protected"?%r]=> int(2) [%r"?c"?:("Obj":)?private"?%r]=> NULL } OK object(Obj)#%d (5) { ["a"]=> NULL [%r"?b"?:protected"?%r]=> NULL [%r"?c"?:("Obj":)?private"?%r]=> NULL ["one"]=> int(1) ["two"]=> int(2) } OK object(Obj)#%d (3) { ["a"]=> int(1) [%r"?b"?:protected"?%r]=> int(2) [%r"?c"?:("Obj":)?private"?%r]=> int(3) } OK object(Obj)#%d (3) { ["a"]=> int(1) [%r"?b"?:protected"?%r]=> int(2) [%r"?c"?:("Obj":)?private"?%r]=> int(3) } OK object(Obj)#%d (3) { ["a"]=> int(1) [%r"?b"?:protected"?%r]=> int(2) [%r"?c"?:("Obj":)?private"?%r]=> int(3) } OK object(Obj)#%d (3) { ["a"]=> array(1) { [0]=> string(3) "foo" } [%r"?b"?:protected"?%r]=> array(1) { [0]=> string(3) "foo" } [%r"?c"?:("Obj":)?private"?%r]=> NULL } OK object(Obj)#%d (4) { ["a"]=> array(2) { ["b"]=> string(1) "c" ["d"]=> string(1) "e" } [%r"?b"?:protected"?%r]=> NULL [%r"?c"?:("Obj":)?private"?%r]=> NULL ["f"]=> array(1) { ["g"]=> string(1) "h" } } OK object(Obj)#%d (3) { ["a"]=> int(1) [%r"?b"?:protected"?%r]=> int(2) [%r"?c"?:("Obj":)?private"?%r]=> int(3) } OK object(Obj)#%d (3) { ["a"]=> int(1) [%r"?b"?:protected"?%r]=> int(2) [%r"?c"?:("Obj":)?private"?%r]=> int(3) } OK object(Obj)#%d (3) { ["a"]=> array(3) { [0]=> int(1) [1]=> int(2) [2]=> int(3) } [%r"?b"?:protected"?%r]=> array(3) { [0]=> int(4) [1]=> int(5) [2]=> int(6) } [%r"?c"?:("Obj":)?private"?%r]=> NULL } OK msgpack-2.1.0beta1/tests/103.phpt0000644000175000001440000001732513577133502015300 0ustar mikeusers--TEST-- unpack of object converter: class unpacker (string: OPT_PHPONLY=false) --SKIPIF-- setOption(MessagePack::OPT_PHPONLY, false); $serialized = $msgpack->pack($variable); $unserialized = null; $unpacker = $msgpack->unpacker(); if ($unpacker->execute($serialized)) { $unserialized = $unpacker->data($object); } var_dump($unserialized); if ($result) { echo $unserialized == $result ? 'OK' : 'ERROR', PHP_EOL; } else { echo 'SKIP', PHP_EOL; } } class Obj { public $a; protected $b; private $c; public function __construct($a = null, $b = null, $c = null, $d = null) { $this->a = $a; $this->b = $b; $this->c = $c; if (is_array($d)) { foreach ($d as $key => $val) { $this->{$key} = $val; } } } } test('null', null, 'Obj', new Obj(null, null, null)); test('bool: true', true, 'Obj', new Obj(true, null, null)); test('bool: false', false, 'Obj', new Obj(false, null, null)); test('zero: 0', 0, 'Obj', new Obj(0, null, null)); test('small: 1', 1, 'Obj', new Obj(1, null, null)); test('small: -1', -1, 'Obj', new Obj(-1, null, null)); test('medium: 1000', 1000, 'Obj', new Obj(1000, null, null)); test('medium: -1000', -1000, 'Obj', new Obj(-1000, null, null)); test('large: 100000', 100000, 'Obj', new Obj(100000, null, null)); test('large: -100000', -100000, 'Obj', new Obj(-100000, null, null)); test('double: 123.456', 123.456, 'Obj', new Obj(123.456, null, null)); test('empty: ""', "", 'Obj', new Obj("", null, null)); test('string: "foobar"', "foobar", 'Obj', new Obj("foobar", null, null)); test('array: empty', array(), 'Obj', new Obj(null, null, null)); test('array(1, 2, 3)', array(1, 2, 3), 'Obj', new Obj(1, 2, 3)); test('array(array(1, 2, 3), arr...', array(array(1, 2, 3), array(4, 5, 6), array(7, 8, 9)), 'Obj', new Obj(array(1, 2, 3), array(4, 5, 6), array(7, 8, 9))); test('array(1, 2, 3, 4)', array(1, 2, 3, 4), 'Obj'); test('array("foo", "foobar", "foohoge")', array("foo", "foobar", "hoge"), 'Obj', new Obj("foo", "foobar", "hoge")); test('array("a" => 1, "b" => 2))', array("a" => 1, "b" => 2), 'Obj', new Obj(1, 2, null)); test('array("one" => 1, "two" => 2))', array("one" => 1, "two" => 2), 'Obj', new Obj(null, null, null, array("one" => 1, "two" => 2))); test('array("a" => 1, "b" => 2, 3))', array("a" => 1, "b" => 2, 3), 'Obj', new Obj(1, 2, 3)); test('array(3, "a" => 1, "b" => 2))', array(3, "a" => 1, "b" => 2), 'Obj', new Obj(1, 2, 3)); test('array("a" => 1, 3, "b" => 2))', array("a" => 1, 3, "b" => 2), 'Obj', new Obj(1, 2, 3)); $a = array('foo'); test('array($a, $a)', array($a, $a), 'Obj', new Obj($a, $a, null)); $a = array( 'a' => array( 'b' => 'c', 'd' => 'e' ), 'f' => array( 'g' => 'h' ) ); test('array', $a, 'Obj', new Obj(null, null, null, $a)); $o = new Obj(1, 2, 3); test('object', $o, 'Obj', new Obj(1, 2, 3)); class Obj2 { public $A; protected $B; private $C; function __construct($a, $b, $c) { $this->A = $a; $this->B = $b; $this->C = $c; } } $o = new Obj2(1, 2, 3); test('object', $o, 'Obj', new Obj(1, 2, 3)); $o1 = new Obj2(1, 2, 3); $o2 = new Obj2(4, 5, 6); test('object', array($o1, $o2), 'Obj', new Obj(array(1, 2, 3), array(4, 5, 6))); --EXPECTF-- object(Obj)#%d (3) { ["a"]=> NULL [%r"?b"?:protected"?%r]=> NULL [%r"?c"?:("Obj":)?private"?%r]=> NULL } OK object(Obj)#%d (3) { ["a"]=> bool(true) [%r"?b"?:protected"?%r]=> NULL [%r"?c"?:("Obj":)?private"?%r]=> NULL } OK object(Obj)#%d (3) { ["a"]=> bool(false) [%r"?b"?:protected"?%r]=> NULL [%r"?c"?:("Obj":)?private"?%r]=> NULL } OK object(Obj)#%d (3) { ["a"]=> int(0) [%r"?b"?:protected"?%r]=> NULL [%r"?c"?:("Obj":)?private"?%r]=> NULL } OK object(Obj)#%d (3) { ["a"]=> int(1) [%r"?b"?:protected"?%r]=> NULL [%r"?c"?:("Obj":)?private"?%r]=> NULL } OK object(Obj)#%d (3) { ["a"]=> int(-1) [%r"?b"?:protected"?%r]=> NULL [%r"?c"?:("Obj":)?private"?%r]=> NULL } OK object(Obj)#%d (3) { ["a"]=> int(1000) [%r"?b"?:protected"?%r]=> NULL [%r"?c"?:("Obj":)?private"?%r]=> NULL } OK object(Obj)#%d (3) { ["a"]=> int(-1000) [%r"?b"?:protected"?%r]=> NULL [%r"?c"?:("Obj":)?private"?%r]=> NULL } OK object(Obj)#%d (3) { ["a"]=> int(100000) [%r"?b"?:protected"?%r]=> NULL [%r"?c"?:("Obj":)?private"?%r]=> NULL } OK object(Obj)#%d (3) { ["a"]=> int(-100000) [%r"?b"?:protected"?%r]=> NULL [%r"?c"?:("Obj":)?private"?%r]=> NULL } OK object(Obj)#%d (3) { ["a"]=> float(123.456) [%r"?b"?:protected"?%r]=> NULL [%r"?c"?:("Obj":)?private"?%r]=> NULL } OK object(Obj)#%d (3) { ["a"]=> string(0) "" [%r"?b"?:protected"?%r]=> NULL [%r"?c"?:("Obj":)?private"?%r]=> NULL } OK object(Obj)#%d (3) { ["a"]=> string(6) "foobar" [%r"?b"?:protected"?%r]=> NULL [%r"?c"?:("Obj":)?private"?%r]=> NULL } OK object(Obj)#%d (3) { ["a"]=> NULL [%r"?b"?:protected"?%r]=> NULL [%r"?c"?:("Obj":)?private"?%r]=> NULL } OK object(Obj)#%d (3) { ["a"]=> int(1) [%r"?b"?:protected"?%r]=> int(2) [%r"?c"?:("Obj":)?private"?%r]=> int(3) } OK object(Obj)#%d (3) { ["a"]=> array(3) { [0]=> int(1) [1]=> int(2) [2]=> int(3) } [%r"?b"?:protected"?%r]=> array(3) { [0]=> int(4) [1]=> int(5) [2]=> int(6) } [%r"?c"?:("Obj":)?private"?%r]=> array(3) { [0]=> int(7) [1]=> int(8) [2]=> int(9) } } OK object(Obj)#%d (4) { ["a"]=> int(1) [%r"?b"?:protected"?%r]=> int(2) [%r"?c"?:("Obj":)?private"?%r]=> int(3) ["3"]=> int(4) } SKIP object(Obj)#%d (3) { ["a"]=> string(3) "foo" [%r"?b"?:protected"?%r]=> string(6) "foobar" [%r"?c"?:("Obj":)?private"?%r]=> string(4) "hoge" } OK object(Obj)#%d (3) { ["a"]=> int(1) [%r"?b"?:protected"?%r]=> int(2) [%r"?c"?:("Obj":)?private"?%r]=> NULL } OK object(Obj)#%d (5) { ["a"]=> NULL [%r"?b"?:protected"?%r]=> NULL [%r"?c"?:("Obj":)?private"?%r]=> NULL ["one"]=> int(1) ["two"]=> int(2) } OK object(Obj)#%d (3) { ["a"]=> int(1) [%r"?b"?:protected"?%r]=> int(2) [%r"?c"?:("Obj":)?private"?%r]=> int(3) } OK object(Obj)#%d (3) { ["a"]=> int(1) [%r"?b"?:protected"?%r]=> int(2) [%r"?c"?:("Obj":)?private"?%r]=> int(3) } OK object(Obj)#%d (3) { ["a"]=> int(1) [%r"?b"?:protected"?%r]=> int(2) [%r"?c"?:("Obj":)?private"?%r]=> int(3) } OK object(Obj)#%d (3) { ["a"]=> array(1) { [0]=> string(3) "foo" } [%r"?b"?:protected"?%r]=> array(1) { [0]=> string(3) "foo" } [%r"?c"?:("Obj":)?private"?%r]=> NULL } OK object(Obj)#%d (4) { ["a"]=> array(2) { ["b"]=> string(1) "c" ["d"]=> string(1) "e" } [%r"?b"?:protected"?%r]=> NULL [%r"?c"?:("Obj":)?private"?%r]=> NULL ["f"]=> array(1) { ["g"]=> string(1) "h" } } OK object(Obj)#%d (3) { ["a"]=> int(1) [%r"?b"?:protected"?%r]=> int(2) [%r"?c"?:("Obj":)?private"?%r]=> int(3) } OK object(Obj)#%d (3) { ["a"]=> int(1) [%r"?b"?:protected"?%r]=> int(2) [%r"?c"?:("Obj":)?private"?%r]=> int(3) } OK object(Obj)#%d (3) { ["a"]=> array(3) { [0]=> int(1) [1]=> int(2) [2]=> int(3) } [%r"?b"?:protected"?%r]=> array(3) { [0]=> int(4) [1]=> int(5) [2]=> int(6) } [%r"?c"?:("Obj":)?private"?%r]=> NULL } OK msgpack-2.1.0beta1/tests/104.phpt0000644000175000001440000000273413577133502015277 0ustar mikeusers--TEST-- unpack of template converter: class unpacker (array: string) --SKIPIF-- pack($variable); $unserialized = $msgpack->unpack($serialized, $object); var_dump($unserialized); if ($result) { echo $unserialized == $result ? 'OK' : 'ERROR', PHP_EOL; } else { echo 'SKIP', PHP_EOL; } } class MyObj { private $data = null; private $priv = "privdata"; public $pdata = null; function __construct() { $this->data = "datadata"; } } $obj = new MyObj(); $obj->pdata = "pubdata0"; $obj2 = new MyObj(); $obj2->pdata = "pubdata1"; $ary = array($obj, $obj2); $tpl = array("MyObj"); test("object list /w string", $ary, $tpl, $ary); --EXPECTF-- array(2) { [0]=> object(MyObj)#%d (3) { [%r"?data"?:("MyObj":)?private"?%r]=> string(8) "datadata" [%r"?priv"?:("MyObj":)?private"?%r]=> string(8) "privdata" ["pdata"]=> string(8) "pubdata0" } [1]=> object(MyObj)#%d (3) { [%r"?data"?:("MyObj":)?private"?%r]=> string(8) "datadata" [%r"?priv"?:("MyObj":)?private"?%r]=> string(8) "privdata" ["pdata"]=> string(8) "pubdata1" } } OK msgpack-2.1.0beta1/tests/105.phpt0000644000175000001440000000274213577133502015277 0ustar mikeusers--TEST-- unpack of template converter: class unpacker (array: object) --SKIPIF-- pack($variable); $unserialized = $msgpack->unpack($serialized, $object); var_dump($unserialized); if ($result) { echo $unserialized == $result ? 'OK' : 'ERROR', PHP_EOL; } else { echo 'SKIP', PHP_EOL; } } class MyObj { private $data = null; private $priv = "privdata"; public $pdata = null; function __construct() { $this->data = "datadata"; } } $obj = new MyObj(); $obj->pdata = "pubdata0"; $obj2 = new MyObj(); $obj2->pdata = "pubdata1"; $ary = array($obj, $obj2); $tpl = array(new MyObj()); test("object list /w instance", $ary, $tpl, $ary); --EXPECTF-- array(2) { [0]=> object(MyObj)#%d (3) { [%r"?data"?:("MyObj":)?private"?%r]=> string(8) "datadata" [%r"?priv"?:("MyObj":)?private"?%r]=> string(8) "privdata" ["pdata"]=> string(8) "pubdata0" } [1]=> object(MyObj)#%d (3) { [%r"?data"?:("MyObj":)?private"?%r]=> string(8) "datadata" [%r"?priv"?:("MyObj":)?private"?%r]=> string(8) "privdata" ["pdata"]=> string(8) "pubdata1" } } OK msgpack-2.1.0beta1/tests/106.phpt0000644000175000001440000000325013577133502015273 0ustar mikeusers--TEST-- unpack of template converter: class unpacker (string) --SKIPIF-- pack($variable); $unserialized = $msgpack->unpack($serialized, $object); var_dump($unserialized); if ($result) { echo $unserialized == $result ? 'OK' : 'ERROR', PHP_EOL; } else { echo 'SKIP', PHP_EOL; } } class MyObj { private $data = null; private $priv = "privdata"; public $pdata = null; public $subary = null; function __construct() { $this->data = "datadata"; $this->subary = new SubObj(); } } class SubObj { private $subdata = null; private $subpriv = "subprivdata"; public $subpdata = null; function __construct() { $this->subdata = "subdatadata"; } } $obj = new MyObj(); $obj->pdata = "pubdata"; $obj->subary->subpdata = "subpubdata"; $tpl = "MyObj"; test("recursive object /w string", $obj, $tpl, $obj); --EXPECTF-- object(MyObj)#%d (4) { [%r"?data"?:("MyObj":)?private"?%r]=> string(8) "datadata" [%r"?priv"?:("MyObj":)?private"?%r]=> string(8) "privdata" ["pdata"]=> string(7) "pubdata" ["subary"]=> object(SubObj)#%d (3) { [%r"?subdata"?:("SubObj":)?private"?%r]=> string(11) "subdatadata" [%r"?subpriv"?:("SubObj":)?private"?%r]=> string(11) "subprivdata" ["subpdata"]=> string(10) "subpubdata" } } OK msgpack-2.1.0beta1/tests/107.phpt0000644000175000001440000000325613577133502015302 0ustar mikeusers--TEST-- unpack of template converter: class unpacker (object) --SKIPIF-- pack($variable); $unserialized = $msgpack->unpack($serialized, $object); var_dump($unserialized); if ($result) { echo $unserialized == $result ? 'OK' : 'ERROR', PHP_EOL; } else { echo 'SKIP', PHP_EOL; } } class MyObj { private $data = null; private $priv = "privdata"; public $pdata = null; public $subary = null; function __construct() { $this->data = "datadata"; $this->subary = new SubObj(); } } class SubObj { private $subdata = null; private $subpriv = "subprivdata"; public $subpdata = null; function __construct() { $this->subdata = "subdatadata"; } } $obj = new MyObj(); $obj->pdata = "pubdata"; $obj->subary->subpdata = "subpubdata"; $tpl = new MyObj(); test("recursive object /w instance", $obj, $tpl, $obj); --EXPECTF-- object(MyObj)#%d (4) { [%r"?data"?:("MyObj":)?private"?%r]=> string(8) "datadata" [%r"?priv"?:("MyObj":)?private"?%r]=> string(8) "privdata" ["pdata"]=> string(7) "pubdata" ["subary"]=> object(SubObj)#%d (3) { [%r"?subdata"?:("SubObj":)?private"?%r]=> string(11) "subdatadata" [%r"?subpriv"?:("SubObj":)?private"?%r]=> string(11) "subprivdata" ["subpdata"]=> string(10) "subpubdata" } } OK msgpack-2.1.0beta1/tests/108.phpt0000644000175000001440000000344313577133502015301 0ustar mikeusers--TEST-- unpack of template converter: multiple class: class unpacker (array: string) --SKIPIF-- pack($variable); $unserialized = $msgpack->unpack($serialized, $object); var_dump($unserialized); if ($result) { echo $unserialized == $result ? 'OK' : 'ERROR', PHP_EOL; } else { echo 'SKIP', PHP_EOL; } } class MyObj { private $data = null; private $priv = "privdata"; public $pdata = null; public $subary = null; function __construct() { $this->data = "datadata"; $this->subary = new SubObj(); } } class SubObj { private $subdata = null; private $subpriv = "subprivdata"; public $subpdata = null; function __construct() { $this->subdata = "subdatadata"; } } $obj = new MyObj(); $obj->pdata = "pubdata"; $obj->subary->subpdata = "subpubdata"; $ary = array($obj); $tpl = array("MyObj"); test("recursive object with object list /w string", $ary, $tpl, $ary); --EXPECTF-- array(1) { [0]=> object(MyObj)#%d (4) { [%r"?data"?:("MyObj":)?private"?%r]=> string(8) "datadata" [%r"?priv"?:("MyObj":)?private"?%r]=> string(8) "privdata" ["pdata"]=> string(7) "pubdata" ["subary"]=> object(SubObj)#%d (3) { [%r"?subdata"?:("SubObj":)?private"?%r]=> string(11) "subdatadata" [%r"?subpriv"?:("SubObj":)?private"?%r]=> string(11) "subprivdata" ["subpdata"]=> string(10) "subpubdata" } } } OK msgpack-2.1.0beta1/tests/109.phpt0000644000175000001440000000345113577133502015301 0ustar mikeusers--TEST-- unpack of template converter: multiple class: class unpacker (array: object) --SKIPIF-- pack($variable); $unserialized = $msgpack->unpack($serialized, $object); var_dump($unserialized); if ($result) { echo $unserialized == $result ? 'OK' : 'ERROR', PHP_EOL; } else { echo 'SKIP', PHP_EOL; } } class MyObj { private $data = null; private $priv = "privdata"; public $pdata = null; public $subary = null; function __construct() { $this->data = "datadata"; $this->subary = new SubObj(); } } class SubObj { private $subdata = null; private $subpriv = "subprivdata"; public $subpdata = null; function __construct() { $this->subdata = "subdatadata"; } } $obj = new MyObj(); $obj->pdata = "pubdata"; $obj->subary->subpdata = "subpubdata"; $ary = array($obj); $tpl = array(new MyObj()); test("recursive object with object list /w instance", $ary, $tpl, $ary); --EXPECTF-- array(1) { [0]=> object(MyObj)#%d (4) { [%r"?data"?:("MyObj":)?private"?%r]=> string(8) "datadata" [%r"?priv"?:("MyObj":)?private"?%r]=> string(8) "privdata" ["pdata"]=> string(7) "pubdata" ["subary"]=> object(SubObj)#%d (3) { [%r"?subdata"?:("SubObj":)?private"?%r]=> string(11) "subdatadata" [%r"?subpriv"?:("SubObj":)?private"?%r]=> string(11) "subprivdata" ["subpdata"]=> string(10) "subpubdata" } } } OK msgpack-2.1.0beta1/tests/110.phpt0000644000175000001440000000453313577133502015273 0ustar mikeusers--TEST-- unpack of template converter: multiple variable: class unpacker (array: string) --SKIPIF-- pack($variable); $unserialized = $msgpack->unpack($serialized, $object); var_dump($unserialized); if ($result) { echo $unserialized == $result ? 'OK' : 'ERROR', PHP_EOL; } else { echo 'SKIP', PHP_EOL; } } class MyObj { private $data = null; private $priv = "privdata"; public $pdata = null; public $subary = null; function __construct() { $this->data = "datadata"; $this->subary = new SubObj(); } } class SubObj { private $subdata = null; private $subpriv = "subprivdata"; public $subpdata = null; function __construct() { $this->subdata = "subdatadata"; } } $obj0 = new MyObj(); $obj0->pdata = "pubdata0"; $obj0->subary->subpdata = "subpubdata0"; $obj1 = new MyObj(); $obj1->pdata = "pubdata1"; $obj1->subary->subpdata = "subpubdata1"; $ary = array($obj0, $obj1); $tpl = array("MyObj"); test("recursive object list /w string", $ary, $tpl, $ary); --EXPECTF-- array(2) { [0]=> object(MyObj)#%d (4) { [%r"?data"?:("MyObj":)?private"?%r]=> string(8) "datadata" [%r"?priv"?:("MyObj":)?private"?%r]=> string(8) "privdata" ["pdata"]=> string(8) "pubdata0" ["subary"]=> object(SubObj)#%d (3) { [%r"?subdata"?:("SubObj":)?private"?%r]=> string(11) "subdatadata" [%r"?subpriv"?:("SubObj":)?private"?%r]=> string(11) "subprivdata" ["subpdata"]=> string(11) "subpubdata0" } } [1]=> object(MyObj)#%d (4) { [%r"?data"?:("MyObj":)?private"?%r]=> string(8) "datadata" [%r"?priv"?:("MyObj":)?private"?%r]=> string(8) "privdata" ["pdata"]=> string(8) "pubdata1" ["subary"]=> object(SubObj)#%d (3) { [%r"?subdata"?:("SubObj":)?private"?%r]=> string(11) "subdatadata" [%r"?subpriv"?:("SubObj":)?private"?%r]=> string(11) "subprivdata" ["subpdata"]=> string(11) "subpubdata1" } } } OK msgpack-2.1.0beta1/tests/111.phpt0000644000175000001440000000454113577133502015273 0ustar mikeusers--TEST-- unpack of template converter: multiple variable: class unpacker (array: object) --SKIPIF-- pack($variable); $unserialized = $msgpack->unpack($serialized, $object); var_dump($unserialized); if ($result) { echo $unserialized == $result ? 'OK' : 'ERROR', PHP_EOL; } else { echo 'SKIP', PHP_EOL; } } class MyObj { private $data = null; private $priv = "privdata"; public $pdata = null; public $subary = null; function __construct() { $this->data = "datadata"; $this->subary = new SubObj(); } } class SubObj { private $subdata = null; private $subpriv = "subprivdata"; public $subpdata = null; function __construct() { $this->subdata = "subdatadata"; } } $obj0 = new MyObj(); $obj0->pdata = "pubdata0"; $obj0->subary->subpdata = "subpubdata0"; $obj1 = new MyObj(); $obj1->pdata = "pubdata1"; $obj1->subary->subpdata = "subpubdata1"; $ary = array($obj0, $obj1); $tpl = array(new MyObj()); test("recursive object list /w instance", $ary, $tpl, $ary); --EXPECTF-- array(2) { [0]=> object(MyObj)#%d (4) { [%r"?data"?:("MyObj":)?private"?%r]=> string(8) "datadata" [%r"?priv"?:("MyObj":)?private"?%r]=> string(8) "privdata" ["pdata"]=> string(8) "pubdata0" ["subary"]=> object(SubObj)#%d (3) { [%r"?subdata"?:("SubObj":)?private"?%r]=> string(11) "subdatadata" [%r"?subpriv"?:("SubObj":)?private"?%r]=> string(11) "subprivdata" ["subpdata"]=> string(11) "subpubdata0" } } [1]=> object(MyObj)#%d (4) { [%r"?data"?:("MyObj":)?private"?%r]=> string(8) "datadata" [%r"?priv"?:("MyObj":)?private"?%r]=> string(8) "privdata" ["pdata"]=> string(8) "pubdata1" ["subary"]=> object(SubObj)#%d (3) { [%r"?subdata"?:("SubObj":)?private"?%r]=> string(11) "subdatadata" [%r"?subpriv"?:("SubObj":)?private"?%r]=> string(11) "subprivdata" ["subpdata"]=> string(11) "subpubdata1" } } } OK msgpack-2.1.0beta1/tests/112.phpt0000644000175000001440000000627113577133502015276 0ustar mikeusers--TEST-- unpack of template converter: multiple class/variable: class unpacker (array: string) --SKIPIF-- pack($variable); $unserialized = $msgpack->unpack($serialized, $object); var_dump($unserialized); if ($result) { echo $unserialized == $result ? 'OK' : 'ERROR', PHP_EOL; } else { echo 'SKIP', PHP_EOL; } } class MyObj { private $data = null; private $priv = "privdata"; public $pdata = null; public $subary = null; function __construct() { $this->data = "datadata"; $this->subary = array(new SubObj()); } } class SubObj { private $subdata = null; private $subpriv = "subprivdata"; public $subpdata = null; function __construct() { $this->subdata = "subdatadata"; } } $obj0 = new MyObj(); $obj0->pdata = "pubdata0"; $obj0->subary[0]->subpdata = "subpubdata00"; $subobj01 = new SubObj(); $subobj01->subpdata = "subpdata01"; $obj0->subary[1] = $subobj01; $obj1 = new MyObj(); $obj1->pdata = "pubdata1"; $obj1->subary[0]->subpdata = "subpubdata1"; $subobj11 = new SubObj(); $subobj11->subpdata = "subpdata11"; $obj1->subary[1] = $subobj11; $ary = array($obj0, $obj1); $tpl = array("MyObj"); test("recursive object list with object list /w string", $ary, $tpl, $ary); --EXPECTF-- array(2) { [0]=> object(MyObj)#%d (4) { [%r"?data"?:("MyObj":)?private"?%r]=> string(8) "datadata" [%r"?priv"?:("MyObj":)?private"?%r]=> string(8) "privdata" ["pdata"]=> string(8) "pubdata0" ["subary"]=> array(2) { [0]=> object(SubObj)#%d (3) { [%r"?subdata"?:("SubObj":)?private"?%r]=> string(11) "subdatadata" [%r"?subpriv"?:("SubObj":)?private"?%r]=> string(11) "subprivdata" ["subpdata"]=> string(12) "subpubdata00" } [1]=> object(SubObj)#%d (3) { [%r"?subdata"?:("SubObj":)?private"?%r]=> string(11) "subdatadata" [%r"?subpriv"?:("SubObj":)?private"?%r]=> string(11) "subprivdata" ["subpdata"]=> string(10) "subpdata01" } } } [1]=> object(MyObj)#%d (4) { [%r"?data"?:("MyObj":)?private"?%r]=> string(8) "datadata" [%r"?priv"?:("MyObj":)?private"?%r]=> string(8) "privdata" ["pdata"]=> string(8) "pubdata1" ["subary"]=> array(2) { [0]=> object(SubObj)#%d (3) { [%r"?subdata"?:("SubObj":)?private"?%r]=> string(11) "subdatadata" [%r"?subpriv"?:("SubObj":)?private"?%r]=> string(11) "subprivdata" ["subpdata"]=> string(11) "subpubdata1" } [1]=> object(SubObj)#%d (3) { [%r"?subdata"?:("SubObj":)?private"?%r]=> string(11) "subdatadata" [%r"?subpriv"?:("SubObj":)?private"?%r]=> string(11) "subprivdata" ["subpdata"]=> string(10) "subpdata11" } } } } OK msgpack-2.1.0beta1/tests/113.phpt0000644000175000001440000000627713577133502015305 0ustar mikeusers--TEST-- unpack of template converter: multiple class/variable: class unpacker (array: object) --SKIPIF-- pack($variable); $unserialized = $msgpack->unpack($serialized, $object); var_dump($unserialized); if ($result) { echo $unserialized == $result ? 'OK' : 'ERROR', PHP_EOL; } else { echo 'SKIP', PHP_EOL; } } class MyObj { private $data = null; private $priv = "privdata"; public $pdata = null; public $subary = null; function __construct() { $this->data = "datadata"; $this->subary = array(new SubObj()); } } class SubObj { private $subdata = null; private $subpriv = "subprivdata"; public $subpdata = null; function __construct() { $this->subdata = "subdatadata"; } } $obj0 = new MyObj(); $obj0->pdata = "pubdata0"; $obj0->subary[0]->subpdata = "subpubdata00"; $subobj01 = new SubObj(); $subobj01->subpdata = "subpdata01"; $obj0->subary[1] = $subobj01; $obj1 = new MyObj(); $obj1->pdata = "pubdata1"; $obj1->subary[0]->subpdata = "subpubdata1"; $subobj11 = new SubObj(); $subobj11->subpdata = "subpdata11"; $obj1->subary[1] = $subobj11; $ary = array($obj0, $obj1); $tpl = array(new MyObj()); test("recursive object list with object list /w instance", $ary, $tpl, $ary); --EXPECTF-- array(2) { [0]=> object(MyObj)#%d (4) { [%r"?data"?:("MyObj":)?private"?%r]=> string(8) "datadata" [%r"?priv"?:("MyObj":)?private"?%r]=> string(8) "privdata" ["pdata"]=> string(8) "pubdata0" ["subary"]=> array(2) { [0]=> object(SubObj)#%d (3) { [%r"?subdata"?:("SubObj":)?private"?%r]=> string(11) "subdatadata" [%r"?subpriv"?:("SubObj":)?private"?%r]=> string(11) "subprivdata" ["subpdata"]=> string(12) "subpubdata00" } [1]=> object(SubObj)#%d (3) { [%r"?subdata"?:("SubObj":)?private"?%r]=> string(11) "subdatadata" [%r"?subpriv"?:("SubObj":)?private"?%r]=> string(11) "subprivdata" ["subpdata"]=> string(10) "subpdata01" } } } [1]=> object(MyObj)#%d (4) { [%r"?data"?:("MyObj":)?private"?%r]=> string(8) "datadata" [%r"?priv"?:("MyObj":)?private"?%r]=> string(8) "privdata" ["pdata"]=> string(8) "pubdata1" ["subary"]=> array(2) { [0]=> object(SubObj)#%d (3) { [%r"?subdata"?:("SubObj":)?private"?%r]=> string(11) "subdatadata" [%r"?subpriv"?:("SubObj":)?private"?%r]=> string(11) "subprivdata" ["subpdata"]=> string(11) "subpubdata1" } [1]=> object(SubObj)#%d (3) { [%r"?subdata"?:("SubObj":)?private"?%r]=> string(11) "subdatadata" [%r"?subpriv"?:("SubObj":)?private"?%r]=> string(11) "subprivdata" ["subpdata"]=> string(10) "subpdata11" } } } } OK msgpack-2.1.0beta1/tests/114.phpt0000644000175000001440000000662113577133502015277 0ustar mikeusers--TEST-- unpack of template converter: multiple class/variable: class unpacker (array) --SKIPIF-- pack($variable); $unserialized = $msgpack->unpack($serialized, $object); var_dump($unserialized); if ($result) { echo $unserialized == $result ? 'OK' : 'ERROR', PHP_EOL; } else { echo 'SKIP', PHP_EOL; } } class MyObj { private $data = null; private $priv = "privdata"; public $pdata = null; public $subary = null; function __construct() { $this->data = "datadata"; $this->subary = array(new SubObj()); } } class SubObj { private $subdata = null; private $subpriv = "subprivdata"; public $subpdata = null; function __construct() { $this->subdata = "subdatadata"; } } $arySubObj = array( "subdata" => "subdatadata", "subpriv" => "subprivdata", "subpdata" => null, ); $aryMyObj = array( "data" => "datadata", "priv" => "privdata", "pdata" => null, "subary" => array($arySubObj), ); $obj0 = new MyObj(); $obj0->pdata = "pubdata0"; $obj0->subary[0]->subpdata = "subpubdata00"; $subobj01 = new SubObj(); $subobj01->subpdata = "subpdata01"; $obj0->subary[1] = $subobj01; $obj1 = new MyObj(); $obj1->pdata = "pubdata1"; $obj1->subary[0]->subpdata = "subpubdata1"; $subobj11 = new SubObj(); $subobj11->subpdata = "subpdata11"; $obj1->subary[1] = $subobj11; $ary = array($obj0, $obj1); $tpl = array($aryMyObj); $resary = array($aryMyObj, $aryMyObj); $resary[0]["pdata"] = "pubdata0"; $resary[0]["subary"][] = $arySubObj; $resary[0]["subary"][0]["subpdata"] = "subpubdata00"; $resary[0]["subary"][1]["subpdata"] = "subpdata01"; $resary[1]["subary"][] = $arySubObj; $resary[1]["pdata"] = "pubdata1"; $resary[1]["subary"][0]["subpdata"] = "subpubdata1"; $resary[1]["subary"][1]["subpdata"] = "subpdata11"; test("recursive object list to associative array list", $ary, $tpl, $resary); --EXPECTF-- array(2) { [0]=> array(4) { ["data"]=> string(8) "datadata" ["priv"]=> string(8) "privdata" ["pdata"]=> string(8) "pubdata0" ["subary"]=> array(2) { [0]=> array(3) { ["subdata"]=> string(11) "subdatadata" ["subpriv"]=> string(11) "subprivdata" ["subpdata"]=> string(12) "subpubdata00" } [1]=> array(3) { ["subdata"]=> string(11) "subdatadata" ["subpriv"]=> string(11) "subprivdata" ["subpdata"]=> string(10) "subpdata01" } } } [1]=> array(4) { ["data"]=> string(8) "datadata" ["priv"]=> string(8) "privdata" ["pdata"]=> string(8) "pubdata1" ["subary"]=> array(2) { [0]=> array(3) { ["subdata"]=> string(11) "subdatadata" ["subpriv"]=> string(11) "subprivdata" ["subpdata"]=> string(11) "subpubdata1" } [1]=> array(3) { ["subdata"]=> string(11) "subdatadata" ["subpriv"]=> string(11) "subprivdata" ["subpdata"]=> string(10) "subpdata11" } } } } OK msgpack-2.1.0beta1/tests/115.phpt0000644000175000001440000000305113577133502015272 0ustar mikeusers--TEST-- unpack of template converter: class unpacker (array: string: OPT_PHPONLY=false) --SKIPIF-- 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; } } class MyObj { private $data = null; private $priv = "privdata"; public $pdata = null; function __construct() { $this->data = "datadata"; } } $obj = new MyObj(); $obj->pdata = "pubdata0"; $obj2 = new MyObj(); $obj2->pdata = "pubdata1"; $ary = array($obj, $obj2); $tpl = array("MyObj"); test("object list /w string", $ary, $tpl, $ary); --EXPECTF-- array(2) { [0]=> object(MyObj)#%d (3) { [%r"?data"?:("MyObj":)?private"?%r]=> string(8) "datadata" [%r"?priv"?:("MyObj":)?private"?%r]=> string(8) "privdata" ["pdata"]=> string(8) "pubdata0" } [1]=> object(MyObj)#%d (3) { [%r"?data"?:("MyObj":)?private"?%r]=> string(8) "datadata" [%r"?priv"?:("MyObj":)?private"?%r]=> string(8) "privdata" ["pdata"]=> string(8) "pubdata1" } } OK msgpack-2.1.0beta1/tests/116.phpt0000644000175000001440000000305713577133502015301 0ustar mikeusers--TEST-- unpack of template converter: class unpacker (array: object: OPT_PHPONLY=false) --SKIPIF-- 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; } } class MyObj { private $data = null; private $priv = "privdata"; public $pdata = null; function __construct() { $this->data = "datadata"; } } $obj = new MyObj(); $obj->pdata = "pubdata0"; $obj2 = new MyObj(); $obj2->pdata = "pubdata1"; $ary = array($obj, $obj2); $tpl = array(new MyObj()); test("object list /w instance", $ary, $tpl, $ary); --EXPECTF-- array(2) { [0]=> object(MyObj)#%d (3) { [%r"?data"?:("MyObj":)?private"?%r]=> string(8) "datadata" [%r"?priv"?:("MyObj":)?private"?%r]=> string(8) "privdata" ["pdata"]=> string(8) "pubdata0" } [1]=> object(MyObj)#%d (3) { [%r"?data"?:("MyObj":)?private"?%r]=> string(8) "datadata" [%r"?priv"?:("MyObj":)?private"?%r]=> string(8) "privdata" ["pdata"]=> string(8) "pubdata1" } } OK msgpack-2.1.0beta1/tests/117.phpt0000644000175000001440000000336513577133502015304 0ustar mikeusers--TEST-- unpack of template converter: class unpacker (string: OPT_PHPONLY=false) --SKIPIF-- 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; } } class MyObj { private $data = null; private $priv = "privdata"; public $pdata = null; public $subary = null; function __construct() { $this->data = "datadata"; $this->subary = new SubObj(); } } class SubObj { private $subdata = null; private $subpriv = "subprivdata"; public $subpdata = null; function __construct() { $this->subdata = "subdatadata"; } } $obj = new MyObj(); $obj->pdata = "pubdata"; $obj->subary->subpdata = "subpubdata"; $tpl = "MyObj"; test("recursive object /w string", $obj, $tpl, $obj); --EXPECTF-- object(MyObj)#%d (4) { [%r"?data"?:("MyObj":)?private"?%r]=> string(8) "datadata" [%r"?priv"?:("MyObj":)?private"?%r]=> string(8) "privdata" ["pdata"]=> string(7) "pubdata" ["subary"]=> object(SubObj)#%d (3) { [%r"?subdata"?:("SubObj":)?private"?%r]=> string(11) "subdatadata" [%r"?subpriv"?:("SubObj":)?private"?%r]=> string(11) "subprivdata" ["subpdata"]=> string(10) "subpubdata" } } OK msgpack-2.1.0beta1/tests/118.phpt0000644000175000001440000000337313577133502015304 0ustar mikeusers--TEST-- unpack of template converter: class unpacker (object: OPT_PHPONLY=false) --SKIPIF-- 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; } } class MyObj { private $data = null; private $priv = "privdata"; public $pdata = null; public $subary = null; function __construct() { $this->data = "datadata"; $this->subary = new SubObj(); } } class SubObj { private $subdata = null; private $subpriv = "subprivdata"; public $subpdata = null; function __construct() { $this->subdata = "subdatadata"; } } $obj = new MyObj(); $obj->pdata = "pubdata"; $obj->subary->subpdata = "subpubdata"; $tpl = new MyObj(); test("recursive object /w instance", $obj, $tpl, $obj); --EXPECTF-- object(MyObj)#%d (4) { [%r"?data"?:("MyObj":)?private"?%r]=> string(8) "datadata" [%r"?priv"?:("MyObj":)?private"?%r]=> string(8) "privdata" ["pdata"]=> string(7) "pubdata" ["subary"]=> object(SubObj)#%d (3) { [%r"?subdata"?:("SubObj":)?private"?%r]=> string(11) "subdatadata" [%r"?subpriv"?:("SubObj":)?private"?%r]=> string(11) "subprivdata" ["subpdata"]=> string(10) "subpubdata" } } OK msgpack-2.1.0beta1/tests/119.phpt0000644000175000001440000000356013577133502015303 0ustar mikeusers--TEST-- unpack of template converter: multiple class: class unpacker (array: string: OPT_PHPONLY=false) --SKIPIF-- 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; } } class MyObj { private $data = null; private $priv = "privdata"; public $pdata = null; public $subary = null; function __construct() { $this->data = "datadata"; $this->subary = new SubObj(); } } class SubObj { private $subdata = null; private $subpriv = "subprivdata"; public $subpdata = null; function __construct() { $this->subdata = "subdatadata"; } } $obj = new MyObj(); $obj->pdata = "pubdata"; $obj->subary->subpdata = "subpubdata"; $ary = array($obj); $tpl = array("MyObj"); test("recursive object with object list /w string", $ary, $tpl, $ary); --EXPECTF-- array(1) { [0]=> object(MyObj)#%d (4) { [%r"?data"?:("MyObj":)?private"?%r]=> string(8) "datadata" [%r"?priv"?:("MyObj":)?private"?%r]=> string(8) "privdata" ["pdata"]=> string(7) "pubdata" ["subary"]=> object(SubObj)#%d (3) { [%r"?subdata"?:("SubObj":)?private"?%r]=> string(11) "subdatadata" [%r"?subpriv"?:("SubObj":)?private"?%r]=> string(11) "subprivdata" ["subpdata"]=> string(10) "subpubdata" } } } OK msgpack-2.1.0beta1/tests/120.phpt0000644000175000001440000000356613577133502015301 0ustar mikeusers--TEST-- unpack of template converter: multiple class: class unpacker (array: object: OPT_PHPONLY=false) --SKIPIF-- 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; } } class MyObj { private $data = null; private $priv = "privdata"; public $pdata = null; public $subary = null; function __construct() { $this->data = "datadata"; $this->subary = new SubObj(); } } class SubObj { private $subdata = null; private $subpriv = "subprivdata"; public $subpdata = null; function __construct() { $this->subdata = "subdatadata"; } } $obj = new MyObj(); $obj->pdata = "pubdata"; $obj->subary->subpdata = "subpubdata"; $ary = array($obj); $tpl = array(new MyObj()); test("recursive object with object list /w instance", $ary, $tpl, $ary); --EXPECTF-- array(1) { [0]=> object(MyObj)#%d (4) { [%r"?data"?:("MyObj":)?private"?%r]=> string(8) "datadata" [%r"?priv"?:("MyObj":)?private"?%r]=> string(8) "privdata" ["pdata"]=> string(7) "pubdata" ["subary"]=> object(SubObj)#%d (3) { [%r"?subdata"?:("SubObj":)?private"?%r]=> string(11) "subdatadata" [%r"?subpriv"?:("SubObj":)?private"?%r]=> string(11) "subprivdata" ["subpdata"]=> string(10) "subpubdata" } } } OK msgpack-2.1.0beta1/tests/121.phpt0000644000175000001440000000465013577133502015275 0ustar mikeusers--TEST-- unpack of template converter: multiple variable: class unpacker (array: string: OPT_PHPONLY=false) --SKIPIF-- 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; } } class MyObj { private $data = null; private $priv = "privdata"; public $pdata = null; public $subary = null; function __construct() { $this->data = "datadata"; $this->subary = new SubObj(); } } class SubObj { private $subdata = null; private $subpriv = "subprivdata"; public $subpdata = null; function __construct() { $this->subdata = "subdatadata"; } } $obj0 = new MyObj(); $obj0->pdata = "pubdata0"; $obj0->subary->subpdata = "subpubdata0"; $obj1 = new MyObj(); $obj1->pdata = "pubdata1"; $obj1->subary->subpdata = "subpubdata1"; $ary = array($obj0, $obj1); $tpl = array("MyObj"); test("recursive object list /w string", $ary, $tpl, $ary); --EXPECTF-- array(2) { [0]=> object(MyObj)#%d (4) { [%r"?data"?:("MyObj":)?private"?%r]=> string(8) "datadata" [%r"?priv"?:("MyObj":)?private"?%r]=> string(8) "privdata" ["pdata"]=> string(8) "pubdata0" ["subary"]=> object(SubObj)#%d (3) { [%r"?subdata"?:("SubObj":)?private"?%r]=> string(11) "subdatadata" [%r"?subpriv"?:("SubObj":)?private"?%r]=> string(11) "subprivdata" ["subpdata"]=> string(11) "subpubdata0" } } [1]=> object(MyObj)#%d (4) { [%r"?data"?:("MyObj":)?private"?%r]=> string(8) "datadata" [%r"?priv"?:("MyObj":)?private"?%r]=> string(8) "privdata" ["pdata"]=> string(8) "pubdata1" ["subary"]=> object(SubObj)#%d (3) { [%r"?subdata"?:("SubObj":)?private"?%r]=> string(11) "subdatadata" [%r"?subpriv"?:("SubObj":)?private"?%r]=> string(11) "subprivdata" ["subpdata"]=> string(11) "subpubdata1" } } } OK msgpack-2.1.0beta1/tests/122.phpt0000644000175000001440000000465613577133502015304 0ustar mikeusers--TEST-- unpack of template converter: multiple variable: class unpacker (array: object: OPT_PHPONLY=false) --SKIPIF-- 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; } } class MyObj { private $data = null; private $priv = "privdata"; public $pdata = null; public $subary = null; function __construct() { $this->data = "datadata"; $this->subary = new SubObj(); } } class SubObj { private $subdata = null; private $subpriv = "subprivdata"; public $subpdata = null; function __construct() { $this->subdata = "subdatadata"; } } $obj0 = new MyObj(); $obj0->pdata = "pubdata0"; $obj0->subary->subpdata = "subpubdata0"; $obj1 = new MyObj(); $obj1->pdata = "pubdata1"; $obj1->subary->subpdata = "subpubdata1"; $ary = array($obj0, $obj1); $tpl = array(new MyObj()); test("recursive object list /w instance", $ary, $tpl, $ary); --EXPECTF-- array(2) { [0]=> object(MyObj)#%d (4) { [%r"?data"?:("MyObj":)?private"?%r]=> string(8) "datadata" [%r"?priv"?:("MyObj":)?private"?%r]=> string(8) "privdata" ["pdata"]=> string(8) "pubdata0" ["subary"]=> object(SubObj)#%d (3) { [%r"?subdata"?:("SubObj":)?private"?%r]=> string(11) "subdatadata" [%r"?subpriv"?:("SubObj":)?private"?%r]=> string(11) "subprivdata" ["subpdata"]=> string(11) "subpubdata0" } } [1]=> object(MyObj)#%d (4) { [%r"?data"?:("MyObj":)?private"?%r]=> string(8) "datadata" [%r"?priv"?:("MyObj":)?private"?%r]=> string(8) "privdata" ["pdata"]=> string(8) "pubdata1" ["subary"]=> object(SubObj)#%d (3) { [%r"?subdata"?:("SubObj":)?private"?%r]=> string(11) "subdatadata" [%r"?subpriv"?:("SubObj":)?private"?%r]=> string(11) "subprivdata" ["subpdata"]=> string(11) "subpubdata1" } } } OK msgpack-2.1.0beta1/tests/123.phpt0000644000175000001440000000640613577133502015300 0ustar mikeusers--TEST-- unpack of template converter: multiple class/variable: class unpacker (array: string: OPT_PHPONLY=false) --SKIPIF-- 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; } } class MyObj { private $data = null; private $priv = "privdata"; public $pdata = null; public $subary = null; function __construct() { $this->data = "datadata"; $this->subary = array(new SubObj()); } } class SubObj { private $subdata = null; private $subpriv = "subprivdata"; public $subpdata = null; function __construct() { $this->subdata = "subdatadata"; } } $obj0 = new MyObj(); $obj0->pdata = "pubdata0"; $obj0->subary[0]->subpdata = "subpubdata00"; $subobj01 = new SubObj(); $subobj01->subpdata = "subpdata01"; $obj0->subary[1] = $subobj01; $obj1 = new MyObj(); $obj1->pdata = "pubdata1"; $obj1->subary[0]->subpdata = "subpubdata1"; $subobj11 = new SubObj(); $subobj11->subpdata = "subpdata11"; $obj1->subary[1] = $subobj11; $ary = array($obj0, $obj1); $tpl = array("MyObj"); test("recursive object list with object list /w string", $ary, $tpl, $ary); --EXPECTF-- array(2) { [0]=> object(MyObj)#%d (4) { [%r"?data"?:("MyObj":)?private"?%r]=> string(8) "datadata" [%r"?priv"?:("MyObj":)?private"?%r]=> string(8) "privdata" ["pdata"]=> string(8) "pubdata0" ["subary"]=> array(2) { [0]=> object(SubObj)#%d (3) { [%r"?subdata"?:("SubObj":)?private"?%r]=> string(11) "subdatadata" [%r"?subpriv"?:("SubObj":)?private"?%r]=> string(11) "subprivdata" ["subpdata"]=> string(12) "subpubdata00" } [1]=> object(SubObj)#%d (3) { [%r"?subdata"?:("SubObj":)?private"?%r]=> string(11) "subdatadata" [%r"?subpriv"?:("SubObj":)?private"?%r]=> string(11) "subprivdata" ["subpdata"]=> string(10) "subpdata01" } } } [1]=> object(MyObj)#%d (4) { [%r"?data"?:("MyObj":)?private"?%r]=> string(8) "datadata" [%r"?priv"?:("MyObj":)?private"?%r]=> string(8) "privdata" ["pdata"]=> string(8) "pubdata1" ["subary"]=> array(2) { [0]=> object(SubObj)#%d (3) { [%r"?subdata"?:("SubObj":)?private"?%r]=> string(11) "subdatadata" [%r"?subpriv"?:("SubObj":)?private"?%r]=> string(11) "subprivdata" ["subpdata"]=> string(11) "subpubdata1" } [1]=> object(SubObj)#%d (3) { [%r"?subdata"?:("SubObj":)?private"?%r]=> string(11) "subdatadata" [%r"?subpriv"?:("SubObj":)?private"?%r]=> string(11) "subprivdata" ["subpdata"]=> string(10) "subpdata11" } } } } OK msgpack-2.1.0beta1/tests/124.phpt0000644000175000001440000000641413577133502015300 0ustar mikeusers--TEST-- unpack of template converter: multiple class/variable: class unpacker (array: object: OPT_PHPONLY=false) --SKIPIF-- 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; } } class MyObj { private $data = null; private $priv = "privdata"; public $pdata = null; public $subary = null; function __construct() { $this->data = "datadata"; $this->subary = array(new SubObj()); } } class SubObj { private $subdata = null; private $subpriv = "subprivdata"; public $subpdata = null; function __construct() { $this->subdata = "subdatadata"; } } $obj0 = new MyObj(); $obj0->pdata = "pubdata0"; $obj0->subary[0]->subpdata = "subpubdata00"; $subobj01 = new SubObj(); $subobj01->subpdata = "subpdata01"; $obj0->subary[1] = $subobj01; $obj1 = new MyObj(); $obj1->pdata = "pubdata1"; $obj1->subary[0]->subpdata = "subpubdata1"; $subobj11 = new SubObj(); $subobj11->subpdata = "subpdata11"; $obj1->subary[1] = $subobj11; $ary = array($obj0, $obj1); $tpl = array(new MyObj()); test("recursive object list with object list /w instance", $ary, $tpl, $ary); --EXPECTF-- array(2) { [0]=> object(MyObj)#%d (4) { [%r"?data"?:("MyObj":)?private"?%r]=> string(8) "datadata" [%r"?priv"?:("MyObj":)?private"?%r]=> string(8) "privdata" ["pdata"]=> string(8) "pubdata0" ["subary"]=> array(2) { [0]=> object(SubObj)#%d (3) { [%r"?subdata"?:("SubObj":)?private"?%r]=> string(11) "subdatadata" [%r"?subpriv"?:("SubObj":)?private"?%r]=> string(11) "subprivdata" ["subpdata"]=> string(12) "subpubdata00" } [1]=> object(SubObj)#%d (3) { [%r"?subdata"?:("SubObj":)?private"?%r]=> string(11) "subdatadata" [%r"?subpriv"?:("SubObj":)?private"?%r]=> string(11) "subprivdata" ["subpdata"]=> string(10) "subpdata01" } } } [1]=> object(MyObj)#%d (4) { [%r"?data"?:("MyObj":)?private"?%r]=> string(8) "datadata" [%r"?priv"?:("MyObj":)?private"?%r]=> string(8) "privdata" ["pdata"]=> string(8) "pubdata1" ["subary"]=> array(2) { [0]=> object(SubObj)#%d (3) { [%r"?subdata"?:("SubObj":)?private"?%r]=> string(11) "subdatadata" [%r"?subpriv"?:("SubObj":)?private"?%r]=> string(11) "subprivdata" ["subpdata"]=> string(11) "subpubdata1" } [1]=> object(SubObj)#%d (3) { [%r"?subdata"?:("SubObj":)?private"?%r]=> string(11) "subdatadata" [%r"?subpriv"?:("SubObj":)?private"?%r]=> string(11) "subprivdata" ["subpdata"]=> string(10) "subpdata11" } } } } OK msgpack-2.1.0beta1/tests/125.phpt0000644000175000001440000000673613577133502015310 0ustar mikeusers--TEST-- unpack of template converter: multiple class/variable: class unpacker (array: OPT_PHPONLY=false) --SKIPIF-- 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; } } class MyObj { private $data = null; private $priv = "privdata"; public $pdata = null; public $subary = null; function __construct() { $this->data = "datadata"; $this->subary = array(new SubObj()); } } class SubObj { private $subdata = null; private $subpriv = "subprivdata"; public $subpdata = null; function __construct() { $this->subdata = "subdatadata"; } } $arySubObj = array( "subdata" => "subdatadata", "subpriv" => "subprivdata", "subpdata" => null, ); $aryMyObj = array( "data" => "datadata", "priv" => "privdata", "pdata" => null, "subary" => array($arySubObj), ); $obj0 = new MyObj(); $obj0->pdata = "pubdata0"; $obj0->subary[0]->subpdata = "subpubdata00"; $subobj01 = new SubObj(); $subobj01->subpdata = "subpdata01"; $obj0->subary[1] = $subobj01; $obj1 = new MyObj(); $obj1->pdata = "pubdata1"; $obj1->subary[0]->subpdata = "subpubdata1"; $subobj11 = new SubObj(); $subobj11->subpdata = "subpdata11"; $obj1->subary[1] = $subobj11; $ary = array($obj0, $obj1); $tpl = array($aryMyObj); $resary = array($aryMyObj, $aryMyObj); $resary[0]["pdata"] = "pubdata0"; $resary[0]["subary"][] = $arySubObj; $resary[0]["subary"][0]["subpdata"] = "subpubdata00"; $resary[0]["subary"][1]["subpdata"] = "subpdata01"; $resary[1]["subary"][] = $arySubObj; $resary[1]["pdata"] = "pubdata1"; $resary[1]["subary"][0]["subpdata"] = "subpubdata1"; $resary[1]["subary"][1]["subpdata"] = "subpdata11"; test("recursive object list to associative array list", $ary, $tpl, $resary); --EXPECTF-- array(2) { [0]=> array(4) { ["data"]=> string(8) "datadata" ["priv"]=> string(8) "privdata" ["pdata"]=> string(8) "pubdata0" ["subary"]=> array(2) { [0]=> array(3) { ["subdata"]=> string(11) "subdatadata" ["subpriv"]=> string(11) "subprivdata" ["subpdata"]=> string(12) "subpubdata00" } [1]=> array(3) { ["subdata"]=> string(11) "subdatadata" ["subpriv"]=> string(11) "subprivdata" ["subpdata"]=> string(10) "subpdata01" } } } [1]=> array(4) { ["data"]=> string(8) "datadata" ["priv"]=> string(8) "privdata" ["pdata"]=> string(8) "pubdata1" ["subary"]=> array(2) { [0]=> array(3) { ["subdata"]=> string(11) "subdatadata" ["subpriv"]=> string(11) "subprivdata" ["subpdata"]=> string(11) "subpubdata1" } [1]=> array(3) { ["subdata"]=> string(11) "subdatadata" ["subpriv"]=> string(11) "subprivdata" ["subpdata"]=> string(10) "subpdata11" } } } } OK msgpack-2.1.0beta1/tests/126.phpt0000644000175000001440000000264413577133502015303 0ustar mikeusers--TEST-- unpack of template converter (array: string) --SKIPIF-- data = "datadata"; } } $obj = new MyObj(); $obj->pdata = "pubdata0"; $obj2 = new MyObj(); $obj2->pdata = "pubdata1"; $ary = array($obj, $obj2); $tpl = array("MyObj"); test("object list /w string", $ary, $tpl, $ary); --EXPECTF-- array(2) { [0]=> object(MyObj)#%d (3) { [%r"?data"?:("MyObj":)?private"?%r]=> string(8) "datadata" [%r"?priv"?:("MyObj":)?private"?%r]=> string(8) "privdata" ["pdata"]=> string(8) "pubdata0" } [1]=> object(MyObj)#%d (3) { [%r"?data"?:("MyObj":)?private"?%r]=> string(8) "datadata" [%r"?priv"?:("MyObj":)?private"?%r]=> string(8) "privdata" ["pdata"]=> string(8) "pubdata1" } } OK msgpack-2.1.0beta1/tests/127.phpt0000644000175000001440000000265213577133502015303 0ustar mikeusers--TEST-- unpack of template converter (array: object) --SKIPIF-- data = "datadata"; } } $obj = new MyObj(); $obj->pdata = "pubdata0"; $obj2 = new MyObj(); $obj2->pdata = "pubdata1"; $ary = array($obj, $obj2); $tpl = array(new MyObj()); test("object list /w instance", $ary, $tpl, $ary); --EXPECTF-- array(2) { [0]=> object(MyObj)#%d (3) { [%r"?data"?:("MyObj":)?private"?%r]=> string(8) "datadata" [%r"?priv"?:("MyObj":)?private"?%r]=> string(8) "privdata" ["pdata"]=> string(8) "pubdata0" } [1]=> object(MyObj)#%d (3) { [%r"?data"?:("MyObj":)?private"?%r]=> string(8) "datadata" [%r"?priv"?:("MyObj":)?private"?%r]=> string(8) "privdata" ["pdata"]=> string(8) "pubdata1" } } OK msgpack-2.1.0beta1/tests/128.phpt0000644000175000001440000000316013577133502015277 0ustar mikeusers--TEST-- unpack of template converter (string) --SKIPIF-- data = "datadata"; $this->subary = new SubObj(); } } class SubObj { private $subdata = null; private $subpriv = "subprivdata"; public $subpdata = null; function __construct() { $this->subdata = "subdatadata"; } } $obj = new MyObj(); $obj->pdata = "pubdata"; $obj->subary->subpdata = "subpubdata"; $tpl = "MyObj"; test("recursive object /w string", $obj, $tpl, $obj); --EXPECTF-- object(MyObj)#%d (4) { [%r"?data"?:("MyObj":)?private"?%r]=> string(8) "datadata" [%r"?priv"?:("MyObj":)?private"?%r]=> string(8) "privdata" ["pdata"]=> string(7) "pubdata" ["subary"]=> object(SubObj)#%d (3) { [%r"?subdata"?:("SubObj":)?private"?%r]=> string(11) "subdatadata" [%r"?subpriv"?:("SubObj":)?private"?%r]=> string(11) "subprivdata" ["subpdata"]=> string(10) "subpubdata" } } OK msgpack-2.1.0beta1/tests/129.phpt0000644000175000001440000000316613577133502015306 0ustar mikeusers--TEST-- unpack of template converter (object) --SKIPIF-- data = "datadata"; $this->subary = new SubObj(); } } class SubObj { private $subdata = null; private $subpriv = "subprivdata"; public $subpdata = null; function __construct() { $this->subdata = "subdatadata"; } } $obj = new MyObj(); $obj->pdata = "pubdata"; $obj->subary->subpdata = "subpubdata"; $tpl = new MyObj(); test("recursive object /w instance", $obj, $tpl, $obj); --EXPECTF-- object(MyObj)#%d (4) { [%r"?data"?:("MyObj":)?private"?%r]=> string(8) "datadata" [%r"?priv"?:("MyObj":)?private"?%r]=> string(8) "privdata" ["pdata"]=> string(7) "pubdata" ["subary"]=> object(SubObj)#%d (3) { [%r"?subdata"?:("SubObj":)?private"?%r]=> string(11) "subdatadata" [%r"?subpriv"?:("SubObj":)?private"?%r]=> string(11) "subprivdata" ["subpdata"]=> string(10) "subpubdata" } } OK msgpack-2.1.0beta1/tests/130.phpt0000644000175000001440000000335413577133502015275 0ustar mikeusers--TEST-- unpack of template converter: multiple class: (array: string) --SKIPIF-- data = "datadata"; $this->subary = new SubObj(); } } class SubObj { private $subdata = null; private $subpriv = "subprivdata"; public $subpdata = null; function __construct() { $this->subdata = "subdatadata"; } } $obj = new MyObj(); $obj->pdata = "pubdata"; $obj->subary->subpdata = "subpubdata"; $ary = array($obj); $tpl = array("MyObj"); test("recursive object with object list /w string", $ary, $tpl, $ary); --EXPECTF-- array(1) { [0]=> object(MyObj)#%d (4) { [%r"?data"?:("MyObj":)?private"?%r]=> string(8) "datadata" [%r"?priv"?:("MyObj":)?private"?%r]=> string(8) "privdata" ["pdata"]=> string(7) "pubdata" ["subary"]=> object(SubObj)#%d (3) { [%r"?subdata"?:("SubObj":)?private"?%r]=> string(11) "subdatadata" [%r"?subpriv"?:("SubObj":)?private"?%r]=> string(11) "subprivdata" ["subpdata"]=> string(10) "subpubdata" } } } OK msgpack-2.1.0beta1/tests/131.phpt0000644000175000001440000000336213577133502015275 0ustar mikeusers--TEST-- unpack of template converter: multiple class: (array: object) --SKIPIF-- data = "datadata"; $this->subary = new SubObj(); } } class SubObj { private $subdata = null; private $subpriv = "subprivdata"; public $subpdata = null; function __construct() { $this->subdata = "subdatadata"; } } $obj = new MyObj(); $obj->pdata = "pubdata"; $obj->subary->subpdata = "subpubdata"; $ary = array($obj); $tpl = array(new MyObj()); test("recursive object with object list /w instance", $ary, $tpl, $ary); --EXPECTF-- array(1) { [0]=> object(MyObj)#%d (4) { [%r"?data"?:("MyObj":)?private"?%r]=> string(8) "datadata" [%r"?priv"?:("MyObj":)?private"?%r]=> string(8) "privdata" ["pdata"]=> string(7) "pubdata" ["subary"]=> object(SubObj)#%d (3) { [%r"?subdata"?:("SubObj":)?private"?%r]=> string(11) "subdatadata" [%r"?subpriv"?:("SubObj":)?private"?%r]=> string(11) "subprivdata" ["subpdata"]=> string(10) "subpubdata" } } } OK msgpack-2.1.0beta1/tests/132.phpt0000644000175000001440000000444413577133502015300 0ustar mikeusers--TEST-- unpack of template converter: multiple variable: (array: string) --SKIPIF-- data = "datadata"; $this->subary = new SubObj(); } } class SubObj { private $subdata = null; private $subpriv = "subprivdata"; public $subpdata = null; function __construct() { $this->subdata = "subdatadata"; } } $obj0 = new MyObj(); $obj0->pdata = "pubdata0"; $obj0->subary->subpdata = "subpubdata0"; $obj1 = new MyObj(); $obj1->pdata = "pubdata1"; $obj1->subary->subpdata = "subpubdata1"; $ary = array($obj0, $obj1); $tpl = array("MyObj"); test("recursive object list /w string", $ary, $tpl, $ary); --EXPECTF-- array(2) { [0]=> object(MyObj)#%d (4) { [%r"?data"?:("MyObj":)?private"?%r]=> string(8) "datadata" [%r"?priv"?:("MyObj":)?private"?%r]=> string(8) "privdata" ["pdata"]=> string(8) "pubdata0" ["subary"]=> object(SubObj)#%d (3) { [%r"?subdata"?:("SubObj":)?private"?%r]=> string(11) "subdatadata" [%r"?subpriv"?:("SubObj":)?private"?%r]=> string(11) "subprivdata" ["subpdata"]=> string(11) "subpubdata0" } } [1]=> object(MyObj)#%d (4) { [%r"?data"?:("MyObj":)?private"?%r]=> string(8) "datadata" [%r"?priv"?:("MyObj":)?private"?%r]=> string(8) "privdata" ["pdata"]=> string(8) "pubdata1" ["subary"]=> object(SubObj)#%d (3) { [%r"?subdata"?:("SubObj":)?private"?%r]=> string(11) "subdatadata" [%r"?subpriv"?:("SubObj":)?private"?%r]=> string(11) "subprivdata" ["subpdata"]=> string(11) "subpubdata1" } } } OK msgpack-2.1.0beta1/tests/133.phpt0000644000175000001440000000445213577133502015300 0ustar mikeusers--TEST-- unpack of template converter: multiple variable: (array: object) --SKIPIF-- data = "datadata"; $this->subary = new SubObj(); } } class SubObj { private $subdata = null; private $subpriv = "subprivdata"; public $subpdata = null; function __construct() { $this->subdata = "subdatadata"; } } $obj0 = new MyObj(); $obj0->pdata = "pubdata0"; $obj0->subary->subpdata = "subpubdata0"; $obj1 = new MyObj(); $obj1->pdata = "pubdata1"; $obj1->subary->subpdata = "subpubdata1"; $ary = array($obj0, $obj1); $tpl = array(new MyObj()); test("recursive object list /w instance", $ary, $tpl, $ary); --EXPECTF-- array(2) { [0]=> object(MyObj)#%d (4) { [%r"?data"?:("MyObj":)?private"?%r]=> string(8) "datadata" [%r"?priv"?:("MyObj":)?private"?%r]=> string(8) "privdata" ["pdata"]=> string(8) "pubdata0" ["subary"]=> object(SubObj)#%d (3) { [%r"?subdata"?:("SubObj":)?private"?%r]=> string(11) "subdatadata" [%r"?subpriv"?:("SubObj":)?private"?%r]=> string(11) "subprivdata" ["subpdata"]=> string(11) "subpubdata0" } } [1]=> object(MyObj)#%d (4) { [%r"?data"?:("MyObj":)?private"?%r]=> string(8) "datadata" [%r"?priv"?:("MyObj":)?private"?%r]=> string(8) "privdata" ["pdata"]=> string(8) "pubdata1" ["subary"]=> object(SubObj)#%d (3) { [%r"?subdata"?:("SubObj":)?private"?%r]=> string(11) "subdatadata" [%r"?subpriv"?:("SubObj":)?private"?%r]=> string(11) "subprivdata" ["subpdata"]=> string(11) "subpubdata1" } } } OK msgpack-2.1.0beta1/tests/134.phpt0000644000175000001440000000620213577133502015274 0ustar mikeusers--TEST-- unpack of template converter: multiple class/variable: (array: string) --SKIPIF-- data = "datadata"; $this->subary = array(new SubObj()); } } class SubObj { private $subdata = null; private $subpriv = "subprivdata"; public $subpdata = null; function __construct() { $this->subdata = "subdatadata"; } } $obj0 = new MyObj(); $obj0->pdata = "pubdata0"; $obj0->subary[0]->subpdata = "subpubdata00"; $subobj01 = new SubObj(); $subobj01->subpdata = "subpdata01"; $obj0->subary[1] = $subobj01; $obj1 = new MyObj(); $obj1->pdata = "pubdata1"; $obj1->subary[0]->subpdata = "subpubdata1"; $subobj11 = new SubObj(); $subobj11->subpdata = "subpdata11"; $obj1->subary[1] = $subobj11; $ary = array($obj0, $obj1); $tpl = array("MyObj"); test("recursive object list with object list /w string", $ary, $tpl, $ary); --EXPECTF-- array(2) { [0]=> object(MyObj)#%d (4) { [%r"?data"?:("MyObj":)?private"?%r]=> string(8) "datadata" [%r"?priv"?:("MyObj":)?private"?%r]=> string(8) "privdata" ["pdata"]=> string(8) "pubdata0" ["subary"]=> array(2) { [0]=> object(SubObj)#%d (3) { [%r"?subdata"?:("SubObj":)?private"?%r]=> string(11) "subdatadata" [%r"?subpriv"?:("SubObj":)?private"?%r]=> string(11) "subprivdata" ["subpdata"]=> string(12) "subpubdata00" } [1]=> object(SubObj)#%d (3) { [%r"?subdata"?:("SubObj":)?private"?%r]=> string(11) "subdatadata" [%r"?subpriv"?:("SubObj":)?private"?%r]=> string(11) "subprivdata" ["subpdata"]=> string(10) "subpdata01" } } } [1]=> object(MyObj)#%d (4) { [%r"?data"?:("MyObj":)?private"?%r]=> string(8) "datadata" [%r"?priv"?:("MyObj":)?private"?%r]=> string(8) "privdata" ["pdata"]=> string(8) "pubdata1" ["subary"]=> array(2) { [0]=> object(SubObj)#%d (3) { [%r"?subdata"?:("SubObj":)?private"?%r]=> string(11) "subdatadata" [%r"?subpriv"?:("SubObj":)?private"?%r]=> string(11) "subprivdata" ["subpdata"]=> string(11) "subpubdata1" } [1]=> object(SubObj)#%d (3) { [%r"?subdata"?:("SubObj":)?private"?%r]=> string(11) "subdatadata" [%r"?subpriv"?:("SubObj":)?private"?%r]=> string(11) "subprivdata" ["subpdata"]=> string(10) "subpdata11" } } } } OK msgpack-2.1.0beta1/tests/135.phpt0000644000175000001440000000621013577133502015274 0ustar mikeusers--TEST-- unpack of template converter: multiple class/variable: (array: object) --SKIPIF-- data = "datadata"; $this->subary = array(new SubObj()); } } class SubObj { private $subdata = null; private $subpriv = "subprivdata"; public $subpdata = null; function __construct() { $this->subdata = "subdatadata"; } } $obj0 = new MyObj(); $obj0->pdata = "pubdata0"; $obj0->subary[0]->subpdata = "subpubdata00"; $subobj01 = new SubObj(); $subobj01->subpdata = "subpdata01"; $obj0->subary[1] = $subobj01; $obj1 = new MyObj(); $obj1->pdata = "pubdata1"; $obj1->subary[0]->subpdata = "subpubdata1"; $subobj11 = new SubObj(); $subobj11->subpdata = "subpdata11"; $obj1->subary[1] = $subobj11; $ary = array($obj0, $obj1); $tpl = array(new MyObj()); test("recursive object list with object list /w instance", $ary, $tpl, $ary); --EXPECTF-- array(2) { [0]=> object(MyObj)#%d (4) { [%r"?data"?:("MyObj":)?private"?%r]=> string(8) "datadata" [%r"?priv"?:("MyObj":)?private"?%r]=> string(8) "privdata" ["pdata"]=> string(8) "pubdata0" ["subary"]=> array(2) { [0]=> object(SubObj)#%d (3) { [%r"?subdata"?:("SubObj":)?private"?%r]=> string(11) "subdatadata" [%r"?subpriv"?:("SubObj":)?private"?%r]=> string(11) "subprivdata" ["subpdata"]=> string(12) "subpubdata00" } [1]=> object(SubObj)#%d (3) { [%r"?subdata"?:("SubObj":)?private"?%r]=> string(11) "subdatadata" [%r"?subpriv"?:("SubObj":)?private"?%r]=> string(11) "subprivdata" ["subpdata"]=> string(10) "subpdata01" } } } [1]=> object(MyObj)#%d (4) { [%r"?data"?:("MyObj":)?private"?%r]=> string(8) "datadata" [%r"?priv"?:("MyObj":)?private"?%r]=> string(8) "privdata" ["pdata"]=> string(8) "pubdata1" ["subary"]=> array(2) { [0]=> object(SubObj)#%d (3) { [%r"?subdata"?:("SubObj":)?private"?%r]=> string(11) "subdatadata" [%r"?subpriv"?:("SubObj":)?private"?%r]=> string(11) "subprivdata" ["subpdata"]=> string(11) "subpubdata1" } [1]=> object(SubObj)#%d (3) { [%r"?subdata"?:("SubObj":)?private"?%r]=> string(11) "subdatadata" [%r"?subpriv"?:("SubObj":)?private"?%r]=> string(11) "subprivdata" ["subpdata"]=> string(10) "subpdata11" } } } } OK msgpack-2.1.0beta1/tests/136.phpt0000644000175000001440000000653213577133502015304 0ustar mikeusers--TEST-- unpack of template converter: multiple class/variable: (array) --SKIPIF-- data = "datadata"; $this->subary = array(new SubObj()); } } class SubObj { private $subdata = null; private $subpriv = "subprivdata"; public $subpdata = null; function __construct() { $this->subdata = "subdatadata"; } } $arySubObj = array( "subdata" => "subdatadata", "subpriv" => "subprivdata", "subpdata" => null, ); $aryMyObj = array( "data" => "datadata", "priv" => "privdata", "pdata" => null, "subary" => array($arySubObj), ); $obj0 = new MyObj(); $obj0->pdata = "pubdata0"; $obj0->subary[0]->subpdata = "subpubdata00"; $subobj01 = new SubObj(); $subobj01->subpdata = "subpdata01"; $obj0->subary[1] = $subobj01; $obj1 = new MyObj(); $obj1->pdata = "pubdata1"; $obj1->subary[0]->subpdata = "subpubdata1"; $subobj11 = new SubObj(); $subobj11->subpdata = "subpdata11"; $obj1->subary[1] = $subobj11; $ary = array($obj0, $obj1); $tpl = array($aryMyObj); $resary = array($aryMyObj, $aryMyObj); $resary[0]["pdata"] = "pubdata0"; $resary[0]["subary"][] = $arySubObj; $resary[0]["subary"][0]["subpdata"] = "subpubdata00"; $resary[0]["subary"][1]["subpdata"] = "subpdata01"; $resary[1]["subary"][] = $arySubObj; $resary[1]["pdata"] = "pubdata1"; $resary[1]["subary"][0]["subpdata"] = "subpubdata1"; $resary[1]["subary"][1]["subpdata"] = "subpdata11"; test("recursive object list to associative array list", $ary, $tpl, $resary); --EXPECTF-- array(2) { [0]=> array(4) { ["data"]=> string(8) "datadata" ["priv"]=> string(8) "privdata" ["pdata"]=> string(8) "pubdata0" ["subary"]=> array(2) { [0]=> array(3) { ["subdata"]=> string(11) "subdatadata" ["subpriv"]=> string(11) "subprivdata" ["subpdata"]=> string(12) "subpubdata00" } [1]=> array(3) { ["subdata"]=> string(11) "subdatadata" ["subpriv"]=> string(11) "subprivdata" ["subpdata"]=> string(10) "subpdata01" } } } [1]=> array(4) { ["data"]=> string(8) "datadata" ["priv"]=> string(8) "privdata" ["pdata"]=> string(8) "pubdata1" ["subary"]=> array(2) { [0]=> array(3) { ["subdata"]=> string(11) "subdatadata" ["subpriv"]=> string(11) "subprivdata" ["subpdata"]=> string(11) "subpubdata1" } [1]=> array(3) { ["subdata"]=> string(11) "subdatadata" ["subpriv"]=> string(11) "subprivdata" ["subpdata"]=> string(10) "subpdata11" } } } } OK msgpack-2.1.0beta1/tests/137.phpt0000644000175000001440000000220213577133502015273 0ustar mikeusers--TEST-- unpack/pack str8 --INI-- msgpack.use_str8_serialization = 1 --SKIPIF-- --EXPECTF-- Simple test for short string - type str8 string(84) "d92853696d706c65207465737420666f722073686f727420737472696e67202d20747970652073747238" OK string(86) "da002853696d706c65207465737420666f722073686f727420737472696e67202d20747970652073747238" OK msgpack-2.1.0beta1/tests/138.phpt0000644000175000001440000000205213577133502015277 0ustar mikeusers--TEST-- unpack bin format family --SKIPIF-- --EXPECTF-- string(9) "bin8 test" OK string(10) "bin16 test" OK string(10) "bin32 test" OK msgpack-2.1.0beta1/tests/139.phpt0000644000175000001440000000472013577133502015304 0ustar mikeusers--TEST-- Null byte key position while unpacking objects --SKIPIF-- 'stdClass' $placeholder = hex2bin('a178a178'); // 'x' => 'x' $serialized = msgpack_pack($array); $serialized = str_replace($placeholder, $stdClass, $serialized); $unserialized = msgpack_unpack($serialized); var_dump($unserialized); unset($array['x']); echo $unserialized == (object) $array ? 'OK' : 'ERROR', PHP_EOL; } $array = array('x' => 'x', 'foo' => 1); test('single property, key at the beginning', $array); $array = array('foo' => 1, 'x' => 'x'); test('single property, key at the end', $array); $array = array('x' => 'x', 'foo' => 1, 'bar' => 2); test('multiple properties, key at the beginning', $array); $array = array('foo' => 1, 'x' => 'x', 'bar' => 2); test('multiple properties, key in the middle', $array); $array = array('foo' => 1, 'bar' => 2, 'x' => 'x'); test('multiple properties, key at the end', $array); $array = array('null' => null, 'x' => 'x'); test('null, key at the end', $array); $array = array('int' => 1, 'x' => 'x'); test('int, key at the end', $array); $array = array('float' => 4.2, 'x' => 'x'); test('float, key at the end', $array); $array = array('string' => 'str', 'x' => 'x'); test('string, key at the end', $array); $array = array('array' => array(42), 'x' => 'x'); test('array, key at the end', $array); class Foo { public $a = null; } $obj = new Foo(); $array = array('object' => $obj, 'x' => 'x'); test('object, key at the end', $array); --EXPECTF-- object(stdClass)#%d (1) { ["foo"]=> int(1) } OK object(stdClass)#%d (1) { ["foo"]=> int(1) } OK object(stdClass)#%d (2) { ["foo"]=> int(1) ["bar"]=> int(2) } OK object(stdClass)#%d (2) { ["foo"]=> int(1) ["bar"]=> int(2) } OK object(stdClass)#%d (2) { ["foo"]=> int(1) ["bar"]=> int(2) } OK object(stdClass)#%d (1) { ["null"]=> NULL } OK object(stdClass)#%d (1) { ["int"]=> int(1) } OK object(stdClass)#%d (1) { ["float"]=> float(4.2) } OK object(stdClass)#%d (1) { ["string"]=> string(3) "str" } OK object(stdClass)#%d (1) { ["array"]=> array(1) { [0]=> int(42) } } OK object(stdClass)#%d (1) { ["object"]=> object(Foo)#%d (1) { ["a"]=> NULL } } OK msgpack-2.1.0beta1/tests/140.phpt0000644000175000001440000000472013577133502015274 0ustar mikeusers--TEST-- Null byte key position while unpacking objects --SKIPIF-- 'stdClass' $placeholder = hex2bin('a178a178'); // 'x' => 'x' $serialized = msgpack_pack($array); $serialized = str_replace($placeholder, $stdClass, $serialized); $unserialized = msgpack_unpack($serialized); var_dump($unserialized); unset($array['x']); echo $unserialized == (object) $array ? 'OK' : 'ERROR', PHP_EOL; } $array = array('x' => 'x', 'foo' => 1); test('single property, key at the beginning', $array); $array = array('foo' => 1, 'x' => 'x'); test('single property, key at the end', $array); $array = array('x' => 'x', 'foo' => 1, 'bar' => 2); test('multiple properties, key at the beginning', $array); $array = array('foo' => 1, 'x' => 'x', 'bar' => 2); test('multiple properties, key in the middle', $array); $array = array('foo' => 1, 'bar' => 2, 'x' => 'x'); test('multiple properties, key at the end', $array); $array = array('null' => null, 'x' => 'x'); test('null, key at the end', $array); $array = array('int' => 1, 'x' => 'x'); test('int, key at the end', $array); $array = array('float' => 4.2, 'x' => 'x'); test('float, key at the end', $array); $array = array('string' => 'str', 'x' => 'x'); test('string, key at the end', $array); $array = array('array' => array(42), 'x' => 'x'); test('array, key at the end', $array); class Foo { public $a = null; } $obj = new Foo(); $array = array('object' => $obj, 'x' => 'x'); test('object, key at the end', $array); --EXPECTF-- object(stdClass)#%d (1) { ["foo"]=> int(1) } OK object(stdClass)#%d (1) { ["foo"]=> int(1) } OK object(stdClass)#%d (2) { ["foo"]=> int(1) ["bar"]=> int(2) } OK object(stdClass)#%d (2) { ["foo"]=> int(1) ["bar"]=> int(2) } OK object(stdClass)#%d (2) { ["foo"]=> int(1) ["bar"]=> int(2) } OK object(stdClass)#%d (1) { ["null"]=> NULL } OK object(stdClass)#%d (1) { ["int"]=> int(1) } OK object(stdClass)#%d (1) { ["float"]=> float(4.2) } OK object(stdClass)#%d (1) { ["string"]=> string(3) "str" } OK object(stdClass)#%d (1) { ["array"]=> array(1) { [0]=> int(42) } } OK object(stdClass)#%d (1) { ["object"]=> object(Foo)#%d (1) { ["a"]=> NULL } } OK msgpack-2.1.0beta1/tests/bug002.phpt0000644000175000001440000000063113577133502015764 0ustar mikeusers--TEST-- Bug #2 (Deserializing a large array of nested objects gives "zend_mm_heap corrupted") --SKIPIF-- --FILE-- --EXPECTF-- bool(true) msgpack-2.1.0beta1/tests/bug006.phpt0000644000175000001440000000121413577133502015766 0ustar mikeusers--TEST-- Bug #6 (bug with incorrect packing of mixed arrays) --SKIPIF-- 2, 1 => 3); print_r(msgpack_unpack(msgpack_pack($data))); $var = array( 1=> "foo", 2 => "bar"); $var[0] = "dummy"; print_r(msgpack_unpack(msgpack_pack($var))); while ($v = current($var)) { var_dump($v); next($var); } ?> --EXPECTF-- Array ( [key] => 2 [1] => 3 ) Array ( [1] => foo [2] => bar [0] => dummy ) string(3) "foo" string(3) "bar" string(5) "dummy" msgpack-2.1.0beta1/tests/bug011.phpt0000644000175000001440000000046713577133502015773 0ustar mikeusers--TEST-- Bug #011 (Check for segfault with empty array structures) --FILE-- array( ) ); } var_dump( count( msgpack_unpack( msgpack_pack( $items ) ) ) ); ?> --EXPECT-- int(1025) msgpack-2.1.0beta1/tests/bug012.phpt0000644000175000001440000000161313577133502015766 0ustar mikeusers--TEST-- Bug #12 (msgpack_seriallize interfere with php serialize) --SKIPIF-- --EXPECTF-- Array ( [0] => Demo Object ( [storage:ArrayObject:private] => Array ( [0] => stdClass Object ( ) [1] => stdClass Object ( ) ) ) [1] => stdClass Object ( ) [2] => stdClass Object ( ) ) msgpack-2.1.0beta1/tests/bug013.phpt0000644000175000001440000000145213577133502015770 0ustar mikeusers--TEST-- Bug #13 (ensure that __get/__set aren't called when packing/unpacking) --SKIPIF-- $name = $value; } public function __get($name) { echo 'Called __get' . PHP_EOL; return $this->$name; } } $magicInstance = new \magicClass; $magicInstance->val = 5; var_dump($magicInstance); $packed = msgpack_pack($magicInstance); var_dump(bin2hex($packed)); $unpacked = msgpack_unpack($packed); var_dump($unpacked); ?> --EXPECTF-- Called __set object(magicClass)#%d (1) { ["val"]=> int(5) } string(36) "82c0aa6d61676963436c617373a376616c05" object(magicClass)#%d (1) { ["val"]=> int(5) } msgpack-2.1.0beta1/tests/issue023.phpt0000644000175000001440000000041013577133502016335 0ustar mikeusers--TEST-- Issue #23 (Empty objects get serialized with incorrect type) --SKIPIF-- --EXPECTF-- test Object ( ) msgpack-2.1.0beta1/tests/issue067.phpt0000644000175000001440000000035213577133502016352 0ustar mikeusers--TEST-- Issue #67 (uint64_t) --SKIPIF-- --FILE-- OK --EXPECT-- 18446744073709551615 OK msgpack-2.1.0beta1/tests/issue080.phpt0000644000175000001440000000065413577133502016352 0ustar mikeusers--TEST-- Issue #80 (Serialized failed on unseted value) --SKIPIF-- field); } } $t = new MyClass(); $t->preSerialize(); var_dump(msgpack_unserialize(msgpack_serialize($t))); ?> --EXPECTF-- object(MyClass)#%d (1) { ["field":protected]=> NULL } msgpack-2.1.0beta1/tests/issue081.phpt0000644000175000001440000000216413577133502016351 0ustar mikeusers--TEST-- Issue #81 (Ignore IS_UNDEF) --SKIPIF-- --FILE-- first_field = 'first_field'; $this->second_field = 'second_field'; } public function preSerialize() { unset($this->first_field); } } $t = new MyClass(); var_dump($t); var_dump(msgpack_unpack(msgpack_pack($t))); $t = new MyClass(); $t->preSerialize(); var_dump($t); var_dump(msgpack_unpack(msgpack_pack($t))); ?> OK --EXPECTF-- object(MyClass)#%d (2) { ["first_field":"MyClass":private]=> string(11) "first_field" ["second_field":"MyClass":private]=> string(12) "second_field" } object(MyClass)#%d (2) { ["first_field":"MyClass":private]=> string(11) "first_field" ["second_field":"MyClass":private]=> string(12) "second_field" } object(MyClass)#%d (1) { ["second_field":"MyClass":private]=> string(12) "second_field" } object(MyClass)#%d (2) { ["first_field":"MyClass":private]=> NULL ["second_field":"MyClass":private]=> string(12) "second_field" } OK msgpack-2.1.0beta1/tests/issue083.phpt0000644000175000001440000000100013577133502016337 0ustar mikeusers--TEST-- Issue #83 (Arrays and negative index) --SKIPIF-- --FILE-- -1,1=>1]))); $a = [ -1 => -1, 0, 1 => 1, 2 ]; // next free element == 3 and count() == 3, but it's still not an MP array unset($a[1]); var_dump(msgpack_unpack(msgpack_pack($a))); ?> OK --EXPECT-- array(2) { [-1]=> int(-1) [1]=> int(1) } array(3) { [-1]=> int(-1) [0]=> int(0) [2]=> int(2) } OK msgpack-2.1.0beta1/tests/issue091.phpt0000644000175000001440000000135713577133502016355 0ustar mikeusers--TEST-- Issue #91 (private property in base class) --SKIPIF-- --FILE-- name; } public function setName($name) { $this->name = $name; } } class Test extends TestBase { } $test = new Test(); $test->setName('new-name'); var_dump($test, $test->getName()); $new_test = msgpack_unpack(msgpack_pack($test)); var_dump($new_test, $new_test->getName()); ?> OK --EXPECTF-- object(Test)#%d (1) { ["name":"TestBase":private]=> string(8) "new-name" } string(8) "new-name" object(Test)#%d (1) { ["name":"TestBase":private]=> string(8) "new-name" } string(8) "new-name" OK msgpack-2.1.0beta1/tests/issue094.phpt0000644000175000001440000000216013577133502016351 0ustar mikeusers--TEST-- Issue #94 (PHP7 segmentation fault with references) --SKIPIF-- Array ( [verylongid] => 1 ) [10] => Array ( [verylongid] => 10 ) [16] => Array ( [verylongid] => 16 ) [0] => Array ( [children] => Array ( [16] => Array ( [verylongid] => 16 ) [10] => Array ( [verylongid] => 10 ) [1] => Array ( [verylongid] => 1 ) ) ) ) msgpack-2.1.0beta1/tests/issue107.phpt0000644000175000001440000004052313577133502016351 0ustar mikeusers--TEST-- Issue #107 ($unpacker->execute() bug) --SKIPIF-- --FILE-- feed($data1); if($unpacker->execute()) //return TRUE { $unpacked = $unpacker->data(); print_r($unpacked); //here we have partial data, sometime we have Exception, sometime other errors } $unpacker->reset(); $unpacker = new \MessagePackUnpacker(false); $unpacker->feed($data1 . $data2); if($unpacker->execute()) //return TRUE as expected { $unpacked = $unpacker->data(); print_r($unpacked); //all is OK } $unpacker->reset(); ?> OK --EXPECTF-- Array ( [0] => Array ( [o] => Array ( [u] => 8574784417457 [o] => Array ( [0] => [1] => m [2] => EF [3] => tdz [4] => zgq8 [5] => 3qhNf [6] => 3flgrx [7] => RZyxxyT [8] => byuabxm1 [9] => uubhMS94r [10] => nalmK3scpZ [11] => JvRaF0rrTki [12] => XCzv7TGs3n6E [13] => LINbk4wSLVz4o [14] => rQjQzSLjo1deQW [15] => A5KyWsTVRZm3MvE [16] => BOLrD5HisVGILXt5 [17] => FY93IhqdCJPzhmJ6o [18] => bghiUSXm72JrJZMzT2 [19] => zgVkW0A5I07azYq6imA [20] => Q5ESh1605Ignm7aiiJRv [21] => YCTckHEpg737ahpfrW6FW [22] => BFCrNU2q3ows3g8aA1Ct8D [23] => UBBTpwlnMHlZavcIlRM56Rp [24] => 6AreTFvRRso5B5orVLtkrHwi [25] => yb2CDFlpDYU8TwjNhuarfYogj [26] => d5CG9ZIL3LuoUyKrkp81E0ERy3 [27] => y3xhYYNG23tAXQeDW67ETuMcMKj [28] => 7uRO4B1je9AaTxINzcOrWoFPOyIG [29] => nDRFVJDCViux4eqSDBI1FwcCd01B6 [30] => N3fWcqQ8xquTnuyYA5FzKjIcR25BJG [31] => A6OTNiBV6DZgWl7ADe8UIVLNNJjeRGi [32] => 1SvZSvM1l1CG2zA2ArfoHGnvbUCF1RFd [33] => ZvVf7ZYkwmyBep5U94BltVn6LsjNcoyyw [34] => Z9XHgdZoBa2FIEBnYtQ8Cj3am0GMyC3DC9 [35] => 89BoSGUYs7OqS34Ey6ErpztmpgBVlQdJUfo [36] => ssn2CcpjMAJZTpqbW6QJvXiiIwykNHnZOTC1 [37] => weds8PJSZbCmEVbb5Cv4WgzlmyeqyBQovB3NA [38] => 8oNwlxhES6lEkD9HVAePRyG8hUWmI9Vb14pZnF [39] => Eb94khH0O66Ljz0w8MHcAoyWeRk5AjXqcU6PbfV [40] => ERiVAwDTCkA20jR0Jy4sLrUJZzDFcJ5qd4jymBhk [41] => 08RPau4ZQ4191dzA5fkGtMXE1ud6rIQ6zicXUzHHE [42] => mnZEEUJ12H1Tu0SxaZTQMCShRX895qz0bpoETf7GfF [43] => P2TJaHMUe2V7F1aokrOTzfpeJHog81nrb44LlKEszJW [44] => deYMNMBzazWxf1lRUKRpueoZNFtOhw47MnNImbbhGBWZ [45] => rPTdvsbMCeoWFc8xJahOTI5yuH0ndXMOs0HW96aGtYk11 [46] => 79x1qCx9nhqkS0CuOeOvkRw0fnnb67amFyk1CsCmQ4J3we [47] => Uv7bmYFa55TXRkOf2TaDuLapsQpLH7k3BVekkwRphpzJR5z [48] => fLfGKmVHFZi7kVBfhWYLKHiqX5bCXOyvDfnbSSGEEg6vLGcL [49] => 3NCun6xLrUgMMG9VuNotyzdGileAJdauHU1VXhB2qt59oOOqc [50] => IcVhCZa0Y1b2MlK0yuPrgGdz3dbBaBxC2SUNSAywjkipebNJhb [51] => h45wr67pk5UZlA2ejnOUaKoF2ONraI6dl0c4vNE4pL50bdUuuJn [52] => Vz9XIi75S47SByXq06LX9LA86PSuUY1xmMqOnINSpMHdsYAxrodk [53] => JViSRSSI9dJubnAkyYc76TPsCkjHwimP5msTJNUlVJfB6I5K76V1G [54] => WBhXo83LuFrPl32x1CHnH9TicyhWRxWnEE6q9bhuz8Ks19qM0PPzoc [55] => zPvG9TwoMvgVZaaMAygTCTsl9GR3TDfzqUMIxEeYClc8fnDzbMM0Zin [56] => lfgrTMElZWbfJF2KL9clUphBFrFEIkYLeWXyGQB0fNToYBqt1zv4jGAH [57] => hf2b25DK24bbC3zXEqtboE0EcXFfgF0K9Klcogzn74z7MhhLflCdxHCXO [58] => Mtk1XWeo6dtDUwp3HFaFqpWOi3owdD6ZRBOIf8WXEfm5Asbdf8aTYa7deg [59] => 47YsVzx0wvPsLFiNMe2LJwa67sDir9ylmr5gyUNRBjOv9hXQ039M7T96sfI [60] => NJtH2cAnVykWB9UlcJrNbVCsYdRC83f5Zyx1Z4J1Kyr7K1RIYfk4kIaxEaHb [61] => AnaQftKcQdi7x3dg3oFV0lZB0pRvBUEeaX9zOowC7au0Vzq38OEdL8e3vGpEg [62] => xOKJfDOhzDF47b05lVhyGj6QR1p2KKgZNdFhHTZg2M2h7olCEORnSHLtWSXvov [63] => xfdPdlW0Sj8sLVxijsi4BS14z0NVSpnPqDAZcOjk9G6PPS1gSPfKALSJPItlwIa [64] => 454TZeEAv8Mu2nmmsGvVG3sEk6i7h5SdzubpaC7OSTWDP4oJCp7gPoi45X05uhYa [65] => 6W2NnjijysFTgSv64Fi28OCySGll4fL9zCpz3s6xuyf1CUip0DPhOZYZsGfq5aAY4 [66] => 5VDVzpD2GCtFyqRre0vHBgJ3ea1kAHw2pWS7croLDOsTXRpVb4RSmv8F8s86a0Yj9g [67] => FAsUbVkkZDyIoYPnxVq1uWh4QCsoW2uH9YKsxbbweMdkziRyovVkQdZLLxmYdPoSaHF [68] => vX4Lv6CE2MRcvxw1rZ131cvBxzyMiVlsqktTYddJZhJWxcwAUtDlfpuGIZdsTLAMdR4O [69] => yua0oXQlLUbECQw6sDsDh8JJXtv66rF8nO55WpgvaLMp8VNZNp96QHtb7QgUCLpjtesgQ [70] => BMiM0fWMOnhfvQs1xZIPv1VtpSkydGSiFru4SxFVNOFgzM6iWFB61d5xaAdSChm7vmp2UN [71] => S1Ashe7eygYCX8u49UcgFeTt7UrGiJzqK8j06fzf4MaLlXuh0URraXnDeTNkO3WVIN3uN7D [72] => WXRwRRr767ECFzhDbiRue6A1PxXkJDBcVHHd3AjMjRLy6uhx1gGFWSL34yXhnxnSofP0IPjc [73] => XpLsGuhMRVjAS68UtAuZ7IbDmttuV26CMRhQBL2HSDmnVeGf5QqVUij4cSQ1qB5AAewTJZn2J [74] => ZXAzEGdrSJH3UyOBGk5Zup7mxHqpdK1g7QRe3ftDjMCFOldlSWUntz06pf5ov6v2mHr0tBgcDc [75] => XlrldXDOWRmRfcmk7sF8y7sr2f3IF26eWlchARV9TKXZhOQKI7gLWVpHA3mdEdm086d2ymJ4Fo5 [76] => AL9XhGxfDkFoPaXnh2aquyxELL54R91r8dMigvg8FqbGcPUGM5HzvhcR4m7FCOwJZG20c0nbYp0x [77] => PW0VrigeqatOANtI1fI78im6Bgs1t5xV0vvUAX4XZjydVbBmK4YapDKiuPOhPiSnnE37xbjcI7sMq [78] => 14wHzbwBKifRYFhoYrxXOsuwsZsGYZEyCfhcLg7iihKRNz3pCP2MJuWY7i2FeWcIFlTxqqXnBQysbc [79] => V0wvPnKWHso2nJ2V9Gqfm2LBAjXo9Fe1dUyBVjtVSSC3zBi2QfPo0RGAS23yr73QBYh8kBM0C5p992D [80] => YyPNlyIiPWYjfwMrAQhoMh8M3Zx7Qy8P9BKPXidCu4ZLYe3KJ0DZcRMSPAFjra3AWMeRdR9n4ik49Zno [81] => hEo0jNfpnVLKLNXVPgwjimqNRGpuvW3wecUOLJfbWL9b9bPINjfd7yyQoRmogjOwEc4nGvknACrvReExN [82] => 03bC7eXZbJMIIhT9Qt8t3RHOIAP1l0UM4OgH0waIxGXJjBEmcPKOagrtXodx0oGPn2KrviUo5XKrJ2mxI1 [83] => GGxbLTz6r4qtymIRG4cAJA0Bv0TZsjU0NeFoe5aRL8RJ5PIUi8M9S6N5FsR3cH9kEJ1OdeXsSOxE5NnQ4Pm [84] => BG1mdmvmjRALL3BJrandBqL7YIeJqnKyJTnPtbFOfxF9yn1kmLbKDVFUxc4AXNiSfMKnHoAW7XJHcalwjJLw [85] => JorFFNr0grvFLXjO5GHUphbDIxx1ATNKEKXgMLUOmGSyr3YjdtioGgmtJBfCLNgjwegSNBk2LTneROjePgN3m [86] => 8rdRnRJogZ24OCEfPvpkgTceF35NoAoth64EDB9BWOVHfVRK6ZAmZuvPfje8OVkMOqStnlYyqaK2YeZlzBX0qC [87] => hfQLIrDVn4YIwoQSLMXnxxq7vQo9N5NmdaP2iNk8m6krK00VMelcXQoT3k25eMWXU7cZ4GiRuVCW5kI32Zx9Yjr [88] => W0erFeCopYKW3fK8jXvXKR8TxMfSbkFQlsB12VcZ4VJwosOpT4oNptmH5u9qib9JpmmyQSO756EVp3edaHwNxY6h [89] => bkgASrL1SSCc4tWYNQaZWZMP27obHKsR1yPLMCWbwCkvJmprMxaqj3wGAzjqwWhqYeb1Ohyev5Hf4ThSdWlRLrJZr [90] => thc7CO0kXWeo86p1UQo9qOOq6T0cD3ZniqBPCmjRRGF8RuwkteBt4LTH9CbrvQIL22WksAgyv0MowruAAzlUguyUUw [91] => Rxm39FvnApPD595XvvhhyueaiySMYKQVxhZts2H6x2zo1hyv5ROitneOhbMgXPZvAyTPMjddPMOTwYToABpQEir9Pg9 [92] => njC6sBFVtYaFYzVUt2JLUlj0LBiyxKs7pcPfwcLTtLW1Ua8fYOilmjQaWpbXvhsOfOvf4osd4iElNmbXxOfUoM5VpaTd [93] => xmz4yHsNdhiVh9MyJJ04gCSlb8qCipIBOFrJ9B3pVASzFTYq6nY8EMhap1Y4vCqCnLSdG2HxMsI1o3wN2X4Je5sQM6yZi [94] => 43FfCMbrg0KG91mcMCtxRos1kXiWXiMkXxrzfGXrPitRdP85nxWjYC0GPluSJcwOx7WTNUkqclGmZRm5Lc5OwNC8Lfhttv [95] => LqbFl0TQvl5XhDh0JnSaEwxQEUPX2l2JRnI0EwdtRRI87m0pYvZCEABBldJf5uTTC85Ho23oimlsbM7HyBG7dwkG3WqDpCm [96] => WvtUnrHFjjrRNGd4y2BnRhYzaUOvjw0vv1afpQD2JT2rhXVcldoAGF6moLR2oRcHQpbeB2Y6wX2AI5G4N0hMsQms04xBLPsg [97] => qFAwkOit45suSM5G8ciUOvYIJ5Ef8UA1QriN4EuLkhKIaj4cMSsup9XYaYVCNnaRGatB6mUFKLAPv3hmmYgtUO91oNJrQy4Ah [98] => 2vuH8DmWEi4LRrZJGdtjfJilkRtE97WGm4m3uaByl2MjGPR3w1lpy3Y5zEVvElAnR7tYek0dY7UXmySFxcRKnWVhsmtFMX2u9o [99] => zFAZN8FzHU0fbG0vhgArZqn0bWoPLdpZKhYBApkZLgvAabp96DD7jxDdtjMSwG5GXK1ldl0wao8iKF25a6NAUmWQR2HbrbLDUT2 ) [a] => 1 ) [s] => cfc7e0ad1321c75e8470261422c9f3c3 ) ) OK msgpack-2.1.0beta1/tests/issue132.phpt0000644000175000001440000000057213577133502016347 0ustar mikeusers--TEST-- Issue #132 (Segmentation fault when using cloned unpacker) --SKIPIF-- --FILE-- OK --EXPECT-- OK msgpack-2.1.0beta1/tests/issue137.phpt0000644000175000001440000000062213577133502016350 0ustar mikeusers--TEST-- Issue #137 (DateTime(Immutable) serialization doesn't work with php 7.4) --SKIPIF-- OK --EXPECTF-- object(DateTimeImmutable)#%d (3) { ["date"]=> string(26) "%d-%d-%d %d:%d:%f" ["timezone_type"]=> int(%d) ["timezone"]=> string(%d) "%s" } OK msgpack-2.1.0beta1/tests/issue139.phpt0000644000175000001440000000102213577133502016345 0ustar mikeusers--TEST-- Issue #139 (Segmentation fault when using cloned unpacker) --SKIPIF-- feed("\xc3"); $unpacker->execute(); $data = $unpacker->data(); } catch (\Throwable $e) { echo $e->getMessage(),"\n"; } ?> OK --EXPECT-- Trying to clone an uncloneable object of class MessagePackUnpacker OKmsgpack-2.1.0beta1/LICENSE0000644000175000001440000000274013577133502013736 0ustar mikeusersCopyright (c) 2010, advect All rights reserved. Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: * Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. * Neither the name of the advect nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. msgpack-2.1.0beta1/README.md0000644000175000001440000000370713577133502014214 0ustar mikeusers# Msgpack for PHP [![Build Status](https://secure.travis-ci.org/msgpack/msgpack-php.png)](https://travis-ci.org/msgpack/msgpack-php) This extension provide API for communicating with MessagePack serialization. MessagePack is a binary-based efficient object serialization library. It enables to exchange structured objects between many languages like JSON. But unlike JSON, it is very fast and small. ## Requirement - PHP 7.0 + ## Install ### Install from PECL Msgpack is an PECL extension, thus you can simply install it by: ```shell $ pecl install msgpack ``` ### Compile Msgpack from source ```shell $ /path/to/phpize $ ./configure --with-php-config=/path/to/php-config $ make && make install ``` ### Example ```php 1, 1 => 2, 2 => 3); $msg = msgpack_pack($data); $data = msgpack_unpack($msg); ``` ### Advanced Example ```php 1, 1 => 2, 2 => 3); $packer = new \MessagePack(false); // ^ same as $packer->setOption(\MessagePack::OPT_PHPONLY, false); $packed = $packer->pack($data); $unpacker = new \MessagePackUnpacker(false); // ^ same as $unpacker->setOption(\MessagePack::OPT_PHPONLY, false); $unpacker->feed($packed); $unpacker->execute(); $unpacked = $unpacker->data(); $unpacker->reset(); ``` ### Advanced Streaming Example ```php 1, 1 => 2, 2 => 3); $data2 = array("a" => 1, "b" => 2, "c" => 3); $packer = new \MessagePack(false); $packed1 = $packer->pack($data1); $packed2 = $packer->pack($data2); $unpacker = new \MessagePackUnpacker(false); $buffer = ""; $nread = 0; //Simulating streaming data :) $buffer .= $packed1; $buffer .= $packed2; while(true) { if($unpacker->execute($buffer, $nread)) { $msg = $unpacker->data(); var_dump($msg); $unpacker->reset(); $buffer = substr($buffer, $nread); $nread = 0; if(!empty($buffer)) { continue; } } break; } ``` ## Resources * [msgpack](http://msgpack.org/) msgpack-2.1.0beta1/CREDITS0000644000175000001440000000010113577133502013736 0ustar mikeusersmsgpack Advect Vasquaz, Sean DuBois, Xinchen Hui, Michael Wallnermsgpack-2.1.0beta1/EXPERIMENTAL0000644000175000001440000000000013577133502014534 0ustar mikeusersmsgpack-2.1.0beta1/config.m40000644000175000001440000000072513577133502014441 0ustar mikeusersdnl config.m4 for extension msgpack PHP_ARG_WITH(msgpack, for msgpack support, Make sure that the comment is aligned: [ --with-msgpack Include msgpack support]) if test "$PHP_MSGPACK" != "no"; then PHP_NEW_EXTENSION(msgpack, msgpack.c msgpack_pack.c msgpack_unpack.c msgpack_class.c msgpack_convert.c, $ext_shared) ifdef([PHP_INSTALL_HEADERS], [ PHP_INSTALL_HEADERS([ext/msgpack], [php_msgpack.h]) ], [ PHP_ADD_MAKEFILE_FRAGMENT ]) fi msgpack-2.1.0beta1/config.w320000644000175000001440000000045013577133502014527 0ustar mikeusers// $Id$ // vim:ft=javascript ARG_ENABLE("msgpack", "for msgpack support", "no"); if (PHP_MSGPACK != "no") { EXTENSION("msgpack", "msgpack.c", PHP_MSGPACK_SHARED, ""); ADD_SOURCES(configure_module_dirname, "msgpack_pack.c msgpack_unpack.c msgpack_class.c msgpack_convert.c", "msgpack"); } msgpack-2.1.0beta1/msgpack.c0000644000175000001440000001762513577133502014532 0ustar mikeusers #ifdef HAVE_CONFIG_H #include "config.h" #endif #include "php.h" #include "php_ini.h" #include "ext/standard/info.h" /* for php_info */ #include "ext/standard/php_incomplete_class.h" /* for incomplete_class */ #include "ext/standard/php_var.h" /* for PHP_VAR_SERIALIZE */ #if HAVE_PHP_SESSION #include "ext/session/php_session.h" /* for php_session_register_serializer */ #endif #include "php_msgpack.h" #include "msgpack_pack.h" #include "msgpack_unpack.h" #include "msgpack_class.h" #include "msgpack_convert.h" #include "msgpack_errors.h" #include "msgpack/version.h" ZEND_DECLARE_MODULE_GLOBALS(msgpack) static ZEND_FUNCTION(msgpack_serialize); static ZEND_FUNCTION(msgpack_unserialize); ZEND_BEGIN_ARG_INFO_EX(arginfo_msgpack_serialize, 0, 0, 1) ZEND_ARG_INFO(0, value) ZEND_END_ARG_INFO() ZEND_BEGIN_ARG_INFO_EX(arginfo_msgpack_unserialize, 0, 0, 1) ZEND_ARG_INFO(0, str) ZEND_ARG_INFO(0, object) ZEND_END_ARG_INFO() PHP_INI_BEGIN() STD_PHP_INI_BOOLEAN( "msgpack.error_display", "1", PHP_INI_ALL, OnUpdateBool, error_display, zend_msgpack_globals, msgpack_globals) STD_PHP_INI_BOOLEAN( "msgpack.php_only", "1", PHP_INI_ALL, OnUpdateBool, php_only, zend_msgpack_globals, msgpack_globals) STD_PHP_INI_BOOLEAN( "msgpack.illegal_key_insert", "0", PHP_INI_ALL, OnUpdateBool, illegal_key_insert, zend_msgpack_globals, msgpack_globals) STD_PHP_INI_BOOLEAN( "msgpack.use_str8_serialization", "1", PHP_INI_ALL, OnUpdateBool, use_str8_serialization, zend_msgpack_globals, msgpack_globals) PHP_INI_END() #if HAVE_PHP_SESSION PS_SERIALIZER_FUNCS(msgpack); #endif static zend_function_entry msgpack_functions[] = { ZEND_FE(msgpack_serialize, arginfo_msgpack_serialize) ZEND_FE(msgpack_unserialize, arginfo_msgpack_unserialize) ZEND_FALIAS(msgpack_pack, msgpack_serialize, arginfo_msgpack_serialize) ZEND_FALIAS(msgpack_unpack, msgpack_unserialize, arginfo_msgpack_unserialize) {NULL, NULL, NULL} }; static void msgpack_init_globals(zend_msgpack_globals *msgpack_globals) /* {{{ */ { if (PG(display_errors)) { msgpack_globals->error_display = 1; } else { msgpack_globals->error_display = 0; } msgpack_globals->php_only = 1; msgpack_globals->illegal_key_insert = 0; msgpack_globals->use_str8_serialization = 1; msgpack_globals->serialize.var_hash = NULL; msgpack_globals->serialize.level = 0; } /* }}} */ static ZEND_MINIT_FUNCTION(msgpack) /* {{{ */ { ZEND_INIT_MODULE_GLOBALS(msgpack, msgpack_init_globals, NULL); REGISTER_INI_ENTRIES(); #if HAVE_PHP_SESSION php_session_register_serializer("msgpack", PS_SERIALIZER_ENCODE_NAME(msgpack), PS_SERIALIZER_DECODE_NAME(msgpack)); #endif msgpack_init_class(); REGISTER_LONG_CONSTANT("MESSAGEPACK_OPT_PHPONLY", MSGPACK_CLASS_OPT_PHPONLY, CONST_CS | CONST_PERSISTENT); return SUCCESS; } /* }}} */ static ZEND_MSHUTDOWN_FUNCTION(msgpack) /* {{{ */ { UNREGISTER_INI_ENTRIES(); return SUCCESS; } /* }}} */ static ZEND_MINFO_FUNCTION(msgpack) /* {{{ */ { php_info_print_table_start(); php_info_print_table_row(2, "MessagePack Support", "enabled"); #if HAVE_PHP_SESSION php_info_print_table_row(2, "Session Support", "enabled" ); #endif php_info_print_table_row(2, "extension Version", PHP_MSGPACK_VERSION); php_info_print_table_row(2, "header Version", MSGPACK_VERSION); php_info_print_table_end(); DISPLAY_INI_ENTRIES(); } /* }}} */ zend_module_entry msgpack_module_entry = { STANDARD_MODULE_HEADER, "msgpack", msgpack_functions, ZEND_MINIT(msgpack), ZEND_MSHUTDOWN(msgpack), NULL, NULL, ZEND_MINFO(msgpack), PHP_MSGPACK_VERSION, STANDARD_MODULE_PROPERTIES }; #ifdef COMPILE_DL_MSGPACK ZEND_GET_MODULE(msgpack) #endif #if HAVE_PHP_SESSION PS_SERIALIZER_ENCODE_FUNC(msgpack) /* {{{ */ { smart_str buf = {0}; msgpack_serialize_data_t var_hash; msgpack_serialize_var_init(&var_hash); msgpack_serialize_zval(&buf, &PS(http_session_vars), var_hash); msgpack_serialize_var_destroy(&var_hash); smart_str_0(&buf); return buf.s; } /* }}} */ PS_SERIALIZER_DECODE_FUNC(msgpack) /* {{{ */ { int ret; zend_string *key_str; zval tmp, *value; msgpack_unpack_t mp; size_t off = 0; template_init(&mp); ZVAL_UNDEF(&tmp); mp.user.retval = &tmp; mp.user.eof = val + vallen; ret = template_execute(&mp, val, vallen, &off); if (Z_TYPE_P(mp.user.retval) == IS_REFERENCE) { ZVAL_DEREF(mp.user.retval); } if (ret == MSGPACK_UNPACK_EXTRA_BYTES || ret == MSGPACK_UNPACK_SUCCESS) { msgpack_unserialize_var_destroy(&mp.user.var_hash, 0); switch(Z_TYPE_P(mp.user.retval)) { case IS_ARRAY: case IS_OBJECT: ZEND_HASH_FOREACH_STR_KEY_VAL(HASH_OF(mp.user.retval), key_str, value) { if (key_str) { php_set_session_var(key_str, value, NULL); php_add_session_var(key_str); ZVAL_UNDEF(value); } } ZEND_HASH_FOREACH_END(); break; } zval_ptr_dtor(&tmp); } else { msgpack_unserialize_var_destroy(&mp.user.var_hash, 1); } return SUCCESS; } /* }}} */ #endif PHP_MSGPACK_API void php_msgpack_serialize(smart_str *buf, zval *val) /* {{{ */ { msgpack_serialize_data_t var_hash; msgpack_serialize_var_init(&var_hash); msgpack_serialize_zval(buf, val, var_hash); msgpack_serialize_var_destroy(&var_hash); } /* }}} */ PHP_MSGPACK_API int php_msgpack_unserialize(zval *return_value, char *str, size_t str_len) /* {{{ */ { int ret; size_t off = 0; msgpack_unpack_t mp; if (str_len <= 0) { RETVAL_NULL(); return FAILURE; } template_init(&mp); mp.user.retval = return_value; mp.user.eof = str + str_len; ret = template_execute(&mp, str, (size_t)str_len, &off); switch (ret) { case MSGPACK_UNPACK_NOMEM_ERROR: MSGPACK_WARNING("[msgpack] (%s) Memory error", __FUNCTION__); break; case MSGPACK_UNPACK_PARSE_ERROR: MSGPACK_WARNING("[msgpack] (%s) Parse error", __FUNCTION__); break; case MSGPACK_UNPACK_CONTINUE: MSGPACK_WARNING("[msgpack] (%s) Insufficient data for unserializing", __FUNCTION__); break; case MSGPACK_UNPACK_EXTRA_BYTES: case MSGPACK_UNPACK_SUCCESS: msgpack_unserialize_var_destroy(&mp.user.var_hash, 0); if (off < str_len) { MSGPACK_WARNING("[msgpack] (%s) Extra bytes", __FUNCTION__); } return SUCCESS; default: MSGPACK_WARNING("[msgpack] (%s) Unknown result", __FUNCTION__); } zval_dtor(return_value); msgpack_unserialize_var_destroy(&mp.user.var_hash, 1); RETVAL_FALSE; return FAILURE; } /* }}} */ static ZEND_FUNCTION(msgpack_serialize) /* {{{ */ { zval *parameter; smart_str buf = {0}; if (zend_parse_parameters(ZEND_NUM_ARGS(), "z", ¶meter) == FAILURE) { return; } php_msgpack_serialize(&buf, parameter); if (buf.s) { smart_str_0(&buf); ZVAL_STR(return_value, buf.s); } else { RETURN_EMPTY_STRING(); } } /* }}} */ static ZEND_FUNCTION(msgpack_unserialize) /* {{{ */ { zend_string *str; zval *object = NULL; if (zend_parse_parameters(ZEND_NUM_ARGS(), "S|z", &str, &object) == FAILURE) { return; } if (!str) { RETURN_NULL(); } if (object == NULL) { php_msgpack_unserialize(return_value, ZSTR_VAL(str), ZSTR_LEN(str)); } else { zval zv; php_msgpack_unserialize(&zv, ZSTR_VAL(str), ZSTR_LEN(str)); if (msgpack_convert_template(return_value, object, &zv) != SUCCESS) { RETVAL_NULL(); } zval_ptr_dtor(&zv); } } /* }}} */ /* * Local variables: * tab-width: 4 * c-basic-offset: 4 * End: * vim600: noet sw=4 ts=4 fdm=marker * vim<600: noet sw=4 ts=4 */ msgpack-2.1.0beta1/msgpack_class.c0000644000175000001440000003530213577133502015707 0ustar mikeusers#include "php.h" #include "php_msgpack.h" #include "msgpack_pack.h" #include "msgpack_unpack.h" #include "msgpack_class.h" #include "msgpack_convert.h" #include "msgpack_errors.h" typedef struct { long php_only; zend_object object; } php_msgpack_base_t; typedef struct { smart_str buffer; zval retval; long offset; msgpack_unpack_t mp; long php_only; zend_bool finished; int error; zend_object object; } php_msgpack_unpacker_t; static inline php_msgpack_base_t *msgpack_base_fetch_object(zend_object *obj) { return (php_msgpack_base_t *)((char*)(obj) - XtOffsetOf(php_msgpack_base_t, object)); } #define Z_MSGPACK_BASE_P(zv) msgpack_base_fetch_object(Z_OBJ_P((zv))) static inline php_msgpack_unpacker_t *msgpack_unpacker_fetch_object(zend_object *obj) { return (php_msgpack_unpacker_t *)((char*)(obj) - XtOffsetOf(php_msgpack_unpacker_t, object)); } #define Z_MSGPACK_UNPACKER_P(zv) msgpack_unpacker_fetch_object(Z_OBJ_P((zv))) /* MessagePack */ static zend_class_entry *msgpack_ce; zend_object_handlers msgpack_handlers; static ZEND_METHOD(msgpack, __construct); static ZEND_METHOD(msgpack, setOption); static ZEND_METHOD(msgpack, pack); static ZEND_METHOD(msgpack, unpack); static ZEND_METHOD(msgpack, unpacker); ZEND_BEGIN_ARG_INFO_EX(arginfo_msgpack_base___construct, 0, 0, 0) ZEND_ARG_INFO(0, opt) ZEND_END_ARG_INFO() ZEND_BEGIN_ARG_INFO_EX(arginfo_msgpack_base_setOption, 0, 0, 2) ZEND_ARG_INFO(0, option) ZEND_ARG_INFO(0, value) ZEND_END_ARG_INFO() ZEND_BEGIN_ARG_INFO_EX(arginfo_msgpack_base_pack, 0, 0, 1) ZEND_ARG_INFO(0, value) ZEND_END_ARG_INFO() ZEND_BEGIN_ARG_INFO_EX(arginfo_msgpack_base_unpack, 0, 0, 1) ZEND_ARG_INFO(0, str) ZEND_ARG_INFO(0, object) ZEND_END_ARG_INFO() ZEND_BEGIN_ARG_INFO_EX(arginfo_msgpack_base_unpacker, 0, 0, 0) ZEND_END_ARG_INFO() static zend_function_entry msgpack_base_methods[] = { ZEND_ME(msgpack, __construct, arginfo_msgpack_base___construct, ZEND_ACC_PUBLIC) ZEND_ME(msgpack, setOption, arginfo_msgpack_base_setOption, ZEND_ACC_PUBLIC) ZEND_ME(msgpack, pack, arginfo_msgpack_base_pack, ZEND_ACC_PUBLIC) ZEND_ME(msgpack, unpack, arginfo_msgpack_base_unpack, ZEND_ACC_PUBLIC) ZEND_ME(msgpack, unpacker, arginfo_msgpack_base_unpacker, ZEND_ACC_PUBLIC) {NULL, NULL, NULL} }; /* MessagePackUnpacker */ static zend_class_entry *msgpack_unpacker_ce = NULL; zend_object_handlers msgpack_unpacker_handlers; static ZEND_METHOD(msgpack_unpacker, __construct); static ZEND_METHOD(msgpack_unpacker, __destruct); static ZEND_METHOD(msgpack_unpacker, setOption); static ZEND_METHOD(msgpack_unpacker, feed); static ZEND_METHOD(msgpack_unpacker, execute); static ZEND_METHOD(msgpack_unpacker, data); static ZEND_METHOD(msgpack_unpacker, reset); ZEND_BEGIN_ARG_INFO_EX(arginfo_msgpack_unpacker___construct, 0, 0, 0) ZEND_ARG_INFO(0, opt) ZEND_END_ARG_INFO() ZEND_BEGIN_ARG_INFO_EX(arginfo_msgpack_unpacker___destruct, 0, 0, 0) ZEND_END_ARG_INFO() ZEND_BEGIN_ARG_INFO_EX(arginfo_msgpack_unpacker_setOption, 0, 0, 2) ZEND_ARG_INFO(0, option) ZEND_ARG_INFO(0, value) ZEND_END_ARG_INFO() ZEND_BEGIN_ARG_INFO_EX(arginfo_msgpack_unpacker_feed, 0, 0, 1) ZEND_ARG_INFO(0, str) ZEND_END_ARG_INFO() ZEND_BEGIN_ARG_INFO_EX(arginfo_msgpack_unpacker_execute, 1, 0, 0) ZEND_ARG_INFO(0, str) ZEND_ARG_INFO(1, offset) ZEND_END_ARG_INFO() ZEND_BEGIN_ARG_INFO_EX(arginfo_msgpack_unpacker_data, 0, 0, 0) ZEND_ARG_INFO(0, object) ZEND_END_ARG_INFO() ZEND_BEGIN_ARG_INFO_EX(arginfo_msgpack_unpacker_reset, 0, 0, 0) ZEND_END_ARG_INFO() static zend_function_entry msgpack_unpacker_methods[] = { ZEND_ME(msgpack_unpacker, __construct, arginfo_msgpack_unpacker___construct, ZEND_ACC_PUBLIC) ZEND_ME(msgpack_unpacker, __destruct, arginfo_msgpack_unpacker___destruct, ZEND_ACC_PUBLIC) ZEND_ME(msgpack_unpacker, setOption, arginfo_msgpack_unpacker_setOption, ZEND_ACC_PUBLIC) ZEND_ME(msgpack_unpacker, feed, arginfo_msgpack_unpacker_feed, ZEND_ACC_PUBLIC) ZEND_ME(msgpack_unpacker, execute, arginfo_msgpack_unpacker_execute, ZEND_ACC_PUBLIC) ZEND_ME(msgpack_unpacker, data, arginfo_msgpack_unpacker_data, ZEND_ACC_PUBLIC) ZEND_ME(msgpack_unpacker, reset, arginfo_msgpack_unpacker_reset, ZEND_ACC_PUBLIC) {NULL, NULL, NULL} }; zend_object *php_msgpack_base_new(zend_class_entry *ce) /* {{{ */ { php_msgpack_base_t *intern = ecalloc(1, sizeof(php_msgpack_base_t) + zend_object_properties_size(ce)); zend_object_std_init(&intern->object, ce); object_properties_init(&intern->object, ce); intern->object.handlers = &msgpack_handlers; return &intern->object; } /* }}} */ static void php_msgpack_base_free(zend_object *object) /* {{{ */ { php_msgpack_base_t *intern = msgpack_base_fetch_object(object); if (!intern) { return; } zend_object_std_dtor(&intern->object); } /* }}} */ zend_object *php_msgpack_unpacker_new(zend_class_entry *ce) /* {{{ */ { php_msgpack_unpacker_t *intern = ecalloc(1, sizeof(php_msgpack_unpacker_t) + zend_object_properties_size(ce)); zend_object_std_init(&intern->object, ce); object_properties_init(&intern->object, ce); intern->object.handlers = &msgpack_unpacker_handlers; return &intern->object; } /* }}} */ static void php_msgpack_unpacker_free(zend_object *object) /* {{{ */ { php_msgpack_unpacker_t *intern = msgpack_unpacker_fetch_object(object); if (!intern) { return; } zend_object_std_dtor(&intern->object); } /* }}} */ /* MessagePack */ static ZEND_METHOD(msgpack, __construct) /* {{{ */ { zend_bool php_only = MSGPACK_G(php_only); php_msgpack_base_t *base = Z_MSGPACK_BASE_P(getThis()); if (zend_parse_parameters(ZEND_NUM_ARGS(), "|b", &php_only) == FAILURE) { return; } base->php_only = php_only; } /* }}} */ static ZEND_METHOD(msgpack, setOption) /* {{{ */ { zval *value; zend_long option; php_msgpack_base_t *base = Z_MSGPACK_BASE_P(getThis()); if (zend_parse_parameters(ZEND_NUM_ARGS(), "lz", &option, &value) == FAILURE) { return; } switch (option) { case MSGPACK_CLASS_OPT_PHPONLY: base->php_only = i_zend_is_true(value); break; default: MSGPACK_WARNING("[msgpack] (MessagePack::setOption) " "error setting msgpack option"); RETURN_FALSE; break; } RETURN_TRUE; } /* }}} */ static ZEND_METHOD(msgpack, pack) /* {{{ */ { zval *parameter; smart_str buf = {0}; int php_only = MSGPACK_G(php_only); php_msgpack_base_t *base = Z_MSGPACK_BASE_P(getThis()); if (zend_parse_parameters(ZEND_NUM_ARGS(), "z", ¶meter) == FAILURE) { return; } MSGPACK_G(php_only) = base->php_only; php_msgpack_serialize(&buf, parameter); MSGPACK_G(php_only) = php_only; if (buf.s) { smart_str_0(&buf); ZVAL_STR(return_value, buf.s); } else { RETURN_EMPTY_STRING(); } } /* }}} */ static ZEND_METHOD(msgpack, unpack) /* {{{ */ { zend_string *str; zval *object = NULL; zend_bool php_only = MSGPACK_G(php_only); php_msgpack_base_t *base = Z_MSGPACK_BASE_P(getThis()); if (zend_parse_parameters(ZEND_NUM_ARGS(), "S|z", &str, &object) == FAILURE) { return; } if (!str) { RETURN_NULL(); } MSGPACK_G(php_only) = base->php_only; if (object == NULL) { php_msgpack_unserialize(return_value, ZSTR_VAL(str), ZSTR_LEN(str)); } else { zval zv; php_msgpack_unserialize(&zv, ZSTR_VAL(str), ZSTR_LEN(str)); if (msgpack_convert_template(return_value, object, &zv) != SUCCESS) { RETVAL_NULL(); } zval_ptr_dtor(&zv); } MSGPACK_G(php_only) = php_only; } /* }}} */ static ZEND_METHOD(msgpack, unpacker) /* {{{ */ { zval args[1], func_name, construct_return; php_msgpack_base_t *base = Z_MSGPACK_BASE_P(getThis()); ZVAL_BOOL(&args[0], base->php_only); ZVAL_STRING(&func_name, "__construct"); object_init_ex(return_value, msgpack_unpacker_ce); call_user_function_ex(CG(function_table), return_value, &func_name, &construct_return, 1, args, 0, NULL); zval_ptr_dtor(&func_name); } /* }}} */ /* MessagePackUnpacker */ static ZEND_METHOD(msgpack_unpacker, __construct) /* {{{ */ { zend_bool php_only = MSGPACK_G(php_only); php_msgpack_unpacker_t *unpacker = Z_MSGPACK_UNPACKER_P(getThis()); if (zend_parse_parameters(ZEND_NUM_ARGS(), "|b", &php_only) == FAILURE) { return; } unpacker->php_only = php_only; unpacker->buffer.s = NULL; unpacker->buffer.a = 0; unpacker->offset = 0; unpacker->finished = 0; unpacker->error = 0; template_init(&unpacker->mp); } /* }}} */ static ZEND_METHOD(msgpack_unpacker, __destruct) /* {{{ */ { php_msgpack_unpacker_t *unpacker = Z_MSGPACK_UNPACKER_P(getThis()); smart_str_free(&unpacker->buffer); zval_ptr_dtor(&unpacker->retval); msgpack_unserialize_var_destroy(&unpacker->mp.user.var_hash, unpacker->error); } /* }}} */ static ZEND_METHOD(msgpack_unpacker, setOption) /* {{{ */ { zend_long option; zval *value; php_msgpack_unpacker_t *unpacker = Z_MSGPACK_UNPACKER_P(getThis()); if (zend_parse_parameters(ZEND_NUM_ARGS(), "lz", &option, &value) == FAILURE) { return; } switch (option) { case MSGPACK_CLASS_OPT_PHPONLY: unpacker->php_only = i_zend_is_true(value); break; default: MSGPACK_WARNING("[msgpack] (MessagePackUnpacker::setOption) " "error setting msgpack option"); RETURN_FALSE; break; } RETURN_TRUE; } /* }}} */ static ZEND_METHOD(msgpack_unpacker, feed) /* {{{ */ { zend_string *str; php_msgpack_unpacker_t *unpacker = Z_MSGPACK_UNPACKER_P(getThis()); if (zend_parse_parameters(ZEND_NUM_ARGS(), "S", &str) == FAILURE) { return; } if (!str) { RETURN_FALSE; } smart_str_appendl(&unpacker->buffer, ZSTR_VAL(str), ZSTR_LEN(str)); RETURN_TRUE; } /* }}} */ static ZEND_METHOD(msgpack_unpacker, execute) /* {{{ */ { char *data; size_t len, off; zend_string *str = NULL; int ret, error_display = MSGPACK_G(error_display), php_only = MSGPACK_G(php_only); zval *offset = NULL; php_msgpack_unpacker_t *unpacker = Z_MSGPACK_UNPACKER_P(getThis()); if (zend_parse_parameters(ZEND_NUM_ARGS(), "|Sz/", &str, &offset) == FAILURE) { return; } if (str) { data = ZSTR_VAL(str); len = ZSTR_LEN(str); if (offset != NULL && (Z_TYPE_P(offset) == IS_LONG || Z_TYPE_P(offset) == IS_DOUBLE)) { off = Z_LVAL_P(offset); } else { off = 0; } } else if (unpacker->buffer.s) { data = ZSTR_VAL(unpacker->buffer.s); len = ZSTR_LEN(unpacker->buffer.s); off = unpacker->offset; } else { data = NULL; len = 0; off = 0; } if (unpacker->finished) { msgpack_unserialize_var_destroy(&unpacker->mp.user.var_hash, unpacker->error); unpacker->error = 0; template_init(&unpacker->mp); } (&unpacker->mp)->user.retval = &unpacker->retval; (&unpacker->mp)->user.eof = data + len; MSGPACK_G(error_display) = 0; MSGPACK_G(php_only) = unpacker->php_only; ret = template_execute(&unpacker->mp, data, len, &off); MSGPACK_G(error_display) = error_display; MSGPACK_G(php_only) = php_only; if (str != NULL) { if (offset != NULL) { ZVAL_LONG(offset, off); } } else { unpacker->offset = off; } switch (ret) { case MSGPACK_UNPACK_EXTRA_BYTES: case MSGPACK_UNPACK_SUCCESS: unpacker->finished = 1; unpacker->error = 0; RETURN_TRUE; default: unpacker->error = 1; RETURN_FALSE; } } /* }}} */ static ZEND_METHOD(msgpack_unpacker, data) /* {{{ */ { zval *object = NULL; php_msgpack_unpacker_t *unpacker = Z_MSGPACK_UNPACKER_P(getThis()); if (zend_parse_parameters(ZEND_NUM_ARGS(), "|z", &object) == FAILURE) { return; } if (unpacker->finished) { if (object == NULL) { ZVAL_COPY_VALUE(return_value, &unpacker->retval); } else { zval zv; ZVAL_COPY_VALUE(&zv, &unpacker->retval); if (msgpack_convert_object(return_value, object, &zv) != SUCCESS) { zval_ptr_dtor(&zv); RETURN_NULL(); } zval_ptr_dtor(&zv); } ZVAL_UNDEF(&unpacker->retval); } else { RETURN_FALSE; } ZEND_MN(msgpack_unpacker_reset)(INTERNAL_FUNCTION_PARAM_PASSTHRU); } /* }}} */ static ZEND_METHOD(msgpack_unpacker, reset) /* {{{ */ { smart_str buffer = {0}; php_msgpack_unpacker_t *unpacker = Z_MSGPACK_UNPACKER_P(getThis()); if (unpacker->buffer.s && ZSTR_LEN(unpacker->buffer.s) > unpacker->offset) { smart_str_appendl(&buffer, ZSTR_VAL(unpacker->buffer.s) + unpacker->offset, ZSTR_LEN(unpacker->buffer.s) - unpacker->offset); } smart_str_free(&unpacker->buffer); unpacker->buffer.s = NULL; unpacker->buffer.a = 0; unpacker->offset = 0; unpacker->finished = 0; if (buffer.s) { smart_str_appendl(&unpacker->buffer, ZSTR_VAL(buffer.s), ZSTR_LEN(buffer.s)); } smart_str_free(&buffer); msgpack_unserialize_var_destroy(&unpacker->mp.user.var_hash, unpacker->error); unpacker->error = 0; template_init(&unpacker->mp); } /* }}} */ void msgpack_init_class() /* {{{ */ { zend_class_entry ce; /* base */ INIT_CLASS_ENTRY(ce, "MessagePack", msgpack_base_methods); msgpack_ce = zend_register_internal_class(&ce); msgpack_ce->create_object = php_msgpack_base_new; memcpy(&msgpack_handlers, zend_get_std_object_handlers(),sizeof msgpack_handlers); msgpack_handlers.offset = XtOffsetOf(php_msgpack_base_t, object); msgpack_handlers.free_obj = php_msgpack_base_free; zend_declare_class_constant_long(msgpack_ce, ZEND_STRS("OPT_PHPONLY") - 1, MSGPACK_CLASS_OPT_PHPONLY); /* unpacker */ INIT_CLASS_ENTRY(ce, "MessagePackUnpacker", msgpack_unpacker_methods); msgpack_unpacker_ce = zend_register_internal_class(&ce); msgpack_unpacker_ce->create_object = php_msgpack_unpacker_new; memcpy(&msgpack_unpacker_handlers, zend_get_std_object_handlers(),sizeof msgpack_unpacker_handlers); msgpack_unpacker_handlers.offset = XtOffsetOf(php_msgpack_unpacker_t, object); msgpack_unpacker_handlers.free_obj = php_msgpack_unpacker_free; msgpack_unpacker_handlers.clone_obj = NULL; } /* }}} */ /* * Local variables: * tab-width: 4 * c-basic-offset: 4 * End: * vim600: noet sw=4 ts=4 fdm=marker * vim<600: noet sw=4 ts=4 */ msgpack-2.1.0beta1/msgpack_class.h0000644000175000001440000000017613577133502015715 0ustar mikeusers #ifndef MSGPACK_CLASS_H #define MSGPACK_CLASS_H #define MSGPACK_CLASS_OPT_PHPONLY -1001 void msgpack_init_class(); #endif msgpack-2.1.0beta1/msgpack_convert.c0000644000175000001440000004114713577133502016266 0ustar mikeusers#include "php.h" #include "php_msgpack.h" #include "msgpack_convert.h" #include "msgpack_errors.h" static inline int msgpack_convert_long_to_properties(HashTable *ht, zval *object, HashTable **properties, HashPosition *prop_pos, unsigned int key_index, zval *val, HashTable *var) /* {{{ */ { zval key_zv; HashTable *props = *properties; if (props != NULL) { zval *data, tplval, *dataval, prop_key_zv; zend_string *prop_key; zend_ulong prop_key_index; const char *class_name, *prop_name; size_t prop_len; for (;; zend_hash_move_forward_ex(props, prop_pos)) { if (zend_hash_get_current_key_ex(props, &prop_key, &prop_key_index, prop_pos) == HASH_KEY_IS_STRING) { zend_unmangle_property_name_ex(prop_key, &class_name, &prop_name, &prop_len); ZVAL_NEW_STR(&prop_key_zv, prop_key); if (var == NULL || !zend_hash_str_exists(var, prop_name, prop_len)) { if ((data = zend_hash_find(ht, prop_key)) != NULL) { switch (Z_TYPE_P(data)) { case IS_ARRAY: { HashTable *dataht; dataht = HASH_OF(val); if ((dataval = zend_hash_index_find(dataht, prop_key_index)) == NULL) { MSGPACK_WARNING("[msgpack] (%s) " "can't get data value by index", __FUNCTION__); return FAILURE; } if (msgpack_convert_array(&tplval, data, dataval) == SUCCESS) { zend_hash_move_forward_ex(props, prop_pos); zend_update_property(Z_OBJCE_P(object), object, prop_name, prop_len, &tplval); return SUCCESS; } return FAILURE; } case IS_OBJECT: { if (msgpack_convert_object(&tplval, data, val) == SUCCESS) { zend_hash_move_forward_ex(props, prop_pos); zend_update_property(Z_OBJCE_P(object), object, prop_name, prop_len, &tplval); return SUCCESS; } return FAILURE; } default: zend_hash_move_forward_ex(props, prop_pos); zend_update_property(Z_OBJCE_P(object), object, prop_name, prop_len, val); return SUCCESS; } } } } else { break; } } *properties = NULL; } ZVAL_LONG(&key_zv, key_index); zend_std_write_property(object, &key_zv, val, NULL); return SUCCESS; } /* }}} */ static inline int msgpack_convert_string_to_properties(zval *object, zend_string *key, zval *val, HashTable *var)/* {{{ */ { zend_class_entry *ce = Z_OBJCE_P(object); HashTable *propers = Z_OBJPROP_P(object); zend_string *prot_name, *priv_name; zval pub_name; int return_code; ZVAL_STR(&pub_name, key); priv_name = zend_mangle_property_name(ZSTR_VAL(ce->name), ZSTR_LEN(ce->name), ZSTR_VAL(key), ZSTR_LEN(key), 1); prot_name = zend_mangle_property_name("*", 1, ZSTR_VAL(key), ZSTR_LEN(key), 1); if (zend_hash_find(propers, priv_name) != NULL) { zend_update_property_ex(ce, object, key, val); return_code = SUCCESS; } else if (zend_hash_find(propers, prot_name) != NULL) { zend_update_property_ex(ce, object, key, val); return_code = SUCCESS; } else { zend_std_write_property(object, &pub_name, val, NULL); return_code = FAILURE; } zend_hash_add(var, Z_STR(pub_name), val); zend_string_release(priv_name); zend_string_release(prot_name); return return_code; } /* }}} */ int msgpack_convert_array(zval *return_value, zval *tpl, zval *value) /* {{{ */ { zend_string *key; int key_type; zend_ulong key_index; zval *data; HashTable *ht, *htval; if (Z_TYPE_P(tpl) != IS_ARRAY) { MSGPACK_WARNING("[msgpack] (%s) template is not array", __FUNCTION__); return FAILURE; } if (Z_TYPE_P(value) == IS_INDIRECT) { value = Z_INDIRECT_P(value); } ht = HASH_OF(tpl); array_init(return_value); if (zend_hash_num_elements(ht) == 0) { MSGPACK_WARNING("[msgpack] (%s) template array length is 0", __FUNCTION__); return FAILURE; } /* string */ if (ht->nNumOfElements != ht->nNextFreeElement) { HashPosition valpos; htval = HASH_OF(value); if (!htval) { MSGPACK_WARNING("[msgpack] (%s) input data is not array", __FUNCTION__); return FAILURE; } zend_hash_internal_pointer_reset_ex(htval, &valpos); ZEND_HASH_FOREACH_KEY_VAL(ht, key_index, key, data) { if (key) { zval *dataval; int (*convert_function)(zval *, zval *, zval *) = NULL; switch (Z_TYPE_P(data)) { case IS_ARRAY: convert_function = msgpack_convert_array; break; case IS_OBJECT: // case IS_STRING: convert_function = msgpack_convert_object; break; default: break; } if ((dataval = zend_hash_get_current_data_ex(htval, &valpos)) == NULL) { MSGPACK_WARNING("[msgpack] (%s) can't get data", __FUNCTION__); return FAILURE; } if (Z_TYPE_P(dataval) == IS_INDIRECT) { dataval = Z_INDIRECT_P(dataval); } if (convert_function) { zval rv; if (convert_function(&rv, data, dataval) != SUCCESS) { return FAILURE; } zend_symtable_update(Z_ARRVAL_P(return_value), key, &rv); } else { Z_TRY_ADDREF_P(dataval); zend_symtable_update(Z_ARRVAL_P(return_value), key, dataval); } } zend_hash_move_forward_ex(htval, &valpos); } ZEND_HASH_FOREACH_END(); return SUCCESS; } else { /* index */ zval *arydata; HashPosition pos; int (*convert_function)(zval *, zval *, zval *) = NULL; if (Z_TYPE_P(value) != IS_ARRAY) { MSGPACK_WARNING("[msgpack] (%s) unserialized data must be array.", __FUNCTION__); return FAILURE; } zend_hash_internal_pointer_reset_ex(ht, &pos); key_type = zend_hash_get_current_key_ex(ht, &key, &key_index, &pos); if (key_type == HASH_KEY_NON_EXISTENT) { MSGPACK_WARNING( "[msgpack] (%s) first element in template array is empty", __FUNCTION__); return FAILURE; } if ((data = zend_hash_get_current_data_ex(ht, &pos)) == NULL) { MSGPACK_WARNING("[msgpack] (%s) invalid template: empty array?", __FUNCTION__); return FAILURE; } switch (Z_TYPE_P(data)) { case IS_ARRAY: convert_function = msgpack_convert_array; break; case IS_OBJECT: case IS_STRING: convert_function = msgpack_convert_object; break; default: break; } htval = HASH_OF(value); if (zend_hash_num_elements(htval) == 0) { MSGPACK_WARNING("[msgpack] (%s) array length is 0 in unserialized data", __FUNCTION__); return FAILURE; } ZEND_HASH_FOREACH_KEY_VAL_IND(htval, key_index, key, arydata) { if (key) { MSGPACK_WARNING("[msgpack] (%s) key is string", __FUNCTION__); return FAILURE; } else { zval rv; if (convert_function) { if (convert_function(&rv, data, arydata) != SUCCESS) { MSGPACK_WARNING( "[msgpack] (%s) " "convert failure in HASH_KEY_IS_LONG " "in indexed array", __FUNCTION__); return FAILURE; } add_next_index_zval(return_value, &rv); } else { Z_TRY_ADDREF_P(arydata); add_next_index_zval(return_value, arydata); } } } ZEND_HASH_FOREACH_END(); return SUCCESS; } return FAILURE; } /* }}} */ int msgpack_convert_object(zval *return_value, zval *tpl, zval *value) /* {{{ */ { zend_class_entry *ce; switch (Z_TYPE_P(tpl)) { case IS_STRING: ce = zend_lookup_class(Z_STR_P(tpl)); if (ce == NULL) { MSGPACK_ERROR("[msgpack] (%s) Class '%s' not found", __FUNCTION__, Z_STRVAL_P(tpl)); return FAILURE; } break; case IS_OBJECT: ce = Z_OBJCE_P(tpl); break; default: MSGPACK_ERROR("[msgpack] (%s) object type is unsupported", __FUNCTION__); return FAILURE; } if (Z_TYPE_P(value) == IS_INDIRECT) { value = Z_INDIRECT_P(value); } if (Z_TYPE_P(value) == IS_OBJECT) { zend_class_entry *vce = Z_OBJCE_P(value); if (zend_string_equals(ce->name, vce->name)) { ZVAL_COPY(return_value, value); return SUCCESS; } } object_init_ex(return_value, ce); /* Run the constructor if there is one */ if (ce->constructor && (ce->constructor->common.fn_flags & ZEND_ACC_PUBLIC)) { zval retval, params, function_name; zend_fcall_info fci; zend_fcall_info_cache fcc; fci.size = sizeof(fci); #if PHP_VERSION_ID < 70100 fci.function_table = EG(function_table); fci.symbol_table = NULL; #endif fci.function_name = function_name; fci.object = Z_OBJ_P(return_value); fci.retval = &retval; fci.param_count = 0; fci.params = ¶ms; fci.no_separation = 1; #if PHP_VERSION_ID < 70300 fcc.initialized = 1; #endif fcc.function_handler = ce->constructor; #if PHP_VERSION_ID < 70100 fcc.calling_scope = EG(scope); #else fcc.calling_scope = zend_get_executed_scope(); #endif fcc.called_scope = Z_OBJCE_P(return_value); fcc.object = Z_OBJ_P(return_value); if (zend_call_function(&fci, &fcc) == FAILURE) { MSGPACK_WARNING( "[msgpack] (%s) Invocation of %s's constructor failed", __FUNCTION__, ZSTR_VAL(ce->name)); return FAILURE; } } switch (Z_TYPE_P(value)) { case IS_ARRAY: { int num; HashTable *ht, *ret, *var = NULL; zend_string *str_key; zval *data; zend_ulong num_key; ht = HASH_OF(value); ret = HASH_OF(return_value); num = zend_hash_num_elements(ht); if (num <= 0) { break; } /* string - php_only mode? */ if (ht->nNumOfElements != ht->nNextFreeElement || ht->nNumOfElements != ret->nNumOfElements) { HashTable *properties = NULL; HashPosition prop_pos; ALLOC_HASHTABLE(var); zend_hash_init(var, num, NULL, NULL, 0); ZEND_HASH_FOREACH_STR_KEY_VAL(ht, str_key, data) { if (str_key) { if (msgpack_convert_string_to_properties(return_value, str_key, data, var) != SUCCESS) { MSGPACK_WARNING("[msgpack] (%s) " "illegal offset type, skip this decoding", __FUNCTION__); } } } ZEND_HASH_FOREACH_END(); /* index */ properties = Z_OBJ_HT_P(return_value)->get_properties(return_value); if (HASH_OF(tpl)) { properties = HASH_OF(tpl); } zend_hash_internal_pointer_reset_ex(properties, &prop_pos); ZEND_HASH_FOREACH_KEY_VAL(ht, num_key, str_key, data) { if (str_key == NULL) { if (msgpack_convert_long_to_properties(ret, return_value, &properties, &prop_pos, num_key, data, var) != SUCCESS) { MSGPACK_WARNING("[msgpack] (%s) " "illegal offset type, skip this decoding", __FUNCTION__); } } } ZEND_HASH_FOREACH_END(); zend_hash_destroy(var); FREE_HASHTABLE(var); } else { int (*convert_function)(zval *, zval *, zval *) = NULL; const char *class_name, *prop_name; size_t prop_len; zval *aryval; num_key = 0; ZEND_HASH_FOREACH_STR_KEY_VAL(ret, str_key, data) { aryval = zend_hash_index_find(ht, num_key); if (data == NULL) { MSGPACK_WARNING("[msgpack] (%s) can't get data value by index", __FUNCTION__); return FAILURE; } if (Z_TYPE_P(data) == IS_INDIRECT) { data = Z_INDIRECT_P(data); } switch (Z_TYPE_P(data)) { case IS_ARRAY: convert_function = msgpack_convert_array; break; case IS_OBJECT: //case IS_STRING: -- may have default values of // class members, so it's not wise to allow convert_function = msgpack_convert_object; break; } zend_unmangle_property_name_ex(str_key, &class_name, &prop_name, &prop_len); if (convert_function) { zval nv; if (convert_function(&nv, data, aryval) != SUCCESS) { MSGPACK_WARNING("[msgpack] (%s) " "convert failure in convert_object", __FUNCTION__); return FAILURE; } zend_update_property_ex(ce, return_value, str_key, &nv); zval_ptr_dtor(&nv); } else { zend_update_property(ce, return_value, prop_name, prop_len, aryval); } num_key++; } ZEND_HASH_FOREACH_END(); } break; } default: { HashTable *properties = NULL; HashPosition prop_pos; properties = Z_OBJ_HT_P(return_value)->get_properties(return_value); zend_hash_internal_pointer_reset_ex(properties, &prop_pos); if (msgpack_convert_long_to_properties(HASH_OF(return_value), return_value, &properties, &prop_pos, 0, value, NULL) != SUCCESS) { MSGPACK_WARNING("[msgpack] (%s) illegal offset type, skip this decoding", __FUNCTION__); } } } return SUCCESS; } /* }}} */ int msgpack_convert_template(zval *return_value, zval *tpl, zval *value) /* {{{ */ { switch (Z_TYPE_P(tpl)) { case IS_ARRAY: return msgpack_convert_array(return_value, tpl, value); case IS_STRING: case IS_OBJECT: return msgpack_convert_object(return_value, tpl, value); default: MSGPACK_ERROR("[msgpack] (%s) Template type is unsupported", __FUNCTION__); return FAILURE; } } /* }}} */ /* * Local variables: * tab-width: 4 * c-basic-offset: 4 * End: * vim600: noet sw=4 ts=4 fdm=marker * vim<600: noet sw=4 ts=4 */ msgpack-2.1.0beta1/msgpack_convert.h0000644000175000001440000000043213577133502016263 0ustar mikeusers #ifndef MSGPACK_CONVERT_H #define MSGPACK_CONVERT_H int msgpack_convert_object(zval *return_value, zval *object, zval *value); int msgpack_convert_array(zval *return_value, zval *tpl, zval *value); int msgpack_convert_template(zval *return_value, zval *tpl, zval *value); #endif msgpack-2.1.0beta1/msgpack_errors.h0000644000175000001440000000062613577133502016124 0ustar mikeusers#ifndef MSGPACK_ERRORS_H #define MSGPACK_ERRORS_H #define MSGPACK_NOTICE(...) \ if (MSGPACK_G(error_display)) { \ zend_error(E_NOTICE, __VA_ARGS__); \ } #define MSGPACK_WARNING(...) \ if (MSGPACK_G(error_display)) { \ zend_error(E_WARNING, __VA_ARGS__); \ } #define MSGPACK_ERROR(...) zend_error(E_ERROR, __VA_ARGS__) #endif msgpack-2.1.0beta1/msgpack_pack.c0000644000175000001440000004353513577133502015527 0ustar mikeusers #include "php.h" #include "php_ini.h" #include "Zend/zend_smart_str.h" #include "ext/standard/php_incomplete_class.h" #include "ext/standard/php_var.h" #include "php_msgpack.h" #include "msgpack_pack.h" #include "msgpack_errors.h" #include "msgpack/pack_define.h" #define msgpack_pack_user smart_str* #define msgpack_pack_inline_func(name) \ static inline void msgpack_pack ## name #define msgpack_pack_inline_func_cint(name) \ static inline void msgpack_pack ## name #define msgpack_pack_append_buffer(user, buf, len) \ smart_str_appendl(user, (const void*)buf, len) #include "msgpack/pack_template.h" static inline int msgpack_check_ht_is_map(zval *array) /* {{{ */ { Bucket *b; zend_ulong i = 0; ZEND_HASH_FOREACH_BUCKET(Z_ARRVAL_P(array), b) { if (b->key || b->h != i++) { return 1; } } ZEND_HASH_FOREACH_END(); return 0; } /* }}} */ static inline int msgpack_var_add(HashTable *var_hash, zval *var, zend_long *var_old) /* {{{ */ { uint32_t len; char id[32], *p; zval *var_noref, *var_exists, zv; if (UNEXPECTED(Z_TYPE_P(var) == IS_REFERENCE)) { var_noref = Z_REFVAL_P(var); } else { var_noref = var; } if ((Z_TYPE_P(var_noref) == IS_OBJECT) && Z_OBJCE_P(var_noref)) { p = zend_print_long_to_buf( id + sizeof(id) - 1, (((size_t)Z_OBJCE_P(var_noref) << 5) | ((size_t)Z_OBJCE_P(var_noref) >> (sizeof(long) * 8 - 5))) + (long)Z_OBJ_HANDLE_P(var_noref)); len = id + sizeof(id) - 1 - p; } else if (Z_TYPE_P(var_noref) == IS_ARRAY) { p = zend_print_long_to_buf(id + sizeof(id) - 1, (long)(var_noref)); len = id + sizeof(id) - 1 - p; } else { /* TODO: uninitialized var_old? */ return 0; } if (var_old && (var_exists = zend_hash_str_find(var_hash, p, len)) != NULL) { *var_old = Z_LVAL_P(var_exists); if (!Z_ISREF_P(var)) { ZVAL_LONG(&zv, -1); zend_hash_next_index_insert(var_hash, &zv); } return 0; } ZVAL_LONG(&zv, zend_hash_num_elements(var_hash) + 1); zend_hash_str_add(var_hash, p, len, &zv); return 1; } /* }}} */ void msgpack_serialize_var_init(msgpack_serialize_data_t *var_hash) /* {{{ */ { HashTable **var_hash_ptr = (HashTable **)var_hash; if (MSGPACK_G(serialize).level) { *var_hash_ptr = MSGPACK_G(serialize).var_hash; } else { ALLOC_HASHTABLE(*var_hash_ptr); zend_hash_init(*var_hash_ptr, 10, NULL, NULL, 0); MSGPACK_G(serialize).var_hash = *var_hash_ptr; } ++MSGPACK_G(serialize).level; } /* }}} */ void msgpack_serialize_var_destroy(msgpack_serialize_data_t *var_hash) /* {{{ */ { HashTable **var_hash_ptr = (HashTable **)var_hash; --MSGPACK_G(serialize).level; if (!MSGPACK_G(serialize).level) { zend_hash_destroy(*var_hash_ptr); FREE_HASHTABLE(*var_hash_ptr); } } /* }}} */ inline static void msgpack_serialize_string(smart_str *buf, char *str, size_t len) /* {{{ */ { if (MSGPACK_G(use_str8_serialization)) { msgpack_pack_str(buf, len); msgpack_pack_str_body(buf, str, len); } else { msgpack_pack_v4raw(buf, len); msgpack_pack_v4raw_body(buf, str, len); } } /* }}} */ static inline void msgpack_serialize_class(smart_str *buf, zval *val, zval *retval_ptr, HashTable *var_hash, char *class_name, uint32_t name_len, zend_bool incomplete_class) /* {{{ */ { uint32_t count; HashTable *ht = HASH_OF(retval_ptr); count = zend_hash_num_elements(ht); if (incomplete_class) { --count; } if (count > 0) { zend_string *key_str; zval *value, *data; msgpack_pack_map(buf, count + 1); msgpack_pack_nil(buf); msgpack_serialize_string(buf, class_name, name_len); ZEND_HASH_FOREACH_STR_KEY_VAL(ht, key_str, value) { if (incomplete_class && strcmp(ZSTR_VAL(key_str), MAGIC_MEMBER) == 0) { continue; } if (Z_TYPE_P(value) != IS_STRING) { ZVAL_DEREF(value); if (Z_TYPE_P(value) != IS_STRING) { MSGPACK_NOTICE( "[msgpack] (%s) __sleep should return an array only " "containing the names of instance-variables to serialize", __FUNCTION__); continue; } } if ((data = zend_hash_find(Z_OBJPROP_P(val), Z_STR_P(value))) != NULL) { msgpack_serialize_string(buf, Z_STRVAL_P(value), Z_STRLEN_P(value)); msgpack_serialize_zval(buf, data, var_hash); } else { zval nval; zend_class_entry *ce = Z_OBJCE_P(val); ZVAL_NULL(&nval); if (ce) { zend_string *priv_name, *prot_name; do { priv_name = zend_mangle_property_name(ZSTR_VAL(ce->name), ZSTR_LEN(ce->name), Z_STRVAL_P(value), Z_STRLEN_P(value), ce->type & ZEND_INTERNAL_CLASS); if ((data = zend_hash_find(Z_OBJPROP_P(val), priv_name)) != NULL) { msgpack_serialize_string(buf, ZSTR_VAL(priv_name), ZSTR_LEN(priv_name)); pefree(priv_name, ce->type & ZEND_INTERNAL_CLASS); msgpack_serialize_zval(buf, data, var_hash); break; } pefree(priv_name, ce->type & ZEND_INTERNAL_CLASS); prot_name = zend_mangle_property_name("*", 1, Z_STRVAL_P(value), Z_STRLEN_P(value), ce->type & ZEND_INTERNAL_CLASS); if ((data = zend_hash_find(Z_OBJPROP_P(val), prot_name)) != NULL) { msgpack_serialize_string(buf, ZSTR_VAL(prot_name), ZSTR_LEN(prot_name)); pefree(prot_name, ce->type & ZEND_INTERNAL_CLASS); msgpack_serialize_zval(buf, data, var_hash); break; } pefree(prot_name, ce->type & ZEND_INTERNAL_CLASS); MSGPACK_NOTICE( "[msgpack] (%s) \"%s\" returned as member " "variable from __sleep() but does not exist", __FUNCTION__, Z_STRVAL_P(value)); msgpack_serialize_string(buf, Z_STRVAL_P(value), Z_STRLEN_P(value)); msgpack_serialize_zval(buf, &nval, var_hash); } while (0); } else { msgpack_serialize_string(buf, Z_STRVAL_P(value), Z_STRLEN_P(value)); msgpack_serialize_zval(buf, &nval, var_hash); } } } ZEND_HASH_FOREACH_END(); } } /* }}} */ #if PHP_VERSION_ID < 70300 # define Z_IS_RECURSIVE_P(zv) ZEND_HASH_GET_APPLY_COUNT(Z_ARRVAL_P(zv)) # define Z_PROTECT_RECURSION_P(zv) ZEND_HASH_INC_APPLY_COUNT(Z_ARRVAL_P(zv)) # define Z_UNPROTECT_RECURSION_P(zv) ZEND_HASH_DEC_APPLY_COUNT(Z_ARRVAL_P(zv)) # define Z_CAN_PROTECT_RECURSION_P(zv) ZEND_HASH_APPLY_PROTECTION(Z_ARRVAL_P(zv)) #else # define Z_CAN_PROTECT_RECURSION_P(zv) Z_REFCOUNTED_P(zv) #endif static inline void msgpack_serialize_array(smart_str *buf, zval *val, HashTable *var_hash, zend_bool object, char* class_name, uint32_t name_len, zend_bool incomplete_class) /* {{{ */ { uint32_t n; HashTable *ht; zend_bool hash = 1; zend_bool is_ref = 0; #if PHP_VERSION_ID >= 70400 zend_bool free_ht = 0; #endif if (UNEXPECTED(Z_TYPE_P(val) == IS_REFERENCE)) { is_ref = 1; val = Z_REFVAL_P(val); } if (object) { #if PHP_VERSION_ID >= 70400 if (Z_OBJ_HANDLER_P(val, get_properties_for)) { ht = Z_OBJ_HANDLER_P(val, get_properties_for)(val, ZEND_PROP_PURPOSE_ARRAY_CAST); free_ht = 1; } else { ht = Z_OBJPROP_P(val); } #else ht = Z_OBJPROP_P(val); #endif } else { ZEND_ASSERT(Z_TYPE_P(val) == IS_ARRAY); ht = Z_ARRVAL_P(val); } if (ht) { n = zend_array_count(ht); } else { n = 0; } if (n > 0 && incomplete_class) { --n; } if (object) { if (MSGPACK_G(php_only)) { if (is_ref) { msgpack_pack_map(buf, n + 2); msgpack_pack_nil(buf); msgpack_pack_long(buf, MSGPACK_SERIALIZE_TYPE_REFERENCE); } else { msgpack_pack_map(buf, n + 1); } msgpack_pack_nil(buf); msgpack_serialize_string(buf, class_name, name_len); } else { hash = 0; msgpack_pack_array(buf, n); } } else if (n == 0) { hash = 0; msgpack_pack_array(buf, n); } else if (is_ref && MSGPACK_G(php_only)) { msgpack_pack_map(buf, n + 1); msgpack_pack_nil(buf); msgpack_pack_long(buf, MSGPACK_SERIALIZE_TYPE_REFERENCE); } else if (!msgpack_check_ht_is_map(val)) { hash = 0; msgpack_pack_array(buf, n); } else { msgpack_pack_map(buf, n); } if (n > 0) { if (object || hash) { zend_string *key_str; zend_ulong key_long; zval *value, *value_noref; ZEND_HASH_FOREACH_KEY_VAL_IND(ht, key_long, key_str, value) { if (key_str && incomplete_class && strcmp(ZSTR_VAL(key_str), MAGIC_MEMBER) == 0) { continue; } if (key_str && hash) { msgpack_serialize_string(buf, ZSTR_VAL(key_str), ZSTR_LEN(key_str)); } else if (hash) { msgpack_pack_long(buf, key_long); } if (Z_TYPE_P(value) == IS_REFERENCE) { value_noref = Z_REFVAL_P(value); } else { value_noref = value; } if (Z_TYPE_P(value_noref) == IS_ARRAY && Z_IS_RECURSIVE_P(value_noref)) { if (MSGPACK_G(php_only)) { /* pack ref */ msgpack_serialize_zval(buf, value, var_hash); } else { /* you lose */ msgpack_pack_nil(buf); } } else { if (Z_TYPE_P(value_noref) == IS_ARRAY && Z_CAN_PROTECT_RECURSION_P(value_noref)) { Z_PROTECT_RECURSION_P(value_noref); } msgpack_serialize_zval(buf, value, var_hash); if (Z_TYPE_P(value_noref) == IS_ARRAY && Z_CAN_PROTECT_RECURSION_P(value_noref)) { Z_UNPROTECT_RECURSION_P(value_noref); } } } ZEND_HASH_FOREACH_END(); } else { uint32_t i; for (i = 0; i < n; i++) { zval *data_noref, *data = zend_hash_index_find(ht, i); if (!data) { MSGPACK_WARNING("[msgpack (%s) array index %u is not set", __FUNCTION__, i); msgpack_pack_nil(buf); continue; } if (Z_TYPE_P(data) == IS_REFERENCE) { data_noref = Z_REFVAL_P(data); } else { data_noref = data; } if (Z_TYPE_P(data_noref) == IS_ARRAY && Z_IS_RECURSIVE_P(data_noref)) { if (MSGPACK_G(php_only)) { /* pack ref */ msgpack_serialize_zval(buf, data, var_hash); } else { /* you lose */ msgpack_pack_nil(buf); } } else { if (Z_TYPE_P(data_noref) == IS_ARRAY && Z_CAN_PROTECT_RECURSION_P(data_noref)) { Z_PROTECT_RECURSION_P(data_noref); } msgpack_serialize_zval(buf, data, var_hash); if (Z_TYPE_P(data_noref) == IS_ARRAY && Z_CAN_PROTECT_RECURSION_P(data_noref)) { Z_UNPROTECT_RECURSION_P(data_noref); } } } } } #if PHP_VERSION_ID >= 70400 if (free_ht && ht) { zend_array_destroy(ht); } #endif } /* }}} */ static inline void msgpack_serialize_object(smart_str *buf, zval *val, HashTable *var_hash, char* class_name, uint32_t name_len, zend_bool incomplete_class) /* {{{ */ { int res; zval retval, fname; zval *val_noref; zend_class_entry *ce = NULL; zend_string *sleep_zstring; if (UNEXPECTED(Z_TYPE_P(val) == IS_REFERENCE)) { val_noref = Z_REFVAL_P(val); } else { val_noref = val; } if (Z_OBJCE_P(val_noref)) { ce = Z_OBJCE_P(val_noref); } if (ce && ce->serialize != NULL) { unsigned char *serialized_data = NULL; size_t serialized_length; if (ce->serialize(val_noref, &serialized_data, &serialized_length, (zend_serialize_data *)var_hash) == SUCCESS && !EG(exception)) { /* has custom handler */ msgpack_pack_map(buf, 2); msgpack_pack_nil(buf); msgpack_pack_long(buf, MSGPACK_SERIALIZE_TYPE_CUSTOM_OBJECT); msgpack_serialize_string(buf, ZSTR_VAL(ce->name), ZSTR_LEN(ce->name)); msgpack_pack_str(buf, serialized_length); msgpack_pack_str_body(buf, serialized_data, serialized_length); } else { msgpack_pack_nil(buf); } if (serialized_data) { efree(serialized_data); } return; } sleep_zstring = zend_string_init("__sleep", sizeof("__sleep") - 1, 0); ZVAL_STR(&fname, sleep_zstring); if (ce && ce != PHP_IC_ENTRY && zend_hash_exists(&ce->function_table, sleep_zstring)) { if ((res = call_user_function_ex(CG(function_table), val_noref, &fname, &retval, 0, 0, 1, NULL)) == SUCCESS) { if (EG(exception)) { zval_ptr_dtor(&retval); zval_ptr_dtor(&fname); return; } if (Z_TYPE(retval) == IS_ARRAY) { msgpack_serialize_class( buf, val_noref, &retval, var_hash, class_name, name_len, incomplete_class); } else { MSGPACK_NOTICE( "[msgpack] (%s) __sleep should return an array only " "containing the names of instance-variables " "to serialize", __FUNCTION__); msgpack_pack_nil(buf); } zval_ptr_dtor(&retval); zval_ptr_dtor(&fname); return; } } zval_ptr_dtor(&fname); msgpack_serialize_array( buf, val, var_hash, 1, class_name, name_len, incomplete_class); } /* }}} */ void msgpack_serialize_zval(smart_str *buf, zval *val, HashTable *var_hash) /* {{{ */ { zval *val_noref; zend_long var_already; if (Z_TYPE_P(val) == IS_INDIRECT) { val = Z_INDIRECT_P(val); } if (MSGPACK_G(php_only) && var_hash && !msgpack_var_add(var_hash, val, &var_already)) { if (Z_ISREF_P(val)) { if (Z_TYPE_P(Z_REFVAL_P(val)) == IS_ARRAY) { msgpack_pack_map(buf, 2); msgpack_pack_nil(buf); msgpack_pack_long(buf, MSGPACK_SERIALIZE_TYPE_RECURSIVE); msgpack_pack_long(buf, 0); msgpack_pack_long(buf, var_already); return; } else if (Z_TYPE_P(Z_REFVAL_P(val)) == IS_OBJECT) { msgpack_pack_map(buf, 2); msgpack_pack_nil(buf); msgpack_pack_long(buf, MSGPACK_SERIALIZE_TYPE_OBJECT_REFERENCE); msgpack_pack_long(buf, 0); msgpack_pack_long(buf, var_already); return; } } else if (Z_TYPE_P(val) == IS_OBJECT) { msgpack_pack_map(buf, 2); msgpack_pack_nil(buf); msgpack_pack_long(buf, MSGPACK_SERIALIZE_TYPE_OBJECT); msgpack_pack_long(buf, 0); msgpack_pack_long(buf, var_already); return; } } if (UNEXPECTED(Z_TYPE_P(val) == IS_REFERENCE)) { val_noref = Z_REFVAL_P(val); } else { val_noref = val; } switch (Z_TYPE_P(val_noref)) { case IS_UNDEF: case IS_NULL: msgpack_pack_nil(buf); break; case IS_TRUE: msgpack_pack_true(buf); break; case IS_FALSE: msgpack_pack_false(buf); break; case IS_LONG: msgpack_pack_long(buf, zval_get_long(val_noref)); break; case IS_DOUBLE: msgpack_pack_double(buf, Z_DVAL_P(val_noref)); break; case IS_STRING: msgpack_serialize_string(buf, Z_STRVAL_P(val_noref), Z_STRLEN_P(val_noref)); break; case IS_ARRAY: msgpack_serialize_array(buf, val, var_hash, 0, NULL, 0, 0); break; case IS_OBJECT: { PHP_CLASS_ATTRIBUTES; PHP_SET_CLASS_ATTRIBUTES(val_noref); msgpack_serialize_object(buf, val, var_hash, ZSTR_VAL(class_name), ZSTR_LEN(class_name), incomplete_class); PHP_CLEANUP_CLASS_ATTRIBUTES(); } break; default: MSGPACK_WARNING( "[msgpack] (%s) type is unsupported, encoded as null", __FUNCTION__); msgpack_pack_nil(buf); break; } return; } /* }}} */ /* * Local variables: * tab-width: 4 * c-basic-offset: 4 * End: * vim600: noet sw=4 ts=4 fdm=marker * vim<600: noet sw=4 ts=4 */ msgpack-2.1.0beta1/msgpack_pack.h0000644000175000001440000000133113577133502015520 0ustar mikeusers #ifndef MSGPACK_PACK_H #define MSGPACK_PACK_H #include "ext/standard/php_var.h" typedef HashTable* msgpack_serialize_data_t; typedef struct msgpack_timestamp { int64_t tv_sec; uint32_t tv_nsec; } msgpack_timestamp; enum msgpack_serialize_type { MSGPACK_SERIALIZE_TYPE_NONE = 0, MSGPACK_SERIALIZE_TYPE_REFERENCE = 1, MSGPACK_SERIALIZE_TYPE_RECURSIVE, MSGPACK_SERIALIZE_TYPE_CUSTOM_OBJECT, MSGPACK_SERIALIZE_TYPE_OBJECT, MSGPACK_SERIALIZE_TYPE_OBJECT_REFERENCE, }; void msgpack_serialize_var_init(msgpack_serialize_data_t *var_hash); void msgpack_serialize_var_destroy(msgpack_serialize_data_t *var_hash); void msgpack_serialize_zval(smart_str *buf, zval *val, HashTable *var_hash); #endif msgpack-2.1.0beta1/msgpack_unpack.c0000644000175000001440000006535613577133502016077 0ustar mikeusers#include "php.h" #include "php_ini.h" #include "ext/standard/php_incomplete_class.h" #include "php_msgpack.h" #include "msgpack_pack.h" #include "msgpack_unpack.h" #include "msgpack_errors.h" #define VAR_ENTRIES_MAX 1024 #if PHP_VERSION_ID < 70400 # define zval_try_get_string zval_get_string #endif #if PHP_VERSION_ID < 70200 # define zend_string_init_interned zend_string_init #endif typedef struct { zend_long used_slots; void *next; zval data[VAR_ENTRIES_MAX]; } var_entries; #define MSGPACK_UNSERIALIZE_ALLOC_STACK(_unpack) \ if (UNEXPECTED(_unpack->deps == 0)) { \ *obj = _unpack->retval; \ } else { \ *obj = msgpack_stack_push(&_unpack->var_hash); \ } #define MSGPACK_UNSERIALIZE_ALLOC_VALUE(_unpack) \ if (UNEXPECTED(_unpack->deps <= 0)) { \ *obj = _unpack->retval; \ } else { \ *obj = msgpack_var_push(&_unpack->var_hash); \ } #define MSGPACK_UNSERIALIZE_DEC_DEP(_unpack) \ _unpack->stack[_unpack->deps-1]--; \ if (_unpack->stack[_unpack->deps-1] <= 0) { \ _unpack->deps--; \ } #define MSGPACK_UNSERIALIZE_FINISH_ITEM(_unpack, _v1, _v2) \ if ((_v2) && MSGPACK_IS_STACK_VALUE((_v2))) { \ msgpack_stack_pop(&_unpack->var_hash, (_v2)); \ } \ if ((_v1) && MSGPACK_IS_STACK_VALUE((_v1))) { \ msgpack_stack_pop(&_unpack->var_hash, (_v1)); \ } \ MSGPACK_UNSERIALIZE_DEC_DEP(_unpack); #define MSGPACK_UNSERIALIZE_FINISH_MAP_ITEM(_unpack, _key, _val) \ zval_ptr_dtor(_key); \ zval_ptr_dtor(_val); \ MSGPACK_UNSERIALIZE_FINISH_ITEM(_unpack, _key, _val); #define UNSET_MAGIC_METHODS(_ce) \ __get = _ce->__get; \ _ce->__get = NULL; \ __set = _ce->__set; \ _ce->__set = NULL; \ #define RESET_MAGIC_METHODS(_ce) \ ce->__set = __set; \ ce->__get = __get; \ #define MSGPACK_IS_STACK_VALUE(_v) (Z_TYPE_P((zval *)(_v)) < IS_ARRAY) #define MSGPACK_VALIDATE_INPUT_DATA_LENGTH(data, len, eof) \ ((data) + (len) <= (eof)) #define MSGPACK_VALIDATE_INPUT(user, data, len) \ if (!MSGPACK_VALIDATE_INPUT_DATA_LENGTH(data, len, (user)->eof)) { \ return MSGPACK_UNPACK_PARSE_ERROR; \ } static zval *msgpack_var_push(msgpack_unserialize_data_t *var_hashx) /* {{{ */ { var_entries *var_hash, *prev = NULL; if (!var_hashx) { return NULL; } var_hash = var_hashx->last; while (var_hash && var_hash->used_slots == VAR_ENTRIES_MAX) { prev = var_hash; var_hash = var_hash->next; } if (!var_hash) { var_hash = emalloc(sizeof(var_entries)); var_hash->used_slots = 0; var_hash->next = 0; if (!var_hashx->first) { var_hashx->first = var_hash; } else { prev->next = var_hash; } var_hashx->last = var_hash; } return &var_hash->data[var_hash->used_slots++]; } /* }}} */ static inline void msgpack_var_replace(zval *old, zval *new) /* {{{ */ { if (!MSGPACK_IS_STACK_VALUE(old) && Z_TYPE_P(old) != IS_REFERENCE) { ZVAL_INDIRECT(old, new); } } /* }}} */ static zval *msgpack_var_access(msgpack_unserialize_data_t *var_hashx, zend_long id) /* {{{ */ { var_entries *var_hash = var_hashx->first; while (id >= VAR_ENTRIES_MAX && var_hash && var_hash->used_slots == VAR_ENTRIES_MAX) { var_hash = var_hash->next; id -= VAR_ENTRIES_MAX; } if (!var_hash) { return NULL; } if (id > 0 && id < var_hash->used_slots) { zval *zv = &var_hash->data[id - 1]; if (UNEXPECTED(Z_TYPE_P(zv) == IS_INDIRECT)) { zv = Z_INDIRECT_P(zv); } return zv; } return NULL; } /* }}} */ static zval *msgpack_stack_push(msgpack_unserialize_data_t *var_hashx) /* {{{ */ { var_entries *var_hash, *prev = NULL; if (!var_hashx) { return NULL; } var_hash = var_hashx->last_dtor; while (var_hash && var_hash->used_slots == VAR_ENTRIES_MAX) { prev = var_hash; var_hash = var_hash->next; } if (!var_hash) { var_hash = emalloc(sizeof(var_entries)); var_hash->used_slots = 0; var_hash->next = 0; if (!var_hashx->first_dtor) { var_hashx->first_dtor = var_hash; } else { prev->next = var_hash; } var_hashx->last_dtor = var_hash; } return &var_hash->data[var_hash->used_slots++]; } /* }}} */ static void msgpack_stack_pop(msgpack_unserialize_data_t *var_hashx, zval *v) /* {{{ */ { var_entries *var_hash = var_hashx->last_dtor; while (var_hash && var_hash->used_slots == VAR_ENTRIES_MAX) { var_hash = var_hash->next; } if (!var_hash) { return; } ZEND_ASSERT((&(var_hash->data[var_hash->used_slots -1]) == v)); if ((&(var_hash->data[var_hash->used_slots -1]) == v)) { var_hash->used_slots--; ZVAL_UNDEF(v); } /* for (i = count; i > 0; i--) { var_hash->used_slots--; if (var_hash->used_slots < 0) { var_hash->used_slots = 0; ZVAL_UNDEF(&var_hash->data[var_hash->used_slots]); break; } else { ZVAL_UNDEF(&var_hash->data[var_hash->used_slots]); } } */ } /* }}} */ static inline zval *update_property(const zend_class_entry *ce, HashTable *props, zend_string *mangled, zval *val) { const char *class_name, *prop_name; size_t prop_len; zval *new_val; zend_string *unmangled, *new_key; zend_property_info *existing_propinfo; if (SUCCESS != zend_unmangle_property_name_ex(mangled, &class_name, &prop_name, &prop_len)) { return NULL; } unmangled = zend_string_init(prop_name, prop_len, 0); existing_propinfo = zend_hash_find_ptr(&ce->properties_info, unmangled); if ((class_name == NULL || !strcmp(class_name, "*") || !strcasecmp(class_name, ZSTR_VAL(ce->name))) && (existing_propinfo != NULL) && (existing_propinfo->flags & ZEND_ACC_PPP_MASK)) { if (existing_propinfo->flags & ZEND_ACC_PROTECTED) { new_key = zend_mangle_property_name( "*", 1, ZSTR_VAL(unmangled), ZSTR_LEN(unmangled), 0); } else if (existing_propinfo->flags & ZEND_ACC_PRIVATE) { if (class_name != NULL && strcmp(class_name, "*") != 0) { new_key = zend_mangle_property_name( class_name, strlen(class_name), ZSTR_VAL(unmangled), ZSTR_LEN(unmangled), 0); } else { new_key = zend_mangle_property_name( ZSTR_VAL(existing_propinfo->ce->name), ZSTR_LEN(existing_propinfo->ce->name), ZSTR_VAL(unmangled), ZSTR_LEN(unmangled), 0); } } else { ZEND_ASSERT(existing_propinfo->flags & ZEND_ACC_PUBLIC); new_key = unmangled; } } else { new_key = mangled; } Z_TRY_ADDREF_P(val); new_val = zend_hash_update_ind(props, new_key, val); if (new_key != unmangled) { zend_string_release(unmangled); } if (new_key != mangled) { zend_string_release(new_key); } return new_val; } static zend_class_entry* msgpack_unserialize_class(zval **container, zend_string *class_name, zend_bool init_class) /* {{{ */ { zend_class_entry *ce; int func_call_status; zend_bool incomplete_class = 0; zval user_func, retval, args[1], *container_val, container_tmp, *val; zend_string *str_key; container_val = Z_ISREF_P(*container) ? Z_REFVAL_P(*container) : *container; ZVAL_UNDEF(&container_tmp); do { /* Try to find class directly */ ce = zend_lookup_class(class_name); if (ce != NULL) { break; } /* Check for unserialize callback */ if ((PG(unserialize_callback_func) == NULL) || (PG(unserialize_callback_func)[0] == '\0')) { incomplete_class = 1; ce = PHP_IC_ENTRY; break; } /* Call unserialize callback */ ZVAL_STRING(&user_func, PG(unserialize_callback_func)); ZVAL_STR(&args[0], class_name); func_call_status = call_user_function_ex(CG(function_table), NULL, &user_func, &retval, 1, args, 0, NULL); zval_ptr_dtor(&user_func); if (func_call_status != SUCCESS) { MSGPACK_WARNING("[msgpack] (%s) defined (%s) but not found", __FUNCTION__, ZSTR_VAL(class_name)); incomplete_class = 1; ce = PHP_IC_ENTRY; break; } if ((ce = zend_lookup_class(class_name)) == NULL) { MSGPACK_WARNING("[msgpack] (%s) Function %s() hasn't defined " "the class it was called for", __FUNCTION__, ZSTR_VAL(class_name)); incomplete_class = 1; ce = PHP_IC_ENTRY; } } while(0); if (EG(exception)) { MSGPACK_WARNING("[msgpack] (%s) Exception error", __FUNCTION__); return NULL; } if (init_class || incomplete_class) { if (Z_TYPE_P(container_val) == IS_ARRAY) { ZVAL_COPY_VALUE(&container_tmp, container_val); } object_init_ex(container_val, ce); if (Z_TYPE(container_tmp) != IS_UNDEF) { HashTable *props = Z_OBJPROP_P(container_val); ZEND_HASH_FOREACH_STR_KEY_VAL(HASH_OF(&container_tmp), str_key, val) { update_property(ce, props, str_key, val); } ZEND_HASH_FOREACH_END(); zval_dtor(&container_tmp); } } /* store incomplete class name */ if (incomplete_class) { php_store_class_name(container_val, ZSTR_VAL(class_name), ZSTR_LEN(class_name)); } return ce; } /* }}} */ void msgpack_unserialize_var_init(msgpack_unserialize_data_t *var_hashx) /* {{{ */ { var_hashx->first = var_hashx->last = NULL; var_hashx->first_dtor = var_hashx->last_dtor = NULL; } /* }}} */ void msgpack_unserialize_var_destroy(msgpack_unserialize_data_t *var_hashx, zend_bool err) /* {{{ */ { zend_long i; void *next; var_entries *var_hash = var_hashx->first; while (var_hash) { if (err) { for (i = var_hash->used_slots; i > 0; i--) { zval_ptr_dtor(&var_hash->data[i - 1]); } } next = var_hash->next; efree(var_hash); var_hash = next; } var_hash = var_hashx->first_dtor; while (var_hash) { for (i = var_hash->used_slots; i > 0; i--) { zval_ptr_dtor(&var_hash->data[i-1]); } next = var_hash->next; efree(var_hash); var_hash = next; } } /* }}} */ void msgpack_unserialize_init(msgpack_unserialize_data *unpack) /* {{{ */ { unpack->deps = 0; unpack->type = MSGPACK_SERIALIZE_TYPE_NONE; msgpack_unserialize_var_init(&unpack->var_hash); } /* }}} */ int msgpack_unserialize_uint8(msgpack_unserialize_data *unpack, uint8_t data, zval **obj) /* {{{ */ { MSGPACK_UNSERIALIZE_ALLOC_STACK(unpack); ZVAL_LONG(*obj, data); return 0; } /* }}} */ int msgpack_unserialize_uint16(msgpack_unserialize_data *unpack, uint16_t data, zval **obj) /* {{{ */ { MSGPACK_UNSERIALIZE_ALLOC_STACK(unpack); ZVAL_LONG(*obj, data); return 0; } /* }}} */ int msgpack_unserialize_uint32(msgpack_unserialize_data *unpack, uint32_t data, zval **obj) /* {{{ */ { MSGPACK_UNSERIALIZE_ALLOC_STACK(unpack); if (data <= (uint32_t) ZEND_LONG_MAX) { ZVAL_LONG(*obj, data); } else { ZVAL_DOUBLE(*obj, data); } return 0; } /* }}} */ /* see zend_print_ulong_to_buf() in Zend/zend_operators.h */ static inline char *print_u64_to_buf(char *buf, uint64_t num) { *buf = '\0'; do { *--buf = (char) (num % 10) + '0'; num /= 10; } while (num > 0); return buf; } int msgpack_unserialize_uint64(msgpack_unserialize_data *unpack, uint64_t data, zval **obj) /* {{{ */ { MSGPACK_UNSERIALIZE_ALLOC_STACK(unpack); if (data <= (uint64_t) ZEND_LONG_MAX) { ZVAL_LONG(*obj, data); } else if (data <= 1L<<52) { ZVAL_DOUBLE(*obj, data); } else { char buf[0x20] = {0}, *ptr = print_u64_to_buf(&buf[sizeof(buf)-1], data); ZVAL_STRING(*obj, ptr); } return 0; } /* }}} */ int msgpack_unserialize_int8(msgpack_unserialize_data *unpack, int8_t data, zval **obj) /* {{{ */ { MSGPACK_UNSERIALIZE_ALLOC_STACK(unpack); ZVAL_LONG(*obj, data); return 0; } /* }}} */ int msgpack_unserialize_int16(msgpack_unserialize_data *unpack, int16_t data, zval **obj) /* {{{ */ { MSGPACK_UNSERIALIZE_ALLOC_STACK(unpack); ZVAL_LONG(*obj, data); return 0; } /* }}} */ int msgpack_unserialize_int32(msgpack_unserialize_data *unpack, int32_t data, zval **obj) /* {{{ */ { MSGPACK_UNSERIALIZE_ALLOC_STACK(unpack); ZVAL_LONG(*obj, data); return 0; } /* }}} */ int msgpack_unserialize_int64(msgpack_unserialize_data *unpack, int64_t data, zval **obj) /* {{{ */ { MSGPACK_UNSERIALIZE_ALLOC_STACK(unpack); ZVAL_LONG(*obj, data); return 0; } /* }}} */ int msgpack_unserialize_float(msgpack_unserialize_data *unpack, float data, zval **obj) /* {{{ */ { MSGPACK_UNSERIALIZE_ALLOC_STACK(unpack); ZVAL_DOUBLE(*obj, data); return 0; } /* }}} */ int msgpack_unserialize_double(msgpack_unserialize_data *unpack, double data, zval **obj) /* {{{ */ { MSGPACK_UNSERIALIZE_ALLOC_STACK(unpack); ZVAL_DOUBLE(*obj, data); return 0; } /* }}} */ int msgpack_unserialize_nil(msgpack_unserialize_data *unpack, zval **obj) /* {{{ */ { MSGPACK_UNSERIALIZE_ALLOC_STACK(unpack); ZVAL_NULL(*obj); return 0; } /* }}} */ int msgpack_unserialize_true(msgpack_unserialize_data *unpack, zval **obj) /* {{{ */ { MSGPACK_UNSERIALIZE_ALLOC_STACK(unpack); ZVAL_BOOL(*obj, 1); return 0; } /* }}} */ int msgpack_unserialize_false(msgpack_unserialize_data *unpack, zval **obj) /* {{{ */ { MSGPACK_UNSERIALIZE_ALLOC_STACK(unpack); ZVAL_BOOL(*obj, 0); return 0; } /* }}} */ int msgpack_unserialize_str(msgpack_unserialize_data *unpack, const char* base, const char* data, unsigned int len, zval **obj) /* {{{ */ { MSGPACK_VALIDATE_INPUT(unpack, data, len); MSGPACK_UNSERIALIZE_ALLOC_STACK(unpack); if (len == 0) { ZVAL_EMPTY_STRING(*obj); } else { /* TODO: check malformed input? */ if (len < 1<<8) { zend_string *zs = zend_string_init_interned(data, len, 0); ZVAL_STR(*obj, zs); } else { ZVAL_STRINGL(*obj, data, len); } } return 0; } /* }}} */ int msgpack_unserialize_ext(msgpack_unserialize_data *unpack, const char* base, const char* data, unsigned int len, zval **obj) /* {{{ */ { MSGPACK_VALIDATE_INPUT(unpack, data, len); MSGPACK_UNSERIALIZE_ALLOC_STACK(unpack); ZVAL_NULL(*obj); return 0; } /* }}} */ int msgpack_unserialize_array(msgpack_unserialize_data *unpack, unsigned int count, zval **obj) /* {{{ */ { MSGPACK_UNSERIALIZE_ALLOC_VALUE(unpack); array_init_size(*obj, MIN(count, 1<<16)); if (count) { unpack->stack[unpack->deps++] = count; } return 0; } /* }}} */ int msgpack_unserialize_array_item(msgpack_unserialize_data *unpack, zval **container, zval *obj) /* {{{ */ { zval *nval; if (!*container || Z_TYPE_P(*container) != IS_ARRAY) { return -1; } nval = zend_hash_next_index_insert(Z_ARRVAL_P(*container), obj); if (MSGPACK_IS_STACK_VALUE(obj)) { MSGPACK_UNSERIALIZE_FINISH_ITEM(unpack, obj, NULL); } else { msgpack_var_replace(obj, nval); MSGPACK_UNSERIALIZE_DEC_DEP(unpack); } return 0; } /* }}} */ int msgpack_unserialize_map(msgpack_unserialize_data *unpack, unsigned int count, zval **obj) /* {{{ */ { MSGPACK_UNSERIALIZE_ALLOC_VALUE(unpack); if (count) { unpack->stack[unpack->deps++] = count; } unpack->type = MSGPACK_SERIALIZE_TYPE_NONE; unpack->count = count; if (count == 0) { if (MSGPACK_G(php_only)) { object_init(*obj); } else { array_init(*obj); } } else { ZVAL_NULL(*obj); } return 0; } /* }}} */ int msgpack_unserialize_map_item(msgpack_unserialize_data *unpack, zval **container, zval *key, zval *val) /* {{{ */ { long deps; zval *nval; zval *container_val; if (MSGPACK_G(php_only)) { zend_class_entry *ce; if (Z_TYPE_P(key) == IS_NULL) { unpack->type = MSGPACK_SERIALIZE_TYPE_NONE; if (Z_TYPE_P(val) == IS_LONG) { switch (Z_LVAL_P(val)) { case MSGPACK_SERIALIZE_TYPE_REFERENCE: ZVAL_MAKE_REF(*container); break; case MSGPACK_SERIALIZE_TYPE_RECURSIVE: unpack->type = MSGPACK_SERIALIZE_TYPE_RECURSIVE; break; case MSGPACK_SERIALIZE_TYPE_CUSTOM_OBJECT: unpack->type = MSGPACK_SERIALIZE_TYPE_CUSTOM_OBJECT; break; case MSGPACK_SERIALIZE_TYPE_OBJECT_REFERENCE: unpack->type = MSGPACK_SERIALIZE_TYPE_OBJECT_REFERENCE; break; case MSGPACK_SERIALIZE_TYPE_OBJECT: unpack->type = MSGPACK_SERIALIZE_TYPE_OBJECT; break; default: break; } } else if (Z_TYPE_P(val) == IS_STRING) { ce = msgpack_unserialize_class(container, Z_STR_P(val), 1); if (ce == NULL) { MSGPACK_UNSERIALIZE_FINISH_MAP_ITEM(unpack, key, val); return 0; } } MSGPACK_UNSERIALIZE_FINISH_MAP_ITEM(unpack, key, val); return 0; } else { switch (unpack->type) { case MSGPACK_SERIALIZE_TYPE_CUSTOM_OBJECT: unpack->type = MSGPACK_SERIALIZE_TYPE_NONE; ce = msgpack_unserialize_class(container, Z_STR_P(key), 0); if (ce == NULL) { MSGPACK_UNSERIALIZE_FINISH_MAP_ITEM(unpack, key, val); return 0; } /* implementing Serializable */ if (ce->unserialize == NULL) { MSGPACK_WARNING( "[msgpack] (%s) Class %s has no unserializer", __FUNCTION__, ZSTR_VAL(ce->name)); MSGPACK_UNSERIALIZE_FINISH_MAP_ITEM(unpack, key, val); return 0; } ce->unserialize(*container, ce, (const unsigned char *)Z_STRVAL_P(val), Z_STRLEN_P(val) + 1, NULL); MSGPACK_UNSERIALIZE_FINISH_MAP_ITEM(unpack, key, val); return 0; case MSGPACK_SERIALIZE_TYPE_RECURSIVE: case MSGPACK_SERIALIZE_TYPE_OBJECT: case MSGPACK_SERIALIZE_TYPE_OBJECT_REFERENCE: { zval *rval; int type = unpack->type; unpack->type = MSGPACK_SERIALIZE_TYPE_NONE; if ((rval = msgpack_var_access(&unpack->var_hash, Z_LVAL_P(val) - 1)) == NULL) { if (UNEXPECTED(Z_LVAL_P(val) == 1 /* access the retval */)) { rval = unpack->retval; } else { MSGPACK_WARNING("[msgpack] (%s) Invalid references value: %ld", __FUNCTION__, Z_LVAL_P(val) - 1); MSGPACK_UNSERIALIZE_FINISH_MAP_ITEM(unpack, key, val); return 0; } } if (container != NULL) { zval_ptr_dtor(*container); } ZVAL_COPY_VALUE(*container, rval); if (type == MSGPACK_SERIALIZE_TYPE_OBJECT_REFERENCE) { ZVAL_MAKE_REF(*container); } Z_TRY_ADDREF_P(*container); MSGPACK_UNSERIALIZE_FINISH_MAP_ITEM(unpack, key, val); return 0; } } } } container_val = Z_ISREF_P(*container) ? Z_REFVAL_P(*container) : *container; if (Z_TYPE_P(container_val) == IS_OBJECT) { switch (Z_TYPE_P(key)) { case IS_LONG: if ((nval = zend_hash_index_update(Z_OBJPROP_P(container_val), Z_LVAL_P(key), val)) == NULL) { zval_ptr_dtor(val); MSGPACK_WARNING( "[msgpack] (%s) illegal offset type, skip this decoding", __FUNCTION__); } break; case IS_STRING: if (Z_OBJCE_P(container_val) != PHP_IC_ENTRY) { nval = update_property(Z_OBJCE_P(container_val), Z_OBJPROP_P(container_val), Z_STR_P(key), val); zval_ptr_dtor(key); zval_ptr_dtor(val); } else { if ((nval = zend_symtable_update(Z_OBJPROP_P(container_val), Z_STR_P(key), val)) == NULL) { zval_ptr_dtor(val); MSGPACK_WARNING( "[msgpack] (%s) illegal offset type, skip this decoding", __FUNCTION__); } zval_ptr_dtor(key); } break; default: MSGPACK_WARNING("[msgpack] (%s) illegal key type", __FUNCTION__); if (MSGPACK_G(illegal_key_insert)) { if ((nval = zend_hash_next_index_insert(Z_OBJPROP_P(container_val), key)) == NULL) { zval_ptr_dtor(key); } if ((nval = zend_hash_next_index_insert(Z_OBJPROP_P(container_val), val)) == NULL) { zval_ptr_dtor(val); } } else { zend_string *skey = zval_try_get_string(key); #if PHP_VERSION_ID >= 70400 if (!skey && EG(exception)) { zend_object_release(EG(exception)); EG(exception) = NULL; } #endif if (!skey || !(nval = zend_symtable_update(Z_OBJPROP_P(container_val), skey, val))) { zval_ptr_dtor(val); } if (skey) { zend_string_release(skey); } } break; } } else { if (Z_TYPE_P(container_val) != IS_ARRAY) { array_init_size(container_val, MIN(unpack->count, 1<<16)); #if PHP_VERSION_ID >= 70300 /* avoid re-alloc due packed..mixed conversion */ zend_hash_real_init_mixed(Z_ARRVAL_P(container_val)); #endif } switch (Z_TYPE_P(key)) { case IS_LONG: if ((nval = zend_hash_index_update(Z_ARRVAL_P(container_val), Z_LVAL_P(key), val)) == NULL) { zval_ptr_dtor(val); MSGPACK_WARNING( "[msgpack] (%s) illegal offset type, skip this decoding", __FUNCTION__); } break; case IS_STRING: if ((nval = zend_symtable_update(Z_ARRVAL_P(container_val), Z_STR_P(key), val)) == NULL) { zval_ptr_dtor(val); MSGPACK_WARNING( "[msgpack] (%s) illegal offset type, skip this decoding", __FUNCTION__); } zval_ptr_dtor(key); break; default: MSGPACK_WARNING("[msgpack] (%s) illegal key type", __FUNCTION__); if (MSGPACK_G(illegal_key_insert)) { if ((nval = zend_hash_next_index_insert(Z_ARRVAL_P(container_val), key)) == NULL) { zval_ptr_dtor(key); } if ((nval = zend_hash_next_index_insert(Z_ARRVAL_P(container_val), val)) == NULL) { zval_ptr_dtor(val); } } else { zend_string *skey = zval_try_get_string(key); #if PHP_VERSION_ID >= 70400 if (!skey && EG(exception)) { zend_object_release(EG(exception)); EG(exception) = NULL; } #endif if (!skey || !(nval = zend_symtable_update(Z_ARRVAL_P(container_val), skey, val))) { zval_ptr_dtor(val); } if (skey) { zend_string_release(skey); } } break; } } if (MSGPACK_IS_STACK_VALUE(val)) { msgpack_stack_pop(&unpack->var_hash, val); } else { msgpack_var_replace(val, nval); } if (MSGPACK_IS_STACK_VALUE(key)) { /* just in case for malformed data */ msgpack_stack_pop(&unpack->var_hash, key); } deps = unpack->deps - 1; unpack->stack[deps]--; if (unpack->stack[deps] == 0) { /* wakeup */ unpack->deps--; if (MSGPACK_G(php_only) && Z_TYPE_P(container_val) == IS_OBJECT && Z_OBJCE_P(container_val) != PHP_IC_ENTRY && zend_hash_str_exists(&Z_OBJCE_P(container_val)->function_table, "__wakeup", sizeof("__wakeup") - 1)) { zval wakeup, r; ZVAL_STRING(&wakeup, "__wakeup"); call_user_function_ex(CG(function_table), container_val, &wakeup, &r, 0, NULL, 1, NULL); zval_ptr_dtor(&r); zval_ptr_dtor(&wakeup); } } return 0; } /* }}} */ /* * Local variables: * tab-width: 4 * c-basic-offset: 4 * End: * vim600: noet sw=4 ts=4 fdm=marker * vim<600: noet sw=4 ts=4 */ msgpack-2.1.0beta1/msgpack_unpack.h0000644000175000001440000001323313577133502016067 0ustar mikeusers #ifndef MSGPACK_UNPACK_H #define MSGPACK_UNPACK_H #include "ext/standard/php_var.h" #define MSGPACK_EMBED_STACK_SIZE 1024 #include "msgpack/unpack_define.h" typedef enum { MSGPACK_UNPACK_SUCCESS = 2, MSGPACK_UNPACK_EXTRA_BYTES = 1, MSGPACK_UNPACK_CONTINUE = 0, MSGPACK_UNPACK_PARSE_ERROR = -1, MSGPACK_UNPACK_NOMEM_ERROR = -2 } msgpack_unpack_return; typedef struct _msgpack_unserialize_data { void *first; void *last; void *first_dtor; void *last_dtor; HashTable *allowed_classes; } msgpack_unserialize_data_t; typedef struct { zval *retval; const char *eof; int type; unsigned int count; long deps; long stack[MSGPACK_EMBED_STACK_SIZE]; msgpack_unserialize_data_t var_hash; } msgpack_unserialize_data; void msgpack_unserialize_var_init(msgpack_unserialize_data_t *var_hashx); void msgpack_unserialize_var_destroy(msgpack_unserialize_data_t *var_hashx, zend_bool err); void msgpack_unserialize_init(msgpack_unserialize_data *unpack); int msgpack_unserialize_uint8( msgpack_unserialize_data *unpack, uint8_t data, zval **obj); int msgpack_unserialize_uint16( msgpack_unserialize_data *unpack, uint16_t data, zval **obj); int msgpack_unserialize_uint32( msgpack_unserialize_data *unpack, uint32_t data, zval **obj); int msgpack_unserialize_uint64( msgpack_unserialize_data *unpack, uint64_t data, zval **obj); int msgpack_unserialize_int8( msgpack_unserialize_data *unpack, int8_t data, zval **obj); int msgpack_unserialize_int16( msgpack_unserialize_data *unpack, int16_t data, zval **obj); int msgpack_unserialize_int32( msgpack_unserialize_data *unpack, int32_t data, zval **obj); int msgpack_unserialize_int64( msgpack_unserialize_data *unpack, int64_t data, zval **obj); int msgpack_unserialize_float( msgpack_unserialize_data *unpack, float data, zval **obj); int msgpack_unserialize_double( msgpack_unserialize_data *unpack, double data, zval **obj); int msgpack_unserialize_nil(msgpack_unserialize_data *unpack, zval **obj); int msgpack_unserialize_true(msgpack_unserialize_data *unpack, zval **obj); int msgpack_unserialize_false(msgpack_unserialize_data *unpack, zval **obj); int msgpack_unserialize_str( msgpack_unserialize_data *unpack, const char* base, const char* data, unsigned int len, zval **obj); int msgpack_unserialize_ext( msgpack_unserialize_data *unpack, const char* base, const char* data, unsigned int len, zval **obj); int msgpack_unserialize_array( msgpack_unserialize_data *unpack, unsigned int count, zval **obj); int msgpack_unserialize_array_item( msgpack_unserialize_data *unpack, zval **container, zval *obj); int msgpack_unserialize_map( msgpack_unserialize_data *unpack, unsigned int count, zval **obj); int msgpack_unserialize_map_item( msgpack_unserialize_data *unpack, zval **container, zval *key, zval *val); /* template functions */ #define msgpack_unpack_struct(name) struct template ## name #define msgpack_unpack_func(ret, name) ret template ## name #define msgpack_unpack_callback(name) template_callback ## name #define msgpack_unpack_object zval* #define unpack_user msgpack_unserialize_data #define msgpack_unpack_user msgpack_unserialize_data struct template_context; typedef struct template_context msgpack_unpack_t; static void template_init(msgpack_unpack_t* unpack); static msgpack_unpack_object template_data(msgpack_unpack_t* unpack); static int template_execute( msgpack_unpack_t* unpack, const char* data, size_t len, size_t* off); static inline msgpack_unpack_object template_callback_root(unpack_user* user) { msgpack_unserialize_init(user); return NULL; } #define template_callback_uint8(user, data, obj) \ msgpack_unserialize_uint8(user, data, obj) #define template_callback_uint16(user, data, obj) \ msgpack_unserialize_uint16(user, data, obj) #define template_callback_uint32(user, data, obj) \ msgpack_unserialize_uint32(user, data, obj) #define template_callback_uint64(user, data, obj) \ msgpack_unserialize_uint64(user, data, obj) #define template_callback_int8(user, data, obj) \ msgpack_unserialize_int8(user, data, obj) #define template_callback_int16(user, data, obj) \ msgpack_unserialize_int16(user, data, obj) #define template_callback_int32(user, data, obj) \ msgpack_unserialize_int32(user, data, obj) #define template_callback_int64(user, data, obj) \ msgpack_unserialize_int64(user, data, obj) #define template_callback_float(user, data, obj) \ msgpack_unserialize_float(user, data, obj) #define template_callback_double(user, data, obj) \ msgpack_unserialize_double(user, data, obj) #define template_callback_nil(user, obj) \ msgpack_unserialize_nil(user, obj) #define template_callback_true(user, obj) \ msgpack_unserialize_true(user, obj) #define template_callback_false(user, obj) \ msgpack_unserialize_false(user, obj) #define template_callback_ext(user, base, data, len, obj) \ msgpack_unserialize_ext(user, base, data, len, obj) #define template_callback_raw template_callback_str #define template_callback_bin template_callback_str #define template_callback_str(user, base, data, len, obj) \ msgpack_unserialize_str(user, base, data, len, obj) #define template_callback_array(user, count, obj) \ msgpack_unserialize_array(user, count, obj) #define template_callback_array_item(user, container, obj) \ msgpack_unserialize_array_item(user, container, obj) #define template_callback_map(user, count, obj) \ msgpack_unserialize_map(user, count, obj) #define template_callback_map_item(user, container, key, val) \ msgpack_unserialize_map_item(user, container, key, val) #include "msgpack/unpack_template.h" #endif msgpack-2.1.0beta1/php_msgpack.h0000644000175000001440000000245713577133502015403 0ustar mikeusers#ifndef PHP_MSGPACK_H #define PHP_MSGPACK_H #include "Zend/zend_smart_str.h" /* for smart_string */ #define PHP_MSGPACK_VERSION "2.1.0beta1" extern zend_module_entry msgpack_module_entry; #define phpext_msgpack_ptr &msgpack_module_entry #ifdef PHP_WIN32 # define PHP_MSGPACK_API __declspec(dllexport) #elif defined(__GNUC__) && __GNUC__ >= 4 # define PHP_MSGPACK_API __attribute__ ((visibility("default"))) #else # define PHP_MSGPACK_API #endif #ifdef ZTS #include "TSRM.h" #endif ZEND_BEGIN_MODULE_GLOBALS(msgpack) zend_bool error_display; zend_bool php_only; zend_bool illegal_key_insert; zend_bool use_str8_serialization; struct { void *var_hash; unsigned level; } serialize; ZEND_END_MODULE_GLOBALS(msgpack) ZEND_EXTERN_MODULE_GLOBALS(msgpack) #ifdef ZTS #define MSGPACK_G(v) TSRMG(msgpack_globals_id, zend_msgpack_globals *, v) #else #define MSGPACK_G(v) (msgpack_globals.v) #endif PHP_MSGPACK_API void php_msgpack_serialize( smart_str *buf, zval *val); PHP_MSGPACK_API int php_msgpack_unserialize( zval *return_value, char *str, size_t str_len); #ifdef WORDS_BIGENDIAN # define MSGPACK_ENDIAN_BIG_BYTE 1 # define MSGPACK_ENDIAN_LITTLE_BYTE 0 #else # define MSGPACK_ENDIAN_LITTLE_BYTE 1 # define MSGPACK_ENDIAN_BIG_BYTE 0 #endif #endif /* PHP_MSGPACK_H */ msgpack-2.1.0beta1/msgpack/pack_define.h0000644000175000001440000000066013577133502016756 0ustar mikeusers/* * MessagePack unpacking routine template * * Copyright (C) 2008-2010 FURUHASHI Sadayuki * * Distributed under the Boost Software License, Version 1.0. * (See accompanying file LICENSE_1_0.txt or copy at * http://www.boost.org/LICENSE_1_0.txt) */ #ifndef MSGPACK_PACK_DEFINE_H #define MSGPACK_PACK_DEFINE_H #include "msgpack/sysdep.h" #include #include #endif /* msgpack/pack_define.h */ msgpack-2.1.0beta1/msgpack/pack_template.h0000644000175000001440000006035213577133502017343 0ustar mikeusers/* * MessagePack packing routine template * * Copyright (C) 2008-2010 FURUHASHI Sadayuki * * Distributed under the Boost Software License, Version 1.0. * (See accompanying file LICENSE_1_0.txt or copy at * http://www.boost.org/LICENSE_1_0.txt) */ #if MSGPACK_ENDIAN_LITTLE_BYTE #define TAKE8_8(d) ((uint8_t*)&d)[0] #define TAKE8_16(d) ((uint8_t*)&d)[0] #define TAKE8_32(d) ((uint8_t*)&d)[0] #define TAKE8_64(d) ((uint8_t*)&d)[0] #elif MSGPACK_ENDIAN_BIG_BYTE #define TAKE8_8(d) ((uint8_t*)&d)[0] #define TAKE8_16(d) ((uint8_t*)&d)[1] #define TAKE8_32(d) ((uint8_t*)&d)[3] #define TAKE8_64(d) ((uint8_t*)&d)[7] #else #error msgpack-c supports only big endian and little endian #endif #ifndef msgpack_pack_inline_func #error msgpack_pack_inline_func template is not defined #endif #ifndef msgpack_pack_user #error msgpack_pack_user type is not defined #endif #ifndef msgpack_pack_append_buffer #error msgpack_pack_append_buffer callback is not defined #endif #if defined(_MSC_VER) # pragma warning(push) # pragma warning(disable : 4204) /* nonstandard extension used: non-constant aggregate initializer */ #endif /* * Integer */ #define msgpack_pack_real_uint8(x, d) \ do { \ if(d < (1<<7)) { \ /* fixnum */ \ msgpack_pack_append_buffer(x, &TAKE8_8(d), 1); \ } else { \ /* unsigned 8 */ \ unsigned char buf[2] = {0xcc, TAKE8_8(d)}; \ msgpack_pack_append_buffer(x, buf, 2); \ } \ } while(0) #define msgpack_pack_real_uint16(x, d) \ do { \ if(d < (1<<7)) { \ /* fixnum */ \ msgpack_pack_append_buffer(x, &TAKE8_16(d), 1); \ } else if(d < (1<<8)) { \ /* unsigned 8 */ \ unsigned char buf[2] = {0xcc, TAKE8_16(d)}; \ msgpack_pack_append_buffer(x, buf, 2); \ } else { \ /* unsigned 16 */ \ unsigned char buf[3]; \ buf[0] = 0xcd; _msgpack_store16(&buf[1], (uint16_t)d); \ msgpack_pack_append_buffer(x, buf, 3); \ } \ } while(0) #define msgpack_pack_real_uint32(x, d) \ do { \ if(d < (1<<8)) { \ if(d < (1<<7)) { \ /* fixnum */ \ msgpack_pack_append_buffer(x, &TAKE8_32(d), 1); \ } else { \ /* unsigned 8 */ \ unsigned char buf[2] = {0xcc, TAKE8_32(d)}; \ msgpack_pack_append_buffer(x, buf, 2); \ } \ } else { \ if(d < (1<<16)) { \ /* unsigned 16 */ \ unsigned char buf[3]; \ buf[0] = 0xcd; _msgpack_store16(&buf[1], (uint16_t)d); \ msgpack_pack_append_buffer(x, buf, 3); \ } else { \ /* unsigned 32 */ \ unsigned char buf[5]; \ buf[0] = 0xce; _msgpack_store32(&buf[1], (uint32_t)d); \ msgpack_pack_append_buffer(x, buf, 5); \ } \ } \ } while(0) #define msgpack_pack_real_uint64(x, d) \ do { \ if(d < (1ULL<<8)) { \ if(d < (1ULL<<7)) { \ /* fixnum */ \ msgpack_pack_append_buffer(x, &TAKE8_64(d), 1); \ } else { \ /* unsigned 8 */ \ unsigned char buf[2] = {0xcc, TAKE8_64(d)}; \ msgpack_pack_append_buffer(x, buf, 2); \ } \ } else { \ if(d < (1ULL<<16)) { \ /* unsigned 16 */ \ unsigned char buf[3]; \ buf[0] = 0xcd; _msgpack_store16(&buf[1], (uint16_t)d); \ msgpack_pack_append_buffer(x, buf, 3); \ } else if(d < (1ULL<<32)) { \ /* unsigned 32 */ \ unsigned char buf[5]; \ buf[0] = 0xce; _msgpack_store32(&buf[1], (uint32_t)d); \ msgpack_pack_append_buffer(x, buf, 5); \ } else { \ /* unsigned 64 */ \ unsigned char buf[9]; \ buf[0] = 0xcf; _msgpack_store64(&buf[1], d); \ msgpack_pack_append_buffer(x, buf, 9); \ } \ } \ } while(0) #define msgpack_pack_real_int8(x, d) \ do { \ if(d < -(1<<5)) { \ /* signed 8 */ \ unsigned char buf[2] = {0xd0, TAKE8_8(d)}; \ msgpack_pack_append_buffer(x, buf, 2); \ } else { \ /* fixnum */ \ msgpack_pack_append_buffer(x, &TAKE8_8(d), 1); \ } \ } while(0) #define msgpack_pack_real_int16(x, d) \ do { \ if(d < -(1<<5)) { \ if(d < -(1<<7)) { \ /* signed 16 */ \ unsigned char buf[3]; \ buf[0] = 0xd1; _msgpack_store16(&buf[1], (int16_t)d); \ msgpack_pack_append_buffer(x, buf, 3); \ } else { \ /* signed 8 */ \ unsigned char buf[2] = {0xd0, TAKE8_16(d)}; \ msgpack_pack_append_buffer(x, buf, 2); \ } \ } else if(d < (1<<7)) { \ /* fixnum */ \ msgpack_pack_append_buffer(x, &TAKE8_16(d), 1); \ } else { \ if(d < (1<<8)) { \ /* unsigned 8 */ \ unsigned char buf[2] = {0xcc, TAKE8_16(d)}; \ msgpack_pack_append_buffer(x, buf, 2); \ } else { \ /* unsigned 16 */ \ unsigned char buf[3]; \ buf[0] = 0xcd; _msgpack_store16(&buf[1], (uint16_t)d); \ msgpack_pack_append_buffer(x, buf, 3); \ } \ } \ } while(0) #define msgpack_pack_real_int32(x, d) \ do { \ if(d < -(1<<5)) { \ if(d < -(1<<15)) { \ /* signed 32 */ \ unsigned char buf[5]; \ buf[0] = 0xd2; _msgpack_store32(&buf[1], (int32_t)d); \ msgpack_pack_append_buffer(x, buf, 5); \ } else if(d < -(1<<7)) { \ /* signed 16 */ \ unsigned char buf[3]; \ buf[0] = 0xd1; _msgpack_store16(&buf[1], (int16_t)d); \ msgpack_pack_append_buffer(x, buf, 3); \ } else { \ /* signed 8 */ \ unsigned char buf[2] = {0xd0, TAKE8_32(d)}; \ msgpack_pack_append_buffer(x, buf, 2); \ } \ } else if(d < (1<<7)) { \ /* fixnum */ \ msgpack_pack_append_buffer(x, &TAKE8_32(d), 1); \ } else { \ if(d < (1<<8)) { \ /* unsigned 8 */ \ unsigned char buf[2] = {0xcc, TAKE8_32(d)}; \ msgpack_pack_append_buffer(x, buf, 2); \ } else if(d < (1<<16)) { \ /* unsigned 16 */ \ unsigned char buf[3]; \ buf[0] = 0xcd; _msgpack_store16(&buf[1], (uint16_t)d); \ msgpack_pack_append_buffer(x, buf, 3); \ } else { \ /* unsigned 32 */ \ unsigned char buf[5]; \ buf[0] = 0xce; _msgpack_store32(&buf[1], (uint32_t)d); \ msgpack_pack_append_buffer(x, buf, 5); \ } \ } \ } while(0) #define msgpack_pack_real_int64(x, d) \ do { \ if(d < -(1LL<<5)) { \ if(d < -(1LL<<15)) { \ if(d < -(1LL<<31)) { \ /* signed 64 */ \ unsigned char buf[9]; \ buf[0] = 0xd3; _msgpack_store64(&buf[1], d); \ msgpack_pack_append_buffer(x, buf, 9); \ } else { \ /* signed 32 */ \ unsigned char buf[5]; \ buf[0] = 0xd2; _msgpack_store32(&buf[1], (int32_t)d); \ msgpack_pack_append_buffer(x, buf, 5); \ } \ } else { \ if(d < -(1<<7)) { \ /* signed 16 */ \ unsigned char buf[3]; \ buf[0] = 0xd1; _msgpack_store16(&buf[1], (int16_t)d); \ msgpack_pack_append_buffer(x, buf, 3); \ } else { \ /* signed 8 */ \ unsigned char buf[2] = {0xd0, TAKE8_64(d)}; \ msgpack_pack_append_buffer(x, buf, 2); \ } \ } \ } else if(d < (1<<7)) { \ /* fixnum */ \ msgpack_pack_append_buffer(x, &TAKE8_64(d), 1); \ } else { \ if(d < (1LL<<16)) { \ if(d < (1<<8)) { \ /* unsigned 8 */ \ unsigned char buf[2] = {0xcc, TAKE8_64(d)}; \ msgpack_pack_append_buffer(x, buf, 2); \ } else { \ /* unsigned 16 */ \ unsigned char buf[3]; \ buf[0] = 0xcd; _msgpack_store16(&buf[1], (uint16_t)d); \ msgpack_pack_append_buffer(x, buf, 3); \ } \ } else { \ if(d < (1LL<<32)) { \ /* unsigned 32 */ \ unsigned char buf[5]; \ buf[0] = 0xce; _msgpack_store32(&buf[1], (uint32_t)d); \ msgpack_pack_append_buffer(x, buf, 5); \ } else { \ /* unsigned 64 */ \ unsigned char buf[9]; \ buf[0] = 0xcf; _msgpack_store64(&buf[1], d); \ msgpack_pack_append_buffer(x, buf, 9); \ } \ } \ } \ } while(0) #ifdef msgpack_pack_inline_func_fixint msgpack_pack_inline_func_fixint(_uint8)(msgpack_pack_user x, uint8_t d) { unsigned char buf[2] = {0xcc, TAKE8_8(d)}; msgpack_pack_append_buffer(x, buf, 2); } msgpack_pack_inline_func_fixint(_uint16)(msgpack_pack_user x, uint16_t d) { unsigned char buf[3]; buf[0] = 0xcd; _msgpack_store16(&buf[1], d); msgpack_pack_append_buffer(x, buf, 3); } msgpack_pack_inline_func_fixint(_uint32)(msgpack_pack_user x, uint32_t d) { unsigned char buf[5]; buf[0] = 0xce; _msgpack_store32(&buf[1], d); msgpack_pack_append_buffer(x, buf, 5); } msgpack_pack_inline_func_fixint(_uint64)(msgpack_pack_user x, uint64_t d) { unsigned char buf[9]; buf[0] = 0xcf; _msgpack_store64(&buf[1], d); msgpack_pack_append_buffer(x, buf, 9); } msgpack_pack_inline_func_fixint(_int8)(msgpack_pack_user x, int8_t d) { unsigned char buf[2] = {0xd0, TAKE8_8(d)}; msgpack_pack_append_buffer(x, buf, 2); } msgpack_pack_inline_func_fixint(_int16)(msgpack_pack_user x, int16_t d) { unsigned char buf[3]; buf[0] = 0xd1; _msgpack_store16(&buf[1], d); msgpack_pack_append_buffer(x, buf, 3); } msgpack_pack_inline_func_fixint(_int32)(msgpack_pack_user x, int32_t d) { unsigned char buf[5]; buf[0] = 0xd2; _msgpack_store32(&buf[1], d); msgpack_pack_append_buffer(x, buf, 5); } msgpack_pack_inline_func_fixint(_int64)(msgpack_pack_user x, int64_t d) { unsigned char buf[9]; buf[0] = 0xd3; _msgpack_store64(&buf[1], d); msgpack_pack_append_buffer(x, buf, 9); } #undef msgpack_pack_inline_func_fixint #endif msgpack_pack_inline_func(_uint8)(msgpack_pack_user x, uint8_t d) { msgpack_pack_real_uint8(x, d); } msgpack_pack_inline_func(_uint16)(msgpack_pack_user x, uint16_t d) { msgpack_pack_real_uint16(x, d); } msgpack_pack_inline_func(_uint32)(msgpack_pack_user x, uint32_t d) { msgpack_pack_real_uint32(x, d); } msgpack_pack_inline_func(_uint64)(msgpack_pack_user x, uint64_t d) { msgpack_pack_real_uint64(x, d); } msgpack_pack_inline_func(_int8)(msgpack_pack_user x, int8_t d) { msgpack_pack_real_int8(x, d); } msgpack_pack_inline_func(_int16)(msgpack_pack_user x, int16_t d) { msgpack_pack_real_int16(x, d); } msgpack_pack_inline_func(_int32)(msgpack_pack_user x, int32_t d) { msgpack_pack_real_int32(x, d); } msgpack_pack_inline_func(_int64)(msgpack_pack_user x, int64_t d) { msgpack_pack_real_int64(x, d); } msgpack_pack_inline_func(_char)(msgpack_pack_user x, char d) { #if defined(CHAR_MIN) #if CHAR_MIN < 0 msgpack_pack_real_int8(x, d); #else msgpack_pack_real_uint8(x, d); #endif #else #error CHAR_MIN is not defined #endif } msgpack_pack_inline_func(_signed_char)(msgpack_pack_user x, signed char d) { msgpack_pack_real_int8(x, d); } msgpack_pack_inline_func(_unsigned_char)(msgpack_pack_user x, unsigned char d) { msgpack_pack_real_uint8(x, d); } #ifdef msgpack_pack_inline_func_cint msgpack_pack_inline_func_cint(_short)(msgpack_pack_user x, short d) { #if defined(SIZEOF_SHORT) #if SIZEOF_SHORT == 2 msgpack_pack_real_int16(x, d); #elif SIZEOF_SHORT == 4 msgpack_pack_real_int32(x, d); #else msgpack_pack_real_int64(x, d); #endif #elif defined(SHRT_MAX) #if SHRT_MAX == 0x7fff msgpack_pack_real_int16(x, d); #elif SHRT_MAX == 0x7fffffff msgpack_pack_real_int32(x, d); #else msgpack_pack_real_int64(x, d); #endif #else if(sizeof(short) == 2) { msgpack_pack_real_int16(x, d); } else if(sizeof(short) == 4) { msgpack_pack_real_int32(x, d); } else { msgpack_pack_real_int64(x, d); } #endif } msgpack_pack_inline_func_cint(_int)(msgpack_pack_user x, int d) { #if defined(SIZEOF_INT) #if SIZEOF_INT == 2 msgpack_pack_real_int16(x, d); #elif SIZEOF_INT == 4 msgpack_pack_real_int32(x, d); #else msgpack_pack_real_int64(x, d); #endif #elif defined(INT_MAX) #if INT_MAX == 0x7fff msgpack_pack_real_int16(x, d); #elif INT_MAX == 0x7fffffff msgpack_pack_real_int32(x, d); #else msgpack_pack_real_int64(x, d); #endif #else if(sizeof(int) == 2) { msgpack_pack_real_int16(x, d); } else if(sizeof(int) == 4) { msgpack_pack_real_int32(x, d); } else { msgpack_pack_real_int64(x, d); } #endif } msgpack_pack_inline_func_cint(_long)(msgpack_pack_user x, long d) { #if defined(SIZEOF_LONG) #if SIZEOF_LONG == 2 msgpack_pack_real_int16(x, d); #elif SIZEOF_LONG == 4 msgpack_pack_real_int32(x, d); #else msgpack_pack_real_int64(x, d); #endif #elif defined(LONG_MAX) #if LONG_MAX == 0x7fffL msgpack_pack_real_int16(x, d); #elif LONG_MAX == 0x7fffffffL msgpack_pack_real_int32(x, d); #else msgpack_pack_real_int64(x, d); #endif #else if(sizeof(long) == 2) { msgpack_pack_real_int16(x, d); } else if(sizeof(long) == 4) { msgpack_pack_real_int32(x, d); } else { msgpack_pack_real_int64(x, d); } #endif } msgpack_pack_inline_func_cint(_long_long)(msgpack_pack_user x, long long d) { #if defined(SIZEOF_LONG_LONG) #if SIZEOF_LONG_LONG == 2 msgpack_pack_real_int16(x, d); #elif SIZEOF_LONG_LONG == 4 msgpack_pack_real_int32(x, d); #else msgpack_pack_real_int64(x, d); #endif #elif defined(LLONG_MAX) #if LLONG_MAX == 0x7fffL msgpack_pack_real_int16(x, d); #elif LLONG_MAX == 0x7fffffffL msgpack_pack_real_int32(x, d); #else msgpack_pack_real_int64(x, d); #endif #else if(sizeof(long long) == 2) { msgpack_pack_real_int16(x, d); } else if(sizeof(long long) == 4) { msgpack_pack_real_int32(x, d); } else { msgpack_pack_real_int64(x, d); } #endif } msgpack_pack_inline_func_cint(_unsigned_short)(msgpack_pack_user x, unsigned short d) { #if defined(SIZEOF_SHORT) #if SIZEOF_SHORT == 2 msgpack_pack_real_uint16(x, d); #elif SIZEOF_SHORT == 4 msgpack_pack_real_uint32(x, d); #else msgpack_pack_real_uint64(x, d); #endif #elif defined(USHRT_MAX) #if USHRT_MAX == 0xffffU msgpack_pack_real_uint16(x, d); #elif USHRT_MAX == 0xffffffffU msgpack_pack_real_uint32(x, d); #else msgpack_pack_real_uint64(x, d); #endif #else if(sizeof(unsigned short) == 2) { msgpack_pack_real_uint16(x, d); } else if(sizeof(unsigned short) == 4) { msgpack_pack_real_uint32(x, d); } else { msgpack_pack_real_uint64(x, d); } #endif } msgpack_pack_inline_func_cint(_unsigned_int)(msgpack_pack_user x, unsigned int d) { #if defined(SIZEOF_INT) #if SIZEOF_INT == 2 msgpack_pack_real_uint16(x, d); #elif SIZEOF_INT == 4 msgpack_pack_real_uint32(x, d); #else msgpack_pack_real_uint64(x, d); #endif #elif defined(UINT_MAX) #if UINT_MAX == 0xffffU msgpack_pack_real_uint16(x, d); #elif UINT_MAX == 0xffffffffU msgpack_pack_real_uint32(x, d); #else msgpack_pack_real_uint64(x, d); #endif #else if(sizeof(unsigned int) == 2) { msgpack_pack_real_uint16(x, d); } else if(sizeof(unsigned int) == 4) { msgpack_pack_real_uint32(x, d); } else { msgpack_pack_real_uint64(x, d); } #endif } msgpack_pack_inline_func_cint(_unsigned_long)(msgpack_pack_user x, unsigned long d) { #if defined(SIZEOF_LONG) #if SIZEOF_LONG == 2 msgpack_pack_real_uint16(x, d); #elif SIZEOF_LONG == 4 msgpack_pack_real_uint32(x, d); #else msgpack_pack_real_uint64(x, d); #endif #elif defined(ULONG_MAX) #if ULONG_MAX == 0xffffUL msgpack_pack_real_uint16(x, d); #elif ULONG_MAX == 0xffffffffUL msgpack_pack_real_uint32(x, d); #else msgpack_pack_real_uint64(x, d); #endif #else if(sizeof(unsigned long) == 2) { msgpack_pack_real_uint16(x, d); } else if(sizeof(unsigned long) == 4) { msgpack_pack_real_uint32(x, d); } else { msgpack_pack_real_uint64(x, d); } #endif } msgpack_pack_inline_func_cint(_unsigned_long_long)(msgpack_pack_user x, unsigned long long d) { #if defined(SIZEOF_LONG_LONG) #if SIZEOF_LONG_LONG == 2 msgpack_pack_real_uint16(x, d); #elif SIZEOF_LONG_LONG == 4 msgpack_pack_real_uint32(x, d); #else msgpack_pack_real_uint64(x, d); #endif #elif defined(ULLONG_MAX) #if ULLONG_MAX == 0xffffUL msgpack_pack_real_uint16(x, d); #elif ULLONG_MAX == 0xffffffffUL msgpack_pack_real_uint32(x, d); #else msgpack_pack_real_uint64(x, d); #endif #else if(sizeof(unsigned long long) == 2) { msgpack_pack_real_uint16(x, d); } else if(sizeof(unsigned long long) == 4) { msgpack_pack_real_uint32(x, d); } else { msgpack_pack_real_uint64(x, d); } #endif } #undef msgpack_pack_inline_func_cint #endif /* * Float */ msgpack_pack_inline_func(_float)(msgpack_pack_user x, float d) { unsigned char buf[5]; union { float f; uint32_t i; } mem; mem.f = d; buf[0] = 0xca; _msgpack_store32(&buf[1], mem.i); msgpack_pack_append_buffer(x, buf, 5); } msgpack_pack_inline_func(_double)(msgpack_pack_user x, double d) { unsigned char buf[9]; union { double f; uint64_t i; } mem; mem.f = d; buf[0] = 0xcb; #if defined(TARGET_OS_IPHONE) // ok #elif defined(__arm__) && !(__ARM_EABI__) // arm-oabi // https://github.com/msgpack/msgpack-perl/pull/1 mem.i = (mem.i & 0xFFFFFFFFUL) << 32UL | (mem.i >> 32UL); #endif _msgpack_store64(&buf[1], mem.i); msgpack_pack_append_buffer(x, buf, 9); } /* * Nil */ msgpack_pack_inline_func(_nil)(msgpack_pack_user x) { static const unsigned char d = 0xc0; msgpack_pack_append_buffer(x, &d, 1); } /* * Boolean */ msgpack_pack_inline_func(_true)(msgpack_pack_user x) { static const unsigned char d = 0xc3; msgpack_pack_append_buffer(x, &d, 1); } msgpack_pack_inline_func(_false)(msgpack_pack_user x) { static const unsigned char d = 0xc2; msgpack_pack_append_buffer(x, &d, 1); } /* * Array */ msgpack_pack_inline_func(_array)(msgpack_pack_user x, size_t n) { if(n < 16) { unsigned char d = 0x90 | (uint8_t)n; msgpack_pack_append_buffer(x, &d, 1); } else if(n < 65536) { unsigned char buf[3]; buf[0] = 0xdc; _msgpack_store16(&buf[1], (uint16_t)n); msgpack_pack_append_buffer(x, buf, 3); } else { unsigned char buf[5]; buf[0] = 0xdd; _msgpack_store32(&buf[1], (uint32_t)n); msgpack_pack_append_buffer(x, buf, 5); } } /* * Map */ msgpack_pack_inline_func(_map)(msgpack_pack_user x, size_t n) { if(n < 16) { unsigned char d = 0x80 | (uint8_t)n; msgpack_pack_append_buffer(x, &TAKE8_8(d), 1); } else if(n < 65536) { unsigned char buf[3]; buf[0] = 0xde; _msgpack_store16(&buf[1], (uint16_t)n); msgpack_pack_append_buffer(x, buf, 3); } else { unsigned char buf[5]; buf[0] = 0xdf; _msgpack_store32(&buf[1], (uint32_t)n); msgpack_pack_append_buffer(x, buf, 5); } } /* * Str */ msgpack_pack_inline_func(_str)(msgpack_pack_user x, size_t l) { if(l < 32) { unsigned char d = 0xa0 | (uint8_t)l; msgpack_pack_append_buffer(x, &TAKE8_8(d), 1); } else if(l < 256) { unsigned char buf[2]; buf[0] = 0xd9; buf[1] = (uint8_t)l; msgpack_pack_append_buffer(x, buf, 2); } else if(l < 65536) { unsigned char buf[3]; buf[0] = 0xda; _msgpack_store16(&buf[1], (uint16_t)l); msgpack_pack_append_buffer(x, buf, 3); } else { unsigned char buf[5]; buf[0] = 0xdb; _msgpack_store32(&buf[1], (uint32_t)l); msgpack_pack_append_buffer(x, buf, 5); } } msgpack_pack_inline_func(_str_body)(msgpack_pack_user x, const void* b, size_t l) { msgpack_pack_append_buffer(x, (const unsigned char*)b, l); } /* * Raw (V4) */ msgpack_pack_inline_func(_v4raw)(msgpack_pack_user x, size_t l) { if(l < 32) { unsigned char d = 0xa0 | (uint8_t)l; msgpack_pack_append_buffer(x, &TAKE8_8(d), 1); } else if(l < 65536) { unsigned char buf[3]; buf[0] = 0xda; _msgpack_store16(&buf[1], (uint16_t)l); msgpack_pack_append_buffer(x, buf, 3); } else { unsigned char buf[5]; buf[0] = 0xdb; _msgpack_store32(&buf[1], (uint32_t)l); msgpack_pack_append_buffer(x, buf, 5); } } msgpack_pack_inline_func(_v4raw_body)(msgpack_pack_user x, const void* b, size_t l) { msgpack_pack_append_buffer(x, (const unsigned char*)b, l); } /* * Bin */ msgpack_pack_inline_func(_bin)(msgpack_pack_user x, size_t l) { if(l < 256) { unsigned char buf[2]; buf[0] = 0xc4; buf[1] = (uint8_t)l; msgpack_pack_append_buffer(x, buf, 2); } else if(l < 65536) { unsigned char buf[3]; buf[0] = 0xc5; _msgpack_store16(&buf[1], (uint16_t)l); msgpack_pack_append_buffer(x, buf, 3); } else { unsigned char buf[5]; buf[0] = 0xc6; _msgpack_store32(&buf[1], (uint32_t)l); msgpack_pack_append_buffer(x, buf, 5); } } msgpack_pack_inline_func(_bin_body)(msgpack_pack_user x, const void* b, size_t l) { msgpack_pack_append_buffer(x, (const unsigned char*)b, l); } /* * Ext */ msgpack_pack_inline_func(_ext)(msgpack_pack_user x, size_t l, int8_t type) { switch(l) { case 1: { unsigned char buf[2]; buf[0] = 0xd4; buf[1] = (unsigned char)type; msgpack_pack_append_buffer(x, buf, 2); } break; case 2: { unsigned char buf[2]; buf[0] = 0xd5; buf[1] = (unsigned char)type; msgpack_pack_append_buffer(x, buf, 2); } break; case 4: { unsigned char buf[2]; buf[0] = 0xd6; buf[1] = (unsigned char)type; msgpack_pack_append_buffer(x, buf, 2); } break; case 8: { unsigned char buf[2]; buf[0] = 0xd7; buf[1] = (unsigned char)type; msgpack_pack_append_buffer(x, buf, 2); } break; case 16: { unsigned char buf[2]; buf[0] = 0xd8; buf[1] = (unsigned char)type; msgpack_pack_append_buffer(x, buf, 2); } break; default: if(l < 256) { unsigned char buf[3]; buf[0] = 0xc7; buf[1] = (unsigned char)l; buf[2] = (unsigned char)type; msgpack_pack_append_buffer(x, buf, 3); } else if(l < 65536) { unsigned char buf[4]; buf[0] = 0xc8; _msgpack_store16(&buf[1], l); buf[3] = (unsigned char)type; msgpack_pack_append_buffer(x, buf, 4); } else { unsigned char buf[6]; buf[0] = 0xc9; _msgpack_store32(&buf[1], l); buf[5] = (unsigned char)type; msgpack_pack_append_buffer(x, buf, 6); } break; } } msgpack_pack_inline_func(_ext_body)(msgpack_pack_user x, const void* b, size_t l) { msgpack_pack_append_buffer(x, (const unsigned char*)b, l); } msgpack_pack_inline_func(_timestamp)(msgpack_pack_user x, const msgpack_timestamp* d) { if ((((int64_t)d->tv_sec) >> 34) == 0) { uint64_t data64 = ((uint64_t) d->tv_nsec << 34) | (uint64_t)d->tv_sec; if ((data64 & 0xffffffff00000000L) == 0) { // timestamp 32 char buf[4]; uint32_t data32 = (uint32_t)data64; msgpack_pack_ext(x, 4, -1); _msgpack_store32(buf, data32); msgpack_pack_append_buffer(x, buf, 4); } else { // timestamp 64 char buf[8]; msgpack_pack_ext(x, 8, -1); _msgpack_store64(buf, data64); msgpack_pack_append_buffer(x, buf, 8); } } else { // timestamp 96 char buf[12]; _msgpack_store32(&buf[0], d->tv_nsec); _msgpack_store64(&buf[4], d->tv_sec); msgpack_pack_ext(x, 12, -1); msgpack_pack_append_buffer(x, buf, 12); } } #undef msgpack_pack_inline_func #undef msgpack_pack_user #undef msgpack_pack_append_buffer #undef TAKE8_8 #undef TAKE8_16 #undef TAKE8_32 #undef TAKE8_64 #undef msgpack_pack_real_uint8 #undef msgpack_pack_real_uint16 #undef msgpack_pack_real_uint32 #undef msgpack_pack_real_uint64 #undef msgpack_pack_real_int8 #undef msgpack_pack_real_int16 #undef msgpack_pack_real_int32 #undef msgpack_pack_real_int64 #if defined(_MSC_VER) # pragma warning(pop) #endif msgpack-2.1.0beta1/msgpack/unpack_define.h0000644000175000001440000000440113577133502017316 0ustar mikeusers/* * MessagePack unpacking routine template * * Copyright (C) 2008-2010 FURUHASHI Sadayuki * * Distributed under the Boost Software License, Version 1.0. * (See accompanying file LICENSE_1_0.txt or copy at * http://www.boost.org/LICENSE_1_0.txt) */ #ifndef MSGPACK_UNPACK_DEFINE_H #define MSGPACK_UNPACK_DEFINE_H #include "msgpack/sysdep.h" #include #include #include #include #ifdef __cplusplus extern "C" { #endif #ifndef MSGPACK_EMBED_STACK_SIZE #define MSGPACK_EMBED_STACK_SIZE 32 #endif typedef enum { MSGPACK_CS_HEADER = 0x00, // nil //MSGPACK_CS_ = 0x01, //MSGPACK_CS_ = 0x02, // false //MSGPACK_CS_ = 0x03, // true MSGPACK_CS_BIN_8 = 0x04, MSGPACK_CS_BIN_16 = 0x05, MSGPACK_CS_BIN_32 = 0x06, MSGPACK_CS_EXT_8 = 0x07, MSGPACK_CS_EXT_16 = 0x08, MSGPACK_CS_EXT_32 = 0x09, MSGPACK_CS_FLOAT = 0x0a, MSGPACK_CS_DOUBLE = 0x0b, MSGPACK_CS_UINT_8 = 0x0c, MSGPACK_CS_UINT_16 = 0x0d, MSGPACK_CS_UINT_32 = 0x0e, MSGPACK_CS_UINT_64 = 0x0f, MSGPACK_CS_INT_8 = 0x10, MSGPACK_CS_INT_16 = 0x11, MSGPACK_CS_INT_32 = 0x12, MSGPACK_CS_INT_64 = 0x13, MSGPACK_CS_FIXEXT_1 = 0x14, MSGPACK_CS_FIXEXT_2 = 0x15, MSGPACK_CS_FIXEXT_4 = 0x16, MSGPACK_CS_FIXEXT_8 = 0x17, MSGPACK_CS_FIXEXT_16 = 0x18, MSGPACK_CS_STR_8 = 0x19, // str8 MSGPACK_CS_STR_16 = 0x1a, // str16 MSGPACK_CS_STR_32 = 0x1b, // str32 MSGPACK_CS_ARRAY_16 = 0x1c, MSGPACK_CS_ARRAY_32 = 0x1d, MSGPACK_CS_MAP_16 = 0x1e, MSGPACK_CS_MAP_32 = 0x1f, //MSGPACK_ACS_BIG_INT_VALUE, //MSGPACK_ACS_BIG_FLOAT_VALUE, MSGPACK_ACS_STR_VALUE, MSGPACK_ACS_BIN_VALUE, MSGPACK_ACS_EXT_VALUE } msgpack_unpack_state; typedef enum { MSGPACK_CT_ARRAY_ITEM, MSGPACK_CT_MAP_KEY, MSGPACK_CT_MAP_VALUE } msgpack_container_type; #ifdef __cplusplus } #endif #endif /* msgpack/unpack_define.h */ msgpack-2.1.0beta1/msgpack/unpack_template.h0000644000175000001440000004041713577133502017706 0ustar mikeusers/* * MessagePack unpacking routine template * * Copyright (C) 2008-2010 FURUHASHI Sadayuki * * Distributed under the Boost Software License, Version 1.0. * (See accompanying file LICENSE_1_0.txt or copy at * http://www.boost.org/LICENSE_1_0.txt) */ #ifndef msgpack_unpack_func #error msgpack_unpack_func template is not defined #endif #ifndef msgpack_unpack_callback #error msgpack_unpack_callback template is not defined #endif #ifndef msgpack_unpack_struct #error msgpack_unpack_struct template is not defined #endif #ifndef msgpack_unpack_struct_decl #define msgpack_unpack_struct_decl(name) msgpack_unpack_struct(name) #endif #ifndef msgpack_unpack_object #error msgpack_unpack_object type is not defined #endif #ifndef msgpack_unpack_user #error msgpack_unpack_user type is not defined #endif #ifndef USE_CASE_RANGE #if !defined(_MSC_VER) #define USE_CASE_RANGE #endif #endif #if defined(_KERNEL_MODE) #undef assert #define assert NT_ASSERT #endif msgpack_unpack_struct_decl(_stack) { msgpack_unpack_object obj; size_t count; unsigned int ct; msgpack_unpack_object map_key; }; msgpack_unpack_struct_decl(_context) { msgpack_unpack_user user; unsigned int cs; unsigned int trail; unsigned int top; /* msgpack_unpack_struct(_stack)* stack; unsigned int stack_size; msgpack_unpack_struct(_stack) embed_stack[MSGPACK_EMBED_STACK_SIZE]; */ msgpack_unpack_struct(_stack) stack[MSGPACK_EMBED_STACK_SIZE]; }; msgpack_unpack_func(void, _init)(msgpack_unpack_struct(_context)* ctx) { ctx->cs = MSGPACK_CS_HEADER; ctx->trail = 0; ctx->top = 0; /* ctx->stack = ctx->embed_stack; ctx->stack_size = MSGPACK_EMBED_STACK_SIZE; */ ctx->stack[0].obj = msgpack_unpack_callback(_root)(&ctx->user); } /* msgpack_unpack_func(void, _destroy)(msgpack_unpack_struct(_context)* ctx) { if(ctx->stack_size != MSGPACK_EMBED_STACK_SIZE) { free(ctx->stack); } } */ msgpack_unpack_func(msgpack_unpack_object, _data)(msgpack_unpack_struct(_context)* ctx) { return (ctx)->stack[0].obj; } msgpack_unpack_func(int, _execute)(msgpack_unpack_struct(_context)* ctx, const char* data, size_t len, size_t* off) { assert(len >= *off); { const unsigned char* p = (unsigned char*)data + *off; const unsigned char* const pe = (unsigned char*)data + len; const void* n = NULL; unsigned int trail = ctx->trail; unsigned int cs = ctx->cs; unsigned int top = ctx->top; msgpack_unpack_struct(_stack)* stack = ctx->stack; /* unsigned int stack_size = ctx->stack_size; */ msgpack_unpack_user* user = &ctx->user; msgpack_unpack_object obj = NULL; msgpack_unpack_struct(_stack)* c = NULL; int ret; #define push_simple_value(func) \ ret = msgpack_unpack_callback(func)(user, &obj); \ if(ret < 0) { goto _failed; } \ goto _push #define push_fixed_value(func, arg) \ ret = msgpack_unpack_callback(func)(user, arg, &obj); \ if(ret < 0) { goto _failed; } \ goto _push #define push_variable_value(func, base, pos, len) \ ret = msgpack_unpack_callback(func)(user, \ (const char*)base, (const char*)pos, len, &obj); \ if(ret < 0) { goto _failed; } \ goto _push #define again_fixed_trail(_cs, trail_len) \ trail = trail_len; \ cs = _cs; \ goto _fixed_trail_again #define again_fixed_trail_if_zero(_cs, trail_len, ifzero) \ trail = trail_len; \ if(trail == 0) { goto ifzero; } \ cs = _cs; \ goto _fixed_trail_again #define start_container(func, count_, ct_) \ if(top >= MSGPACK_EMBED_STACK_SIZE) { \ ret = MSGPACK_UNPACK_NOMEM_ERROR; \ goto _failed; \ } /* FIXME */ \ ret = msgpack_unpack_callback(func)(user, count_, &stack[top].obj); \ if(ret < 0) { goto _failed; } \ if((count_) == 0) { obj = stack[top].obj; goto _push; } \ stack[top].ct = ct_; \ stack[top].count = count_; \ ++top; \ goto _header_again #define NEXT_CS(p) \ ((unsigned int)*p & 0x1f) #ifdef USE_CASE_RANGE #define SWITCH_RANGE_BEGIN switch(*p) { #define SWITCH_RANGE(FROM, TO) case FROM ... TO: #define SWITCH_RANGE_DEFAULT default: #define SWITCH_RANGE_END } #else #define SWITCH_RANGE_BEGIN { if(0) { #define SWITCH_RANGE(FROM, TO) } else if(FROM <= *p && *p <= TO) { #define SWITCH_RANGE_DEFAULT } else { #define SWITCH_RANGE_END } } #endif if(p == pe) { goto _out; } do { switch(cs) { case MSGPACK_CS_HEADER: SWITCH_RANGE_BEGIN SWITCH_RANGE(0x00, 0x7f) // Positive Fixnum push_fixed_value(_uint8, *(uint8_t*)p); SWITCH_RANGE(0xe0, 0xff) // Negative Fixnum push_fixed_value(_int8, *(int8_t*)p); SWITCH_RANGE(0xc0, 0xdf) // Variable switch(*p) { case 0xc0: // nil push_simple_value(_nil); //case 0xc1: // string // again_terminal_trail(NEXT_CS(p), p+1); case 0xc2: // false push_simple_value(_false); case 0xc3: // true push_simple_value(_true); case 0xc4: // bin 8 case 0xc5: // bin 16 case 0xc6: // bin 32 again_fixed_trail(NEXT_CS(p), 1 << (((unsigned int)*p) & 0x03)); case 0xc7: // ext 8 case 0xc8: // ext 16 case 0xc9: // ext 32 again_fixed_trail(NEXT_CS(p), 1 << ((((unsigned int)*p) + 1) & 0x03)); case 0xca: // float case 0xcb: // double case 0xcc: // unsigned int 8 case 0xcd: // unsigned int 16 case 0xce: // unsigned int 32 case 0xcf: // unsigned int 64 case 0xd0: // signed int 8 case 0xd1: // signed int 16 case 0xd2: // signed int 32 case 0xd3: // signed int 64 again_fixed_trail(NEXT_CS(p), 1 << (((unsigned int)*p) & 0x03)); case 0xd4: // fixext 1 case 0xd5: // fixext 2 case 0xd6: // fixext 4 case 0xd7: // fixext 8 again_fixed_trail_if_zero(MSGPACK_ACS_EXT_VALUE, (1 << (((unsigned int)*p) & 0x03)) + 1, _ext_zero); case 0xd8: // fixext 16 again_fixed_trail_if_zero(MSGPACK_ACS_EXT_VALUE, 16+1, _ext_zero); case 0xd9: // str 8 case 0xda: // str 16 case 0xdb: // str 32 again_fixed_trail(NEXT_CS(p), 1 << ((((unsigned int)*p) & 0x03) - 1)); case 0xdc: // array 16 case 0xdd: // array 32 case 0xde: // map 16 case 0xdf: // map 32 again_fixed_trail(NEXT_CS(p), 2u << (((unsigned int)*p) & 0x01)); default: ret = MSGPACK_UNPACK_PARSE_ERROR; goto _failed; } SWITCH_RANGE(0xa0, 0xbf) // FixStr again_fixed_trail_if_zero(MSGPACK_ACS_STR_VALUE, ((unsigned int)*p & 0x1f), _str_zero); SWITCH_RANGE(0x90, 0x9f) // FixArray start_container(_array, ((unsigned int)*p) & 0x0f, MSGPACK_CT_ARRAY_ITEM); SWITCH_RANGE(0x80, 0x8f) // FixMap start_container(_map, ((unsigned int)*p) & 0x0f, MSGPACK_CT_MAP_KEY); SWITCH_RANGE_DEFAULT ret = MSGPACK_UNPACK_PARSE_ERROR; goto _failed; SWITCH_RANGE_END // end MSGPACK_CS_HEADER _fixed_trail_again: ++p; // fallthrough default: if((size_t)(pe - p) < trail) { goto _out; } n = p; p += trail - 1; switch(cs) { //case MSGPACK_CS_ //case MSGPACK_CS_ case MSGPACK_CS_FLOAT: { union { uint32_t i; float f; } mem; _msgpack_load32(uint32_t, n, &mem.i); push_fixed_value(_float, mem.f); } case MSGPACK_CS_DOUBLE: { union { uint64_t i; double f; } mem; _msgpack_load64(uint64_t, n, &mem.i); #if defined(TARGET_OS_IPHONE) // ok #elif defined(__arm__) && !(__ARM_EABI__) // arm-oabi // https://github.com/msgpack/msgpack-perl/pull/1 mem.i = (mem.i & 0xFFFFFFFFUL) << 32UL | (mem.i >> 32UL); #endif push_fixed_value(_double, mem.f); } case MSGPACK_CS_UINT_8: push_fixed_value(_uint8, *(uint8_t*)n); case MSGPACK_CS_UINT_16:{ uint16_t tmp; _msgpack_load16(uint16_t,n,&tmp); push_fixed_value(_uint16, tmp); } case MSGPACK_CS_UINT_32:{ uint32_t tmp; _msgpack_load32(uint32_t,n,&tmp); push_fixed_value(_uint32, tmp); } case MSGPACK_CS_UINT_64:{ uint64_t tmp; _msgpack_load64(uint64_t,n,&tmp); push_fixed_value(_uint64, tmp); } case MSGPACK_CS_INT_8: push_fixed_value(_int8, *(int8_t*)n); case MSGPACK_CS_INT_16:{ int16_t tmp; _msgpack_load16(int16_t,n,&tmp); push_fixed_value(_int16, tmp); } case MSGPACK_CS_INT_32:{ int32_t tmp; _msgpack_load32(int32_t,n,&tmp); push_fixed_value(_int32, tmp); } case MSGPACK_CS_INT_64:{ int64_t tmp; _msgpack_load64(int64_t,n,&tmp); push_fixed_value(_int64, tmp); } case MSGPACK_CS_FIXEXT_1: again_fixed_trail_if_zero(MSGPACK_ACS_EXT_VALUE, 1+1, _ext_zero); case MSGPACK_CS_FIXEXT_2: again_fixed_trail_if_zero(MSGPACK_ACS_EXT_VALUE, 2+1, _ext_zero); case MSGPACK_CS_FIXEXT_4: again_fixed_trail_if_zero(MSGPACK_ACS_EXT_VALUE, 4+1, _ext_zero); case MSGPACK_CS_FIXEXT_8: again_fixed_trail_if_zero(MSGPACK_ACS_EXT_VALUE, 8+1, _ext_zero); case MSGPACK_CS_FIXEXT_16: again_fixed_trail_if_zero(MSGPACK_ACS_EXT_VALUE, 16+1, _ext_zero); case MSGPACK_CS_STR_8: again_fixed_trail_if_zero(MSGPACK_ACS_STR_VALUE, *(uint8_t*)n, _str_zero); case MSGPACK_CS_BIN_8: again_fixed_trail_if_zero(MSGPACK_ACS_BIN_VALUE, *(uint8_t*)n, _bin_zero); case MSGPACK_CS_EXT_8: again_fixed_trail_if_zero(MSGPACK_ACS_EXT_VALUE, (*(uint8_t*)n) + 1, _ext_zero); case MSGPACK_CS_STR_16:{ uint16_t tmp; _msgpack_load16(uint16_t,n,&tmp); again_fixed_trail_if_zero(MSGPACK_ACS_STR_VALUE, tmp, _str_zero); } case MSGPACK_CS_BIN_16:{ uint16_t tmp; _msgpack_load16(uint16_t,n,&tmp); again_fixed_trail_if_zero(MSGPACK_ACS_BIN_VALUE, tmp, _bin_zero); } case MSGPACK_CS_EXT_16:{ uint16_t tmp; _msgpack_load16(uint16_t,n,&tmp); again_fixed_trail_if_zero(MSGPACK_ACS_EXT_VALUE, tmp + 1, _ext_zero); } case MSGPACK_CS_STR_32:{ uint32_t tmp; _msgpack_load32(uint32_t,n,&tmp); again_fixed_trail_if_zero(MSGPACK_ACS_STR_VALUE, tmp, _str_zero); } case MSGPACK_CS_BIN_32:{ uint32_t tmp; _msgpack_load32(uint32_t,n,&tmp); again_fixed_trail_if_zero(MSGPACK_ACS_BIN_VALUE, tmp, _bin_zero); } case MSGPACK_CS_EXT_32:{ uint32_t tmp; _msgpack_load32(uint32_t,n,&tmp); again_fixed_trail_if_zero(MSGPACK_ACS_EXT_VALUE, tmp + 1, _ext_zero); } case MSGPACK_ACS_STR_VALUE: _str_zero: push_variable_value(_str, data, n, trail); case MSGPACK_ACS_BIN_VALUE: _bin_zero: push_variable_value(_bin, data, n, trail); case MSGPACK_ACS_EXT_VALUE: _ext_zero: push_variable_value(_ext, data, n, trail); case MSGPACK_CS_ARRAY_16:{ uint16_t tmp; _msgpack_load16(uint16_t,n,&tmp); start_container(_array, tmp, MSGPACK_CT_ARRAY_ITEM); } case MSGPACK_CS_ARRAY_32:{ /* FIXME security guard */ uint32_t tmp; _msgpack_load32(uint32_t,n,&tmp); start_container(_array, tmp, MSGPACK_CT_ARRAY_ITEM); } case MSGPACK_CS_MAP_16:{ uint16_t tmp; _msgpack_load16(uint16_t,n,&tmp); start_container(_map, tmp, MSGPACK_CT_MAP_KEY); } case MSGPACK_CS_MAP_32:{ /* FIXME security guard */ uint32_t tmp; _msgpack_load32(uint32_t,n,&tmp); start_container(_map, tmp, MSGPACK_CT_MAP_KEY); } default: ret = MSGPACK_UNPACK_PARSE_ERROR; goto _failed; } } _push: if(top == 0) { goto _finish; } c = &stack[top-1]; switch(c->ct) { case MSGPACK_CT_ARRAY_ITEM: ret = msgpack_unpack_callback(_array_item)(user, &c->obj, obj); \ if(ret < 0) { goto _failed; } if(--c->count == 0) { obj = c->obj; --top; /*printf("stack pop %d\n", top);*/ goto _push; } goto _header_again; case MSGPACK_CT_MAP_KEY: c->map_key = obj; c->ct = MSGPACK_CT_MAP_VALUE; goto _header_again; case MSGPACK_CT_MAP_VALUE: ret = msgpack_unpack_callback(_map_item)(user, &c->obj, c->map_key, obj); \ if(ret < 0) { goto _failed; } if(--c->count == 0) { obj = c->obj; --top; /*printf("stack pop %d\n", top);*/ goto _push; } c->ct = MSGPACK_CT_MAP_KEY; goto _header_again; default: ret = MSGPACK_UNPACK_PARSE_ERROR; goto _failed; } _header_again: cs = MSGPACK_CS_HEADER; ++p; } while(p != pe); goto _out; _finish: stack[0].obj = obj; ++p; ret = 1; /*printf("-- finish --\n"); */ goto _end; _failed: /*printf("** FAILED **\n"); */ goto _end; _out: ret = 0; goto _end; _end: ctx->cs = cs; ctx->trail = trail; ctx->top = top; *off = (size_t)(p - (const unsigned char*)data); return ret; } } #undef msgpack_unpack_func #undef msgpack_unpack_callback #undef msgpack_unpack_struct #undef msgpack_unpack_object #undef msgpack_unpack_user #undef push_simple_value #undef push_fixed_value #undef push_variable_value #undef again_fixed_trail #undef again_fixed_trail_if_zero #undef start_container #undef NEXT_CS #undef SWITCH_RANGE_BEGIN #undef SWITCH_RANGE #undef SWITCH_RANGE_DEFAULT #undef SWITCH_RANGE_END msgpack-2.1.0beta1/msgpack/sysdep.h0000644000175000001440000001551213577133502016037 0ustar mikeusers/* * MessagePack system dependencies * * Copyright (C) 2008-2010 FURUHASHI Sadayuki * * Distributed under the Boost Software License, Version 1.0. * (See accompanying file LICENSE_1_0.txt or copy at * http://www.boost.org/LICENSE_1_0.txt) */ #ifndef MSGPACK_SYSDEP_H #define MSGPACK_SYSDEP_H #include #include #if defined(_MSC_VER) && _MSC_VER <= 1800 # define snprintf(buf, len, format,...) _snprintf_s(buf, len, len, format, __VA_ARGS__) #endif #if defined(_MSC_VER) && _MSC_VER < 1600 typedef signed __int8 int8_t; typedef unsigned __int8 uint8_t; typedef signed __int16 int16_t; typedef unsigned __int16 uint16_t; typedef signed __int32 int32_t; typedef unsigned __int32 uint32_t; typedef signed __int64 int64_t; typedef unsigned __int64 uint64_t; #elif defined(_MSC_VER) // && _MSC_VER >= 1600 # include #else # include # include #endif #if !defined(MSGPACK_DLLEXPORT) #if defined(_MSC_VER) # define MSGPACK_DLLEXPORT __declspec(dllexport) #else /* _MSC_VER */ # define MSGPACK_DLLEXPORT #endif /* _MSC_VER */ #endif #ifdef _WIN32 # if defined(_KERNEL_MODE) # define _msgpack_atomic_counter_header # else # define _msgpack_atomic_counter_header # if !defined(WIN32_LEAN_AND_MEAN) # define WIN32_LEAN_AND_MEAN # endif /* WIN32_LEAN_AND_MEAN */ # endif typedef long _msgpack_atomic_counter_t; #if defined(_AMD64_) || defined(_M_X64) || defined(_M_ARM64) # define _msgpack_sync_decr_and_fetch(ptr) _InterlockedDecrement(ptr) # define _msgpack_sync_incr_and_fetch(ptr) _InterlockedIncrement(ptr) #else # define _msgpack_sync_decr_and_fetch(ptr) InterlockedDecrement(ptr) # define _msgpack_sync_incr_and_fetch(ptr) InterlockedIncrement(ptr) #endif #elif defined(__GNUC__) && ((__GNUC__*10 + __GNUC_MINOR__) < 41) # if defined(__cplusplus) # define _msgpack_atomic_counter_header "msgpack/gcc_atomic.hpp" # else # define _msgpack_atomic_counter_header "msgpack/gcc_atomic.h" # endif #else typedef unsigned int _msgpack_atomic_counter_t; # define _msgpack_sync_decr_and_fetch(ptr) __sync_sub_and_fetch(ptr, 1) # define _msgpack_sync_incr_and_fetch(ptr) __sync_add_and_fetch(ptr, 1) #endif #ifdef _WIN32 # ifdef __cplusplus /* numeric_limits::min,max */ # ifdef max # undef max # endif # ifdef min # undef min # endif # endif #elif defined(unix) || defined(__unix) || defined(__APPLE__) || defined(__OpenBSD__) #include /* __BYTE_ORDER */ # if defined(linux) # include # endif #endif #if !defined(MSGPACK_ENDIAN_LITTLE_BYTE) && !defined(MSGPACK_ENDIAN_BIG_BYTE) #include #endif // !defined(MSGPACK_ENDIAN_LITTLE_BYTE) && !defined(MSGPACK_ENDIAN_BIG_BYTE) #if MSGPACK_ENDIAN_LITTLE_BYTE # if defined(unix) || defined(__unix) || defined(__APPLE__) || defined(__OpenBSD__) # define _msgpack_be16(x) ntohs((uint16_t)x) # else # if defined(ntohs) # define _msgpack_be16(x) ntohs(x) # elif defined(_byteswap_ushort) || (defined(_MSC_VER) && _MSC_VER >= 1400) # define _msgpack_be16(x) ((uint16_t)_byteswap_ushort((unsigned short)x)) # else # define _msgpack_be16(x) ( \ ((((uint16_t)x) << 8) ) | \ ((((uint16_t)x) >> 8) ) ) # endif # endif # if defined(unix) || defined(__unix) || defined(__APPLE__) || defined(__OpenBSD__) # define _msgpack_be32(x) ntohl((uint32_t)x) # else # if defined(ntohl) # define _msgpack_be32(x) ntohl(x) # elif defined(_byteswap_ulong) || (defined(_MSC_VER) && _MSC_VER >= 1400) # define _msgpack_be32(x) ((uint32_t)_byteswap_ulong((unsigned long)x)) # else # define _msgpack_be32(x) \ ( ((((uint32_t)x) << 24) ) | \ ((((uint32_t)x) << 8) & 0x00ff0000U ) | \ ((((uint32_t)x) >> 8) & 0x0000ff00U ) | \ ((((uint32_t)x) >> 24) ) ) # endif # endif # if defined(_byteswap_uint64) || (defined(_MSC_VER) && _MSC_VER >= 1400) # define _msgpack_be64(x) (_byteswap_uint64(x)) # elif defined(bswap_64) # define _msgpack_be64(x) bswap_64(x) # elif defined(__DARWIN_OSSwapInt64) # define _msgpack_be64(x) __DARWIN_OSSwapInt64(x) # else # define _msgpack_be64(x) \ ( ((((uint64_t)x) << 56) ) | \ ((((uint64_t)x) << 40) & 0x00ff000000000000ULL ) | \ ((((uint64_t)x) << 24) & 0x0000ff0000000000ULL ) | \ ((((uint64_t)x) << 8) & 0x000000ff00000000ULL ) | \ ((((uint64_t)x) >> 8) & 0x00000000ff000000ULL ) | \ ((((uint64_t)x) >> 24) & 0x0000000000ff0000ULL ) | \ ((((uint64_t)x) >> 40) & 0x000000000000ff00ULL ) | \ ((((uint64_t)x) >> 56) ) ) # endif #elif MSGPACK_ENDIAN_BIG_BYTE # define _msgpack_be16(x) (x) # define _msgpack_be32(x) (x) # define _msgpack_be64(x) (x) #else # error msgpack-c supports only big endian and little endian #endif /* MSGPACK_ENDIAN_LITTLE_BYTE */ #define _msgpack_load16(cast, from, to) do { \ memcpy((cast*)(to), (from), sizeof(cast)); \ *(to) = (cast)_msgpack_be16(*(to)); \ } while (0); #define _msgpack_load32(cast, from, to) do { \ memcpy((cast*)(to), (from), sizeof(cast)); \ *(to) = (cast)_msgpack_be32(*(to)); \ } while (0); #define _msgpack_load64(cast, from, to) do { \ memcpy((cast*)(to), (from), sizeof(cast)); \ *(to) = (cast)_msgpack_be64(*(to)); \ } while (0); #define _msgpack_store16(to, num) \ do { uint16_t val = _msgpack_be16(num); memcpy(to, &val, 2); } while(0) #define _msgpack_store32(to, num) \ do { uint32_t val = _msgpack_be32(num); memcpy(to, &val, 4); } while(0) #define _msgpack_store64(to, num) \ do { uint64_t val = _msgpack_be64(num); memcpy(to, &val, 8); } while(0) /* #define _msgpack_load16(cast, from) \ ({ cast val; memcpy(&val, (char*)from, 2); _msgpack_be16(val); }) #define _msgpack_load32(cast, from) \ ({ cast val; memcpy(&val, (char*)from, 4); _msgpack_be32(val); }) #define _msgpack_load64(cast, from) \ ({ cast val; memcpy(&val, (char*)from, 8); _msgpack_be64(val); }) */ #if !defined(__cplusplus) && defined(_MSC_VER) # if !defined(_KERNEL_MODE) # if !defined(FALSE) # define FALSE (0) # endif # if !defined(TRUE) # define TRUE (!FALSE) # endif # endif # if _MSC_VER >= 1800 # include # else # define bool int # define true TRUE # define false FALSE # endif # define inline __inline #endif #ifdef __APPLE__ # include #endif #endif /* msgpack/sysdep.h */ msgpack-2.1.0beta1/msgpack/version.h0000644000175000001440000000160413577133502016212 0ustar mikeusers/* * MessagePack for C version information * * Copyright (C) 2008-2009 FURUHASHI Sadayuki * * Distributed under the Boost Software License, Version 1.0. * (See accompanying file LICENSE_1_0.txt or copy at * http://www.boost.org/LICENSE_1_0.txt) */ #ifndef MSGPACK_VERSION_H #define MSGPACK_VERSION_H #ifdef __cplusplus extern "C" { #endif MSGPACK_DLLEXPORT const char* msgpack_version(void); MSGPACK_DLLEXPORT int msgpack_version_major(void); MSGPACK_DLLEXPORT int msgpack_version_minor(void); MSGPACK_DLLEXPORT int msgpack_version_revision(void); #include "version_master.h" #define MSGPACK_STR(v) #v #define MSGPACK_VERSION_I(maj, min, rev) MSGPACK_STR(maj) "." MSGPACK_STR(min) "." MSGPACK_STR(rev) #define MSGPACK_VERSION MSGPACK_VERSION_I(MSGPACK_VERSION_MAJOR, MSGPACK_VERSION_MINOR, MSGPACK_VERSION_REVISION) #ifdef __cplusplus } #endif #endif /* msgpack/version.h */ msgpack-2.1.0beta1/msgpack/version_master.h0000644000175000001440000000015113577133502017561 0ustar mikeusers#define MSGPACK_VERSION_MAJOR 3 #define MSGPACK_VERSION_MINOR 2 #define MSGPACK_VERSION_REVISION 0