forked from bramp/protoc-gen-php
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtest.php
84 lines (63 loc) · 1.55 KB
/
test.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
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
<?php
require('protocolbuffers.inc.php');
/*
$varint_tests = array(
1 => "\x01",
2 => "\x02",
127 => "\x7F",
128 => "\x80\x01",
300 => "\xAC\x02",
);
function test_varint() {
global $varint_tests;
$fp = fopen('php://memory', 'r+b');
if ($fp === false)
exit('Unable to open stream');
foreach ($varint_tests as $i => $enc) {
// Write the answer into the buffer
fseek($fp, 0, SEEK_SET);
fwrite($fp, $enc);
fseek($fp, 0, SEEK_SET);
$a = Protobuf::read_varint($fp);
if ($a != $i)
exit("Failed to decode varint($i) got $a\n");
$len = Protobuf::write_varint($fp, $i);
fseek($fp, 0, SEEK_SET);
$b = fread($fp, $len);
if ($b != $enc)
exit("Failed to encode varint($i)\n");
$len = Protobuf::size_varint($i);
echo "$i len($len) OK\n";
}
fclose($fp);
}
test_varint();
*/
if ($argc > 1) {
$test = $argv[1];
require("$test.php");
if ($test == 'addressbook.proto') {
$fp = fopen('test.book', 'rb');
$m = new tutorial_AddressBook($fp);
var_dump($m);
fclose($fp);
} else if ($test == 'market.proto') {
//$fp = fopen('market2-in-1.dec', 'rb');
$fp = fopen('market2-in-2.dec', 'rb');
//$fp = fopen('temp', 'rb');
$m = new Response($fp);
echo $m;
//$mem = fopen('php://memory', 'wb');
$mem = fopen('temp', 'wb');
if ($mem === false)
exit('Unable to open output stream');
$s = fstat($fp);
echo 'File size: ' . $s['size'] . "\n";
echo 'Guested size: ' . $m->size() . "\n";
$m->write($mem);
echo 'Write size: ' . ftell($mem) . "\n";
fclose($mem);
fclose($fp);
}
}
?>