Bimba.git

ref: 0b6039cf449d83f01c916d7d6ed496a5c680a441

converter/server/vendor/rybakit/msgpack/examples/array_iterator.php


 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
<?php

/*
 * This file is part of the rybakit/msgpack.php package.
 *
 * (c) Eugene Leonovich <gen.work@gmail.com>
 *
 * For the full copyright and license information, please view the LICENSE
 * file that was distributed with this source code.
 */

use App\MessagePack\ArrayIteratorTransformer;
use MessagePack\BufferUnpacker;
use MessagePack\Packer;

require __DIR__.'/autoload.php';

$transformer = new ArrayIteratorTransformer(1);

$packer = new Packer();
$packer->registerTransformer($transformer);
$packed = $packer->pack(new ArrayIterator(range(1, 10000)));

$unpacker = new BufferUnpacker($packed);
$unpacker->registerTransformer($transformer);

$sum = 0;
foreach ($unpacker->unpack() as $i) {
    $sum += $i;
}

echo "Sum: $sum\n";

/* OUTPUT
Sum: 50005000
*/