Beispiel #1
0
<?php

// EXECUTE test_new.php first
// first include pb_message
require_once '../message/pb_message.php';
// now read it with the old file
// include the generated file
require_once './pb_proto_test.php';
$string = file_get_contents('./test.pb');
// Just read it
$book = new AddressBook();
$book->parseFromString($string);
var_dump($book->persons_size());
$person = $book->person(0);
var_dump($person->name());
$person = $book->person(1);
var_dump($person->name());
var_dump($person->phone(0)->number());
var_dump($person->phone(0)->type());
var_dump($person->phone(1)->number());
var_dump($person->phone(1)->type());
var_dump($person->phone(2)->number());
var_dump($person->phone(2)->type());
Beispiel #2
0
<?php

/*
 * Primitive Fields repeated
 */
// first include pb_message
require_once '../../message/pb_message.php';
// include the generated file
require_once './pb_proto_primitive.php';
$book = new AddressBook();
$book->append_person("Hello");
$book->append_person("Test");
$book->append_type(AddressBook_PhoneType::MOBILE);
// in $ p now there is Hello
$p = $book->person(0);
var_dump($p);
$string = $book->SerializeToString();
// now test the reading
$book = new AddressBook();
$book->parseFromString($string);
var_dump($book->person(0));
var_dump($book->person_size());
var_dump($book->person(1));
var_dump($book->type(0) == AddressBook_PhoneType::MOBILE);