1--TEST--
2Extra bytes unbuffered streaming unserialization (single)
3--SKIPIF--
4--FILE--
5<?php
6if(!extension_loaded('msgpack')) {
7    dl('msgpack.' . PHP_SHLIB_SUFFIX);
8}
9
10$unpacker = new MessagePackUnpacker();
11
12function test($type, $variable, $test = null) {
13    global $unpacker;
14
15    $str = "";
16    $offset = 0;
17
18    foreach ($variable as $var)
19    {
20        $serialized = pack('H*', $var);
21
22        $length = strlen($serialized);
23
24        for ($i = 0; $i < $length;) {
25            $len = rand(1, 10);
26            $str .= substr($serialized, $i, $len);
27
28            while (true) {
29                if ($unpacker->execute($str, $offset)) {
30                    $unserialized = $unpacker->data();
31                    var_dump($unserialized);
32
33                    $unpacker->reset();
34                    $str = substr($str, $offset);
35                    $offset = 0;
36                } else {
37                    break;
38                }
39            }
40            $i += $len;
41        }
42    }
43}
44
45test('array(1, 2, 3)', array('9301020392'));
46test('array(1, 2, 3), array(3, 9), 4', array('9301020392', '030904'));
47--EXPECTF--
48array(3) {
49  [0]=>
50  int(1)
51  [1]=>
52  int(2)
53  [2]=>
54  int(3)
55}
56array(2) {
57  [0]=>
58  array(3) {
59    [0]=>
60    int(1)
61    [1]=>
62    int(2)
63    [2]=>
64    int(3)
65  }
66  [1]=>
67  array(2) {
68    [0]=>
69    int(3)
70    [1]=>
71    int(9)
72  }
73}
74int(4)
75