├── .gitignore ├── .travis.yml ├── CREDITS ├── EXPERIMENTAL ├── LICENSE ├── README.md ├── Rakefile ├── config.m4 ├── config.w32 ├── contents └── php-protocolbuffers.png ├── core.c ├── core.h ├── core_inl.h ├── descriptor.c ├── descriptor.h ├── descriptor_builder.c ├── descriptor_builder.h ├── enum.c ├── enum.h ├── enum_descriptor.c ├── enum_descriptor.h ├── enum_descriptor_builder.c ├── enum_descriptor_builder.h ├── enum_value_descriptor.c ├── enum_value_descriptor.h ├── examples ├── Json.md ├── README.md ├── addressbook.php ├── addressbook.proto ├── extension.php ├── misc │ ├── address.php │ ├── address2.php │ ├── address3.php │ ├── address4.php │ ├── address5.php │ └── reflection.php ├── php │ ├── addressbook.proto.php │ └── prefecture.proto.php ├── prefecture.php ├── prefecture.proto ├── prefecture.tsv └── uv │ ├── README.md │ ├── client.php │ ├── message.proto │ ├── proto │ └── message.proto.php │ └── server.php ├── extension_registry.c ├── extension_registry.h ├── field_descriptor.c ├── field_descriptor.h ├── helper.c ├── helper.h ├── json_serializer.c ├── json_serializer.h ├── message.c ├── message.h ├── message_options.c ├── message_options.h ├── package.xml ├── php_message_options.c ├── php_message_options.h ├── php_protocolbuffers.h ├── phpunit.xml.dist ├── protocolbuffers.c ├── protocolbuffers.h ├── serializer.c ├── serializer.h ├── stubs └── protocolbuffers.stub.php ├── tests ├── 000_aliases.phpt ├── 001_big_tag.phpt ├── 001_bool.phpt ├── 001_bytes.phpt ├── 001_constants.phpt ├── 001_double_sample.phpt ├── 001_fixed32_init.phpt ├── 001_fixed32_max.phpt ├── 001_fixed64_init.phpt ├── 001_fixed64_max.phpt ├── 001_float_sample.phpt ├── 001_float_signed.phpt ├── 001_int32_init.phpt ├── 001_int32_max.phpt ├── 001_int32_min.phpt ├── 001_int64_init.phpt ├── 001_int64_max.phpt ├── 001_int64_min.phpt ├── 001_sfixed32_signed.phpt ├── 001_sfixed32_unsigned.phpt ├── 001_sfixed64_init.phpt ├── 001_sfixed64_max.phpt ├── 001_sfixed64_min.phpt ├── 001_sint32_init.phpt ├── 001_sint32_max.phpt ├── 001_sint32_min.phpt ├── 001_sint64.init.phpt ├── 001_sint64_max.phpt ├── 001_sint64_min.phpt ├── 001_string_0bytes.phpt ├── 001_string_1024bytes.phpt ├── 001_string_invaild_encoding.phpt ├── 001_string_invalid_encoding_with_no_string_validate.phpt ├── 001_string_should_keep_object.phpt ├── 001_string_small.phpt ├── 001_string_utf8.phpt ├── 001_uint64_max.phpt ├── 002_repeated_int32.phpt ├── 002_repeated_message.phpt ├── 002_repeated_string.phpt ├── 002_simple_encode.phpt ├── 003_bool_packed.phpt ├── 003_double_packed.phpt ├── 003_fixed32_packed.phpt ├── 003_fixed64_packed.phpt ├── 003_float_packed.phpt ├── 003_has_message_decode.phpt ├── 003_has_message_encode.phpt ├── 003_int32_packed.phpt ├── 003_int32_packed_many.phpt ├── 003_int64_packed.phpt ├── 003_sfixed32_packed.phpt ├── 003_sfixed64_packed.phpt ├── 003_sint32_packed.phpt ├── 003_sint64_packed.phpt ├── 003_uint32_packed.phpt ├── 004_decode_bool.phpt ├── 004_decode_bytes.phpt ├── 004_decode_double_sample.phpt ├── 004_decode_fixed32_init.phpt ├── 004_decode_fixed32_max.phpt ├── 004_decode_float_sample.phpt ├── 004_decode_float_signed.phpt ├── 004_decode_int32_init.phpt ├── 004_decode_int32_max.phpt ├── 004_decode_int32_min.phpt ├── 004_decode_sfixed32_signed.phpt ├── 004_decode_sfixed32_unsigned.phpt ├── 004_decode_sint32_init.phpt ├── 004_decode_sint32_max.phpt ├── 004_decode_sint32_min.phpt ├── 004_decode_string_0bytes.phpt ├── 004_decode_string_1024bytes.phpt ├── 005_decode_bool_packed.phpt ├── 005_decode_double_packed.phpt ├── 005_decode_fixed32_packed.phpt ├── 005_decode_fixed64_packed.phpt ├── 005_decode_float_packed.phpt ├── 005_decode_int32_packed.phpt ├── 005_decode_int32_packed_many.phpt ├── 005_decode_int64_packed.phpt ├── 005_decode_sfixed32_packed.phpt ├── 005_decode_sfixed64_packed.phpt ├── 005_decode_sint32_packed.phpt ├── 005_decode_sint64_packed.phpt ├── 100_field_descriptor.phpt ├── 101_descirptor_builder.phpt ├── 102_descriptor_builder_with_noargs.phpt ├── 103_descriptor_force_add.phpt ├── 103_descriptor_throws_an_exception.phpt ├── 104_descriptor_builder_add_extension_range.phpt ├── 105_enum_descriptor_builder.phpt ├── 200_unknown_fields.phpt ├── 200_unknown_fields_discard.phpt ├── 300_use_single_property.phpt ├── 400_message_clear.phpt ├── 400_message_clear_all.phpt ├── 400_message_iterator.phpt ├── 400_message_magicmethods.phpt ├── 500_unknown_bytes.phpt ├── 500_unknown_double.phpt ├── 500_unknown_float.phpt ├── 500_unknown_int32.phpt ├── 500_unknown_iterator.phpt ├── 500_unknown_repeated_string.phpt ├── 500_unknown_string.phpt ├── 600_constructor.phpt ├── 600_extension.phpt ├── 600_extension_clear.phpt ├── 600_sleep.phpt ├── 600_wakeup.phpt ├── 700_jsonserializable.phpt ├── 700_jsonserializable_invalid_utf8.phpt ├── 700_merge_from.phpt ├── 700_set_from.phpt ├── 700_toarray_invalid_utf8.phpt ├── 800_helper_debug_zval.phpt ├── 800_helper_write_varint32.phpt ├── 800_helper_zigzag.phpt ├── 999_append.phpt ├── 999_bytes_bug.phpt ├── 999_conformance_quick.phpt ├── 999_default_value.phpt ├── 999_dont_accept_null_value.phpt ├── 999_dummy_string.phpt ├── 999_empty_string.phpt ├── 999_illegal_bytes.phpt ├── 999_magicmethod_snakecase_to_lower_case.phpt ├── 999_magicmethod_throw_exception_when_doesnt_resolve.phpt ├── 999_missing_message.phpt ├── 999_no15_varint_should_read_64bit_integer.phpt ├── 999_no25_setter_getter_consider_camel_case_fields.phpt ├── 999_no31_initialize_target_should_be_same_name_as_declarations.phpt ├── 999_no33_batch_assignment.phpt ├── 999_no41_constructor_should_accept_object.phpt ├── 999_no_19_regression_script_contains_large_number_literals.phpt ├── 999_no_8_magic_method_for_case_sensitive_field.phpt ├── 999_no_descriptor.phpt ├── 999_null.phpt ├── 999_number_larger_2_63-1.phpt ├── 999_php_message_options_set_single_property_name.phpt ├── 999_regression_multiple_repeated_fields.phpt ├── 999_remove_first_ns.phpt ├── 999_required_property.phpt ├── conformance │ ├── CmakeLists.txt │ ├── conformance_test.cc │ └── proto │ │ └── message_sint32.proto ├── fixtures │ ├── 001_big_tag.bin │ ├── 001_bool.bin │ ├── 001_bytes.bin │ ├── 001_double_sample.bin │ ├── 001_fixed32_init.bin │ ├── 001_fixed32_max.bin │ ├── 001_fixed64_init.bin │ ├── 001_fixed64_max.bin │ ├── 001_float_sample.bin │ ├── 001_float_signed.bin │ ├── 001_int32_init.bin │ ├── 001_int32_max.bin │ ├── 001_int32_min.bin │ ├── 001_int64_init.bin │ ├── 001_int64_max.bin │ ├── 001_int64_min.bin │ ├── 001_sfixed32_signed.bin │ ├── 001_sfixed32_unsigned.bin │ ├── 001_sfixed64_max.bin │ ├── 001_sfixed64_min.bin │ ├── 001_sfixed64_zero.bin │ ├── 001_sint32_init.bin │ ├── 001_sint32_max.bin │ ├── 001_sint32_min.bin │ ├── 001_sint64_init.bin │ ├── 001_sint64_max.bin │ ├── 001_sint64_min.bin │ ├── 001_string_0bytes.bin │ ├── 001_string_1024bytes.bin │ ├── 001_string_small.bin │ ├── 001_string_utf8.bin │ ├── 001_uint64_max.bin │ ├── 002_repeated_int32.bin │ ├── 002_repeated_message.bin │ ├── 002_repeated_string.bin │ ├── 002_simple_encode.bin │ ├── 003_bool_packed.bin │ ├── 003_double_packed.bin │ ├── 003_fixed32_packed.bin │ ├── 003_fixed64_packed.bin │ ├── 003_float_packed.bin │ ├── 003_has_message.bin │ ├── 003_int32_packed_many.bin │ ├── 003_int32_packed_one.bin │ ├── 003_int64_packed.bin │ ├── 003_sfixed32_packed.bin │ ├── 003_sfixed64_packed.bin │ ├── 003_sint32_packed.bin │ ├── 003_sint64_packed.bin │ ├── 003_uint32_packed.bin │ ├── 999_conformance_quick.bin │ ├── android_logo.gif │ └── fixture001.bin ├── integration │ ├── README.md │ ├── bootstrap.php │ ├── composer.json │ ├── composer.lock │ ├── messages │ │ ├── autoload.php │ │ ├── pecl │ │ │ └── protocolbuffers │ │ │ │ └── User.php │ │ └── proto │ │ │ └── user.proto.php │ ├── php-fpm.conf │ ├── phpunit.xml.dist │ ├── proto │ │ └── user.proto │ ├── protocolbuffers.ini │ ├── src │ │ └── MultipleRequest.php │ ├── test.php │ └── tests │ │ └── MultipleRequestTest.php ├── messages │ ├── 003_has_message.proto.php │ ├── AllTypes.proto.php │ ├── addressbook.proto.php │ ├── big_tag.proto.php │ ├── field.proto.php │ ├── field_bool.proto.php │ ├── field_bool_packed.proto.php │ ├── field_bytes.proto.php │ ├── field_double.proto.php │ ├── field_double_packed.proto.php │ ├── field_fixed32.proto.php │ ├── field_fixed32_packed.proto.php │ ├── field_fixed64.proto.php │ ├── field_fixed64_packed.proto.php │ ├── field_float.proto.php │ ├── field_float_packed.proto.php │ ├── field_int32.proto.php │ ├── field_int32_packed.proto.php │ ├── field_int64.proto.php │ ├── field_int64_packed.proto.php │ ├── field_sfixed32.proto.php │ ├── field_sfixed32_packed.proto.php │ ├── field_sfixed64.proto.php │ ├── field_sfixed64_packed.proto.php │ ├── field_sint32.proto.php │ ├── field_sint32_packed.proto.php │ ├── field_sint64.proto.php │ ├── field_sint64_packed.proto.php │ ├── field_string.proto.php │ ├── field_uint32_packed.proto.php │ ├── field_uint64.proto.php │ ├── outer_inner.proto.php │ ├── repeated_int32.proto.php │ └── repeated_string.proto.php └── proto │ ├── addressbook.proto │ ├── big_tag.proto │ ├── field_bool.proto │ ├── field_bool_packed.proto │ ├── field_bytes.proto │ ├── field_double.proto │ ├── field_double_packed.proto │ ├── field_fixed32.proto │ ├── field_fixed32_packed.proto │ ├── field_fixed64.proto │ ├── field_fixed64_packed.proto │ ├── field_float.proto │ ├── field_float_packed.proto │ ├── field_int32.proto │ ├── field_int32_packed.proto │ ├── field_int64.proto │ ├── field_int64_packed.proto │ ├── field_sfixed32.proto │ ├── field_sfixed32_packed.proto │ ├── field_sfixed64.proto │ ├── field_sfixed64_packed.proto │ ├── field_sint32.proto │ ├── field_sint32_packed.proto │ ├── field_sint64.proto │ ├── field_sint64_packed.proto │ ├── field_string.proto │ ├── field_uint32_packed.proto │ ├── has_message.proto │ ├── repeated_int32.proto │ └── repeated_string.proto ├── unknown_field.c ├── unknown_field.h ├── unknown_field_set.c └── unknown_field_set.h /.gitignore: -------------------------------------------------------------------------------- 1 | *.o 2 | .idea 3 | *.iml 4 | 5 | .Rakefile 6 | 7 | contrib/php_options.pb.cc 8 | contrib/php_options.pb.h 9 | 10 | # ignore phpized files 11 | Makefile.global 12 | acinclude.m4 13 | aclocal.m4 14 | autom4te.cache 15 | build 16 | config.* 17 | configure 18 | configure* 19 | install-sh 20 | iltmain.sh 21 | missing 22 | mkinstalldirs 23 | run-tests.php 24 | *.lo 25 | .deps 26 | .libs 27 | libtool 28 | Makefile* 29 | modules 30 | ltmain.sh 31 | *.la 32 | tmp-php.ini 33 | php_test_results* 34 | 35 | -------------------------------------------------------------------------------- /.travis.yml: -------------------------------------------------------------------------------- 1 | language: php 2 | php: 3 | - 5.2 4 | - 5.3 5 | - 5.4 6 | - 5.5 7 | 8 | script: 9 | - uname -a 10 | - cat /etc/issue 11 | - rake compile test 12 | - rake integration 13 | 14 | notifications: 15 | irc: "chat.freenode.net#php-protocolbuffers" 16 | use_notice: true 17 | -------------------------------------------------------------------------------- /CREDITS: -------------------------------------------------------------------------------- 1 | protocolbuffers 2 | Shuhei Tanuma 3 | -------------------------------------------------------------------------------- /EXPERIMENTAL: -------------------------------------------------------------------------------- 1 | this extension is experimental, 2 | its functions may change their names 3 | or move to extension all together 4 | so do not rely to much on them 5 | you have been warned! 6 | -------------------------------------------------------------------------------- /Rakefile: -------------------------------------------------------------------------------- 1 | if File.exists?(".Rakefile") 2 | import ".Rakefile" 3 | end 4 | 5 | def cmd_run(command) 6 | print "\#execute #{command}...\n" 7 | IO.popen(command) {|pipe| 8 | pipe.each { |line| 9 | print "+ " + line 10 | } 11 | $?.to_i 12 | } 13 | end 14 | 15 | task :package do 16 | cmd_run('php -ddate.timezone="Asia/Tokyo" pyrus.phar pickle -n protocolbuffers pecl.php.net php-protocolbuffers') 17 | end 18 | 19 | task :compile do 20 | cmd_run("phpize") 21 | cmd_run("./configure") 22 | cmd_run("make") 23 | end 24 | 25 | task :install do 26 | cmd_run("make install") 27 | end 28 | 29 | desc "run php test cases" 30 | task :test do 31 | ENV["TESTS"] = "--show-diff -q" 32 | cmd_run("make test") 33 | sh "cat tests/*.diff; if [ $? -eq 0 ];then exit 1; fi" 34 | end 35 | 36 | task :integration do 37 | if ENV["TRAVIS_PHP_VERSION"].to_f >= 5.3 then 38 | sh "phpenv config-add tests/integration/protocolbuffers.ini" 39 | sh "sudo make install" 40 | sh "sudo cp tests/integration/php-fpm.conf ~/.phpenv/versions/$(phpenv version-name)/etc/php-fpm.conf" 41 | sh "sudo ~/.phpenv/versions/$(phpenv version-name)/sbin/php-fpm" 42 | 43 | Dir.chdir("tests/integration") do 44 | cmd_run("composer install --no-interaction") 45 | cmd_run("./vendor/bin/phpunit") 46 | end 47 | end 48 | end -------------------------------------------------------------------------------- /config.m4: -------------------------------------------------------------------------------- 1 | PHP_ARG_ENABLE(protocolbuffers, Whether to enable the "protocolbuffers" extension, 2 | [ --enable-protocolbuffers Enable "protocolbuffers" extension support]) 3 | 4 | PHP_ARG_ENABLE(protocolbuffers-debug, for protocolbuffers debug support, 5 | [ --enable-protocolbuffers-debug Enable enable protocolbuffers debug support], no, no) 6 | 7 | if test $PHP_PROTOCOLBUFFERS != "no"; then 8 | if test "$PHP_PROTOCOLBUFFERS_DEBUG" != "no"; then 9 | CFLAGS="$CFLAGS -Wall -g -ggdb -O0 -DPHP_PROTOCOLBUFFERS_DEBUG=1" 10 | AC_DEFINE(PHP_PROTOCOLBUFFERS_DEBUG, 1, [Enable protocolbuffers debug support]) 11 | else 12 | //CFLAGS="$CFLAGS -Wall -g -ggdb -O0 -Wunused-variable -Wpointer-sign -Wimplicit-function-declaration -Winline -Wunused-macros -Wredundant-decls -Wstrict-aliasing=2 -Wswitch-enum -Wdeclaration-after-statement" 13 | fi 14 | 15 | PHP_PROTOBUF_SRCS="protocolbuffers.c descriptor.c descriptor_builder.c field_descriptor.c message.c message_options.c enum.c enum_descriptor.c enum_value_descriptor.c enum_descriptor_builder.c php_message_options.c unknown_field.c unknown_field_set.c helper.c extension_registry.c core.c serializer.c json_serializer.c" 16 | 17 | PHP_SUBST(PROTOCOLBUFFERS_SHARED_LIBADD) 18 | PHP_NEW_EXTENSION(protocolbuffers, $PHP_PROTOBUF_SRCS, $ext_shared) 19 | PHP_ADD_EXTENSION_DEP(protocolbuffers, spl, true) 20 | 21 | PHP_SUBST([CFLAGS]) 22 | fi 23 | -------------------------------------------------------------------------------- /config.w32: -------------------------------------------------------------------------------- 1 | ARG_WITH('protocolbuffers', 'protocolbuffers extension', 'no'); 2 | 3 | if (PHP_PROTOCOLBUFFERS != "no") { 4 | EXTENSION("protocolbuffers", "protocolbuffers.c descriptor.c descriptor_builder.c field_descriptor.c message.c message_options.c enum.c enum_descriptor.c enum_value_descriptor.c enum_descriptor_builder.c php_message_options.c unknown_field.c unknown_field_set.c helper.c extension_registry.c core.c serializer.c json_serializer.c"); 5 | ADD_EXTENSION_DEP('protocolbuffers','spl',true); 6 | } 7 | -------------------------------------------------------------------------------- /contents/php-protocolbuffers.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/chobie/php-protocolbuffers/747a2238f14de0be67d5747089b50ebcc5e1116c/contents/php-protocolbuffers.png -------------------------------------------------------------------------------- /enum.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Protocol Buffers for PHP 3 | * Copyright 2013 Shuhei Tanuma. All rights reserved. 4 | * 5 | * https://github.com/chobie/php-protocolbuffers 6 | * 7 | * Redistribution and use in source and binary forms, with or without 8 | * modification, are permitted provided that the following conditions are 9 | * met: 10 | * 11 | * 1. Redistributions of source code must retain the above copyright 12 | * notice, this list of conditions and the following disclaimer. 13 | * 2. Redistributions in binary form must reproduce the above 14 | * copyright notice, this list of conditions and the following disclaimer 15 | * in the documentation and/or other materials provided with the 16 | * distribution. 17 | * 18 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 19 | * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 20 | * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 21 | * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 22 | * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 23 | * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 24 | * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 25 | * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 26 | * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 27 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 28 | * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 29 | */ 30 | 31 | #ifndef PHP_PROTOCOLBUFFERS_ENUM_H 32 | #define PHP_PROTOCOLBUFFERS_ENUM_H 33 | 34 | void php_protocolbuffers_enum_class(TSRMLS_D); 35 | 36 | #endif -------------------------------------------------------------------------------- /enum_descriptor.c: -------------------------------------------------------------------------------- 1 | #include "protocolbuffers.h" 2 | #include "enum_descriptor.h" 3 | 4 | ZEND_BEGIN_ARG_INFO_EX(arginfo_protocolbuffers_enum_descriptor_is_valid, 0, 0, 1) 5 | ZEND_ARG_INFO(0, value) 6 | ZEND_END_ARG_INFO() 7 | 8 | 9 | /* {{{ proto void ProtocolBuffersEnumDescriptor::__construct() 10 | */ 11 | PHP_METHOD(protocolbuffers_enum_descriptor, __construct) 12 | { 13 | } 14 | /* }}} */ 15 | 16 | static zend_function_entry protocolbuffers_enum_descriptor_methods[] = { 17 | PHP_ME(protocolbuffers_enum_descriptor, __construct, NULL, ZEND_ACC_PRIVATE | ZEND_ACC_CTOR) 18 | PHP_FE_END 19 | }; 20 | 21 | void php_protocolbuffers_enum_descriptor_class(TSRMLS_D) 22 | { 23 | zend_class_entry ce; 24 | 25 | INIT_CLASS_ENTRY(ce, "ProtocolBuffersEnumDescriptor", protocolbuffers_enum_descriptor_methods); 26 | php_protocol_buffers_enum_descriptor_class_entry = zend_register_internal_class(&ce TSRMLS_CC); 27 | PHP_PROTOCOLBUFFERS_REGISTER_NS_CLASS_ALIAS(PHP_PROTOCOLBUFFERS_NAMESPACE, "EnumDescriptor", php_protocol_buffers_enum_descriptor_class_entry); 28 | } 29 | -------------------------------------------------------------------------------- /examples/Json.md: -------------------------------------------------------------------------------- 1 | # JsonSerialize specification 2 | 3 | ## Types 4 | 5 | Basically, json serialize implementation respects protocol buffers serialization rule. 6 | 7 | | PB Type | Json Type | 8 | |-------------|-----------| 9 | |TYPE_DOUBLE | NUMBER | 10 | |TYPE_FLOAT | NUMBER | 11 | |TYPE_INT64 | NUMBER | 12 | |TYPE_UINT64 | NUMBER | 13 | |TYPE_INT32 | NUMBER | 14 | |TYPE_FIXED64 | NUMBER | 15 | |TYPE_FIXED32 | NUMBER | 16 | |TYPE_BOOL | BOOLEAN | 17 | |TYPE_STRING | STRING | 18 | |TYPE_BYTES | STRING | 19 | |TYPE_UINT32 | NUMBER | 20 | |TYPE_ENUM | NUMBER | 21 | |TYPE_SFIXED32| NUMBER | 22 | |TYPE_SFIXED64| NUMBER | 23 | |TYPE_SINT32 | NUMBER | 24 | |TYPE_SINT64 | NUMBER | 25 | |TYPE_MESSAGE | OBJECT | 26 | 27 | * JsonSerialize does not serialize NULL value. 28 | * JsonSerialize uses original field name (same as proto file) as property key. 29 | * JsonSerialize might loose precision when using big number. this is PHP limitation. 30 | 31 | ### Errors 32 | 33 | * jsonSerialize method doesn't use exceptions. 34 | 35 | ## Unknown Field 36 | 37 | * does not support. 38 | 39 | ## Extensions 40 | 41 | * supported 42 | 43 | ## Overriding 44 | 45 | `jsonSerialize` method can override. you can filter needless values with overriding jsonSerialize method. 46 | 47 | ``` 48 | public function jsonSerialize() 49 | { 50 | $array = parent::jsonSerialize(); // also you can use toArray() method. 51 | return $this->filter_needless_values($array); 52 | } 53 | 54 | ``` 55 | 56 | ## Others 57 | 58 | * `__sleep` and `__wakeup` method doesn't invoke when serializing json. 59 | -------------------------------------------------------------------------------- /examples/README.md: -------------------------------------------------------------------------------- 1 | # Protocol Buffers Examples 2 | 3 | ```` 4 | # generate message classes from .proto file 5 | protoc --plugin=../contrib/protoc-gen-php addressbook.proto --php_out=php -I . -I /usr/local/include 6 | ```` 7 | -------------------------------------------------------------------------------- /examples/addressbook.php: -------------------------------------------------------------------------------- 1 | setId(1); 9 | $person->setName("John Doe"); 10 | $person->setEmail("john.doe@example.com"); 11 | 12 | $phone = new Tutorial_Person_PhoneNumber(); 13 | $phone->setNumber("1234 5 67 78"); 14 | $phone->setType(Tutorial_Person_PhoneType::HOME); 15 | $person->appendPhone($phone); 16 | 17 | 18 | $phone = new Tutorial_Person_PhoneNumber(); 19 | $phone->setNumber("1234 5 67 79"); 20 | $phone->setType(Tutorial_Person_PhoneType::HOME); 21 | $person->appendPhone($phone); 22 | 23 | echo $person; 24 | exit; 25 | echo "____________________\n"; 26 | 27 | $addressbook->appendPerson($person); 28 | 29 | 30 | var_dump($addressbook); 31 | 32 | save($db, $addressbook); 33 | 34 | exit; 35 | 36 | function load($path) 37 | { 38 | $data = @file_get_contents($path); 39 | try { 40 | $result = ProtocolBuffers::decode("Tutorial_AddressBook", $data); 41 | } catch (ProtocolBuffersInvalidProtocolBufferException $e) { 42 | $result = new Tutorial_AddressBook(); 43 | } 44 | 45 | return $result; 46 | } 47 | 48 | function save($path, Tutorial_AddressBook $addresbook) 49 | { 50 | file_put_contents($path, $addresbook->serializeToString()); 51 | } 52 | -------------------------------------------------------------------------------- /examples/addressbook.proto: -------------------------------------------------------------------------------- 1 | package Tutorial; 2 | 3 | message Person { 4 | required string name = 1; 5 | required int32 id = 2; 6 | optional string email = 3; 7 | 8 | enum PhoneType { 9 | MOBILE = 0; 10 | HOME = 1; 11 | WORK = 2; 12 | } 13 | 14 | message PhoneNumber { 15 | required string number = 1; 16 | optional PhoneType type = 2 [default = HOME]; 17 | } 18 | 19 | repeated PhoneNumber phone = 4; 20 | } 21 | 22 | message AddressBook { 23 | repeated Person person = 1; 24 | } 25 | -------------------------------------------------------------------------------- /examples/misc/address.php: -------------------------------------------------------------------------------- 1 | setId(21); 6 | $person->setName("John Doe"); 7 | 8 | $data = ProtocolBuffers::encode($person); 9 | 10 | printf("# decoding benchmark (protocolbuffers).\n"); 11 | printf("# target message size: %d bytes.\n", strlen($data)); 12 | printf("# start\n"); 13 | 14 | $begin = microtime(true); 15 | $attempts = 100000; 16 | for ($i = 0; $i < $attempts; $i++) { 17 | ProtocolBuffers::decode("Tutorial_Person", $data); 18 | } 19 | $end = microtime(true); 20 | 21 | printf("# Result:\n"); 22 | printf("# decoding %d messages\n", $attempts); 23 | printf("# processing time: %6f (%f/message)\n", $end - $begin, ($end - $begin) / $attempts); 24 | printf("# total bytes: %d bytes\n", strlen($data) * $attempts); 25 | -------------------------------------------------------------------------------- /examples/misc/address2.php: -------------------------------------------------------------------------------- 1 | setId(21); 6 | $person->setName("John Doe"); 7 | 8 | $data = serialize($person); 9 | 10 | printf("# decoding benchmark (serialize / unserialize).\n"); 11 | printf("# target message size: %d bytes.\n", strlen($data)); 12 | printf("# start\n"); 13 | 14 | $begin = microtime(true); 15 | $attempts = 100000; 16 | for ($i = 0; $i < $attempts; $i++) { 17 | unserialize($data); 18 | } 19 | $end = microtime(true); 20 | 21 | printf("# Result:\n"); 22 | printf("# decoding %d messages\n", $attempts); 23 | printf("# processing time: %6f (%f/message)\n", $end - $begin, ($end - $begin) / $attempts); 24 | printf("# total bytes: %d bytes\n", strlen($data) * $attempts); 25 | -------------------------------------------------------------------------------- /examples/misc/address3.php: -------------------------------------------------------------------------------- 1 | setId(21); 6 | $person->setName("John Doe"); 7 | 8 | $data = $person->serializeToString($person); 9 | 10 | printf("# decoding benchmark (protocolbuffers).\n"); 11 | printf("# target message size: %d bytes.\n", strlen($data)); 12 | printf("# start\n"); 13 | 14 | $begin = microtime(true); 15 | $attempts = 100000; 16 | for ($i = 0; $i < $attempts; $i++) { 17 | Tutorial_Person::parseFromString($data); 18 | } 19 | $end = microtime(true); 20 | 21 | printf("# Result:\n"); 22 | printf("# decoding %d messages\n", $attempts); 23 | printf("# processing time: %6f (%f/message)\n", $end - $begin, ($end - $begin) / $attempts); 24 | printf("# total bytes: %d bytes\n", strlen($data) * $attempts); 25 | -------------------------------------------------------------------------------- /examples/misc/address4.php: -------------------------------------------------------------------------------- 1 | setId(21); 6 | $person->setName("John Doe"); 7 | 8 | $data = msgpack_pack($person); 9 | 10 | printf("# decoding benchmark (msgpack).\n"); 11 | printf("# target message size: %d bytes.\n", strlen($data)); 12 | printf("# start\n"); 13 | 14 | $begin = microtime(true); 15 | $attempts = 100000; 16 | for ($i = 0; $i < $attempts; $i++) { 17 | msgpack_unpack($data); 18 | } 19 | $end = microtime(true); 20 | 21 | printf("# Result:\n"); 22 | printf("# decoding %d messages\n", $attempts); 23 | printf("# processing time: %6f (%f/message)\n", $end - $begin, ($end - $begin) / $attempts); 24 | printf("# total bytes: %d bytes\n", strlen($data) * $attempts); 25 | -------------------------------------------------------------------------------- /examples/misc/address5.php: -------------------------------------------------------------------------------- 1 | 21, "name" => "John Doe")); 5 | 6 | printf("# decoding benchmark (msgpack array).\n"); 7 | printf("# target message size: %d bytes.\n", strlen($data)); 8 | printf("# start\n"); 9 | 10 | $begin = microtime(true); 11 | $attempts = 100000; 12 | for ($i = 0; $i < $attempts; $i++) { 13 | msgpack_unpack($data); 14 | } 15 | $end = microtime(true); 16 | 17 | printf("# Result:\n"); 18 | printf("# decoding %d messages\n", $attempts); 19 | printf("# processing time: %6f (%f/message)\n", $end - $begin, ($end - $begin) / $attempts); 20 | printf("# total bytes: %d bytes\n", strlen($data) * $attempts); 21 | -------------------------------------------------------------------------------- /examples/misc/reflection.php: -------------------------------------------------------------------------------- 1 | setId(21); 8 | $person->setName("John Doe"); 9 | 10 | $descriptor = $person->getDescriptor(); 11 | $result = array(); 12 | 13 | foreach ($descriptor->getFields() as $field) { 14 | if (!$field->isExtension()) { 15 | if ($person->has($field->getName())) { 16 | // this does not care about Message. 17 | $value = $person->get($field->getName()); 18 | $result[$field->getName()] = $value; 19 | } 20 | } 21 | } 22 | 23 | echo json_encode($result, JSON_PRETTY_PRINT); 24 | -------------------------------------------------------------------------------- /examples/prefecture.php: -------------------------------------------------------------------------------- 1 | setId($i); 17 | $prefecture->setName($args[0]); 18 | $prefecture->setPopulation($args[1]); 19 | $prefecture->setArea($args[2]); 20 | $prefecture->setPopulationDensity($args[3]); 21 | 22 | $jpn->appendPrefecture($prefecture); 23 | $i++; 24 | } 25 | 26 | file_put_contents("prefecture.db", $jpn->serializeToString()); 27 | 28 | $data = $jpn->serializeToString(); 29 | $data = file_get_contents("prefecture.db"); 30 | 31 | printf("# decoding benchmark (protocolbuffers).\n"); 32 | printf("# target message size: %d bytes.\n", strlen($data)); 33 | printf("# start\n"); 34 | 35 | $begin = microtime(true); 36 | $attempts = 10000; 37 | for ($i = 0; $i < $attempts; $i++) { 38 | ProtocolBuffers::decode("Tutorial_Japan", $data); 39 | } 40 | $end = microtime(true); 41 | 42 | printf("# Result:\n"); 43 | printf("# decoding %d messages\n", $attempts); 44 | printf("# processing time: %6f (%f/message)\n", $end - $begin, ($end - $begin) / $attempts); 45 | printf("# total bytes: %d bytes\n", strlen($data) * $attempts); 46 | -------------------------------------------------------------------------------- /examples/prefecture.proto: -------------------------------------------------------------------------------- 1 | package Tutorial; 2 | 3 | message Prefecture { 4 | required uint32 id = 1; 5 | optional string name = 2; 6 | optional uint32 population = 3; 7 | optional uint32 area = 4; 8 | optional uint32 population_density = 5; 9 | } 10 | 11 | message Japan { 12 | repeated Prefecture prefecture = 1; 13 | } 14 | -------------------------------------------------------------------------------- /examples/prefecture.tsv: -------------------------------------------------------------------------------- 1 | 東京都 13216221 6038 2189 2 | 北海道 78421 5460668 70 3 | 神奈川県 9072133 3755 2416 4 | 岩手県 15279 1303351 85 5 | 大阪府 4661 8863324 1901 6 | 福島県 13783 1962333 142 7 | 愛知県 7425952 1438 5165 8 | 長野県 13562 2133014 157 9 | 埼玉県 1898 7208122 3798 10 | 新潟県 12584 2347092 187 11 | 千葉県 6195576 1201 5157 12 | 秋田県 11636 1063168 91 13 | 兵庫県 5571096 664 8396 14 | 岐阜県 10621 2064940 194 15 | 福岡県 1021 5085368 4979 16 | 青森県 9645 1349899 140 17 | 山形県 9323 1151863 124 18 | 沖縄県 619 1410138 2277 19 | 静岡県 3736600 7781 480 20 | 鹿児島県 9189 1689397 184 21 | 京都府 570 2627313 4613 22 | 茨城県 2945824 483 6096 23 | 広島県 8480 2849104 336 24 | 香川県 527 989159 1877 25 | 宮崎県 7736 1126132 146 26 | 奈良県 377 1389690 3691 27 | 宮城県 2325407 7286 319 28 | 熊本県 7405 1807201 244 29 | 滋賀県 353 1416546 4017 30 | 佐賀県 346 843505 2440 31 | 岡山県 7113 1936575 272 32 | 長崎県 343 1407904 4106 33 | 栃木県 1993386 6408 311 34 | 高知県 7105 106 752042 35 | 群馬県 1992432 6362 313 36 | 島根県 6708 105 707074 37 | 三重県 318 1838611 5777 38 | 大分県 6340 1185830 187 39 | 山口県 6114 1431294 234 40 | 石川県 278 1162953 4186 41 | 富山県 255 4248 1082763 42 | 愛媛県 5679 249 1414996 43 | 和歌山県 209 4726 987483 44 | 福井県 191 4190 799127 45 | 山梨県 4465 191 851681 46 | 徳島県 187 4147 775871 47 | 鳥取県 166 3507 581870 48 | -------------------------------------------------------------------------------- /examples/uv/README.md: -------------------------------------------------------------------------------- 1 | # Protocol Buffer Example 2 | 3 | Overview 4 | -------- 5 | 6 | this example explains memcached like server which using protocol buffers. 7 | 8 | Requirements 9 | ------------ 10 | 11 | * php 5.3 higher 12 | * php-uv (https://github.com/chobie/php-uv/) 13 | 14 | 15 | Generate messages 16 | ----------------- 17 | 18 | ```` 19 | protoc --plugin=../../contrib/protoc-gen-php message.proto --php_out=proto -I . -I /usr/local/include 20 | ```` 21 | 22 | Starting Server Process 23 | ----------------------- 24 | 25 | ``` 26 | php server.php 27 | ```` 28 | 29 | you need to run server process when playing this example. 30 | 31 | 32 | SET operation 33 | ------------- 34 | 35 | ```` 36 | // php client.php SET 37 | php client.php SET chobie "Helo World" 38 | ```` 39 | 40 | GET operation 41 | ------------- 42 | 43 | ```` 44 | // php client.php GET 45 | php client.php GET chobie 46 | ```` 47 | -------------------------------------------------------------------------------- /examples/uv/message.proto: -------------------------------------------------------------------------------- 1 | package ProtocolCached; 2 | 3 | message Request { 4 | enum RequestType 5 | { 6 | GET = 1; 7 | SET = 2; 8 | } 9 | required RequestType type = 1 [default = GET]; 10 | optional SetRequest set = 2; 11 | optional GetRequest get = 3; 12 | } 13 | 14 | message Response { 15 | enum ResponseType 16 | { 17 | GET = 1; 18 | SET = 2; 19 | } 20 | required ResponseType type = 1 [default = GET]; 21 | optional GetResponse get = 2; 22 | } 23 | 24 | message SetRequest { 25 | required bytes key = 1; 26 | required bytes value = 2; 27 | } 28 | 29 | message GetRequest { 30 | required bytes key = 1; 31 | } 32 | 33 | 34 | message GetResponse { 35 | required bytes value = 1; 36 | } -------------------------------------------------------------------------------- /helper.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Protocol Buffers for PHP 3 | * Copyright 2013 Shuhei Tanuma. All rights reserved. 4 | * 5 | * https://github.com/chobie/php-protocolbuffers 6 | * 7 | * Redistribution and use in source and binary forms, with or without 8 | * modification, are permitted provided that the following conditions are 9 | * met: 10 | * 11 | * 1. Redistributions of source code must retain the above copyright 12 | * notice, this list of conditions and the following disclaimer. 13 | * 2. Redistributions in binary form must reproduce the above 14 | * copyright notice, this list of conditions and the following disclaimer 15 | * in the documentation and/or other materials provided with the 16 | * distribution. 17 | * 18 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 19 | * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 20 | * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 21 | * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 22 | * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 23 | * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 24 | * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 25 | * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 26 | * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 27 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 28 | * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 29 | */ 30 | 31 | #ifndef PHP_PROTOCOLBUFFERS_HELPER_H 32 | #define PHP_PROTOCOLBUFFERS_HELPER_H 33 | 34 | void php_protocolbuffers_helper_class(TSRMLS_D); 35 | 36 | #endif -------------------------------------------------------------------------------- /message.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Protocol Buffers for PHP 3 | * Copyright 2013 Shuhei Tanuma. All rights reserved. 4 | * 5 | * https://github.com/chobie/php-protocolbuffers 6 | * 7 | * Redistribution and use in source and binary forms, with or without 8 | * modification, are permitted provided that the following conditions are 9 | * met: 10 | * 11 | * 1. Redistributions of source code must retain the above copyright 12 | * notice, this list of conditions and the following disclaimer. 13 | * 2. Redistributions in binary form must reproduce the above 14 | * copyright notice, this list of conditions and the following disclaimer 15 | * in the documentation and/or other materials provided with the 16 | * distribution. 17 | * 18 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 19 | * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 20 | * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 21 | * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 22 | * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 23 | * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 24 | * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 25 | * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 26 | * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 27 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 28 | * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 29 | */ 30 | 31 | #ifndef PHP_PROTOCOLBUFFERS_MESSAGE_H 32 | #define PHP_PROTOCOLBUFFERS_MESSAGE_H 33 | 34 | void php_protocolbuffers_message_class(TSRMLS_D); 35 | 36 | #endif -------------------------------------------------------------------------------- /phpunit.xml.dist: -------------------------------------------------------------------------------- 1 | 6 | 7 | 8 | ./tests/ 9 | 10 | 11 | -------------------------------------------------------------------------------- /tests/001_big_tag.phpt: -------------------------------------------------------------------------------- 1 | --TEST-- 2 | Check for protocol buffers big tag implementations 3 | --FILE-- 4 | setValue(1); 11 | 12 | $data = ProtocolBuffers::encode($u); 13 | 14 | if ($data == $expect) { 15 | echo "OK" . PHP_EOL; 16 | } else { 17 | echo $data; 18 | } 19 | --EXPECT-- 20 | OK 21 | -------------------------------------------------------------------------------- /tests/001_bool.phpt: -------------------------------------------------------------------------------- 1 | --TEST-- 2 | Check for protocol buffers bool implementations 3 | --FILE-- 4 | setValue(true); 11 | 12 | $data = ProtocolBuffers::encode($u); 13 | 14 | if ($data == $expect) { 15 | echo "OK" . PHP_EOL; 16 | } else { 17 | echo $data; 18 | } 19 | --EXPECT-- 20 | OK -------------------------------------------------------------------------------- /tests/001_bytes.phpt: -------------------------------------------------------------------------------- 1 | --TEST-- 2 | Check for protocol buffers bytes implementations 3 | --FILE-- 4 | setValue($droid); 12 | 13 | $data = ProtocolBuffers::encode($u); 14 | 15 | if ($data == $expect) { 16 | echo "OK" . PHP_EOL; 17 | } else { 18 | echo $data; 19 | } 20 | --EXPECT-- 21 | OK -------------------------------------------------------------------------------- /tests/001_double_sample.phpt: -------------------------------------------------------------------------------- 1 | --TEST-- 2 | Check for protocol buffers double implementations 3 | --FILE-- 4 | setValue(1.05); 11 | 12 | $data = ProtocolBuffers::encode($u); 13 | 14 | if ($data == $expect) { 15 | echo "OK" . PHP_EOL; 16 | } else { 17 | echo "FAILED" . PHP_EOL; 18 | } 19 | --EXPECT-- 20 | OK -------------------------------------------------------------------------------- /tests/001_fixed32_init.phpt: -------------------------------------------------------------------------------- 1 | --TEST-- 2 | Check for protocol buffers fixed32 implementations 3 | --FILE-- 4 | setValue(0); 11 | 12 | $data = ProtocolBuffers::encode($u); 13 | 14 | if ($data == $expect) { 15 | echo "OK" . PHP_EOL; 16 | } else { 17 | echo $data; 18 | } 19 | --EXPECT-- 20 | OK -------------------------------------------------------------------------------- /tests/001_fixed32_max.phpt: -------------------------------------------------------------------------------- 1 | --TEST-- 2 | Check for protocol buffers fixed32 implementations 3 | --FILE-- 4 | setValue(4294967295); 11 | 12 | $data = ProtocolBuffers::encode($u); 13 | 14 | if ($data == $expect) { 15 | echo "OK" . PHP_EOL; 16 | } else { 17 | echo $data; 18 | } 19 | --EXPECT-- 20 | OK -------------------------------------------------------------------------------- /tests/001_fixed64_init.phpt: -------------------------------------------------------------------------------- 1 | --TEST-- 2 | Check for protocol buffers fixed64 implementations 3 | --SKIPIF-- 4 | 5 | --FILE-- 6 | setValue(0); 13 | 14 | $data = ProtocolBuffers::encode($u); 15 | 16 | if ($data == $expect) { 17 | echo "OK" . PHP_EOL; 18 | } else { 19 | echo $data; 20 | } 21 | --EXPECT-- 22 | OK -------------------------------------------------------------------------------- /tests/001_fixed64_max.phpt: -------------------------------------------------------------------------------- 1 | --TEST-- 2 | Check for protocol buffers fixed64 implementations 3 | --SKIPIF-- 4 | 5 | --FILE-- 6 | setValue(9223372036854775807); 12 | 13 | $data = ProtocolBuffers::encode($u); 14 | 15 | if ($data == $expect) { 16 | echo "OK" . PHP_EOL; 17 | } else { 18 | echo $data; 19 | } 20 | --EXPECT-- 21 | OK -------------------------------------------------------------------------------- /tests/001_float_sample.phpt: -------------------------------------------------------------------------------- 1 | --TEST-- 2 | Check for protocol buffers float implementations 3 | --FILE-- 4 | setValue(1.05); 11 | 12 | $data = ProtocolBuffers::encode($u); 13 | 14 | if ($data == $expect) { 15 | echo "OK" . PHP_EOL; 16 | } else { 17 | echo "FAILED" . PHP_EOL; 18 | } 19 | --EXPECT-- 20 | OK -------------------------------------------------------------------------------- /tests/001_float_signed.phpt: -------------------------------------------------------------------------------- 1 | --TEST-- 2 | Check for protocol buffers float implementations 3 | --FILE-- 4 | setValue(-1.05); 11 | 12 | $data = ProtocolBuffers::encode($u); 13 | 14 | if ($data == $expect) { 15 | echo "OK" . PHP_EOL; 16 | } else { 17 | echo "FAILED" . PHP_EOL; 18 | } 19 | --EXPECT-- 20 | OK -------------------------------------------------------------------------------- /tests/001_int32_init.phpt: -------------------------------------------------------------------------------- 1 | --TEST-- 2 | Check for protocol buffers int32 implementations 3 | --FILE-- 4 | setValue(0); 11 | 12 | $data = ProtocolBuffers::encode($u); 13 | 14 | if ($data == $expect) { 15 | echo "OK" . PHP_EOL; 16 | } else { 17 | echo "FAILED" . PHP_EOL; 18 | } 19 | --EXPECT-- 20 | OK -------------------------------------------------------------------------------- /tests/001_int32_max.phpt: -------------------------------------------------------------------------------- 1 | --TEST-- 2 | Check for protocol buffers int32 implementations 3 | --FILE-- 4 | setValue(2147483647); 11 | 12 | $data = ProtocolBuffers::encode($u); 13 | 14 | if ($data == $expect) { 15 | echo "OK" . PHP_EOL; 16 | } else { 17 | echo "FAILED" . PHP_EOL; 18 | } 19 | --EXPECT-- 20 | OK -------------------------------------------------------------------------------- /tests/001_int32_min.phpt: -------------------------------------------------------------------------------- 1 | --TEST-- 2 | Check for protocol buffers int32 implementations 3 | --FILE-- 4 | setValue(-2147483648); 11 | 12 | $data = ProtocolBuffers::encode($u); 13 | 14 | if ($data == $expect) { 15 | echo "OK" . PHP_EOL; 16 | } else { 17 | echo "FAILED" . PHP_EOL; 18 | } 19 | --EXPECT-- 20 | OK -------------------------------------------------------------------------------- /tests/001_int64_init.phpt: -------------------------------------------------------------------------------- 1 | --TEST-- 2 | Check for protocol buffers int64 implementations 3 | --SKIPIF-- 4 | 5 | --FILE-- 6 | setValue(0); 13 | 14 | $data = ProtocolBuffers::encode($u); 15 | 16 | if ($data == $expect) { 17 | echo "OK" . PHP_EOL; 18 | } else { 19 | echo "FAILED" . PHP_EOL; 20 | } 21 | --EXPECT-- 22 | OK -------------------------------------------------------------------------------- /tests/001_int64_max.phpt: -------------------------------------------------------------------------------- 1 | --TEST-- 2 | Check for protocol buffers int64 implementations 3 | --SKIPIF-- 4 | 5 | --FILE-- 6 | setValue(9223372036854775807); 13 | 14 | $data = ProtocolBuffers::encode($u); 15 | 16 | if ($data == $expect) { 17 | echo "OK" . PHP_EOL; 18 | } else { 19 | echo "FAILED" . PHP_EOL; 20 | } 21 | --EXPECT-- 22 | OK -------------------------------------------------------------------------------- /tests/001_int64_min.phpt: -------------------------------------------------------------------------------- 1 | --TEST-- 2 | Check for protocol buffers int64 implementations 3 | --SKIPIF-- 4 | 5 | --FILE-- 6 | setValue(-9223372036854775808); 13 | 14 | $data = ProtocolBuffers::encode($u); 15 | 16 | if ($data == $expect) { 17 | echo "OK" . PHP_EOL; 18 | } else { 19 | echo $data; 20 | } 21 | --EXPECT-- 22 | OK -------------------------------------------------------------------------------- /tests/001_sfixed32_signed.phpt: -------------------------------------------------------------------------------- 1 | --TEST-- 2 | Check for protocol buffers sfixed32 implementations 3 | --FILE-- 4 | setValue(-256); 11 | 12 | $data = ProtocolBuffers::encode($u); 13 | 14 | if ($data == $expect) { 15 | echo "OK" . PHP_EOL; 16 | } else { 17 | echo "FAILED" . PHP_EOL; 18 | } 19 | --EXPECT-- 20 | OK -------------------------------------------------------------------------------- /tests/001_sfixed32_unsigned.phpt: -------------------------------------------------------------------------------- 1 | --TEST-- 2 | Check for protocol buffers sfixed32 implementations 3 | --FILE-- 4 | setValue(256); 11 | 12 | $data = ProtocolBuffers::encode($u); 13 | 14 | if ($data == $expect) { 15 | echo "OK" . PHP_EOL; 16 | } else { 17 | echo "FAILED" . PHP_EOL; 18 | } 19 | --EXPECT-- 20 | OK -------------------------------------------------------------------------------- /tests/001_sfixed64_init.phpt: -------------------------------------------------------------------------------- 1 | --TEST-- 2 | Check for protocol buffers sfixed64 implementations 3 | --SKIPIF-- 4 | 5 | --FILE-- 6 | setValue(0); 13 | 14 | $data = ProtocolBuffers::encode($u); 15 | 16 | if ($data == $expect) { 17 | echo "OK" . PHP_EOL; 18 | } else { 19 | echo $data; 20 | } 21 | --EXPECT-- 22 | OK -------------------------------------------------------------------------------- /tests/001_sfixed64_max.phpt: -------------------------------------------------------------------------------- 1 | --TEST-- 2 | Check for protocol buffers sfixed64 implementations 3 | --SKIPIF-- 4 | 5 | --FILE-- 6 | setValue(9223372036854775807); 13 | 14 | $data = ProtocolBuffers::encode($u); 15 | 16 | if ($data == $expect) { 17 | echo "OK" . PHP_EOL; 18 | } else { 19 | echo $data; 20 | } 21 | --EXPECT-- 22 | OK -------------------------------------------------------------------------------- /tests/001_sfixed64_min.phpt: -------------------------------------------------------------------------------- 1 | --TEST-- 2 | Check for protocol buffers sfixed64 implementations 3 | --SKIPIF-- 4 | 5 | --FILE-- 6 | setValue(-9223372036854775808); 13 | 14 | $data = ProtocolBuffers::encode($u); 15 | 16 | if ($data == $expect) { 17 | echo "OK" . PHP_EOL; 18 | } else { 19 | echo $data; 20 | } 21 | --EXPECT-- 22 | OK -------------------------------------------------------------------------------- /tests/001_sint32_init.phpt: -------------------------------------------------------------------------------- 1 | --TEST-- 2 | Check for protocol buffers sint32 implementations 3 | --FILE-- 4 | setValue(0); 11 | 12 | $data = ProtocolBuffers::encode($u); 13 | 14 | if ($data == $expect) { 15 | echo "OK" . PHP_EOL; 16 | } else { 17 | echo "FAILED" . PHP_EOL; 18 | } 19 | --EXPECT-- 20 | OK -------------------------------------------------------------------------------- /tests/001_sint32_max.phpt: -------------------------------------------------------------------------------- 1 | --TEST-- 2 | Check for protocol buffers sint32 implementations 3 | --FILE-- 4 | setValue(2147483647); 11 | 12 | $data = ProtocolBuffers::encode($u); 13 | 14 | if ($data == $expect) { 15 | echo "OK" . PHP_EOL; 16 | } else { 17 | echo $data; 18 | } 19 | --EXPECT-- 20 | OK -------------------------------------------------------------------------------- /tests/001_sint32_min.phpt: -------------------------------------------------------------------------------- 1 | --TEST-- 2 | Check for protocol buffers sint32 implementations 3 | --FILE-- 4 | setValue(-2147483648); 11 | 12 | $data = ProtocolBuffers::encode($u); 13 | 14 | if ($data == $expect) { 15 | echo "OK" . PHP_EOL; 16 | } else { 17 | echo $data; 18 | } 19 | --EXPECT-- 20 | OK -------------------------------------------------------------------------------- /tests/001_sint64.init.phpt: -------------------------------------------------------------------------------- 1 | --TEST-- 2 | Check for protocol buffers sint64 implementations 3 | --SKIPIF-- 4 | 5 | --FILE-- 6 | setValue(0); 13 | 14 | $data = ProtocolBuffers::encode($u); 15 | 16 | if ($data == $expect) { 17 | echo "OK" . PHP_EOL; 18 | } else { 19 | echo $data; 20 | } 21 | --EXPECT-- 22 | OK -------------------------------------------------------------------------------- /tests/001_sint64_max.phpt: -------------------------------------------------------------------------------- 1 | --TEST-- 2 | Check for protocol buffers sint64 implementations 3 | --SKIPIF-- 4 | 5 | --FILE-- 6 | setValue(9223372036854775807); 13 | 14 | $data = ProtocolBuffers::encode($u); 15 | if ($data == $expect) { 16 | echo "OK" . PHP_EOL; 17 | } else { 18 | echo $data; 19 | } 20 | --EXPECT-- 21 | OK -------------------------------------------------------------------------------- /tests/001_sint64_min.phpt: -------------------------------------------------------------------------------- 1 | --TEST-- 2 | Check for protocol buffers sint64 implementations 3 | --SKIPIF-- 4 | 5 | --FILE-- 6 | setValue(-9223372036854775808); 13 | 14 | $data = ProtocolBuffers::encode($u); 15 | 16 | if ($data == $expect) { 17 | echo "OK" . PHP_EOL; 18 | } else { 19 | echo $data; 20 | } 21 | --EXPECT-- 22 | OK -------------------------------------------------------------------------------- /tests/001_string_0bytes.phpt: -------------------------------------------------------------------------------- 1 | --TEST-- 2 | Check for protocol buffers string implementations 3 | --FILE-- 4 | setValue(""); 11 | 12 | $data = ProtocolBuffers::encode($u); 13 | 14 | if ($data == $expect) { 15 | echo "OK" . PHP_EOL; 16 | } else { 17 | echo "FAILED" . PHP_EOL; 18 | } 19 | --EXPECT-- 20 | OK -------------------------------------------------------------------------------- /tests/001_string_1024bytes.phpt: -------------------------------------------------------------------------------- 1 | --TEST-- 2 | Check for protocol buffers string implementations 3 | --FILE-- 4 | setValue("aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"); 11 | 12 | $data = ProtocolBuffers::encode($u); 13 | 14 | if ($data == $expect) { 15 | echo "OK" . PHP_EOL; 16 | } else { 17 | echo "FAILED" . PHP_EOL; 18 | } 19 | --EXPECT-- 20 | OK -------------------------------------------------------------------------------- /tests/001_string_invaild_encoding.phpt: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/chobie/php-protocolbuffers/747a2238f14de0be67d5747089b50ebcc5e1116c/tests/001_string_invaild_encoding.phpt -------------------------------------------------------------------------------- /tests/001_string_invalid_encoding_with_no_string_validate.phpt: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/chobie/php-protocolbuffers/747a2238f14de0be67d5747089b50ebcc5e1116c/tests/001_string_invalid_encoding_with_no_string_validate.phpt -------------------------------------------------------------------------------- /tests/001_string_should_keep_object.phpt: -------------------------------------------------------------------------------- 1 | --TEST-- 2 | Check for protocol buffers string implementations 3 | --FILE-- 4 | buffer .= $string; 16 | } 17 | 18 | public function __toString() 19 | { 20 | return $this->buffer; 21 | } 22 | } 23 | 24 | $u = new Tutorial_String(); 25 | 26 | $string = new MyString(); 27 | $string->append("Hello"); 28 | $u->setValue($string); 29 | 30 | $u2 = ProtocolBuffers::decode("Tutorial_String", ProtocolBuffers::encode($u)); 31 | 32 | echo $u2->getValue() . PHP_EOL; 33 | if (is_string($u2->getValue())) { 34 | echo "OK" . PHP_EOL; 35 | } else { 36 | echo "FAULT" . PHP_EOL; 37 | } 38 | if ($u->getValue() instanceof MyString) { 39 | echo "OK" . PHP_EOL; 40 | } else { 41 | echo "FAULT" . PHP_EOL; 42 | } 43 | 44 | --EXPECT-- 45 | Hello 46 | OK 47 | OK -------------------------------------------------------------------------------- /tests/001_string_small.phpt: -------------------------------------------------------------------------------- 1 | --TEST-- 2 | Check for protocol buffers string implementations 3 | --FILE-- 4 | setValue("abcdefghijklmn"); 11 | 12 | $data = ProtocolBuffers::encode($u); 13 | 14 | if ($data == $expect) { 15 | echo "OK" . PHP_EOL; 16 | } else { 17 | echo "FAILED" . PHP_EOL; 18 | } 19 | --EXPECT-- 20 | OK -------------------------------------------------------------------------------- /tests/001_string_utf8.phpt: -------------------------------------------------------------------------------- 1 | --TEST-- 2 | Check for protocol buffers string implementations 3 | --FILE-- 4 | setValue("素晴らしい世界"); 11 | 12 | $data = ProtocolBuffers::encode($u); 13 | 14 | if ($data == $expect) { 15 | echo "OK" . PHP_EOL; 16 | } else { 17 | echo "FAILED" . PHP_EOL; 18 | } 19 | --EXPECT-- 20 | OK -------------------------------------------------------------------------------- /tests/001_uint64_max.phpt: -------------------------------------------------------------------------------- 1 | --TEST-- 2 | Check for protocol buffers uint64 implementations 3 | --SKIPIF-- 4 | 5 | --FILE-- 6 | setValue("18446744073709551615"); 12 | 13 | $data = ProtocolBuffers::encode($u); 14 | if ($data == $expect) { 15 | echo "OK" . PHP_EOL; 16 | } else { 17 | echo $data; 18 | } 19 | --EXPECT-- 20 | OK -------------------------------------------------------------------------------- /tests/002_repeated_int32.phpt: -------------------------------------------------------------------------------- 1 | --TEST-- 2 | Check for protocol buffers repeated int32 implementations 3 | --FILE-- 4 | addValue(1); 10 | $u->addValue(2); 11 | $u->addValue(3); 12 | $u->addValue(4); 13 | $u->addValue(5); 14 | $u->addValue(6); 15 | $u->addValue(7); 16 | $u->addValue(8); 17 | $u->addValue(9); 18 | $u->addValue(10); 19 | 20 | $data = ProtocolBuffers::encode($u); 21 | 22 | if ($data == $expect) { 23 | echo "OK" . PHP_EOL; 24 | } else { 25 | echo $data; 26 | } 27 | --EXPECT-- 28 | OK -------------------------------------------------------------------------------- /tests/002_repeated_message.phpt: -------------------------------------------------------------------------------- 1 | --TEST-- 2 | Check for protocol buffers simple message encoding 3 | --FILE-- 4 | setId(20); 11 | $u->setOffense(105); 12 | $u->setName("chobie"); 13 | 14 | $a = new Tutorial_AddressBook(); 15 | $a->addUser($u); 16 | $a->addUser($u); 17 | 18 | $data = ProtocolBuffers::encode($a); 19 | 20 | if ($data == $expect) { 21 | echo "OK" . PHP_EOL; 22 | } else { 23 | echo $data; 24 | } 25 | --EXPECT-- 26 | OK -------------------------------------------------------------------------------- /tests/002_repeated_string.phpt: -------------------------------------------------------------------------------- 1 | --TEST-- 2 | Check for protocol buffers repeated string implementations 3 | --FILE-- 4 | addValues("a"); 10 | $u->addValues("b"); 11 | $u->addValues("c"); 12 | $u->addValues("d"); 13 | $u->addValues("e"); 14 | $u->addValues("f"); 15 | $u->addValues("g"); 16 | $u->addValues("h"); 17 | $u->addValues("i"); 18 | $u->addValues("j"); 19 | 20 | $data = ProtocolBuffers::encode($u); 21 | 22 | if ($data == $expect) { 23 | echo "OK" . PHP_EOL; 24 | } else { 25 | echo $data; 26 | } 27 | --EXPECT-- 28 | OK -------------------------------------------------------------------------------- /tests/002_simple_encode.phpt: -------------------------------------------------------------------------------- 1 | --TEST-- 2 | Check for protocol buffers simple message encoding 3 | --FILE-- 4 | setId(20); 11 | $u->setOffense(105); 12 | $u->setName("chobie"); 13 | 14 | $data = ProtocolBuffers::encode($u); 15 | if ($data == $expect) { 16 | echo "OK" . PHP_EOL; 17 | } else { 18 | echo $data; 19 | } 20 | --EXPECT-- 21 | OK -------------------------------------------------------------------------------- /tests/003_bool_packed.phpt: -------------------------------------------------------------------------------- 1 | --TEST-- 2 | Check for protocol buffers bool packed implementations 3 | --FILE-- 4 | addValue(1); 11 | $u->addValue(0); 12 | 13 | $data = ProtocolBuffers::encode($u); 14 | 15 | if ($data == $expect) { 16 | echo "OK" . PHP_EOL; 17 | } else { 18 | echo $data; 19 | } 20 | --EXPECT-- 21 | OK -------------------------------------------------------------------------------- /tests/003_double_packed.phpt: -------------------------------------------------------------------------------- 1 | --TEST-- 2 | Check for protocol buffers double packed implementations 3 | --FILE-- 4 | addValue(0); 11 | $u->addValue(1.05); 12 | $u->addValue(3.1418); 13 | 14 | $data = ProtocolBuffers::encode($u); 15 | 16 | if ($data == $expect) { 17 | echo "OK" . PHP_EOL; 18 | } else { 19 | echo $data; 20 | } 21 | --EXPECT-- 22 | OK -------------------------------------------------------------------------------- /tests/003_fixed32_packed.phpt: -------------------------------------------------------------------------------- 1 | --TEST-- 2 | Check for protocol buffers fixed32 packed implementations 3 | --FILE-- 4 | addValue(0); 11 | $u->addValue(128); 12 | $u->addValue(256); 13 | $u->addValue(512); 14 | $u->addValue(1024); 15 | 16 | $data = ProtocolBuffers::encode($u); 17 | 18 | if ($data == $expect) { 19 | echo "OK" . PHP_EOL; 20 | } else { 21 | echo $data; 22 | } 23 | --EXPECT-- 24 | OK -------------------------------------------------------------------------------- /tests/003_fixed64_packed.phpt: -------------------------------------------------------------------------------- 1 | --TEST-- 2 | Check for protocol buffers fixed64 packed implementations 3 | --SKIPIF-- 4 | 5 | --FILE-- 6 | addValue(0); 13 | $u->addValue(1024); 14 | 15 | $data = ProtocolBuffers::encode($u); 16 | 17 | if ($data == $expect) { 18 | echo "OK" . PHP_EOL; 19 | } else { 20 | echo $data; 21 | } 22 | --EXPECT-- 23 | OK -------------------------------------------------------------------------------- /tests/003_float_packed.phpt: -------------------------------------------------------------------------------- 1 | --TEST-- 2 | Check for protocol buffers double packed implementations 3 | --FILE-- 4 | addValue(0); 11 | $u->addValue(1.05); 12 | $u->addValue(3.1418); 13 | 14 | $data = ProtocolBuffers::encode($u); 15 | 16 | if ($data == $expect) { 17 | echo "OK" . PHP_EOL; 18 | } else { 19 | echo $data; 20 | } 21 | --EXPECT-- 22 | OK -------------------------------------------------------------------------------- /tests/003_has_message_decode.phpt: -------------------------------------------------------------------------------- 1 | --TEST-- 2 | Check for protocol buffers simple message encoding 3 | --FILE-- 4 | getId() . PHP_EOL; 13 | echo $person->getName() . PHP_EOL; 14 | echo $person->getPhone()->getType() . PHP_EOL; 15 | echo $person->getPhone()->getNumber() . PHP_EOL; 16 | --EXPECT-- 17 | 20 18 | chobie 19 | 1 20 | 0120-222-222 -------------------------------------------------------------------------------- /tests/003_has_message_encode.phpt: -------------------------------------------------------------------------------- 1 | --TEST-- 2 | Check for protocol buffers simple message encoding 3 | --FILE-- 4 | setId(20); 11 | $person->setName("chobie"); 12 | $phone = new Tutorial_Person_PhoneNumber(); 13 | $phone->setType(1); 14 | $phone->setNumber("0120-222-222"); 15 | $person->setPhone($phone); 16 | 17 | if (ProtocolBuffers::encode($person) == $expect) { 18 | echo "OK" . PHP_EOL; 19 | } 20 | 21 | --EXPECT-- 22 | OK -------------------------------------------------------------------------------- /tests/003_int32_packed.phpt: -------------------------------------------------------------------------------- 1 | --TEST-- 2 | Check for protocol buffers int32 packed implementations 3 | --FILE-- 4 | addValue(1); 11 | 12 | $data = ProtocolBuffers::encode($u); 13 | 14 | if ($data == $expect) { 15 | echo "OK" . PHP_EOL; 16 | } else { 17 | echo $data; 18 | } 19 | --EXPECT-- 20 | OK -------------------------------------------------------------------------------- /tests/003_int32_packed_many.phpt: -------------------------------------------------------------------------------- 1 | --TEST-- 2 | Check for protocol buffers int32 packed implementations 3 | --FILE-- 4 | addValue(1); 11 | $u->addValue(2); 12 | $u->addValue(1024); 13 | 14 | $data = ProtocolBuffers::encode($u); 15 | 16 | if ($data == $expect) { 17 | echo "OK" . PHP_EOL; 18 | } else { 19 | echo $data; 20 | } 21 | --EXPECT-- 22 | OK -------------------------------------------------------------------------------- /tests/003_int64_packed.phpt: -------------------------------------------------------------------------------- 1 | --TEST-- 2 | Check for protocol buffers int64 packed implementations 3 | --SKIPIF-- 4 | 5 | --FILE-- 6 | addValue(0); 13 | $u->addValue(1024); 14 | 15 | $data = ProtocolBuffers::encode($u); 16 | 17 | if ($data == $expect) { 18 | echo "OK" . PHP_EOL; 19 | } else { 20 | echo $data; 21 | } 22 | --EXPECT-- 23 | OK -------------------------------------------------------------------------------- /tests/003_sfixed32_packed.phpt: -------------------------------------------------------------------------------- 1 | --TEST-- 2 | Check for protocol buffers sfixed32 packed implementations 3 | --FILE-- 4 | addValue(-1024); 11 | $u->addValue(0); 12 | $u->addValue(1024); 13 | 14 | $data = ProtocolBuffers::encode($u); 15 | 16 | if ($data == $expect) { 17 | echo "OK" . PHP_EOL; 18 | } else { 19 | echo $data; 20 | } 21 | --EXPECT-- 22 | OK -------------------------------------------------------------------------------- /tests/003_sfixed64_packed.phpt: -------------------------------------------------------------------------------- 1 | --TEST-- 2 | Check for protocol buffers sfixed64 packed implementations 3 | --SKIPIF-- 4 | 5 | --FILE-- 6 | addValue(-1024); 13 | $u->addValue(0); 14 | $u->addValue(1024); 15 | 16 | $data = ProtocolBuffers::encode($u); 17 | 18 | if ($data == $expect) { 19 | echo "OK" . PHP_EOL; 20 | } else { 21 | echo $data; 22 | } 23 | --EXPECT-- 24 | OK -------------------------------------------------------------------------------- /tests/003_sint32_packed.phpt: -------------------------------------------------------------------------------- 1 | --TEST-- 2 | Check for protocol buffers sint32 packed implementations 3 | --FILE-- 4 | addValue(-1024); 11 | $u->addValue(0); 12 | $u->addValue(1024); 13 | 14 | $data = ProtocolBuffers::encode($u); 15 | 16 | if ($data == $expect) { 17 | echo "OK" . PHP_EOL; 18 | } else { 19 | echo $data; 20 | } 21 | --EXPECT-- 22 | OK -------------------------------------------------------------------------------- /tests/003_sint64_packed.phpt: -------------------------------------------------------------------------------- 1 | --TEST-- 2 | Check for protocol buffers sint64 packed implementations 3 | --SKIPIF-- 4 | 5 | --FILE-- 6 | addValue(-1024); 13 | $u->addValue(0); 14 | $u->addValue(1024); 15 | 16 | $data = ProtocolBuffers::encode($u); 17 | 18 | if ($data == $expect) { 19 | echo "OK" . PHP_EOL; 20 | } else { 21 | echo $data; 22 | } 23 | --EXPECT-- 24 | OK -------------------------------------------------------------------------------- /tests/003_uint32_packed.phpt: -------------------------------------------------------------------------------- 1 | --TEST-- 2 | Check for protocol buffers uint32 packed implementations 3 | --FILE-- 4 | addValue(0); 11 | $u->addValue(1024); 12 | 13 | $data = ProtocolBuffers::encode($u); 14 | 15 | if ($data == $expect) { 16 | echo "OK" . PHP_EOL; 17 | } else { 18 | echo $data; 19 | } 20 | --EXPECT-- 21 | OK -------------------------------------------------------------------------------- /tests/004_decode_bool.phpt: -------------------------------------------------------------------------------- 1 | --TEST-- 2 | Check for protocol buffers bool implementations 3 | --FILE-- 4 | setValue(true); 11 | 12 | $obj = ProtocolBuffers::decode("Tutorial_Boolean", $data); 13 | 14 | if ($obj instanceof Tutorial_Boolean) { 15 | if ($obj->getValue() === true) { 16 | echo "OK" . PHP_EOL; 17 | } else { 18 | var_dump($obj); 19 | } 20 | } else { 21 | var_dump($obj); 22 | } 23 | 24 | ini_set("protocolbuffers.native_scalars", 1); 25 | $obj = ProtocolBuffers::decode("Tutorial_Boolean", $data); 26 | 27 | if ($obj instanceof Tutorial_Boolean) { 28 | if ($obj->getValue() === true) { 29 | echo "OK" . PHP_EOL; 30 | } else { 31 | var_dump($obj); 32 | } 33 | } else { 34 | var_dump($obj); 35 | } 36 | 37 | --EXPECT-- 38 | OK 39 | OK -------------------------------------------------------------------------------- /tests/004_decode_bytes.phpt: -------------------------------------------------------------------------------- 1 | --TEST-- 2 | Check for protocol buffers bytes implementations 3 | --FILE-- 4 | getValue() === $droid) { 14 | echo "OK" . PHP_EOL; 15 | } else { 16 | var_dump($obj); 17 | } 18 | } else { 19 | var_dump($obj); 20 | } 21 | 22 | ini_set("protocolbuffers.native_scalars", 1); 23 | $obj = ProtocolBuffers::decode("Tutorial_Bytes", $bytes); 24 | 25 | if ($obj instanceof Tutorial_Bytes) { 26 | if ($obj->getValue() === $droid) { 27 | echo "OK" . PHP_EOL; 28 | } else { 29 | var_dump($obj); 30 | } 31 | } else { 32 | var_dump($obj); 33 | } 34 | 35 | --EXPECT-- 36 | OK 37 | OK -------------------------------------------------------------------------------- /tests/004_decode_double_sample.phpt: -------------------------------------------------------------------------------- 1 | --TEST-- 2 | Check for protocol buffers double implementations 3 | --FILE-- 4 | getValue(), 2) == 1.05) { 13 | echo "OK" . PHP_EOL; 14 | } else { 15 | var_dump($obj); 16 | } 17 | } else { 18 | var_dump($obj); 19 | } 20 | 21 | ini_set("protocolbuffers.native_scalars", 1); 22 | if ($obj instanceof Tutorial_Double) { 23 | if (round($obj->getValue(), 2) === 1.05) { 24 | echo "OK" . PHP_EOL; 25 | } else { 26 | var_dump($obj); 27 | } 28 | } else { 29 | var_dump($obj); 30 | } 31 | --EXPECT-- 32 | OK 33 | OK -------------------------------------------------------------------------------- /tests/004_decode_fixed32_init.phpt: -------------------------------------------------------------------------------- 1 | --TEST-- 2 | Check for protocol buffers fixed32 implementations 3 | --FILE-- 4 | getValue() == 0) { 13 | echo "OK" . PHP_EOL; 14 | } else { 15 | var_dump($obj); 16 | } 17 | } else { 18 | var_dump($obj); 19 | } 20 | 21 | ini_set("protocolbuffers.native_scalars", 1); 22 | $obj = ProtocolBuffers::decode("Tutorial_Fixed32", $bytes); 23 | if ($obj instanceof Tutorial_Fixed32) { 24 | if ($obj->getValue() === 0) { 25 | echo "OK" . PHP_EOL; 26 | } else { 27 | var_dump($obj); 28 | } 29 | } else { 30 | var_dump($obj); 31 | } 32 | 33 | --EXPECT-- 34 | OK 35 | OK -------------------------------------------------------------------------------- /tests/004_decode_fixed32_max.phpt: -------------------------------------------------------------------------------- 1 | --TEST-- 2 | Check for protocol buffers fixed32 implementations 3 | --FILE-- 4 | setValue(4294967295); 11 | 12 | $obj = ProtocolBuffers::decode("Tutorial_Fixed32", $bytes); 13 | 14 | if ($obj instanceof Tutorial_Fixed32) { 15 | if ($obj->getValue() == 4294967295) { 16 | echo "OK" . PHP_EOL; 17 | } else { 18 | var_dump($obj); 19 | } 20 | } else { 21 | var_dump($obj); 22 | } 23 | 24 | ini_set("protocolbuffers.native_scalars", 1); 25 | $obj = ProtocolBuffers::decode("Tutorial_Fixed32", $bytes); 26 | if ($obj instanceof Tutorial_Fixed32) { 27 | if ($obj->getValue() === 4294967295) { 28 | echo "OK" . PHP_EOL; 29 | } else { 30 | var_dump($obj); 31 | } 32 | } else { 33 | var_dump($obj); 34 | } 35 | 36 | --EXPECT-- 37 | OK 38 | OK -------------------------------------------------------------------------------- /tests/004_decode_float_sample.phpt: -------------------------------------------------------------------------------- 1 | --TEST-- 2 | Check for protocol buffers float implementations 3 | --FILE-- 4 | setValue(1.05); 11 | 12 | $obj = ProtocolBuffers::decode("Tutorial_Float", $bytes); 13 | 14 | if ($obj instanceof Tutorial_Float) { 15 | if (round($obj->getValue(), 2) == 1.05) { 16 | echo "OK" . PHP_EOL; 17 | } else { 18 | var_dump($obj); 19 | } 20 | } else { 21 | var_dump($obj); 22 | } 23 | 24 | ini_set("protocolbuffers.native_scalars", 1); 25 | $obj = ProtocolBuffers::decode("Tutorial_Float", $bytes); 26 | if ($obj instanceof Tutorial_Float) { 27 | if (round($obj->getValue(), 2) === 1.05) { 28 | echo "OK" . PHP_EOL; 29 | } else { 30 | var_dump($obj); 31 | } 32 | } else { 33 | var_dump($obj); 34 | } 35 | 36 | --EXPECT-- 37 | OK 38 | OK -------------------------------------------------------------------------------- /tests/004_decode_float_signed.phpt: -------------------------------------------------------------------------------- 1 | --TEST-- 2 | Check for protocol buffers float implementations 3 | --FILE-- 4 | setValue(-1.05); 11 | 12 | $obj = ProtocolBuffers::decode("Tutorial_Float", $bytes); 13 | 14 | if ($obj instanceof Tutorial_Float) { 15 | if (round($obj->getValue(), 2) == -1.05) { 16 | echo "OK" . PHP_EOL; 17 | } else { 18 | var_dump($obj); 19 | } 20 | } else { 21 | var_dump($obj); 22 | } 23 | 24 | ini_set("protocolbuffers.native_scalars", 1); 25 | $obj = ProtocolBuffers::decode("Tutorial_Float", $bytes); 26 | if ($obj instanceof Tutorial_Float) { 27 | if (round($obj->getValue(), 2) === -1.05) { 28 | echo "OK" . PHP_EOL; 29 | } else { 30 | var_dump($obj); 31 | } 32 | } else { 33 | var_dump($obj); 34 | } 35 | 36 | --EXPECT-- 37 | OK 38 | OK -------------------------------------------------------------------------------- /tests/004_decode_int32_init.phpt: -------------------------------------------------------------------------------- 1 | --TEST-- 2 | Check for protocol buffers int32 implementations 3 | --FILE-- 4 | setValue(0); 11 | 12 | $obj = ProtocolBuffers::decode("Tutorial_Integer32", $bytes); 13 | 14 | if ($obj instanceof Tutorial_Integer32) { 15 | if ($obj->getValue() == 0) { 16 | echo "OK" . PHP_EOL; 17 | } else { 18 | var_dump($obj); 19 | } 20 | } else { 21 | var_dump($obj); 22 | } 23 | 24 | ini_set("protocolbuffers.native_scalars", 1); 25 | $obj = ProtocolBuffers::decode("Tutorial_Integer32", $bytes); 26 | if ($obj instanceof Tutorial_Integer32) { 27 | if ($obj->getValue() === 0) { 28 | echo "OK" . PHP_EOL; 29 | } else { 30 | var_dump($obj); 31 | } 32 | } else { 33 | var_dump($obj); 34 | } 35 | 36 | --EXPECT-- 37 | OK 38 | OK -------------------------------------------------------------------------------- /tests/004_decode_int32_max.phpt: -------------------------------------------------------------------------------- 1 | --TEST-- 2 | Check for protocol buffers int32 implementations 3 | --FILE-- 4 | setValue(2147483647); 11 | 12 | $obj = ProtocolBuffers::decode("Tutorial_Integer32", $bytes); 13 | 14 | if ($obj instanceof Tutorial_Integer32) { 15 | if ($obj->getValue() == 2147483647) { 16 | echo "OK" . PHP_EOL; 17 | } else { 18 | var_dump($obj); 19 | } 20 | } else { 21 | var_dump($obj); 22 | } 23 | 24 | ini_set("protocolbuffers.native_scalars", 1); 25 | $obj = ProtocolBuffers::decode("Tutorial_Integer32", $bytes); 26 | if ($obj instanceof Tutorial_Integer32) { 27 | if ($obj->getValue() === 2147483647) { 28 | echo "OK" . PHP_EOL; 29 | } else { 30 | var_dump($obj); 31 | } 32 | } else { 33 | var_dump($obj); 34 | } 35 | 36 | --EXPECT-- 37 | OK 38 | OK -------------------------------------------------------------------------------- /tests/004_decode_int32_min.phpt: -------------------------------------------------------------------------------- 1 | --TEST-- 2 | Check for protocol buffers int32 implementations 3 | --FILE-- 4 | setValue(-2147483648); 11 | 12 | $obj = ProtocolBuffers::decode("Tutorial_Integer32", $bytes); 13 | 14 | if ($obj instanceof Tutorial_Integer32) { 15 | if ($obj->getValue() == -2147483648) { 16 | echo "OK" . PHP_EOL; 17 | } else { 18 | var_dump($obj); 19 | } 20 | } else { 21 | var_dump($obj); 22 | } 23 | 24 | ini_set("protocolbuffers.native_scalars", 1); 25 | $obj = ProtocolBuffers::decode("Tutorial_Integer32", $bytes); 26 | if ($obj instanceof Tutorial_Integer32) { 27 | if ($obj->getValue() == -2147483648) { 28 | echo "OK" . PHP_EOL; 29 | } else { 30 | var_dump($obj); 31 | } 32 | } else { 33 | var_dump($obj); 34 | } 35 | --EXPECT-- 36 | OK 37 | OK -------------------------------------------------------------------------------- /tests/004_decode_sfixed32_signed.phpt: -------------------------------------------------------------------------------- 1 | --TEST-- 2 | Check for protocol buffers sfixed32 implementations 3 | --FILE-- 4 | setValue(-256); 11 | 12 | $obj = ProtocolBuffers::decode("Tutorial_SFixed32", $bytes); 13 | 14 | if ($obj instanceof Tutorial_SFixed32) { 15 | if ($obj->getValue() == -256) { 16 | echo "OK" . PHP_EOL; 17 | } else { 18 | var_dump($obj); 19 | } 20 | } else { 21 | var_dump($obj); 22 | } 23 | 24 | ini_set("protocolbuffers.native_scalars", 1); 25 | $obj = ProtocolBuffers::decode("Tutorial_SFixed32", $bytes); 26 | if ($obj instanceof Tutorial_SFixed32) { 27 | if ($obj->getValue() === -256) { 28 | echo "OK" . PHP_EOL; 29 | } else { 30 | var_dump($obj); 31 | } 32 | } else { 33 | var_dump($obj); 34 | } 35 | 36 | --EXPECT-- 37 | OK 38 | OK -------------------------------------------------------------------------------- /tests/004_decode_sfixed32_unsigned.phpt: -------------------------------------------------------------------------------- 1 | --TEST-- 2 | Check for protocol buffers sfixed32 implementations 3 | --FILE-- 4 | setValue(256); 11 | 12 | $obj = ProtocolBuffers::decode("Tutorial_SFixed32", $bytes); 13 | 14 | if ($obj instanceof Tutorial_SFixed32) { 15 | if ($obj->getValue() == 256) { 16 | echo "OK" . PHP_EOL; 17 | } else { 18 | var_dump($obj); 19 | } 20 | } else { 21 | var_dump($obj); 22 | } 23 | 24 | ini_set("protocolbuffers.native_scalars", 1); 25 | $obj = ProtocolBuffers::decode("Tutorial_SFixed32", $bytes); 26 | if ($obj instanceof Tutorial_SFixed32) { 27 | if ($obj->getValue() === 256) { 28 | echo "OK" . PHP_EOL; 29 | } else { 30 | var_dump($obj); 31 | } 32 | } else { 33 | var_dump($obj); 34 | } 35 | 36 | --EXPECT-- 37 | OK 38 | OK -------------------------------------------------------------------------------- /tests/004_decode_sint32_init.phpt: -------------------------------------------------------------------------------- 1 | --TEST-- 2 | Check for protocol buffers sint32 implementations 3 | --FILE-- 4 | setValue(0); 11 | 12 | $obj = ProtocolBuffers::decode("Tutorial_SInt32", $bytes); 13 | 14 | if ($obj instanceof Tutorial_SInt32) { 15 | if ($obj->getValue() == 0) { 16 | echo "OK" . PHP_EOL; 17 | } else { 18 | var_dump($obj); 19 | } 20 | } else { 21 | var_dump($obj); 22 | } 23 | 24 | ini_set("protocolbuffers.native_scalars", 1); 25 | $obj = ProtocolBuffers::decode("Tutorial_SInt32", $bytes); 26 | if ($obj instanceof Tutorial_SInt32) { 27 | if ($obj->getValue() === 0) { 28 | echo "OK" . PHP_EOL; 29 | } else { 30 | var_dump($obj); 31 | } 32 | } else { 33 | var_dump($obj); 34 | } 35 | 36 | --EXPECT-- 37 | OK 38 | OK -------------------------------------------------------------------------------- /tests/004_decode_sint32_max.phpt: -------------------------------------------------------------------------------- 1 | --TEST-- 2 | Check for protocol buffers sint32 implementations 3 | --FILE-- 4 | setValue(2147483647); 11 | 12 | $obj = ProtocolBuffers::decode("Tutorial_SInt32", $bytes); 13 | 14 | if ($obj instanceof Tutorial_SInt32) { 15 | if ($obj->getValue() == 2147483647) { 16 | echo "OK" . PHP_EOL; 17 | } else { 18 | var_dump($obj); 19 | } 20 | } else { 21 | var_dump($obj); 22 | } 23 | 24 | ini_set("protocolbuffers.native_scalars", 1); 25 | $obj = ProtocolBuffers::decode("Tutorial_SInt32", $bytes); 26 | if ($obj instanceof Tutorial_SInt32) { 27 | if ($obj->getValue() === 2147483647) { 28 | echo "OK" . PHP_EOL; 29 | } else { 30 | var_dump($obj); 31 | } 32 | } else { 33 | var_dump($obj); 34 | } 35 | 36 | --EXPECT-- 37 | OK 38 | OK -------------------------------------------------------------------------------- /tests/004_decode_sint32_min.phpt: -------------------------------------------------------------------------------- 1 | --TEST-- 2 | Check for protocol buffers sint32 implementations 3 | --FILE-- 4 | setValue(-2147483648); 11 | 12 | $obj = ProtocolBuffers::decode("Tutorial_SInt32", $bytes); 13 | if ($obj instanceof Tutorial_SInt32) { 14 | if ($obj->getValue() == -2147483648) { 15 | echo "OK" . PHP_EOL; 16 | } else { 17 | var_dump($obj); 18 | } 19 | } else { 20 | var_dump($obj); 21 | } 22 | 23 | ini_set("protocolbuffers.native_scalars", 1); 24 | $obj = ProtocolBuffers::decode("Tutorial_SInt32", $bytes); 25 | if ($obj instanceof Tutorial_SInt32) { 26 | if ($obj->getValue() === -2147483648) { 27 | echo "OK" . PHP_EOL; 28 | } else { 29 | var_dump($obj); 30 | } 31 | } else { 32 | var_dump($obj); 33 | } 34 | 35 | --EXPECT-- 36 | OK 37 | OK -------------------------------------------------------------------------------- /tests/004_decode_string_0bytes.phpt: -------------------------------------------------------------------------------- 1 | --TEST-- 2 | Check for protocol buffers string implementations 3 | --FILE-- 4 | setValue(""); 11 | 12 | $obj = ProtocolBuffers::decode("Tutorial_String", $bytes); 13 | 14 | if ($obj instanceof Tutorial_String) { 15 | if ($obj->getValue() === "") { 16 | echo "OK" . PHP_EOL; 17 | } else { 18 | var_dump($obj); 19 | } 20 | } else { 21 | var_dump($obj); 22 | } 23 | 24 | ini_set("protocolbuffers.native_scalars", 1); 25 | $obj = ProtocolBuffers::decode("Tutorial_String", $bytes); 26 | if ($obj instanceof Tutorial_String) { 27 | if ($obj->getValue() === "") { 28 | echo "OK" . PHP_EOL; 29 | } else { 30 | var_dump($obj); 31 | } 32 | } else { 33 | var_dump($obj); 34 | } 35 | 36 | --EXPECT-- 37 | OK 38 | OK -------------------------------------------------------------------------------- /tests/005_decode_bool_packed.phpt: -------------------------------------------------------------------------------- 1 | --TEST-- 2 | Check for protocol buffers bool packed implementations 3 | --FILE-- 4 | addValue(1); 11 | $u->addValue(0); 12 | 13 | $obj = ProtocolBuffers::decode("Tutorial_Boolean", $bytes); 14 | 15 | if ($obj instanceof Tutorial_Boolean) { 16 | if (count($obj->getValue()) != 2) { 17 | var_dump($obj); 18 | exit; 19 | } 20 | $values = $obj->getValue(); 21 | if ($values[0] === true && $values[1] === false) { 22 | echo "OK" . PHP_EOL; 23 | } else { 24 | var_dump($obj); 25 | } 26 | } else { 27 | var_dump($obj); 28 | } 29 | 30 | ini_set("protocolbuffers.native_scalars", 1); 31 | $obj = ProtocolBuffers::decode("Tutorial_Boolean", $bytes); 32 | if ($obj instanceof Tutorial_Boolean) { 33 | if (count($obj->getValue()) != 2) { 34 | var_dump($obj); 35 | exit; 36 | } 37 | $values = $obj->getValue(); 38 | if ($values[0] === true && $values[1] === false) { 39 | echo "OK" . PHP_EOL; 40 | } else { 41 | var_dump($obj); 42 | } 43 | } else { 44 | var_dump($obj); 45 | } 46 | 47 | --EXPECT-- 48 | OK 49 | OK -------------------------------------------------------------------------------- /tests/005_decode_double_packed.phpt: -------------------------------------------------------------------------------- 1 | --TEST-- 2 | Check for protocol buffers double packed implementations 3 | --FILE-- 4 | addValue(0); 11 | $u->addValue(1.05); 12 | $u->addValue(3.1418); 13 | 14 | $obj = ProtocolBuffers::decode("Tutorial_Double", $bytes); 15 | 16 | if ($obj instanceof Tutorial_Double) { 17 | if (count($obj->getValue()) != 3) { 18 | var_dump($obj); 19 | exit; 20 | } 21 | $values = $obj->getValue(); 22 | if ($values[0] == 0 && $values[1] == 1.05 && $values[2] == 3.1418) { 23 | echo "OK" . PHP_EOL; 24 | } else { 25 | var_dump($obj); 26 | } 27 | } else { 28 | var_dump($obj); 29 | } 30 | 31 | ini_set("protocolbuffers.native_scalars", 1); 32 | $obj = ProtocolBuffers::decode("Tutorial_Double", $bytes); 33 | if ($obj instanceof Tutorial_Double) { 34 | if (count($obj->getValue()) != 3) { 35 | var_dump($obj); 36 | exit; 37 | } 38 | $values = $obj->getValue(); 39 | if ($values[0] === 0.0 && $values[1] === 1.05 && $values[2] === 3.1418) { 40 | echo "OK" . PHP_EOL; 41 | } else { 42 | var_dump($obj); 43 | } 44 | } else { 45 | var_dump($obj); 46 | } 47 | 48 | --EXPECT-- 49 | OK 50 | OK -------------------------------------------------------------------------------- /tests/005_decode_fixed32_packed.phpt: -------------------------------------------------------------------------------- 1 | --TEST-- 2 | Check for protocol buffers fixed32 packed implementations 3 | --FILE-- 4 | addValue(0); 11 | $u->addValue(128); 12 | $u->addValue(256); 13 | $u->addValue(512); 14 | $u->addValue(1024); 15 | 16 | $obj = ProtocolBuffers::decode("Tutorial_Fixed32", $bytes); 17 | 18 | if ($obj instanceof Tutorial_Fixed32) { 19 | if (count($obj->getValue()) != 5) { 20 | var_dump($obj); 21 | exit; 22 | } 23 | $values = $obj->getValue(); 24 | if ($values[0] == 0 && $values[1] == 128 && $values[2] == 256 && $values[3] == 512 && $values[4] == 1024) { 25 | echo "OK" . PHP_EOL; 26 | } else { 27 | var_dump($obj); 28 | } 29 | } else { 30 | var_dump($obj); 31 | } 32 | 33 | ini_set("protocolbuffers.native_scalars", 1); 34 | $obj = ProtocolBuffers::decode("Tutorial_Fixed32", $bytes); 35 | if ($obj instanceof Tutorial_Fixed32) { 36 | if (count($obj->getValue()) != 5) { 37 | var_dump($obj); 38 | exit; 39 | } 40 | $values = $obj->getValue(); 41 | if ($values[0] === 0 && $values[1] === 128 && $values[2] === 256 && $values[3] === 512 && $values[4] === 1024) { 42 | echo "OK" . PHP_EOL; 43 | } else { 44 | var_dump($obj); 45 | } 46 | } else { 47 | var_dump($obj); 48 | } 49 | 50 | --EXPECT-- 51 | OK 52 | OK -------------------------------------------------------------------------------- /tests/005_decode_fixed64_packed.phpt: -------------------------------------------------------------------------------- 1 | --TEST-- 2 | Check for protocol buffers fixed64 packed implementations 3 | --SKIPIF-- 4 | 5 | --FILE-- 6 | addValue(0); 13 | $u->addValue(1024); 14 | 15 | $obj = ProtocolBuffers::decode("Tutorial_Fixed64", $bytes); 16 | 17 | if ($obj instanceof Tutorial_Fixed64) { 18 | if (count($obj->getValue()) != 2) { 19 | var_dump($obj); 20 | exit; 21 | } 22 | $values = $obj->getValue(); 23 | if ($values[0] == 0 && $values[1] == 1024) { 24 | echo "OK" . PHP_EOL; 25 | } else { 26 | var_dump($obj); 27 | } 28 | } else { 29 | var_dump($obj); 30 | } 31 | 32 | ini_set("protocolbuffers.native_scalars", 1); 33 | $obj = ProtocolBuffers::decode("Tutorial_Fixed64", $bytes); 34 | if ($obj instanceof Tutorial_Fixed64) { 35 | if (count($obj->getValue()) != 2) { 36 | var_dump($obj); 37 | exit; 38 | } 39 | $values = $obj->getValue(); 40 | if ($values[0] === 0 && $values[1] === 1024) { 41 | echo "OK" . PHP_EOL; 42 | } else { 43 | var_dump($obj); 44 | } 45 | } else { 46 | var_dump($obj); 47 | } 48 | 49 | --EXPECT-- 50 | OK 51 | OK -------------------------------------------------------------------------------- /tests/005_decode_float_packed.phpt: -------------------------------------------------------------------------------- 1 | --TEST-- 2 | Check for protocol buffers double packed implementations 3 | --FILE-- 4 | addValue(0); 11 | $u->addValue(1.05); 12 | $u->addValue(3.1418); 13 | 14 | $obj = ProtocolBuffers::decode("Tutorial_Float", $bytes); 15 | 16 | if ($obj instanceof Tutorial_Float) { 17 | if (count($obj->getValue()) != 3) { 18 | var_dump($obj); 19 | exit; 20 | } 21 | 22 | $values = $obj->getValue(); 23 | 24 | echo $values[0] . PHP_EOL; 25 | echo $values[1] . PHP_EOL; 26 | echo $values[2] . PHP_EOL; 27 | } else { 28 | var_dump($obj); 29 | } 30 | 31 | 32 | ini_set("protocolbuffers.native_scalars", 1); 33 | $obj = ProtocolBuffers::decode("Tutorial_Float", $bytes); 34 | if ($obj instanceof Tutorial_Float) { 35 | if (count($obj->getValue()) != 3) { 36 | var_dump($obj); 37 | exit; 38 | } 39 | 40 | $values = $obj->getValue(); 41 | if ($values[0] === 0.0) { 42 | echo "OK" . PHP_EOL; 43 | } 44 | } else { 45 | var_dump($obj); 46 | } 47 | 48 | 49 | --EXPECT-- 50 | 0 51 | 1.0499999523163 52 | 3.1417999267578 53 | OK -------------------------------------------------------------------------------- /tests/005_decode_int32_packed.phpt: -------------------------------------------------------------------------------- 1 | --TEST-- 2 | Check for protocol buffers int32 packed implementations 3 | --FILE-- 4 | getValue()) != 1) { 14 | var_dump($obj); 15 | exit; 16 | } 17 | $values = $obj->getValue(); 18 | if ($values[0] == 1) { 19 | echo "OK" . PHP_EOL; 20 | } else { 21 | var_dump($obj); 22 | } 23 | } else { 24 | var_dump($obj); 25 | } 26 | 27 | ini_set("protocolbuffers.native_scalars", 1); 28 | $obj = ProtocolBuffers::decode("Tutorial_Integer32", $bytes); 29 | if ($obj instanceof Tutorial_Integer32) { 30 | if (count($obj->getValue()) != 1) { 31 | var_dump($obj); 32 | exit; 33 | } 34 | $values = $obj->getValue(); 35 | if ($values[0] === 1) { 36 | echo "OK" . PHP_EOL; 37 | } else { 38 | var_dump($obj); 39 | } 40 | } else { 41 | var_dump($obj); 42 | } 43 | 44 | --EXPECT-- 45 | OK 46 | OK -------------------------------------------------------------------------------- /tests/005_decode_int32_packed_many.phpt: -------------------------------------------------------------------------------- 1 | --TEST-- 2 | Check for protocol buffers int32 packed implementations 3 | --FILE-- 4 | getValue()) != 3) { 13 | var_dump($obj); 14 | exit; 15 | } 16 | 17 | $values = $obj->getValue(); 18 | 19 | echo $values[0] . PHP_EOL; 20 | echo $values[1] . PHP_EOL; 21 | echo $values[2] . PHP_EOL; 22 | } else { 23 | var_dump($obj); 24 | } 25 | 26 | ini_set("protocolbuffers.native_scalars", 1); 27 | $obj = ProtocolBuffers::decode("Tutorial_Integer32", $bytes); 28 | if ($obj instanceof Tutorial_Integer32) { 29 | if (count($obj->getValue()) != 3) { 30 | var_dump($obj); 31 | exit; 32 | } 33 | 34 | $values = $obj->getValue(); 35 | 36 | if ($values[0] === 1) { 37 | echo "OK" . PHP_EOL; 38 | } 39 | if ($values[1] === 2) { 40 | echo "OK" . PHP_EOL; 41 | } 42 | if ($values[2] === 1024) { 43 | echo "OK" . PHP_EOL; 44 | } 45 | } else { 46 | var_dump($obj); 47 | } 48 | 49 | --EXPECT-- 50 | 1 51 | 2 52 | 1024 53 | OK 54 | OK 55 | OK -------------------------------------------------------------------------------- /tests/005_decode_int64_packed.phpt: -------------------------------------------------------------------------------- 1 | --TEST-- 2 | Check for protocol buffers int64 packed implementations 3 | --SKIPIF-- 4 | 5 | --FILE-- 6 | addValue(0); 13 | $u->addValue(1024); 14 | 15 | $obj = ProtocolBuffers::decode("Tutorial_Integer64", $bytes); 16 | 17 | if ($obj instanceof Tutorial_Integer64) { 18 | if (count($obj->getValue()) != 2) { 19 | var_dump($obj); 20 | exit; 21 | } 22 | $values = $obj->getValue(); 23 | if ($values[0] == 0 && $values[1] == 1024) { 24 | echo "OK" . PHP_EOL; 25 | } else { 26 | var_dump($obj); 27 | } 28 | } else { 29 | var_dump($obj); 30 | } 31 | 32 | ini_set("protocolbuffers.native_scalars", 1); 33 | $obj = ProtocolBuffers::decode("Tutorial_Integer64", $bytes); 34 | if ($obj instanceof Tutorial_Integer64) { 35 | if (count($obj->getValue()) != 2) { 36 | var_dump($obj); 37 | exit; 38 | } 39 | $values = $obj->getValue(); 40 | if ($values[0] === 0 && $values[1] === 1024) { 41 | echo "OK" . PHP_EOL; 42 | } else { 43 | var_dump($obj); 44 | } 45 | } else { 46 | var_dump($obj); 47 | } 48 | 49 | 50 | --EXPECT-- 51 | OK 52 | OK -------------------------------------------------------------------------------- /tests/005_decode_sfixed32_packed.phpt: -------------------------------------------------------------------------------- 1 | --TEST-- 2 | Check for protocol buffers sfixed32 packed implementations 3 | --FILE-- 4 | addValue(-1024); 11 | $u->addValue(0); 12 | $u->addValue(1024); 13 | 14 | $obj = ProtocolBuffers::decode("Tutorial_SFixed32", $bytes); 15 | 16 | if ($obj instanceof Tutorial_SFixed32) { 17 | if (count($obj->getValue()) != 3) { 18 | var_dump($obj); 19 | exit; 20 | } 21 | $values = $obj->getValue(); 22 | if ($values[0] == -1024 && $values[1] == 0 && $values[2] == 1024) { 23 | echo "OK" . PHP_EOL; 24 | } else { 25 | var_dump($obj); 26 | } 27 | } else { 28 | var_dump($obj); 29 | } 30 | 31 | ini_set("protocolbuffers.native_scalars", 1); 32 | $obj = ProtocolBuffers::decode("Tutorial_SFixed32", $bytes); 33 | if ($obj instanceof Tutorial_SFixed32) { 34 | if (count($obj->getValue()) != 3) { 35 | var_dump($obj); 36 | exit; 37 | } 38 | $values = $obj->getValue(); 39 | if ($values[0] === -1024 && $values[1] === 0 && $values[2] === 1024) { 40 | echo "OK" . PHP_EOL; 41 | } else { 42 | var_dump($obj); 43 | } 44 | } else { 45 | var_dump($obj); 46 | } 47 | 48 | --EXPECT-- 49 | OK 50 | OK -------------------------------------------------------------------------------- /tests/005_decode_sfixed64_packed.phpt: -------------------------------------------------------------------------------- 1 | --TEST-- 2 | Check for protocol buffers sfixed64 packed implementations 3 | --SKIPIF-- 4 | 5 | --FILE-- 6 | addValue(-1024); 13 | $u->addValue(0); 14 | $u->addValue(1024); 15 | 16 | $obj = ProtocolBuffers::decode("Tutorial_SFixed64", $bytes); 17 | 18 | if ($obj instanceof Tutorial_SFixed64) { 19 | if (count($obj->getValue()) != 3) { 20 | var_dump($obj); 21 | exit; 22 | } 23 | $values = $obj->getValue(); 24 | 25 | if ($values[0] == -1024 && $values[1] == 0 && $values[2] == 1024) { 26 | echo "OK" . PHP_EOL; 27 | } else { 28 | var_dump($obj); 29 | } 30 | } else { 31 | var_dump($obj); 32 | } 33 | 34 | ini_set("protocolbuffers.native_scalars", 1); 35 | $obj = ProtocolBuffers::decode("Tutorial_SFixed64", $bytes); 36 | if ($obj instanceof Tutorial_SFixed64) { 37 | if (count($obj->getValue()) != 3) { 38 | var_dump($obj); 39 | exit; 40 | } 41 | $values = $obj->getValue(); 42 | 43 | if ($values[0] === -1024 && $values[1] === 0 && $values[2] === 1024) { 44 | echo "OK" . PHP_EOL; 45 | } else { 46 | var_dump($obj); 47 | } 48 | } else { 49 | var_dump($obj); 50 | } 51 | 52 | --EXPECT-- 53 | OK 54 | OK -------------------------------------------------------------------------------- /tests/005_decode_sint32_packed.phpt: -------------------------------------------------------------------------------- 1 | --TEST-- 2 | Check for protocol buffers sint32 packed implementations 3 | --FILE-- 4 | addValue(-1024); 11 | $u->addValue(0); 12 | $u->addValue(1024); 13 | 14 | $obj = ProtocolBuffers::decode("Tutorial_SignedInteger32", $bytes); 15 | 16 | if ($obj instanceof Tutorial_SignedInteger32) { 17 | if (count($obj->getValue()) != 3) { 18 | var_dump($obj); 19 | exit; 20 | } 21 | $values = $obj->getValue(); 22 | if ($values[0] == -1024 && $values[1] == 0 && $values[2] == 1024) { 23 | echo "OK" . PHP_EOL; 24 | } else { 25 | var_dump($obj); 26 | } 27 | } else { 28 | var_dump($obj); 29 | } 30 | 31 | ini_set("protocolbuffers.native_scalars", 1); 32 | $obj = ProtocolBuffers::decode("Tutorial_SignedInteger32", $bytes); 33 | if ($obj instanceof Tutorial_SignedInteger32) { 34 | if (count($obj->getValue()) != 3) { 35 | var_dump($obj); 36 | exit; 37 | } 38 | $values = $obj->getValue(); 39 | if ($values[0] === -1024 && $values[1] === 0 && $values[2] === 1024) { 40 | echo "OK" . PHP_EOL; 41 | } else { 42 | var_dump($obj); 43 | } 44 | } else { 45 | var_dump($obj); 46 | } 47 | 48 | --EXPECT-- 49 | OK 50 | OK -------------------------------------------------------------------------------- /tests/005_decode_sint64_packed.phpt: -------------------------------------------------------------------------------- 1 | --TEST-- 2 | Check for protocol buffers sint64 packed implementations 3 | --SKIPIF-- 4 | 5 | --FILE-- 6 | getValue()) != 3) { 15 | var_dump($obj); 16 | exit; 17 | } 18 | $values = $obj->getValue(); 19 | if ($values[0] == -1024 && $values[1] == 0 && $values[2] == 1024) { 20 | echo "OK" . PHP_EOL; 21 | } else { 22 | var_dump($obj); 23 | } 24 | } else { 25 | var_dump($obj); 26 | } 27 | 28 | ini_set("protocolbuffers.native_scalars", 1); 29 | $obj = ProtocolBuffers::decode("Tutorial_SInt64", $bytes); 30 | if ($obj instanceof Tutorial_SInt64) { 31 | if (count($obj->getValue()) != 3) { 32 | var_dump($obj); 33 | exit; 34 | } 35 | $values = $obj->getValue(); 36 | if ($values[0] === -1024 && $values[1] === 0 && $values[2] === 1024) { 37 | echo "OK" . PHP_EOL; 38 | } else { 39 | var_dump($obj); 40 | } 41 | } else { 42 | var_dump($obj); 43 | } 44 | 45 | 46 | --EXPECT-- 47 | OK 48 | OK -------------------------------------------------------------------------------- /tests/100_field_descriptor.phpt: -------------------------------------------------------------------------------- 1 | --TEST-- 2 | Check for protocol buffers field descriptor implementations 3 | --FILE-- 4 | 1)); 7 | echo $field->getType() . PHP_EOL; 8 | 9 | 10 | $field = new ProtocolBuffersFieldDescriptor(array( 11 | "type" => 1, 12 | )); 13 | echo $field->getType() . PHP_EOL; 14 | 15 | --EXPECT-- 16 | 1 17 | 1 18 | -------------------------------------------------------------------------------- /tests/101_descirptor_builder.phpt: -------------------------------------------------------------------------------- 1 | --TEST-- 2 | Check for protocol buffers descriptor builder implementations 3 | --FILE-- 4 | setName("Person"); 8 | 9 | echo $builder->getName("Person") . PHP_EOL; 10 | echo $builder->getName("Person") . PHP_EOL; 11 | echo strlen($builder->getName("Person")) . PHP_EOL; 12 | 13 | $descriptor = $builder->build(); 14 | 15 | if ($descriptor instanceof ProtocolBuffersDescriptor) { 16 | echo $descriptor->getName("Person") . PHP_EOL; 17 | echo $descriptor->getName("Person") . PHP_EOL; 18 | echo strlen($descriptor->getName("Person")) . PHP_EOL; 19 | 20 | } else { 21 | echo "FAULT: INSTANCE IS NOT ProtocolBuffersDescriptor" . PHP_EOL; 22 | } 23 | 24 | --EXPECT-- 25 | Person 26 | Person 27 | 6 28 | Person 29 | Person 30 | 6 -------------------------------------------------------------------------------- /tests/102_descriptor_builder_with_noargs.phpt: -------------------------------------------------------------------------------- 1 | --TEST-- 2 | Check for protocol buffers descriptor builder implementations (accepts empty fields) 3 | --FILE-- 4 | build(); 8 | 9 | if ($descriptor instanceof ProtocolBuffersDescriptor) { 10 | echo "OK"; 11 | } else { 12 | echo "FAULT: INSTANCE IS NOT ProtocolBuffersDescriptor" . PHP_EOL; 13 | } 14 | 15 | --EXPECT-- 16 | OK 17 | -------------------------------------------------------------------------------- /tests/103_descriptor_force_add.phpt: -------------------------------------------------------------------------------- 1 | --TEST-- 2 | Check for protocol buffers descriptor builder should be throw an exception when passed added tag 3 | --FILE-- 4 | addField(1, new ProtocolBuffersFieldDescriptor(array( 8 | "type" => ProtocolBuffers::TYPE_STRING, 9 | "name" => "name", 10 | "required" => false, 11 | "optional" => false, 12 | "repeated" => true, 13 | "packable" => false, 14 | "default" => "", 15 | ))); 16 | try{ 17 | $builder->addField(1, new ProtocolBuffersFieldDescriptor(array( 18 | "type" => ProtocolBuffers::TYPE_STRING, 19 | "name" => "name", 20 | "required" => false, 21 | "optional" => false, 22 | "repeated" => true, 23 | "packable" => false, 24 | "default" => "", 25 | )), true); 26 | echo "OK" . PHP_EOL; 27 | } catch (Exception $e) { 28 | echo "FAULT" . PHP_EOL; 29 | } 30 | --EXPECT-- 31 | OK 32 | -------------------------------------------------------------------------------- /tests/103_descriptor_throws_an_exception.phpt: -------------------------------------------------------------------------------- 1 | --TEST-- 2 | Check for protocol buffers descriptor builder should be throw an exception when passed added tag 3 | --FILE-- 4 | addField(1, new ProtocolBuffersFieldDescriptor(array( 8 | "type" => ProtocolBuffers::TYPE_STRING, 9 | "name" => "name", 10 | "required" => false, 11 | "optional" => false, 12 | "repeated" => true, 13 | "packable" => false, 14 | "default" => "", 15 | ))); 16 | try{ 17 | $builder->addField(1, new ProtocolBuffersFieldDescriptor(array( 18 | "type" => ProtocolBuffers::TYPE_STRING, 19 | "name" => "name", 20 | "required" => false, 21 | "optional" => false, 22 | "repeated" => true, 23 | "packable" => false, 24 | "default" => "", 25 | ))); 26 | } catch (Exception $e) { 27 | echo "OK"; 28 | } 29 | --EXPECT-- 30 | OK 31 | -------------------------------------------------------------------------------- /tests/104_descriptor_builder_add_extension_range.phpt: -------------------------------------------------------------------------------- 1 | --TEST-- 2 | Check for protocol buffers descriptor builder addExtensionRange implementation 3 | --FILE-- 4 | addField(16, new ProtocolBuffersFieldDescriptor(array( 8 | "type" => ProtocolBuffers::TYPE_STRING, 9 | "name" => "name", 10 | "required" => false, 11 | "optional" => false, 12 | "repeated" => true, 13 | "packable" => false, 14 | "default" => "", 15 | ))); 16 | 17 | try { 18 | $builder->addExtensionRange(-1, 100); 19 | } catch (InvalidArgumentException $e) { 20 | echo "OK" . PHP_EOL; 21 | } 22 | 23 | try { 24 | $builder->addExtensionRange(100, 1); 25 | } catch (InvalidArgumentException $e) { 26 | echo "OK" . PHP_EOL; 27 | } 28 | 29 | try { 30 | $builder->addExtensionRange(10, 20); 31 | echo "FAULT" . PHP_EOL; 32 | } catch (InvalidArgumentException $e) { 33 | echo "OK" . PHP_EOL; 34 | } 35 | 36 | try { 37 | $builder->addExtensionRange(10, 15); 38 | echo "OK" . PHP_EOL; 39 | } catch (InvalidArgumentException $e) { 40 | echo "FAULT" . PHP_EOL; 41 | } 42 | 43 | --EXPECT-- 44 | OK 45 | OK 46 | OK 47 | OK -------------------------------------------------------------------------------- /tests/105_enum_descriptor_builder.phpt: -------------------------------------------------------------------------------- 1 | --TEST-- 2 | Check for protocol buffers enum descriptor builder implementations 3 | --FILE-- 4 | addValue(new ProtocolBuffersEnumValueDescriptor(array( 8 | "name" => "PREFECTURE", 9 | "value" => 1, 10 | ))); 11 | 12 | 13 | $descriptor = $builder->build(); 14 | 15 | if ($descriptor instanceof ProtocolBuffersEnumDescriptor) { 16 | echo "OK" . PHP_EOL; 17 | } else { 18 | echo "FAULT: INSTANCE IS NOT ProtocolBuffersEnumDescriptor" . PHP_EOL; 19 | } 20 | 21 | --EXPECT-- 22 | OK -------------------------------------------------------------------------------- /tests/200_unknown_fields.phpt: -------------------------------------------------------------------------------- 1 | --TEST-- 2 | Check for protocol buffers unknown fields implementations 3 | --FILE-- 4 | _unknown; 16 | } 17 | 18 | /** 19 | * get descriptor for protocol buffers 20 | * 21 | * @return array 22 | */ 23 | public static function getDescriptor() 24 | { 25 | if (!isset(self::$descriptor)) { 26 | $desc = new ProtocolBuffersDescriptorBuilder(); 27 | $phpoptions = $desc->getOptions()->getExtension(ProtocolBuffers::PHP_MESSAGE_OPTION); 28 | $phpoptions->setProcessUnknownFields(true); 29 | self::$descriptor = $desc->build(); 30 | } 31 | 32 | return self::$descriptor; 33 | } 34 | } 35 | 36 | $bytes = file_get_contents(dirname(__FILE__) . DIRECTORY_SEPARATOR . "fixtures" . DIRECTORY_SEPARATOR . "003_has_message.bin"); 37 | 38 | $data = ProtocolBuffers::decode("UnknownFields", $bytes); 39 | $unk = $data->getUnknownFieldSet(); 40 | if ($unk instanceof ProtocolBuffersUnknownFieldSet) { 41 | $u = $unk->getField(1); 42 | foreach($u->getAsLengthDelimitedList() as $d) {echo $d . PHP_EOL;}; 43 | $u = $unk->getField(2); 44 | foreach($u->getAsVarintList() as $d) {echo $d . PHP_EOL;}; 45 | } else { 46 | var_dump($u); 47 | } 48 | --EXPECT-- 49 | chobie 50 | 20 -------------------------------------------------------------------------------- /tests/200_unknown_fields_discard.phpt: -------------------------------------------------------------------------------- 1 | --TEST-- 2 | Check for protocol buffers unknown fields implementations 3 | --FILE-- 4 | getOptions()->getExtension(ProtocolBuffers::PHP_MESSAGE_OPTION); 23 | $phpoptions->setProcessUnknownFields(true); 24 | self::$descriptor = $desc->build(); 25 | } 26 | 27 | return self::$descriptor; 28 | } 29 | } 30 | 31 | $bytes = file_get_contents(dirname(__FILE__) . DIRECTORY_SEPARATOR . "fixtures" . DIRECTORY_SEPARATOR . "003_has_message.bin"); 32 | 33 | $data = ProtocolBuffers::decode("UnknownFields", $bytes); 34 | $unk = $data->getUnknownFieldSet(); 35 | if ($unk instanceof ProtocolBuffersUnknownFieldSet) { 36 | $u = $unk->getField(1); 37 | foreach($u->getAsLengthDelimitedList() as $d) {echo $d . PHP_EOL;}; 38 | $u = $unk->getField(2); 39 | foreach($u->getAsVarintList() as $d) {echo $d . PHP_EOL;}; 40 | } else { 41 | var_dump($u); 42 | } 43 | $data->discardUnknownFields(); 44 | $unk = $data->getUnknownFieldSet(); 45 | echo $unk->count(); 46 | --EXPECT-- 47 | chobie 48 | 20 49 | 0 -------------------------------------------------------------------------------- /tests/300_use_single_property.phpt: -------------------------------------------------------------------------------- 1 | --TEST-- 2 | Check for protocol buffers use single property implementations 3 | --FILE-- 4 | _values["name"] = $name; 12 | } 13 | 14 | public function getName() 15 | { 16 | return $this->_values["name"]; 17 | } 18 | 19 | /** 20 | * get descriptor for protocol buffers 21 | * 22 | * @return array 23 | */ 24 | public static function getDescriptor() 25 | { 26 | static $descriptor; 27 | if (!isset($descriptor)) { 28 | $desc = new ProtocolBuffersDescriptorBuilder(); 29 | $desc->addField(1, new ProtocolBuffersFieldDescriptor(array( 30 | "type" => ProtocolBuffers::TYPE_STRING, 31 | "name" => "name", 32 | "required" => true, 33 | "optional" => false, 34 | "repeated" => false, 35 | "packable" => false, 36 | "default" => "", 37 | ))); 38 | 39 | $phpoptions = $desc->getOptions()->getExtension(ProtocolBuffers::PHP_MESSAGE_OPTION); 40 | $phpoptions->setUseSingleProperty(true); 41 | $phpoptions->setSinglePropertyName("_values"); 42 | $descriptor = $desc->build(); 43 | } 44 | 45 | return $descriptor; 46 | } 47 | } 48 | 49 | $p = new SingleProperty(); 50 | $p->setName("chobie"); 51 | 52 | $data = ProtocolBuffers::encode($p); 53 | $p2 = ProtocolBuffers::decode("SingleProperty", $data); 54 | 55 | echo $p2->getName(); 56 | 57 | --EXPECT-- 58 | chobie 59 | -------------------------------------------------------------------------------- /tests/400_message_clear.phpt: -------------------------------------------------------------------------------- 1 | --TEST-- 2 | Check for protocol buffers clear method implementation 3 | --FILE-- 4 | addField(1, new ProtocolBuffersFieldDescriptor(array( 20 | "type" => ProtocolBuffers::TYPE_STRING, 21 | "name" => "name", 22 | "required" => true, 23 | "optional" => false, 24 | "repeated" => false, 25 | "packable" => false, 26 | "default" => "", 27 | ))); 28 | $descriptor = $desc->build(); 29 | } 30 | 31 | return $descriptor; 32 | } 33 | } 34 | 35 | $p = new ClearTest(); 36 | $p->setName("chobie"); 37 | $p->clear("name"); 38 | if (!$p->hasName()) { 39 | echo "OK" . PHP_EOL; 40 | } 41 | 42 | --EXPECT-- 43 | OK -------------------------------------------------------------------------------- /tests/400_message_clear_all.phpt: -------------------------------------------------------------------------------- 1 | --TEST-- 2 | Check for protocol buffers clear method implementation 3 | --FILE-- 4 | addField(1, new ProtocolBuffersFieldDescriptor(array( 20 | "type" => ProtocolBuffers::TYPE_STRING, 21 | "name" => "name", 22 | "required" => true, 23 | "optional" => false, 24 | "repeated" => false, 25 | "packable" => false, 26 | "default" => "", 27 | ))); 28 | $descriptor = $desc->build(); 29 | } 30 | 31 | return $descriptor; 32 | } 33 | } 34 | 35 | $p = new ClearTest(); 36 | $p->setName("chobie"); 37 | $p->clearAll(); 38 | 39 | if (!$p->hasName()) { 40 | echo "OK" . PHP_EOL; 41 | } 42 | 43 | --EXPECT-- 44 | OK -------------------------------------------------------------------------------- /tests/400_message_magicmethods.phpt: -------------------------------------------------------------------------------- 1 | --TEST-- 2 | Check for protocol buffers unknown fields implementations 3 | --FILE-- 4 | addField(1, new ProtocolBuffersFieldDescriptor(array( 20 | "type" => ProtocolBuffers::TYPE_STRING, 21 | "name" => "name", 22 | "required" => true, 23 | "optional" => false, 24 | "repeated" => false, 25 | "packable" => false, 26 | "default" => "", 27 | ))); 28 | $descriptor = $desc->build(); 29 | } 30 | 31 | return $descriptor; 32 | } 33 | } 34 | 35 | $p = new SingleProperty(); 36 | $p->setName("chobie"); 37 | 38 | if ($p->hasName()) { 39 | echo "OK" . PHP_EOL; 40 | } 41 | echo $p->getName() . PHP_EOL; 42 | $p->clearName(); 43 | if (!$p->hasName()) { 44 | echo "OK" . PHP_EOL; 45 | } 46 | echo $p->getName(); // Nothing to display 47 | 48 | --EXPECT-- 49 | OK 50 | chobie 51 | OK -------------------------------------------------------------------------------- /tests/500_unknown_iterator.phpt: -------------------------------------------------------------------------------- 1 | --TEST-- 2 | Check for protocol buffers unknown field iterator implementation 3 | --FILE-- 4 | getOptions()->getExtension("php"); 25 | $php->setProcessUnknownFields(true); 26 | 27 | self::$descriptor = $desc->build(); 28 | } 29 | 30 | return self::$descriptor; 31 | } 32 | } 33 | 34 | $u = new Tutorial_RepeatedString(); 35 | $u->addValues("a"); 36 | $u->addValues("a"); 37 | $u->addValues("a"); 38 | $u->addValues("a"); 39 | $expect = ProtocolBuffers::encode($u); 40 | 41 | $d = ProtocolBuffers::decode("UnknownFields", $expect); 42 | foreach($d->getUnknownFieldSet() as $field) { 43 | if ($field->isLengthDelimited()) { 44 | foreach ($field->getAsLengthDelimitedList() as $l) { 45 | echo $l . PHP_EOL; 46 | } 47 | } 48 | } 49 | 50 | --EXPECT-- 51 | a 52 | a 53 | a 54 | a 55 | -------------------------------------------------------------------------------- /tests/500_unknown_repeated_string.phpt: -------------------------------------------------------------------------------- 1 | --TEST-- 2 | Check for protocol buffers unknown field repeated string implementations 3 | --FILE-- 4 | getOptions()->getExtension("php"); 25 | $php->setProcessUnknownFields(true); 26 | 27 | self::$descriptor = $desc->build(); 28 | } 29 | 30 | return self::$descriptor; 31 | } 32 | } 33 | 34 | $u = new Tutorial_RepeatedString(); 35 | $u->addValues("a"); 36 | $u->addValues("a"); 37 | $u->addValues("a"); 38 | $u->addValues("a"); 39 | $expect = ProtocolBuffers::encode($u); 40 | 41 | $d = ProtocolBuffers::decode("UnknownFields", $expect); 42 | $field_set = $d->getUnknownFieldSet(); 43 | $field = $field_set->getField(1); 44 | 45 | foreach ($field->getAsLengthDelimitedList() as $l) { 46 | echo $l . PHP_EOL; 47 | } 48 | 49 | 50 | --EXPECT-- 51 | a 52 | a 53 | a 54 | a 55 | -------------------------------------------------------------------------------- /tests/600_extension.phpt: -------------------------------------------------------------------------------- 1 | --TEST-- 2 | ProtocolBuffersMessage extension implementation 3 | --FILE-- 4 | addField(1, new ProtocolBuffersFieldDescriptor(array( 21 | "type" => ProtocolBuffers::TYPE_INT32, 22 | "name" => "value", 23 | "required" => false, 24 | "optional" => false, 25 | "repeated" => false, 26 | "packable" => false, 27 | "default" => null, 28 | "message" => "Tutorial_Person", 29 | ))); 30 | $desc->addExtensionRange(200, 500); 31 | $descriptor = $desc->build(); 32 | } 33 | 34 | return $descriptor; 35 | } 36 | } 37 | $registry = ProtocolBuffersExtensionRegistry::getInstance(); 38 | 39 | $registry->add("Person", 256, new ProtocolBuffersFieldDescriptor(array( 40 | "type" => ProtocolBuffers::TYPE_INT32, 41 | "name" => "address", 42 | "required" => false, 43 | "optional" => false, 44 | "repeated" => false, 45 | "packable" => false, 46 | "default" => null, 47 | ))); 48 | 49 | $p = new Person(); 50 | $p->setExtension("address", 256); 51 | 52 | $p2 = ProtocolBuffers::decode("Person", $p->serializeToString()); 53 | echo $p2->getExtension("address"); 54 | --EXPECT-- 55 | 256 -------------------------------------------------------------------------------- /tests/600_wakeup.phpt: -------------------------------------------------------------------------------- 1 | --TEST-- 2 | Check for protocol buffers wakeup implementations 3 | --FILE-- 4 | value = $value; 13 | } 14 | /** 15 | * get descriptor for protocol buffers 16 | * 17 | * @return array 18 | */ 19 | public static function getDescriptor() 20 | { 21 | static $descriptor; 22 | if (!isset($descriptor)) { 23 | $desc = new ProtocolBuffersDescriptorBuilder(); 24 | $desc->addField(1, new ProtocolBuffersFieldDescriptor(array( 25 | "type" => ProtocolBuffers::TYPE_STRING, 26 | "name" => "value", 27 | "required" => true, 28 | "optional" => false, 29 | "repeated" => false, 30 | "packable" => false, 31 | "default" => "", 32 | ))); 33 | $php = $desc->getOptions()->getExtension("php"); 34 | $php->setUseWakeupAndSleep(true); 35 | $descriptor = $desc->build(); 36 | } 37 | return $descriptor; 38 | } 39 | 40 | public function __wakeup() 41 | { 42 | echo "Good Morning" . PHP_EOL; 43 | return array(); 44 | } 45 | } 46 | 47 | $value = "Hello"; 48 | $message = new TestWakeup(); 49 | $message->setValue($value); 50 | 51 | $expected = $message->serializeToString(); 52 | $u = ProtocolBuffers::decode("TestWakeup", $expected); 53 | 54 | --EXPECT-- 55 | Good Morning -------------------------------------------------------------------------------- /tests/700_jsonserializable.phpt: -------------------------------------------------------------------------------- 1 | --TEST-- 2 | Check for JsonSerializable implementations 3 | --SKIPIF-- 4 | 5 | --FILE-- 6 | "3.0", 11 | "float_value" => "3.0", 12 | "int32_value" => "1", 13 | "int64_value" => "1", 14 | "uint32_value" => "1", 15 | "uint64_value" => "1", 16 | "sint32_value" => "1", 17 | "sint64_value" => "-1", 18 | "fixed32_value" => "1", 19 | "fixed64_value" => "1", 20 | "sfixed32_value" => "-1", 21 | "sfixed64_value" => "-1", 22 | "bool_value" => true, 23 | "string_value" => "Hello World", 24 | "bytes_value" => "Hello World", 25 | ); 26 | 27 | foreach ($params as $key => $value) { 28 | $a = new AllTypes(); 29 | $a->set($key, $value); 30 | $result = $a->jsonSerialize(); 31 | 32 | if (count($result) == 1 && $result[$key] == $value) { 33 | echo "OK" . PHP_EOL; 34 | } else { 35 | echo "FAULT: {$key}, " . $result[$key] . PHP_EOL; 36 | var_dump($result); 37 | } 38 | } 39 | 40 | $a = new AllTypes(); 41 | foreach ($params as $key => $value) { 42 | $a->set($key, $value); 43 | } 44 | if ($a->jsonSerialize() == $params) { 45 | echo "OK" . PHP_EOL; 46 | } else { 47 | echo "FAULT" . PHP_EOL; 48 | } 49 | 50 | --EXPECT-- 51 | OK 52 | OK 53 | OK 54 | OK 55 | OK 56 | OK 57 | OK 58 | OK 59 | OK 60 | OK 61 | OK 62 | OK 63 | OK 64 | OK 65 | OK 66 | OK -------------------------------------------------------------------------------- /tests/700_jsonserializable_invalid_utf8.phpt: -------------------------------------------------------------------------------- 1 | --TEST-- 2 | Check for JsonSerializable implementations 3 | --SKIPIF-- 4 | 5 | 6 | --FILE-- 7 | set("int32_value", 1); 12 | $a->set("string_value", chr(0x01)); // don't encode wrong value 13 | $encoded = json_encode($a); 14 | 15 | echo $encoded; 16 | --EXPECTF-- 17 | Warning: ProtocolBuffersMessage::jsonSerialize(): passed string is not valid utf8 string in %s on line %d 18 | {"int32_value":1} -------------------------------------------------------------------------------- /tests/700_toarray_invalid_utf8.phpt: -------------------------------------------------------------------------------- 1 | --TEST-- 2 | Check for toArray implementations 3 | --FILE-- 4 | set("int32_value", 1); 9 | $a->set("string_value", chr(0x01)); // don't encode wrong value 10 | 11 | try { 12 | $a->toArray(); 13 | } catch (ProtocolBuffersInvalidByteSequenceException $e) { 14 | echo "OK"; 15 | } 16 | --EXPECTF-- 17 | OK -------------------------------------------------------------------------------- /tests/800_helper_debug_zval.phpt: -------------------------------------------------------------------------------- 1 | --TEST-- 2 | Check for ProtocolBuffers\Helper::zigzagEncode / zigzagDecode implementeation 3 | --FILE-- 4 | addField(1, new ProtocolBuffersFieldDescriptor(array( 24 | "type" => ProtocolBuffers::TYPE_BYTES, 25 | "name" => "key", 26 | "required" => true, 27 | "optional" => false, 28 | "repeated" => false, 29 | "packable" => false, 30 | "default" => "", 31 | ))); 32 | $desc->addField(2, new ProtocolBuffersFieldDescriptor(array( 33 | "type" => ProtocolBuffers::TYPE_BYTES, 34 | "name" => "value", 35 | "required" => true, 36 | "optional" => false, 37 | "repeated" => false, 38 | "packable" => false, 39 | "default" => "", 40 | ))); 41 | $descriptor = $desc->build(); 42 | } 43 | 44 | return $descriptor; 45 | } 46 | } 47 | 48 | $bytes = new Bytes(); 49 | $bytes->setKey("hello"); 50 | $bytes->setValue("world"); 51 | 52 | $data = $bytes->serializeToString(); 53 | $bytes = ProtocolBuffers::decode("Bytes", $data); 54 | 55 | echo $bytes->getKey() . PHP_EOL; 56 | echo $bytes->getValue() . PHP_EOL; 57 | 58 | --EXPECT-- 59 | hello 60 | world -------------------------------------------------------------------------------- /tests/999_dont_accept_null_value.phpt: -------------------------------------------------------------------------------- 1 | --TEST-- 2 | Check for don't accept null value 3 | --FILE-- 4 | addField(1, new ProtocolBuffersFieldDescriptor(array( 21 | "type" => ProtocolBuffers::TYPE_STRING, 22 | "name" => "value", 23 | "required" => false, 24 | "optional" => true, 25 | "repeated" => false, 26 | "packable" => false, 27 | "default" => "", 28 | ))); 29 | $descriptor = $desc->build(); 30 | } 31 | return $descriptor; 32 | } 33 | } 34 | 35 | $message = new Test(); 36 | try { 37 | $message->setValue(null); 38 | echo "FAILED" . PHP_EOL; 39 | } catch (Exception $e) { 40 | echo "OK" . PHP_EOL; 41 | } 42 | 43 | --EXPECT-- 44 | OK 45 | -------------------------------------------------------------------------------- /tests/999_dummy_string.phpt: -------------------------------------------------------------------------------- 1 | --TEST-- 2 | Check for protocol buffers decode implementations 3 | --FILE-- 4 | addField(1, new ProtocolBuffersFieldDescriptor(array( 21 | "type" => ProtocolBuffers::TYPE_STRING, 22 | "name" => "DEPRECATEDSentence", 23 | "required" => false, 24 | "optional" => true, 25 | "repeated" => false, 26 | "packable" => false, 27 | "default" => "", 28 | ))); 29 | $descriptor = $desc->build(); 30 | } 31 | return $descriptor; 32 | } 33 | } 34 | 35 | $message = new Test(); 36 | $value = "Hello"; 37 | $message->setDEPRECATEDSentence($value); 38 | echo $message->getDEPRECATEDSentence(); 39 | 40 | --EXPECT-- 41 | Hello 42 | -------------------------------------------------------------------------------- /tests/999_magicmethod_throw_exception_when_doesnt_resolve.phpt: -------------------------------------------------------------------------------- 1 | --TEST-- 2 | Check for magic method throws exception 3 | --FILE-- 4 | addField(1, new ProtocolBuffersFieldDescriptor(array( 21 | "type" => ProtocolBuffers::TYPE_STRING, 22 | "name" => "value", 23 | "required" => false, 24 | "optional" => true, 25 | "repeated" => false, 26 | "packable" => false, 27 | "default" => "", 28 | ))); 29 | $descriptor = $desc->build(); 30 | } 31 | return $descriptor; 32 | } 33 | } 34 | 35 | $message = new Test(); 36 | try { 37 | $message->setValue2("HELO"); // check with not exist key. 38 | } catch (Exception $e) { 39 | echo "OK" . PHP_EOL; 40 | } 41 | 42 | --EXPECT-- 43 | OK 44 | -------------------------------------------------------------------------------- /tests/999_missing_message.phpt: -------------------------------------------------------------------------------- 1 | --TEST-- 2 | Check for protocol buffers decode implementations 3 | --FILE-- 4 | user; 25 | } 26 | 27 | public function addUser($user) 28 | { 29 | $this->user[] = $user; 30 | } 31 | 32 | /** 33 | * get descriptor for protocol buffers 34 | * 35 | * @return array 36 | */ 37 | public static function getDescriptor() 38 | { 39 | if (!isset(self::$descriptor)) { 40 | $desc = new ProtocolBuffersDescriptorBuilder(); 41 | $desc->addField(1, new ProtocolBuffersFieldDescriptor(array( 42 | "type" => ProtocolBuffers::TYPE_MESSAGE, 43 | "name" => "user", 44 | "required" => false, 45 | "packable" => false, 46 | "repeated" => true, 47 | "default" => null, 48 | //"message" => "Tutorial_User", 49 | ))); 50 | 51 | self::$descriptor = $desc->build(); 52 | } 53 | 54 | return self::$descriptor; 55 | } 56 | 57 | } 58 | 59 | try { 60 | // we expect an exception. as message parameter was not set. 61 | Tutorial_AddressBook::getDescriptor(); 62 | echo "FAILED"; 63 | } catch (Exception $e) { 64 | echo "OK"; 65 | } 66 | 67 | --EXPECT-- 68 | OK -------------------------------------------------------------------------------- /tests/999_no33_batch_assignment.phpt: -------------------------------------------------------------------------------- 1 | --TEST-- 2 | #33 fix batch assignment 3 | --FILE-- 4 | array( 9 | array( 10 | "id" => 1, 11 | "name" => "John", 12 | ), 13 | array( 14 | "id" => 2, 15 | "name" => "Belushi", 16 | ) 17 | ), 18 | "message" => array( 19 | "id" => 3, 20 | "name" => "Adam", 21 | ), 22 | )); 23 | 24 | foreach ($message->getMessages() as $inner) { 25 | echo $inner->getId() . PHP_EOL; 26 | echo $inner->getName() . PHP_EOL; 27 | } 28 | $adam = $message->getMessage(); 29 | echo $adam->getId() . PHP_EOL; 30 | echo $adam->getName() . PHP_EOL; 31 | 32 | --EXPECT-- 33 | 1 34 | John 35 | 2 36 | Belushi 37 | 3 38 | Adam -------------------------------------------------------------------------------- /tests/999_no_19_regression_script_contains_large_number_literals.phpt: -------------------------------------------------------------------------------- 1 | --TEST-- 2 | Script_contains_large_number_literals 3 | --FILE-- 4 | addField(1, new ProtocolBuffersFieldDescriptor(array( 15 | "type" => ProtocolBuffers::TYPE_FIXED64, 16 | "name" => "value", 17 | "packable" => false, 18 | "repeated" => false, 19 | "default" => null, 20 | ))); 21 | 22 | self::$descriptor = $desc->build(); 23 | } 24 | return self::$descriptor; 25 | } 26 | } 27 | 28 | $foo = "1"; 29 | $a = new TestCase(); 30 | $a->setValue($foo); 31 | echo $a->getValue(); 32 | ProtocolBuffers::encode($a); 33 | 34 | exit(); 35 | // Remove the following line and it works, keep it and it fails 36 | // Yes the line is after the exit() and unrelated, yet it modifies 37 | // the behavior of fixed64 support 38 | $bar = 9223372036854775808; 39 | --EXPECT-- 40 | 1 -------------------------------------------------------------------------------- /tests/999_no_8_magic_method_for_case_sensitive_field.phpt: -------------------------------------------------------------------------------- 1 | --TEST-- 2 | #8 case sensitive field 3 | --FILE-- 4 | addField(1, new ProtocolBuffersFieldDescriptor(array( 21 | "type" => ProtocolBuffers::TYPE_STRING, 22 | "name" => "regPlace", 23 | "required" => true, 24 | "optional" => false, 25 | "repeated" => false, 26 | "packable" => false, 27 | "default" => "", 28 | ))); 29 | $descriptor = $desc->build(); 30 | } 31 | 32 | return $descriptor; 33 | } 34 | } 35 | 36 | 37 | $t = new SensitiveField(); 38 | $t->setRegPlace("https://github.com/chobie/php-protocolbuffers/issues/8"); 39 | echo $t->getRegPlace(); 40 | 41 | --EXPECT-- 42 | https://github.com/chobie/php-protocolbuffers/issues/8 -------------------------------------------------------------------------------- /tests/999_no_descriptor.phpt: -------------------------------------------------------------------------------- 1 | --TEST-- 2 | Check for protocol buffers decode implementations 3 | --FILE-- 4 | _properties)) { 23 | $result = $this->_properties['value']; 24 | } 25 | 26 | return $result; 27 | } 28 | 29 | public function setValue($value) 30 | { 31 | $this->_properties['value'] = $value; 32 | } 33 | 34 | /** 35 | * get descriptor for protocol buffers 36 | * 37 | * @return array 38 | */ 39 | public static function getDescriptor() 40 | { 41 | // return nothing. 42 | } 43 | } 44 | 45 | 46 | $b = new Tutorial_Bytes(); 47 | $droid = file_get_contents(dirname(__FILE__) . DIRECTORY_SEPARATOR . "fixtures" . DIRECTORY_SEPARATOR . "android_logo.gif"); 48 | $b->setValue($droid); 49 | 50 | try { 51 | ProtocolBuffers::encode($b); 52 | } catch (ProtocolBuffersInvalidProtocolBufferException $e) { 53 | echo "OK"; 54 | } 55 | 56 | --EXPECT-- 57 | OK -------------------------------------------------------------------------------- /tests/999_null.phpt: -------------------------------------------------------------------------------- 1 | --TEST-- 2 | Check for protocol buffers decode implementations 3 | --FILE-- 4 | addField(1, new ProtocolBuffersFieldDescriptor(array( 7 | "type" => ProtocolBuffers::TYPE_STRING, 8 | "name" => "name", 9 | "required" => true, 10 | "optional" => false, 11 | "repeated" => false, 12 | "packable" => false, 13 | "default" => "", 14 | ))); 15 | 16 | $phpoptions = $desc->getOptions()->getExtension(ProtocolBuffers::PHP_MESSAGE_OPTION); 17 | $phpoptions->setUseSingleProperty(true); 18 | $phpoptions->setSinglePropertyName("_properties"); // do not segv. 19 | 20 | $descriptor = $desc->build(); 21 | echo "OK"; 22 | --EXPECT-- 23 | OK -------------------------------------------------------------------------------- /tests/999_remove_first_ns.phpt: -------------------------------------------------------------------------------- 1 | --TEST-- 2 | Check for remove first namespace separator 3 | --FILE-- 4 | getValue() == 0) { 14 | echo "OK"; 15 | } else { 16 | var_dump($obj); 17 | } 18 | } else { 19 | var_dump($obj); 20 | } 21 | --EXPECT-- 22 | OK -------------------------------------------------------------------------------- /tests/999_required_property.phpt: -------------------------------------------------------------------------------- 1 | --TEST-- 2 | Check for protocol buffers decode implementations 3 | --FILE-- 4 | addField(1, new ProtocolBuffersFieldDescriptor(array( 19 | "type" => ProtocolBuffers::TYPE_STRING, 20 | "name" => "name", 21 | "packable" => false, 22 | "repeated" => false, 23 | "required" => true, 24 | "default" => "Hello", 25 | ))); 26 | 27 | self::$descriptor = $desc->build(); 28 | } 29 | 30 | return self::$descriptor; 31 | } 32 | 33 | public function setName($name) 34 | { 35 | $this->name = $name; 36 | } 37 | } 38 | 39 | $person = new Person(); 40 | 41 | try { 42 | $data = ProtocolBuffers::encode($person); 43 | echo "FAILED"; 44 | } catch (ProtocolBuffersUninitializedMessageException $e) { 45 | echo "OK"; 46 | } 47 | 48 | 49 | 50 | --EXPECT-- 51 | OK -------------------------------------------------------------------------------- /tests/conformance/proto/message_sint32.proto: -------------------------------------------------------------------------------- 1 | package chobie.github.io; 2 | 3 | message Field { 4 | optional double v_double = 1; 5 | optional float v_float = 2; 6 | optional int64 v_int64 = 3; 7 | optional uint64 v_uint64 = 4; 8 | optional int32 v_int32 = 5; 9 | optional fixed64 v_fixed64 = 6; 10 | optional fixed32 v_fixed32 = 7; 11 | optional bool v_bool = 8; 12 | optional string v_string = 9; 13 | optional bytes v_bytes = 12; 14 | optional uint32 v_uint32 = 13; 15 | optional sfixed32 v_sfixed32 = 15; 16 | optional sfixed64 v_sfixed64 = 16; 17 | optional sint32 v_sint32 = 17; 18 | optional sint64 v_sint64 = 18; 19 | 20 | optional int64 v_int64_min = 20; 21 | optional int32 v_int32_min = 21; 22 | optional sfixed32 v_sfixed32_min = 22; 23 | optional sfixed64 v_sfixed64_min = 23; 24 | optional sint32 v_sint32_min = 24; 25 | optional sint64 v_sint64_min = 25; 26 | 27 | } 28 | -------------------------------------------------------------------------------- /tests/fixtures/001_big_tag.bin: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/chobie/php-protocolbuffers/747a2238f14de0be67d5747089b50ebcc5e1116c/tests/fixtures/001_big_tag.bin -------------------------------------------------------------------------------- /tests/fixtures/001_bool.bin: -------------------------------------------------------------------------------- 1 |  -------------------------------------------------------------------------------- /tests/fixtures/001_bytes.bin: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/chobie/php-protocolbuffers/747a2238f14de0be67d5747089b50ebcc5e1116c/tests/fixtures/001_bytes.bin -------------------------------------------------------------------------------- /tests/fixtures/001_double_sample.bin: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/chobie/php-protocolbuffers/747a2238f14de0be67d5747089b50ebcc5e1116c/tests/fixtures/001_double_sample.bin -------------------------------------------------------------------------------- /tests/fixtures/001_fixed32_init.bin: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /tests/fixtures/001_fixed32_max.bin: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/chobie/php-protocolbuffers/747a2238f14de0be67d5747089b50ebcc5e1116c/tests/fixtures/001_fixed32_max.bin -------------------------------------------------------------------------------- /tests/fixtures/001_fixed64_init.bin: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /tests/fixtures/001_fixed64_max.bin: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/chobie/php-protocolbuffers/747a2238f14de0be67d5747089b50ebcc5e1116c/tests/fixtures/001_fixed64_max.bin -------------------------------------------------------------------------------- /tests/fixtures/001_float_sample.bin: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/chobie/php-protocolbuffers/747a2238f14de0be67d5747089b50ebcc5e1116c/tests/fixtures/001_float_sample.bin -------------------------------------------------------------------------------- /tests/fixtures/001_float_signed.bin: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/chobie/php-protocolbuffers/747a2238f14de0be67d5747089b50ebcc5e1116c/tests/fixtures/001_float_signed.bin -------------------------------------------------------------------------------- /tests/fixtures/001_int32_init.bin: -------------------------------------------------------------------------------- 1 |  -------------------------------------------------------------------------------- /tests/fixtures/001_int32_max.bin: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/chobie/php-protocolbuffers/747a2238f14de0be67d5747089b50ebcc5e1116c/tests/fixtures/001_int32_max.bin -------------------------------------------------------------------------------- /tests/fixtures/001_int32_min.bin: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/chobie/php-protocolbuffers/747a2238f14de0be67d5747089b50ebcc5e1116c/tests/fixtures/001_int32_min.bin -------------------------------------------------------------------------------- /tests/fixtures/001_int64_init.bin: -------------------------------------------------------------------------------- 1 |  -------------------------------------------------------------------------------- /tests/fixtures/001_int64_max.bin: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/chobie/php-protocolbuffers/747a2238f14de0be67d5747089b50ebcc5e1116c/tests/fixtures/001_int64_max.bin -------------------------------------------------------------------------------- /tests/fixtures/001_int64_min.bin: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/chobie/php-protocolbuffers/747a2238f14de0be67d5747089b50ebcc5e1116c/tests/fixtures/001_int64_min.bin -------------------------------------------------------------------------------- /tests/fixtures/001_sfixed32_signed.bin: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/chobie/php-protocolbuffers/747a2238f14de0be67d5747089b50ebcc5e1116c/tests/fixtures/001_sfixed32_signed.bin -------------------------------------------------------------------------------- /tests/fixtures/001_sfixed32_unsigned.bin: -------------------------------------------------------------------------------- 1 |  -------------------------------------------------------------------------------- /tests/fixtures/001_sfixed64_max.bin: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/chobie/php-protocolbuffers/747a2238f14de0be67d5747089b50ebcc5e1116c/tests/fixtures/001_sfixed64_max.bin -------------------------------------------------------------------------------- /tests/fixtures/001_sfixed64_min.bin: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/chobie/php-protocolbuffers/747a2238f14de0be67d5747089b50ebcc5e1116c/tests/fixtures/001_sfixed64_min.bin -------------------------------------------------------------------------------- /tests/fixtures/001_sfixed64_zero.bin: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /tests/fixtures/001_sint32_init.bin: -------------------------------------------------------------------------------- 1 |  -------------------------------------------------------------------------------- /tests/fixtures/001_sint32_max.bin: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/chobie/php-protocolbuffers/747a2238f14de0be67d5747089b50ebcc5e1116c/tests/fixtures/001_sint32_max.bin -------------------------------------------------------------------------------- /tests/fixtures/001_sint32_min.bin: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/chobie/php-protocolbuffers/747a2238f14de0be67d5747089b50ebcc5e1116c/tests/fixtures/001_sint32_min.bin -------------------------------------------------------------------------------- /tests/fixtures/001_sint64_init.bin: -------------------------------------------------------------------------------- 1 |  -------------------------------------------------------------------------------- /tests/fixtures/001_sint64_max.bin: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/chobie/php-protocolbuffers/747a2238f14de0be67d5747089b50ebcc5e1116c/tests/fixtures/001_sint64_max.bin -------------------------------------------------------------------------------- /tests/fixtures/001_sint64_min.bin: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/chobie/php-protocolbuffers/747a2238f14de0be67d5747089b50ebcc5e1116c/tests/fixtures/001_sint64_min.bin -------------------------------------------------------------------------------- /tests/fixtures/001_string_0bytes.bin: -------------------------------------------------------------------------------- 1 | 2 | -------------------------------------------------------------------------------- /tests/fixtures/001_string_1024bytes.bin: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/chobie/php-protocolbuffers/747a2238f14de0be67d5747089b50ebcc5e1116c/tests/fixtures/001_string_1024bytes.bin -------------------------------------------------------------------------------- /tests/fixtures/001_string_small.bin: -------------------------------------------------------------------------------- 1 | 2 | abcdefghijklmn -------------------------------------------------------------------------------- /tests/fixtures/001_string_utf8.bin: -------------------------------------------------------------------------------- 1 | 2 | 素晴らしい世界 -------------------------------------------------------------------------------- /tests/fixtures/001_uint64_max.bin: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/chobie/php-protocolbuffers/747a2238f14de0be67d5747089b50ebcc5e1116c/tests/fixtures/001_uint64_max.bin -------------------------------------------------------------------------------- /tests/fixtures/002_repeated_int32.bin: -------------------------------------------------------------------------------- 1 |   2 | -------------------------------------------------------------------------------- /tests/fixtures/002_repeated_message.bin: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/chobie/php-protocolbuffers/747a2238f14de0be67d5747089b50ebcc5e1116c/tests/fixtures/002_repeated_message.bin -------------------------------------------------------------------------------- /tests/fixtures/002_repeated_string.bin: -------------------------------------------------------------------------------- 1 | 2 | a 3 | b 4 | c 5 | d 6 | e 7 | f 8 | g 9 | h 10 | i 11 | j -------------------------------------------------------------------------------- /tests/fixtures/002_simple_encode.bin: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/chobie/php-protocolbuffers/747a2238f14de0be67d5747089b50ebcc5e1116c/tests/fixtures/002_simple_encode.bin -------------------------------------------------------------------------------- /tests/fixtures/003_bool_packed.bin: -------------------------------------------------------------------------------- 1 | 2 |  -------------------------------------------------------------------------------- /tests/fixtures/003_double_packed.bin: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/chobie/php-protocolbuffers/747a2238f14de0be67d5747089b50ebcc5e1116c/tests/fixtures/003_double_packed.bin -------------------------------------------------------------------------------- /tests/fixtures/003_fixed32_packed.bin: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/chobie/php-protocolbuffers/747a2238f14de0be67d5747089b50ebcc5e1116c/tests/fixtures/003_fixed32_packed.bin -------------------------------------------------------------------------------- /tests/fixtures/003_fixed64_packed.bin: -------------------------------------------------------------------------------- 1 | 2 |  -------------------------------------------------------------------------------- /tests/fixtures/003_float_packed.bin: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/chobie/php-protocolbuffers/747a2238f14de0be67d5747089b50ebcc5e1116c/tests/fixtures/003_float_packed.bin -------------------------------------------------------------------------------- /tests/fixtures/003_has_message.bin: -------------------------------------------------------------------------------- 1 | 2 | chobie" 0120-222-222 -------------------------------------------------------------------------------- /tests/fixtures/003_int32_packed_many.bin: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/chobie/php-protocolbuffers/747a2238f14de0be67d5747089b50ebcc5e1116c/tests/fixtures/003_int32_packed_many.bin -------------------------------------------------------------------------------- /tests/fixtures/003_int32_packed_one.bin: -------------------------------------------------------------------------------- 1 | 2 |  -------------------------------------------------------------------------------- /tests/fixtures/003_int64_packed.bin: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/chobie/php-protocolbuffers/747a2238f14de0be67d5747089b50ebcc5e1116c/tests/fixtures/003_int64_packed.bin -------------------------------------------------------------------------------- /tests/fixtures/003_sfixed32_packed.bin: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/chobie/php-protocolbuffers/747a2238f14de0be67d5747089b50ebcc5e1116c/tests/fixtures/003_sfixed32_packed.bin -------------------------------------------------------------------------------- /tests/fixtures/003_sfixed64_packed.bin: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/chobie/php-protocolbuffers/747a2238f14de0be67d5747089b50ebcc5e1116c/tests/fixtures/003_sfixed64_packed.bin -------------------------------------------------------------------------------- /tests/fixtures/003_sint32_packed.bin: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/chobie/php-protocolbuffers/747a2238f14de0be67d5747089b50ebcc5e1116c/tests/fixtures/003_sint32_packed.bin -------------------------------------------------------------------------------- /tests/fixtures/003_sint64_packed.bin: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/chobie/php-protocolbuffers/747a2238f14de0be67d5747089b50ebcc5e1116c/tests/fixtures/003_sint64_packed.bin -------------------------------------------------------------------------------- /tests/fixtures/003_uint32_packed.bin: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/chobie/php-protocolbuffers/747a2238f14de0be67d5747089b50ebcc5e1116c/tests/fixtures/003_uint32_packed.bin -------------------------------------------------------------------------------- /tests/fixtures/999_conformance_quick.bin: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/chobie/php-protocolbuffers/747a2238f14de0be67d5747089b50ebcc5e1116c/tests/fixtures/999_conformance_quick.bin -------------------------------------------------------------------------------- /tests/fixtures/android_logo.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/chobie/php-protocolbuffers/747a2238f14de0be67d5747089b50ebcc5e1116c/tests/fixtures/android_logo.gif -------------------------------------------------------------------------------- /tests/fixtures/fixture001.bin: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/chobie/php-protocolbuffers/747a2238f14de0be67d5747089b50ebcc5e1116c/tests/fixtures/fixture001.bin -------------------------------------------------------------------------------- /tests/integration/README.md: -------------------------------------------------------------------------------- 1 | SAPI Integration Test 2 | ===================== 3 | 4 | ``` 5 | # run php-fpm 6 | composer install 7 | ./vendor/bin/phpunit 8 | ``` 9 | 10 | these test cases checks php life cycles. -------------------------------------------------------------------------------- /tests/integration/bootstrap.php: -------------------------------------------------------------------------------- 1 | 'FastCGI/1.0', 27 | 'REQUEST_METHOD' => 'GET', 28 | 'SCRIPT_FILENAME' => $url['path'], 29 | 'SCRIPT_NAME' => $req, 30 | 'QUERY_STRING' => $url['query'], 31 | 'REQUEST_URI' => $uri, 32 | 'DOCUMENT_URI' => $req, 33 | 'SERVER_SOFTWARE' => 'php/fcgiclient', 34 | 'REMOTE_ADDR' => '127.0.0.1', 35 | 'REMOTE_PORT' => '9985', 36 | 'SERVER_ADDR' => '127.0.0.1', 37 | 'SERVER_PORT' => '80', 38 | 'SERVER_NAME' => php_uname('n'), 39 | 'SERVER_PROTOCOL' => 'HTTP/1.1', 40 | 'CONTENT_TYPE' => '', 41 | 'CONTENT_LENGTH' => 0 42 | ); 43 | 44 | return $client->request($params, false); 45 | } -------------------------------------------------------------------------------- /tests/integration/composer.json: -------------------------------------------------------------------------------- 1 | { 2 | "require": { 3 | "adoy/fastcgi-client": "dev-master", 4 | "phpunit/phpunit": "3.7.*" 5 | }, 6 | "autoload": { 7 | "psr-4": {"pecl\\": "messages/pecl"} 8 | } 9 | } 10 | -------------------------------------------------------------------------------- /tests/integration/messages/autoload.php: -------------------------------------------------------------------------------- 1 | '/pecl/protocolbuffers/User.php', 7 | // @@protoc_insertion_point(autoloader_scope:classmap) 8 | ); 9 | } 10 | if (isset($classmap[$name])) { 11 | require __DIR__ . DIRECTORY_SEPARATOR . $classmap[$name]; 12 | } 13 | }); 14 | 15 | call_user_func(function(){ 16 | $registry = \ProtocolBuffers\ExtensionRegistry::getInstance(); 17 | // @@protoc_insertion_point(extension_scope:registry) 18 | }); 19 | -------------------------------------------------------------------------------- /tests/integration/messages/proto/user.proto.php: -------------------------------------------------------------------------------- 1 | 2 | 17 | 18 | 19 | 20 | 21 | 22 | tests 23 | 24 | 25 | -------------------------------------------------------------------------------- /tests/integration/proto/user.proto: -------------------------------------------------------------------------------- 1 | package pecl.protocolbuffers; 2 | 3 | message User 4 | { 5 | optional int64 user_id = 1; 6 | optional bytes name = 2; 7 | } -------------------------------------------------------------------------------- /tests/integration/protocolbuffers.ini: -------------------------------------------------------------------------------- 1 | extension=protocolbuffers.so -------------------------------------------------------------------------------- /tests/integration/src/MultipleRequest.php: -------------------------------------------------------------------------------- 1 | setUserId(12345); 6 | $user->setName("chobie"); 7 | echo $user->serializeToString(); -------------------------------------------------------------------------------- /tests/integration/test.php: -------------------------------------------------------------------------------- 1 | assertInstanceOf('\pecl\protocolbuffers\User', $user); 14 | $this->assertEquals("12345", $user->getUserId()); 15 | $this->assertEquals("chobie", $user->getName()); 16 | } 17 | } -------------------------------------------------------------------------------- /tests/messages/big_tag.proto.php: -------------------------------------------------------------------------------- 1 | value; 20 | } 21 | 22 | public function setValue($value) 23 | { 24 | $this->value = $value; 25 | } 26 | 27 | /** 28 | * get descriptor for protocol buffers 29 | * 30 | * @return array 31 | */ 32 | public static function getDescriptor() 33 | { 34 | if (!isset(self::$descriptor)) { 35 | $desc = new ProtocolBuffersDescriptorBuilder(); 36 | $desc->addField(536870911, new ProtocolBuffersFieldDescriptor(array( 37 | "type" => ProtocolBuffers::TYPE_INT32, 38 | "name" => "value", 39 | "packable" => false, 40 | "repeated" => false, 41 | "default" => null, 42 | ))); 43 | 44 | self::$descriptor = $desc->build(); 45 | } 46 | 47 | return self::$descriptor; 48 | 49 | } 50 | 51 | } 52 | 53 | -------------------------------------------------------------------------------- /tests/messages/field_bool.proto.php: -------------------------------------------------------------------------------- 1 | value; 22 | } 23 | 24 | public function setValue($value) 25 | { 26 | $this->value = $value; 27 | } 28 | 29 | /** 30 | * get descriptor for protocol buffers 31 | * 32 | * @return array 33 | */ 34 | public static function getDescriptor() 35 | { 36 | if (!isset(self::$descriptor)) { 37 | $desc = new ProtocolBuffersDescriptorBuilder(); 38 | $desc->addField(1, new ProtocolBuffersFieldDescriptor(array( 39 | "type" => ProtocolBuffers::TYPE_BOOL, 40 | "name" => "value", 41 | "packable" => false, 42 | "repeated" => false, 43 | "default" => null, 44 | ))); 45 | 46 | self::$descriptor = $desc->build(); 47 | } 48 | 49 | return self::$descriptor; 50 | 51 | } 52 | 53 | } 54 | 55 | -------------------------------------------------------------------------------- /tests/messages/field_bool_packed.proto.php: -------------------------------------------------------------------------------- 1 | value; 21 | } 22 | 23 | public function addValue($value) 24 | { 25 | $this->value[] = $value; 26 | } 27 | 28 | /** 29 | * get descriptor for protocol buffers 30 | * 31 | * @return array 32 | */ 33 | public static function getDescriptor() 34 | { 35 | if (!isset(self::$descriptor)) { 36 | $desc = new ProtocolBuffersDescriptorBuilder(); 37 | $desc->addField(1, new ProtocolBuffersFieldDescriptor(array( 38 | "type" => ProtocolBuffers::TYPE_BOOL, 39 | "name" => "value", 40 | "packable" => true, 41 | "repeated" => true, 42 | "default" => null, 43 | ))); 44 | 45 | self::$descriptor = $desc->build(); 46 | } 47 | 48 | return self::$descriptor; 49 | 50 | } 51 | 52 | } 53 | 54 | -------------------------------------------------------------------------------- /tests/messages/field_bytes.proto.php: -------------------------------------------------------------------------------- 1 | value; 20 | } 21 | 22 | public function setValue($value) 23 | { 24 | $this->value = $value; 25 | } 26 | 27 | /** 28 | * get descriptor for protocol buffers 29 | * 30 | * @return array 31 | */ 32 | public static function getDescriptor() 33 | { 34 | if (!isset(self::$descriptor)) { 35 | $desc = new ProtocolBuffersDescriptorBuilder(); 36 | $desc->addField(1, new ProtocolBuffersFieldDescriptor(array( 37 | "type" => ProtocolBuffers::TYPE_BYTES, 38 | "name" => "value", 39 | "packable" => false, 40 | "repeated" => false, 41 | "default" => null, 42 | ))); 43 | 44 | self::$descriptor = $desc->build(); 45 | } 46 | 47 | return self::$descriptor; 48 | 49 | } 50 | 51 | } 52 | 53 | -------------------------------------------------------------------------------- /tests/messages/field_double.proto.php: -------------------------------------------------------------------------------- 1 | value; 20 | } 21 | 22 | public function setValue($value) 23 | { 24 | $this->value = $value; 25 | } 26 | 27 | /** 28 | * get descriptor for protocol buffers 29 | * 30 | * @return array 31 | */ 32 | public static function getDescriptor() 33 | { 34 | if (!isset(self::$descriptor)) { 35 | $desc = new ProtocolBuffersDescriptorBuilder(); 36 | $desc->addField(1, new ProtocolBuffersFieldDescriptor(array( 37 | "type" => ProtocolBuffers::TYPE_FLOAT, 38 | "name" => "value", 39 | "packable" => false, 40 | "repeated" => false, 41 | "default" => null, 42 | ))); 43 | 44 | self::$descriptor = $desc->build(); 45 | } 46 | 47 | return self::$descriptor; 48 | 49 | } 50 | 51 | } 52 | 53 | -------------------------------------------------------------------------------- /tests/messages/field_double_packed.proto.php: -------------------------------------------------------------------------------- 1 | value; 20 | } 21 | 22 | public function addValue($value) 23 | { 24 | $this->value[] = $value; 25 | } 26 | 27 | /** 28 | * get descriptor for protocol buffers 29 | * 30 | * @return array 31 | */ 32 | public static function getDescriptor() 33 | { 34 | if (!isset(self::$descriptor)) { 35 | $desc = new ProtocolBuffersDescriptorBuilder(); 36 | $desc->addField(1, new ProtocolBuffersFieldDescriptor(array( 37 | "type" => ProtocolBuffers::TYPE_DOUBLE, 38 | "name" => "value", 39 | "packable" => true, 40 | "repeated" => true, 41 | "default" => null, 42 | ))); 43 | 44 | self::$descriptor = $desc->build(); 45 | } 46 | 47 | return self::$descriptor; 48 | 49 | } 50 | 51 | } 52 | 53 | -------------------------------------------------------------------------------- /tests/messages/field_fixed32.proto.php: -------------------------------------------------------------------------------- 1 | value; 20 | } 21 | 22 | public function setValue($value) 23 | { 24 | $this->value = $value; 25 | } 26 | 27 | /** 28 | * get descriptor for protocol buffers 29 | * 30 | * @return array 31 | */ 32 | public static function getDescriptor() 33 | { 34 | if (!isset(self::$descriptor)) { 35 | $desc = new ProtocolBuffersDescriptorBuilder(); 36 | $desc->addField(1, new ProtocolBuffersFieldDescriptor(array( 37 | "type" => ProtocolBuffers::TYPE_FIXED32, 38 | "name" => "value", 39 | "packable" => false, 40 | "repeated" => false, 41 | "default" => null, 42 | ))); 43 | 44 | self::$descriptor = $desc->build(); 45 | } 46 | 47 | return self::$descriptor; 48 | 49 | } 50 | 51 | } 52 | 53 | -------------------------------------------------------------------------------- /tests/messages/field_fixed32_packed.proto.php: -------------------------------------------------------------------------------- 1 | value; 22 | } 23 | 24 | public function addValue($value) 25 | { 26 | $this->value[] = $value; 27 | } 28 | 29 | /** 30 | * get descriptor for protocol buffers 31 | * 32 | * @return array 33 | */ 34 | public static function getDescriptor() 35 | { 36 | if (!isset(self::$descriptor)) { 37 | $desc = new ProtocolBuffersDescriptorBuilder(); 38 | $desc->addField(1, new ProtocolBuffersFieldDescriptor(array( 39 | "type" => ProtocolBuffers::TYPE_FIXED32, 40 | "name" => "value", 41 | "packable" => true, 42 | "repeated" => true, 43 | "default" => null, 44 | ))); 45 | 46 | self::$descriptor = $desc->build(); 47 | } 48 | 49 | return self::$descriptor; 50 | 51 | } 52 | 53 | } 54 | 55 | -------------------------------------------------------------------------------- /tests/messages/field_fixed64.proto.php: -------------------------------------------------------------------------------- 1 | value; 20 | } 21 | 22 | public function setValue($value) 23 | { 24 | $this->value = $value; 25 | } 26 | 27 | /** 28 | * get descriptor for protocol buffers 29 | * 30 | * @return array 31 | */ 32 | public static function getDescriptor() 33 | { 34 | if (!isset(self::$descriptor)) { 35 | $desc = new ProtocolBuffersDescriptorBuilder(); 36 | $desc->addField(1, new ProtocolBuffersFieldDescriptor(array( 37 | "type" => ProtocolBuffers::TYPE_FIXED64, 38 | "name" => "value", 39 | "packable" => false, 40 | "repeated" => false, 41 | "default" => null, 42 | ))); 43 | 44 | self::$descriptor = $desc->build(); 45 | } 46 | 47 | return self::$descriptor; 48 | 49 | } 50 | 51 | } 52 | 53 | -------------------------------------------------------------------------------- /tests/messages/field_fixed64_packed.proto.php: -------------------------------------------------------------------------------- 1 | value; 21 | } 22 | 23 | public function addValue($value) 24 | { 25 | $this->value[] = $value; 26 | } 27 | 28 | /** 29 | * get descriptor for protocol buffers 30 | * 31 | * @return array 32 | */ 33 | public static function getDescriptor() 34 | { 35 | if (!isset(self::$descriptor)) { 36 | $desc = new ProtocolBuffersDescriptorBuilder(); 37 | $desc->addField(1, new ProtocolBuffersFieldDescriptor(array( 38 | "type" => ProtocolBuffers::TYPE_FIXED64, 39 | "name" => "value", 40 | "packable" => true, 41 | "repeated" => true, 42 | "default" => null, 43 | ))); 44 | 45 | self::$descriptor = $desc->build(); 46 | } 47 | 48 | return self::$descriptor; 49 | 50 | } 51 | 52 | } 53 | 54 | -------------------------------------------------------------------------------- /tests/messages/field_float.proto.php: -------------------------------------------------------------------------------- 1 | value; 22 | } 23 | 24 | public function setValue($value) 25 | { 26 | $this->value = $value; 27 | } 28 | 29 | /** 30 | * get descriptor for protocol buffers 31 | * 32 | * @return array 33 | */ 34 | public static function getDescriptor() 35 | { 36 | if (!isset(self::$descriptor)) { 37 | $desc = new ProtocolBuffersDescriptorBuilder(); 38 | $desc->addField(1, new ProtocolBuffersFieldDescriptor(array( 39 | "type" => ProtocolBuffers::TYPE_FLOAT, 40 | "name" => "value", 41 | "packable" => false, 42 | "repeated" => false, 43 | "default" => null, 44 | ))); 45 | 46 | self::$descriptor = $desc->build(); 47 | } 48 | 49 | return self::$descriptor; 50 | 51 | } 52 | 53 | } 54 | 55 | -------------------------------------------------------------------------------- /tests/messages/field_float_packed.proto.php: -------------------------------------------------------------------------------- 1 | value; 22 | } 23 | 24 | public function addValue($value) 25 | { 26 | $this->value[] = $value; 27 | } 28 | 29 | /** 30 | * get descriptor for protocol buffers 31 | * 32 | * @return array 33 | */ 34 | public static function getDescriptor() 35 | { 36 | if (!isset(self::$descriptor)) { 37 | $desc = new ProtocolBuffersDescriptorBuilder(); 38 | $desc->addField(1, new ProtocolBuffersFieldDescriptor(array( 39 | "type" => ProtocolBuffers::TYPE_FLOAT, 40 | "name" => "value", 41 | "packable" => true, 42 | "repeated" => true, 43 | "default" => null, 44 | ))); 45 | 46 | self::$descriptor = $desc->build(); 47 | } 48 | 49 | return self::$descriptor; 50 | 51 | } 52 | 53 | } 54 | 55 | -------------------------------------------------------------------------------- /tests/messages/field_int32.proto.php: -------------------------------------------------------------------------------- 1 | value; 22 | } 23 | 24 | public function setValue($value) 25 | { 26 | $this->value = $value; 27 | } 28 | 29 | /** 30 | * get descriptor for protocol buffers 31 | * 32 | * @return array 33 | */ 34 | public static function getDescriptor() 35 | { 36 | if (!isset(self::$descriptor)) { 37 | $desc = new ProtocolBuffersDescriptorBuilder(); 38 | $desc->addField(1, new ProtocolBuffersFieldDescriptor(array( 39 | "type" => ProtocolBuffers::TYPE_INT32, 40 | "name" => "value", 41 | "packable" => false, 42 | "repeated" => false, 43 | "default" => null, 44 | ))); 45 | 46 | self::$descriptor = $desc->build(); 47 | } 48 | 49 | return self::$descriptor; 50 | 51 | } 52 | 53 | } 54 | 55 | -------------------------------------------------------------------------------- /tests/messages/field_int32_packed.proto.php: -------------------------------------------------------------------------------- 1 | value; 22 | } 23 | 24 | public function addValue($value) 25 | { 26 | $this->value[] = $value; 27 | } 28 | 29 | /** 30 | * get descriptor for protocol buffers 31 | * 32 | * @return array 33 | */ 34 | public static function getDescriptor() 35 | { 36 | if (!isset(self::$descriptor)) { 37 | $desc = new ProtocolBuffersDescriptorBuilder(); 38 | $desc->addField(1, new ProtocolBuffersFieldDescriptor(array( 39 | "type" => ProtocolBuffers::TYPE_INT32, 40 | "name" => "value", 41 | "packable" => true, 42 | "repeated" => true, 43 | "default" => null, 44 | ))); 45 | 46 | self::$descriptor = $desc->build(); 47 | } 48 | 49 | return self::$descriptor; 50 | 51 | } 52 | 53 | } 54 | 55 | -------------------------------------------------------------------------------- /tests/messages/field_int64.proto.php: -------------------------------------------------------------------------------- 1 | value; 22 | } 23 | 24 | public function setValue($value) 25 | { 26 | $this->value = $value; 27 | } 28 | 29 | /** 30 | * get descriptor for protocol buffers 31 | * 32 | * @return array 33 | */ 34 | public static function getDescriptor() 35 | { 36 | if (!isset(self::$descriptor)) { 37 | $desc = new ProtocolBuffersDescriptorBuilder(); 38 | $desc->addField(1, new ProtocolBuffersFieldDescriptor(array( 39 | "type" => ProtocolBuffers::TYPE_INT64, 40 | "name" => "value", 41 | "packable" => false, 42 | "repeated" => false, 43 | "default" => null, 44 | ))); 45 | 46 | self::$descriptor = $desc->build(); 47 | } 48 | 49 | return self::$descriptor; 50 | 51 | } 52 | 53 | } 54 | 55 | -------------------------------------------------------------------------------- /tests/messages/field_int64_packed.proto.php: -------------------------------------------------------------------------------- 1 | value; 22 | } 23 | 24 | public function addValue($value) 25 | { 26 | $this->value[] = $value; 27 | } 28 | 29 | /** 30 | * get descriptor for protocol buffers 31 | * 32 | * @return array 33 | */ 34 | public static function getDescriptor() 35 | { 36 | if (!isset(self::$descriptor)) { 37 | $desc = new ProtocolBuffersDescriptorBuilder(); 38 | $desc->addField(1, new ProtocolBuffersFieldDescriptor(array( 39 | "type" => ProtocolBuffers::TYPE_INT64, 40 | "name" => "value", 41 | "packable" => true, 42 | "repeated" => true, 43 | "default" => null, 44 | ))); 45 | 46 | self::$descriptor = $desc->build(); 47 | } 48 | 49 | return self::$descriptor; 50 | } 51 | 52 | } 53 | 54 | -------------------------------------------------------------------------------- /tests/messages/field_sfixed32.proto.php: -------------------------------------------------------------------------------- 1 | value; 20 | } 21 | 22 | public function setValue($value) 23 | { 24 | $this->value = $value; 25 | } 26 | 27 | /** 28 | * get descriptor for protocol buffers 29 | * 30 | * @return array 31 | */ 32 | public static function getDescriptor() 33 | { 34 | if (!isset(self::$descriptor)) { 35 | $desc = new ProtocolBuffersDescriptorBuilder(); 36 | $desc->addField(1, new ProtocolBuffersFieldDescriptor(array( 37 | "type" => ProtocolBuffers::TYPE_SFIXED32, 38 | "name" => "value", 39 | "packable" => false, 40 | "repeated" => false, 41 | "default" => null, 42 | ))); 43 | 44 | self::$descriptor = $desc->build(); 45 | } 46 | 47 | return self::$descriptor; 48 | 49 | } 50 | 51 | } 52 | 53 | -------------------------------------------------------------------------------- /tests/messages/field_sfixed32_packed.proto.php: -------------------------------------------------------------------------------- 1 | value; 22 | } 23 | 24 | public function addValue($value) 25 | { 26 | $this->value[] = $value; 27 | } 28 | 29 | /** 30 | * get descriptor for protocol buffers 31 | * 32 | * @return array 33 | */ 34 | public static function getDescriptor() 35 | { 36 | if (!isset(self::$descriptor)) { 37 | $desc = new ProtocolBuffersDescriptorBuilder(); 38 | $desc->addField(1, new ProtocolBuffersFieldDescriptor(array( 39 | "type" => ProtocolBuffers::TYPE_SFIXED32, 40 | "name" => "value", 41 | "packable" => true, 42 | "repeated" => true, 43 | "default" => null, 44 | ))); 45 | 46 | self::$descriptor = $desc->build(); 47 | } 48 | 49 | return self::$descriptor; 50 | 51 | } 52 | 53 | } 54 | 55 | -------------------------------------------------------------------------------- /tests/messages/field_sfixed64.proto.php: -------------------------------------------------------------------------------- 1 | value; 22 | } 23 | 24 | public function setValue($value) 25 | { 26 | $this->value = $value; 27 | } 28 | 29 | /** 30 | * get descriptor for protocol buffers 31 | * 32 | * @return array 33 | */ 34 | public static function getDescriptor() 35 | { 36 | if (!isset(self::$descriptor)) { 37 | $desc = new ProtocolBuffersDescriptorBuilder(); 38 | $desc->addField(1, new ProtocolBuffersFieldDescriptor(array( 39 | "type" => ProtocolBuffers::TYPE_SFIXED64, 40 | "name" => "value", 41 | "packable" => false, 42 | "repeated" => false, 43 | "default" => null, 44 | ))); 45 | 46 | self::$descriptor = $desc->build(); 47 | } 48 | 49 | return self::$descriptor; 50 | 51 | } 52 | 53 | } 54 | 55 | -------------------------------------------------------------------------------- /tests/messages/field_sfixed64_packed.proto.php: -------------------------------------------------------------------------------- 1 | value; 22 | } 23 | 24 | public function addValue($value) 25 | { 26 | $this->value[] = $value; 27 | } 28 | 29 | /** 30 | * get descriptor for protocol buffers 31 | * 32 | * @return array 33 | */ 34 | public static function getDescriptor() 35 | { 36 | if (!isset(self::$descriptor)) { 37 | $desc = new ProtocolBuffersDescriptorBuilder(); 38 | $desc->addField(1, new ProtocolBuffersFieldDescriptor(array( 39 | "type" => ProtocolBuffers::TYPE_SFIXED64, 40 | "name" => "value", 41 | "packable" => true, 42 | "repeated" => true, 43 | "default" => null, 44 | ))); 45 | 46 | self::$descriptor = $desc->build(); 47 | } 48 | 49 | return self::$descriptor; 50 | 51 | } 52 | 53 | } 54 | 55 | -------------------------------------------------------------------------------- /tests/messages/field_sint32.proto.php: -------------------------------------------------------------------------------- 1 | value; 22 | } 23 | 24 | public function setValue($value) 25 | { 26 | $this->value = $value; 27 | } 28 | 29 | /** 30 | * get descriptor for protocol buffers 31 | * 32 | * @return array 33 | */ 34 | public static function getDescriptor() 35 | { 36 | if (!isset(self::$descriptor)) { 37 | $desc = new ProtocolBuffersDescriptorBuilder(); 38 | $desc->addField(1, new ProtocolBuffersFieldDescriptor(array( 39 | "type" => ProtocolBuffers::TYPE_SINT32, 40 | "name" => "value", 41 | "required" => true, 42 | "packable" => false, 43 | "repeated" => false, 44 | "default" => null, 45 | ))); 46 | 47 | self::$descriptor = $desc->build(); 48 | } 49 | 50 | return self::$descriptor; 51 | 52 | } 53 | 54 | } 55 | 56 | -------------------------------------------------------------------------------- /tests/messages/field_sint32_packed.proto.php: -------------------------------------------------------------------------------- 1 | value; 22 | } 23 | 24 | public function addValue($value) 25 | { 26 | $this->value[] = $value; 27 | } 28 | 29 | /** 30 | * get descriptor for protocol buffers 31 | * 32 | * @return array 33 | */ 34 | public static function getDescriptor() 35 | { 36 | if (!isset(self::$descriptor)) { 37 | $desc = new ProtocolBuffersDescriptorBuilder(); 38 | $desc->addField(1, new ProtocolBuffersFieldDescriptor(array( 39 | "type" => ProtocolBuffers::TYPE_SINT32, 40 | "name" => "value", 41 | "packable" => true, 42 | "repeated" => true, 43 | "default" => null, 44 | ))); 45 | 46 | self::$descriptor = $desc->build(); 47 | } 48 | 49 | return self::$descriptor; 50 | } 51 | 52 | } 53 | 54 | -------------------------------------------------------------------------------- /tests/messages/field_sint64.proto.php: -------------------------------------------------------------------------------- 1 | value; 22 | } 23 | 24 | public function setValue($value) 25 | { 26 | $this->value = $value; 27 | } 28 | 29 | /** 30 | * get descriptor for protocol buffers 31 | * 32 | * @return array 33 | */ 34 | public static function getDescriptor() 35 | { 36 | if (!isset(self::$descriptor)) { 37 | $desc = new ProtocolBuffersDescriptorBuilder(); 38 | $desc->addField(1, new ProtocolBuffersFieldDescriptor(array( 39 | "type" => ProtocolBuffers::TYPE_SINT64, 40 | "name" => "value", 41 | "packable" => false, 42 | "repeated" => false, 43 | "default" => null, 44 | ))); 45 | 46 | self::$descriptor = $desc->build(); 47 | } 48 | 49 | return self::$descriptor; 50 | } 51 | 52 | } 53 | 54 | -------------------------------------------------------------------------------- /tests/messages/field_sint64_packed.proto.php: -------------------------------------------------------------------------------- 1 | value; 22 | } 23 | 24 | public function addValue($value) 25 | { 26 | $this->value[] = $value; 27 | } 28 | 29 | /** 30 | * get descriptor for protocol buffers 31 | * 32 | * @return array 33 | */ 34 | public static function getDescriptor() 35 | { 36 | if (!isset(self::$descriptor)) { 37 | $desc = new ProtocolBuffersDescriptorBuilder(); 38 | $desc->addField(1, new ProtocolBuffersFieldDescriptor(array( 39 | "type" => ProtocolBuffers::TYPE_SINT64, 40 | "name" => "value", 41 | "packable" => true, 42 | "repeated" => true, 43 | "default" => null, 44 | ))); 45 | 46 | self::$descriptor = $desc->build(); 47 | } 48 | 49 | return self::$descriptor; 50 | } 51 | 52 | } 53 | 54 | -------------------------------------------------------------------------------- /tests/messages/field_string.proto.php: -------------------------------------------------------------------------------- 1 | value; 22 | } 23 | 24 | public function setValue($value) 25 | { 26 | $this->value = $value; 27 | } 28 | 29 | /** 30 | * get descriptor for protocol buffers 31 | * 32 | * @return array 33 | */ 34 | public static function getDescriptor() 35 | { 36 | if (!isset(self::$descriptor)) { 37 | $desc = new ProtocolBuffersDescriptorBuilder(); 38 | $desc->addField(1, new ProtocolBuffersFieldDescriptor(array( 39 | "type" => ProtocolBuffers::TYPE_STRING, 40 | "name" => "value", 41 | "packable" => false, 42 | "repeated" => false, 43 | "default" => null, 44 | ))); 45 | 46 | self::$descriptor = $desc->build(); 47 | } 48 | 49 | return self::$descriptor; 50 | } 51 | 52 | } 53 | 54 | -------------------------------------------------------------------------------- /tests/messages/field_uint32_packed.proto.php: -------------------------------------------------------------------------------- 1 | value; 22 | } 23 | 24 | public function addValue($value) 25 | { 26 | $this->value[] = $value; 27 | } 28 | 29 | /** 30 | * get descriptor for protocol buffers 31 | * 32 | * @return array 33 | */ 34 | public static function getDescriptor() 35 | { 36 | if (!isset(self::$descriptor)) { 37 | $desc = new ProtocolBuffersDescriptorBuilder(); 38 | $desc->addField(1, new ProtocolBuffersFieldDescriptor(array( 39 | "type" => ProtocolBuffers::TYPE_UINT32, 40 | "name" => "value", 41 | "packable" => true, 42 | "repeated" => true, 43 | "default" => null, 44 | ))); 45 | 46 | self::$descriptor = $desc->build(); 47 | } 48 | 49 | return self::$descriptor; 50 | } 51 | 52 | } 53 | 54 | -------------------------------------------------------------------------------- /tests/messages/field_uint64.proto.php: -------------------------------------------------------------------------------- 1 | value; 22 | } 23 | 24 | public function setValue($value) 25 | { 26 | $this->value = $value; 27 | } 28 | 29 | /** 30 | * get descriptor for protocol buffers 31 | * 32 | * @return array 33 | */ 34 | public static function getDescriptor() 35 | { 36 | if (!isset(self::$descriptor)) { 37 | $desc = new ProtocolBuffersDescriptorBuilder(); 38 | $desc->addField(1, new ProtocolBuffersFieldDescriptor(array( 39 | "type" => ProtocolBuffers::TYPE_UINT64, 40 | "name" => "value", 41 | "packable" => false, 42 | "repeated" => false, 43 | "default" => null, 44 | ))); 45 | 46 | self::$descriptor = $desc->build(); 47 | } 48 | 49 | return self::$descriptor; 50 | } 51 | 52 | } 53 | 54 | -------------------------------------------------------------------------------- /tests/messages/repeated_int32.proto.php: -------------------------------------------------------------------------------- 1 | value; 22 | } 23 | 24 | public function addValue($value) 25 | { 26 | $this->value[] = $value; 27 | } 28 | 29 | /** 30 | * get descriptor for protocol buffers 31 | * 32 | * @return array 33 | */ 34 | public static function getDescriptor() 35 | { 36 | if (!isset(self::$descriptor)) { 37 | $desc = new ProtocolBuffersDescriptorBuilder(); 38 | $desc->addField(1, new ProtocolBuffersFieldDescriptor(array( 39 | "type" => ProtocolBuffers::TYPE_INT32, 40 | "name" => "value", 41 | "packable" => false, 42 | "repeated" => true, 43 | "default" => null, 44 | ))); 45 | 46 | self::$descriptor = $desc->build(); 47 | } 48 | 49 | return self::$descriptor; 50 | } 51 | 52 | } 53 | 54 | -------------------------------------------------------------------------------- /tests/messages/repeated_string.proto.php: -------------------------------------------------------------------------------- 1 | values; 22 | } 23 | 24 | public function addValues($values) 25 | { 26 | $this->values[] = $values; 27 | } 28 | 29 | /** 30 | * get descriptor for protocol buffers 31 | * 32 | * @return array 33 | */ 34 | public static function getDescriptor() 35 | { 36 | if (!isset(self::$descriptor)) { 37 | $desc = new ProtocolBuffersDescriptorBuilder(); 38 | $desc->addField(1, new ProtocolBuffersFieldDescriptor(array( 39 | "type" => ProtocolBuffers::TYPE_STRING, 40 | "name" => "values", 41 | "packable" => false, 42 | "repeated" => true, 43 | "default" => null, 44 | ))); 45 | 46 | self::$descriptor = $desc->build(); 47 | } 48 | 49 | return self::$descriptor; 50 | } 51 | 52 | } 53 | 54 | -------------------------------------------------------------------------------- /tests/proto/addressbook.proto: -------------------------------------------------------------------------------- 1 | package Tutorial; 2 | 3 | //import "php_options.proto"; 4 | //option (php).generate_getter = true; 5 | //option (php).generate_setter = true; 6 | 7 | message User { 8 | required int32 id = 1; 9 | optional float offense = 2; 10 | optional string name = 3; 11 | } 12 | 13 | message AddressBook { 14 | repeated User user = 1; 15 | } 16 | -------------------------------------------------------------------------------- /tests/proto/big_tag.proto: -------------------------------------------------------------------------------- 1 | package Tutorial; 2 | 3 | //import "php_options.proto"; 4 | ////option (php).base_class = "Base"; 5 | //option (php).generate_getter = true; 6 | //option (php).generate_setter = true; 7 | 8 | message BigTag { 9 | required int32 value = 536870911; 10 | } 11 | 12 | 13 | -------------------------------------------------------------------------------- /tests/proto/field_bool.proto: -------------------------------------------------------------------------------- 1 | package Tutorial; 2 | 3 | import "php_options.proto"; 4 | //option (php).base_class = "Base"; 5 | option (php).generate_getter = true; 6 | option (php).generate_setter = true; 7 | 8 | message Boolean { 9 | required bool value = 1; 10 | } 11 | 12 | 13 | -------------------------------------------------------------------------------- /tests/proto/field_bool_packed.proto: -------------------------------------------------------------------------------- 1 | package Tutorial; 2 | 3 | import "php_options.proto"; 4 | //option (php).base_class = "Base"; 5 | option (php).generate_getter = true; 6 | option (php).generate_setter = true; 7 | 8 | message Boolean { 9 | repeated bool value = 1 [packed = true]; 10 | } 11 | 12 | 13 | -------------------------------------------------------------------------------- /tests/proto/field_bytes.proto: -------------------------------------------------------------------------------- 1 | package Tutorial; 2 | 3 | import "php_options.proto"; 4 | //option (php).base_class = "Base"; 5 | option (php).generate_getter = true; 6 | option (php).generate_setter = true; 7 | 8 | message Bytes { 9 | required bytes value = 1; 10 | } 11 | 12 | 13 | -------------------------------------------------------------------------------- /tests/proto/field_double.proto: -------------------------------------------------------------------------------- 1 | package Tutorial; 2 | 3 | //import "php_options.proto"; 4 | ////option (php).base_class = "Base"; 5 | //option (php).generate_getter = true; 6 | //option (php).generate_setter = true; 7 | 8 | message Double { 9 | required float value = 1; 10 | } 11 | 12 | 13 | -------------------------------------------------------------------------------- /tests/proto/field_double_packed.proto: -------------------------------------------------------------------------------- 1 | package Tutorial; 2 | 3 | //import "php_options.proto"; 4 | ////option (php).base_class = "Base"; 5 | //option (php).generate_getter = true; 6 | //option (php).generate_setter = true; 7 | 8 | message Double { 9 | repeated double value = 1 [packed = true]; 10 | } 11 | 12 | 13 | -------------------------------------------------------------------------------- /tests/proto/field_fixed32.proto: -------------------------------------------------------------------------------- 1 | package Tutorial; 2 | 3 | import "php_options.proto"; 4 | //option (php).base_class = "Base"; 5 | option (php).generate_getter = true; 6 | option (php).generate_setter = true; 7 | 8 | message Fixed32{ 9 | required fixed32 value = 1; 10 | } 11 | 12 | 13 | -------------------------------------------------------------------------------- /tests/proto/field_fixed32_packed.proto: -------------------------------------------------------------------------------- 1 | package Tutorial; 2 | 3 | import "php_options.proto"; 4 | //option (php).base_class = "Base"; 5 | option (php).generate_getter = true; 6 | option (php).generate_setter = true; 7 | 8 | message Fixed32{ 9 | repeated fixed32 value = 1 [packed = true]; 10 | } 11 | 12 | 13 | -------------------------------------------------------------------------------- /tests/proto/field_fixed64.proto: -------------------------------------------------------------------------------- 1 | package Tutorial; 2 | 3 | import "php_options.proto"; 4 | //option (php).base_class = "Base"; 5 | option (php).generate_getter = true; 6 | option (php).generate_setter = true; 7 | 8 | message Fixed64{ 9 | required fixed64 value = 1; 10 | } 11 | 12 | 13 | -------------------------------------------------------------------------------- /tests/proto/field_fixed64_packed.proto: -------------------------------------------------------------------------------- 1 | package Tutorial; 2 | 3 | import "php_options.proto"; 4 | //option (php).base_class = "Base"; 5 | option (php).generate_getter = true; 6 | option (php).generate_setter = true; 7 | 8 | message Fixed64{ 9 | repeated fixed64 value = 1 [packed = true]; 10 | } 11 | 12 | 13 | -------------------------------------------------------------------------------- /tests/proto/field_float.proto: -------------------------------------------------------------------------------- 1 | package Tutorial; 2 | 3 | import "php_options.proto"; 4 | //option (php).base_class = "Base"; 5 | option (php).generate_getter = true; 6 | option (php).generate_setter = true; 7 | 8 | message Float { 9 | required float value = 1; 10 | } 11 | 12 | 13 | -------------------------------------------------------------------------------- /tests/proto/field_float_packed.proto: -------------------------------------------------------------------------------- 1 | package Tutorial; 2 | 3 | //import "php_options.proto"; 4 | ////option (php).base_class = "Base"; 5 | //option (php).generate_getter = true; 6 | //option (php).generate_setter = true; 7 | 8 | message Float { 9 | repeated float value = 1 [packed = true]; 10 | } 11 | 12 | 13 | -------------------------------------------------------------------------------- /tests/proto/field_int32.proto: -------------------------------------------------------------------------------- 1 | package Tutorial; 2 | 3 | import "php_options.proto"; 4 | //option (php).base_class = "Base"; 5 | option (php).generate_getter = true; 6 | option (php).generate_setter = true; 7 | 8 | message Integer32 { 9 | required int32 value = 1; 10 | } 11 | 12 | 13 | -------------------------------------------------------------------------------- /tests/proto/field_int32_packed.proto: -------------------------------------------------------------------------------- 1 | package Tutorial; 2 | 3 | //import "php_options.proto"; 4 | //option (php).base_class = "Base"; 5 | //option (php).generate_getter = true; 6 | //option (php).generate_setter = true; 7 | 8 | message Integer32 { 9 | repeated int32 value = 1 [packed = true]; 10 | } 11 | 12 | 13 | -------------------------------------------------------------------------------- /tests/proto/field_int64.proto: -------------------------------------------------------------------------------- 1 | package Tutorial; 2 | 3 | import "php_options.proto"; 4 | //option (php).base_class = "Base"; 5 | option (php).generate_getter = true; 6 | option (php).generate_setter = true; 7 | 8 | message Integer64 { 9 | required int64 value = 1; 10 | } 11 | 12 | 13 | -------------------------------------------------------------------------------- /tests/proto/field_int64_packed.proto: -------------------------------------------------------------------------------- 1 | package Tutorial; 2 | 3 | import "php_options.proto"; 4 | //option (php).base_class = "Base"; 5 | option (php).generate_getter = true; 6 | option (php).generate_setter = true; 7 | 8 | message Integer64 { 9 | repeated int64 value = 1 [packed = true]; 10 | } 11 | 12 | 13 | -------------------------------------------------------------------------------- /tests/proto/field_sfixed32.proto: -------------------------------------------------------------------------------- 1 | package Tutorial; 2 | 3 | import "php_options.proto"; 4 | //option (php).base_class = "Base"; 5 | option (php).generate_getter = true; 6 | option (php).generate_setter = true; 7 | 8 | message SFixed32{ 9 | required sfixed32 value = 1; 10 | } 11 | 12 | 13 | -------------------------------------------------------------------------------- /tests/proto/field_sfixed32_packed.proto: -------------------------------------------------------------------------------- 1 | package Tutorial; 2 | 3 | import "php_options.proto"; 4 | //option (php).base_class = "Base"; 5 | option (php).generate_getter = true; 6 | option (php).generate_setter = true; 7 | 8 | message SFixed32{ 9 | repeated sfixed32 value = 1 [packed = true]; 10 | } 11 | 12 | 13 | -------------------------------------------------------------------------------- /tests/proto/field_sfixed64.proto: -------------------------------------------------------------------------------- 1 | package Tutorial; 2 | 3 | import "php_options.proto"; 4 | //option (php).base_class = "Base"; 5 | option (php).generate_getter = true; 6 | option (php).generate_setter = true; 7 | 8 | message SFixed64{ 9 | required sfixed64 value = 1; 10 | } 11 | 12 | 13 | -------------------------------------------------------------------------------- /tests/proto/field_sfixed64_packed.proto: -------------------------------------------------------------------------------- 1 | package Tutorial; 2 | 3 | //import "php_options.proto"; 4 | ////option (php).base_class = "Base"; 5 | //option (php).generate_getter = true; 6 | //option (php).generate_setter = true; 7 | 8 | message SFixed64{ 9 | repeated sfixed64 value = 1 [packed = true]; 10 | } 11 | 12 | 13 | -------------------------------------------------------------------------------- /tests/proto/field_sint32.proto: -------------------------------------------------------------------------------- 1 | package Tutorial; 2 | 3 | import "php_options.proto"; 4 | //option (php).base_class = "Base"; 5 | option (php).generate_getter = true; 6 | option (php).generate_setter = true; 7 | 8 | message SInt32{ 9 | required sint32 value = 1; 10 | } 11 | 12 | 13 | -------------------------------------------------------------------------------- /tests/proto/field_sint32_packed.proto: -------------------------------------------------------------------------------- 1 | package Tutorial; 2 | 3 | import "php_options.proto"; 4 | //option (php).base_class = "Base"; 5 | option (php).generate_getter = true; 6 | option (php).generate_setter = true; 7 | 8 | message SignedInteger32 { 9 | repeated sint32 value = 1 [packed = true]; 10 | } 11 | 12 | 13 | -------------------------------------------------------------------------------- /tests/proto/field_sint64.proto: -------------------------------------------------------------------------------- 1 | package Tutorial; 2 | 3 | import "php_options.proto"; 4 | //option (php).base_class = "Base"; 5 | option (php).generate_getter = true; 6 | option (php).generate_setter = true; 7 | 8 | message SInt64{ 9 | required sint64 value = 1; 10 | } 11 | 12 | 13 | -------------------------------------------------------------------------------- /tests/proto/field_sint64_packed.proto: -------------------------------------------------------------------------------- 1 | package Tutorial; 2 | 3 | import "php_options.proto"; 4 | //option (php).base_class = "Base"; 5 | option (php).generate_getter = true; 6 | option (php).generate_setter = true; 7 | 8 | message SInt64{ 9 | repeated sint64 value = 1 [packed = true]; 10 | } 11 | 12 | 13 | -------------------------------------------------------------------------------- /tests/proto/field_string.proto: -------------------------------------------------------------------------------- 1 | package Tutorial; 2 | 3 | import "php_options.proto"; 4 | option (php).generate_getter = true; 5 | option (php).generate_setter = true; 6 | 7 | message String { 8 | required string value = 1; 9 | } 10 | 11 | 12 | -------------------------------------------------------------------------------- /tests/proto/field_uint32_packed.proto: -------------------------------------------------------------------------------- 1 | package Tutorial; 2 | 3 | import "php_options.proto"; 4 | //option (php).base_class = "Base"; 5 | option (php).generate_getter = true; 6 | option (php).generate_setter = true; 7 | 8 | message UInteger32 { 9 | repeated uint32 value = 1 [packed = true]; 10 | } 11 | 12 | 13 | -------------------------------------------------------------------------------- /tests/proto/has_message.proto: -------------------------------------------------------------------------------- 1 | package Tutorial; 2 | 3 | import "php_options.proto"; 4 | //option (php).base_class = "Base"; 5 | option (php).generate_getter = true; 6 | option (php).generate_setter = true; 7 | 8 | message Person { 9 | required string name = 1; 10 | required int32 id = 2; 11 | optional string email = 3; 12 | 13 | enum PhoneType { 14 | MOBILE = 0; 15 | HOME = 1; 16 | WORK = 2; 17 | } 18 | 19 | message PhoneNumber { 20 | optional PhoneType type = 1 [default = HOME]; 21 | required string number = 2; 22 | } 23 | 24 | required PhoneNumber phone = 4; 25 | } 26 | -------------------------------------------------------------------------------- /tests/proto/repeated_int32.proto: -------------------------------------------------------------------------------- 1 | package Tutorial; 2 | 3 | import "php_options.proto"; 4 | //option (php).base_class = "Base"; 5 | option (php).generate_getter = true; 6 | option (php).generate_setter = true; 7 | 8 | message RepeatedInt32{ 9 | repeated int32 value = 1; 10 | } 11 | 12 | 13 | -------------------------------------------------------------------------------- /tests/proto/repeated_string.proto: -------------------------------------------------------------------------------- 1 | package Tutorial; 2 | 3 | import "php_options.proto"; 4 | //option (php).base_class = "Base"; 5 | option (php).generate_getter = true; 6 | option (php).generate_setter = true; 7 | 8 | message RepeatedString{ 9 | repeated string values = 1; 10 | } 11 | 12 | 13 | --------------------------------------------------------------------------------