Squashed 'libs/protobuf/' content from commit fcd3b9a85

git-subtree-dir: libs/protobuf
git-subtree-split: fcd3b9a85ef36e46643dc30176cea1a7ad62e02b
This commit is contained in:
Henry Winkel
2022-10-22 14:46:58 +02:00
commit 36bca61764
2186 changed files with 838730 additions and 0 deletions

139
php/BUILD.bazel Normal file
View File

@@ -0,0 +1,139 @@
# Protobuf PHP runtime
#
# See also code generation logic under /src/google/protobuf/compiler/php.
load("@rules_pkg//:mappings.bzl", "pkg_files", "strip_prefix")
load("@upb//cmake:build_defs.bzl", "staleness_test")
load("//build_defs:internal_shell.bzl", "inline_sh_binary")
load("//conformance:defs.bzl", "conformance_test")
filegroup(
name = "source_files",
visibility = [
"//conformance:__pkg__",
"//php:__pkg__",
],
srcs = glob([
"ext/google/protobuf/*.h",
"ext/google/protobuf/*.c",
"src/GPBMetadata/Google/Protobuf/**/*.php",
"src/Google/Protobuf/**/*.php",
]) + [
"composer.json",
"ext/google/protobuf/wkt.inc",
"ext/google/protobuf/config.m4",
"ext/google/protobuf/package.xml",
],
)
################################################################################
# PHP Extension
################################################################################
inline_sh_binary(
name = "build_extension",
cmd = """
mkdir -p php/ext/google/protobuf/third_party/utf8_range
cp external/utf8_range/* php/ext/google/protobuf/third_party/utf8_range
pushd php/ext/google/protobuf
phpize
./configure --with-php-config=$$(which php-config)
make
popd
""",
)
genrule(
name = "extension",
srcs = [
":source_files",
"@utf8_range//:utf8_range_srcs",
],
tools = [":build_extension"],
outs = ["protobuf.so"],
cmd = """
./$(execpath :build_extension) $@
cp php/ext/google/protobuf/modules/protobuf.so $(OUTS)
""",
visibility = ["//visibility:public"],
)
################################################################################
# Tests
################################################################################
conformance_test(
name = "conformance_test",
failure_list = "//conformance:failure_list_php.txt",
testee = "//conformance:conformance_php",
text_format_failure_list = "//conformance:text_format_failure_list_php.txt",
target_compatible_with = select({
"@platforms//os:osx": ["@platforms//:incompatible"],
"//conditions:default": [],
}),
)
conformance_test(
name = "conformance_test_c",
failure_list = "//conformance:failure_list_php_c.txt",
testee = "//conformance:conformance_php_c",
text_format_failure_list = "//conformance:text_format_failure_list_php.txt",
target_compatible_with = select({
"@platforms//os:osx": [],
"//conditions:default": ["@platforms//:incompatible"],
}),
)
genrule(
name = "copy_php_amalgamation_h",
srcs = ["@upb//:php-upb.h"],
outs = ["generated-in/ext/google/protobuf/php-upb.h"],
cmd = "cp $< $@",
)
genrule(
name = "copy_php_amalgamation_c",
srcs = ["@upb//:php-upb.c"],
outs = ["generated-in/ext/google/protobuf/php-upb.c"],
cmd = "cp $< $@",
)
staleness_test(
name = "test_amalgamation_staleness",
outs = [
"ext/google/protobuf/php-upb.h",
"ext/google/protobuf/php-upb.c",
],
generated_pattern = "generated-in/%s",
)
################################################################################
# Distribution files
################################################################################
pkg_files(
name = "dist_files",
srcs = glob([
"ext/google/protobuf/**/*",
"tests/*.php",
"tests/*.sh",
"tests/generated_previous/**/*.php",
"tests/proto/**/*.proto",
"tests/proto_previous/*.proto",
]) + [
":source_files",
"BUILD.bazel",
"README.md",
"REFCOUNTING.md",
"composer.json",
"generate_descriptor_protos.sh",
"generate_test_protos.sh",
"release.sh",
"src/phpdoc.dist.xml",
"tests/valgrind.supp",
],
prefix = "php",
strip_prefix = strip_prefix.from_pkg(""),
visibility = ["//pkg:__pkg__"],
)

133
php/README.md Normal file
View File

@@ -0,0 +1,133 @@
This directory contains the Protocol Buffers runtime implementation via both a
pure PHP package and a native c extension. The pure PHP package is intended to
provide usability to wider range of PHP platforms, while the c extension is
intended to provide higher performance. Both implementations provide the same
runtime APIs and share the same generated code. Users dont need to re-generate
code for the same proto definition when they want to switch the implementation
later.
Both implementations make use of generated PHP code that defines message and
enum types in PHP. We strongly recommend using protoc's PHP generation support
with .proto files. The build process in this directory only installs the
extension/package; you need to install protoc as well to have PHP code
generation functionality.
## Requirements
To use PHP runtime library requires:
- C extension: PHP 7.x, 8.0
- [PHP package](http://php.net/downloads.php): PHP 5.5, 5.6, 7.x, or 8.0.
## Installation
### C Extension
#### Prerequirements
To install the c extension, the following tools are needed:
* libtool
* make
* gcc
* pear
* pecl
On Ubuntu, you can install them with:
```
sudo apt-get install -y php-pear php-dev libtool make gcc
```
On other platforms, please use the corresponding package managing tool to
install them before proceeding.
#### Installation from Source (Building extension)
To build the c extension, run the following command:
```
cd ext/google/protobuf
pear package
sudo pecl install protobuf-{VERSION}.tgz
```
#### Installation from PECL
When we release a version of Protocol Buffers, we will upload the extension to
[PECL](https://pecl.php.net/). To use this pre-packaged extension, simply
install it as you would any other extension:
```
sudo pecl install protobuf-{VERSION}
```
### PHP Package
#### Installation from composer
Simply add "google/protobuf" to the 'require' section of composer.json in your
project.
To use the pure PHP implementation, you need to install bcmath.
### Protoc
Once the extension or package is installed, if you wish to generate PHP code
from a `.proto` file, you will also want to install the Protocol Buffers
compiler (protoc), as described in this repository's main `README` file. The
version of `protoc` included in the latest release supports the `--php_out`
option to generate PHP code:
```
protoc --php_out=out_dir test.proto
```
## Usage
For generated code:
https://developers.google.com/protocol-buffers/docs/reference/php-generated
Known Issues
------------
* Missing native support for well known types.
* Missing support for proto2.
* No API provided for clear/copy messages.
* No API provided for encoding/decoding with stream.
* Map fields may not be garbage-collected if there is cycle reference.
* No debug information for messages in c extension.
* HHVM not tested.
* C extension not tested on windows, mac, php 7.0.
* Message name cannot be Empty.
## Development
### Test Native PHP
```
# Install Dependencies (Linux)
apt-get install bazel composer php-dev
# Download protobuf
git clone https://github.com/protocolbuffers/protobuf.git
cd protobuf
# Build protoc
bazel build :protoc
# Test native php
cd php
composer install
composer test
```
### Test C Extension
After you have finished testing the native php, you can test the c extension:
```
cd tests
./test.sh 5.6 # The php runtime version.
# We provide 5.5, 5.5-zts, 5.6, 5.6-zts, 7.0, 7.0-zts, 7.1, 7.1-zts, 7.2, 7.2-zts, 7.3 and 7.3-zts
# ls /usr/local for more details
```
If you want to use gdb to debug the c extension, you can do:
```
./gdb_test.sh
```

112
php/REFCOUNTING.md Normal file
View File

@@ -0,0 +1,112 @@
# Refcounting Tips
One of the trickiest parts of the C extension for PHP is getting the refcounting
right. These are some notes about the basics of what you should know,
especially if you're not super familiar with PHP's C API.
These notes cover the same general material as [the Memory Management chapter of
the PHP internal's
book](https://www.phpinternalsbook.com/php7/zvals/memory_management.html), but
calls out some points that were not immediately clear to me.
## Zvals
In the PHP C API, the `zval` type is roughly analogous to a variable in PHP, eg:
```php
// Think of $a as a "zval".
$a = [];
```
The equivalent PHP C code would be:
```c
zval a;
ZVAL_NEW_ARR(&a); // Allocates and assigns a new array.
```
PHP is reference counted, so each variable -- and thus each zval -- will have a
reference on whatever it points to (unless its holding a data type that isn't
refcounted at all, like numbers). Since the zval owns a reference, it must be
explicitly destroyed in order to release this reference.
```c
zval a;
ZVAL_NEW_ARR(&a);
// The destructor for a zval, this must be called or the ref will be leaked.
zval_ptr_dtor(&a);
```
Whenever you see a `zval`, you can assume it owns a ref (or is storing a
non-refcounted type). If you see a `zval*`, which is also quite common, then
this is *pointing to* something that owns a ref, but it does not own a ref
itself.
The [`ZVAL_*` family of
macros](https://github.com/php/php-src/blob/4030a00e8b6453aff929362bf9b25c193f72c94a/Zend/zend_types.h#L883-L1109)
initializes a `zval` from a specific value type. A few examples:
* `ZVAL_NULL(&zv)`: initializes the value to `null`
* `ZVAL_LONG(&zv, 5)`: initializes a `zend_long` (integer) value
* `ZVAL_ARR(&zv, arr)`: initializes a `zend_array*` value (refcounted)
* `ZVAL_OBJ(&zv, obj)`: initializes a `zend_object*` value (refcounted)
Note that all of our custom objects (messages, repeated fields, descriptors,
etc) are `zend_object*`.
The variants that initialize from a refcounted type do *not* increase the
refcount. This makes them suitable for initializing from a newly-created object:
```c
zval zv;
ZVAL_OBJ(&zv, CreateObject());
```
Once in a while, we want to initialize a `zval` while also increasing the
reference count. For this we can use `ZVAL_OBJ_COPY()`:
```c
zend_object *some_global;
void GetGlobal(zval *zv) {
// We want to create a new ref to an existing object.
ZVAL_OBJ_COPY(zv, some_global);
}
```
## Transferring references
A `zval`'s ref must be released at some point. While `zval_ptr_dtor()` is the
simplest way of releasing a ref, it is not the most common (at least in our code
base). More often, we are returning the `zval` back to PHP from C.
```c
zval zv;
InitializeOurZval(&zv);
// Returns the value of zv to the caller and donates our ref.
RETURN_COPY_VALUE(&zv);
```
The `RETURN_COPY_VALUE()` macro (standard in PHP 8.x, and polyfilled in earlier
versions) is the most common way we return a value back to PHP, because it
donates our `zval`'s refcount to the caller, and thus saves us from needing to
destroy our `zval` explicitly. This is ideal when we have a full `zval` to
return.
Once in a while we have a `zval*` to return instead. For example when we parse
parameters to our function and ask for a `zval`, PHP will give us pointers to
the existing `zval` structures instead of creating new ones.
```c
zval *val;
if (zend_parse_parameters(ZEND_NUM_ARGS(), "z", &val) == FAILURE) {
return;
}
// Returns a copy of this zval, adding a ref in the process.
RETURN_COPY(val);
```
When we use `RETURN_COPY`, the refcount is increased; this is perfect for
returning a `zval*` when we do not own a ref on it.

37
php/composer.json Normal file
View File

@@ -0,0 +1,37 @@
{
"name": "google/protobuf",
"type": "library",
"description": "proto library for PHP",
"keywords": ["proto"],
"homepage": "https://developers.google.com/protocol-buffers/",
"license": "BSD-3-Clause",
"require": {
"php": ">=7.0.0"
},
"require-dev": {
"phpunit/phpunit": ">=5.0.0 <8.5.27"
},
"autoload": {
"psr-4": {
"Google\\Protobuf\\": "src/Google/Protobuf",
"GPBMetadata\\Google\\Protobuf\\": "src/GPBMetadata/Google/Protobuf"
}
},
"autoload-dev": {
"psr-4": {
"": "tmp"
},
"classmap": [
"tests/generated_previous"
]
},
"scripts": {
"test_c": "./generate_test_protos.sh && ./tests/compile_extension.sh && php -dextension=ext/google/protobuf/modules/protobuf.so vendor/bin/phpunit --bootstrap tests/force_c_ext.php tests",
"test_valgrind": "./generate_test_protos.sh && ./tests/compile_extension.sh && ZEND_DONT_UNLOAD_MODULES=1 USE_ZEND_ALLOC=0 valgrind --leak-check=full --error-exitcode=1 php -dextension=ext/google/protobuf/modules/protobuf.so vendor/bin/phpunit --bootstrap tests/force_c_ext.php tests",
"test": "./generate_test_protos.sh && vendor/bin/phpunit tests",
"aggregate_metadata_test": "./generate_test_protos.sh --aggregate_metadata && vendor/bin/phpunit tests"
},
"config": {
"process-timeout": 1200
}
}

23
php/composer.json.dist Normal file
View File

@@ -0,0 +1,23 @@
{
"name": "google/protobuf",
"type": "library",
"description": "proto library for PHP",
"keywords": ["proto"],
"homepage": "https://developers.google.com/protocol-buffers/",
"license": "BSD-3-Clause",
"require": {
"php": ">=7.0.0"
},
"require-dev": {
"phpunit/phpunit": ">=5.0.0"
},
"suggest": {
"ext-bcmath": "Need to support JSON deserialization"
},
"autoload": {
"psr-4": {
"Google\\Protobuf\\": "src/Google/Protobuf",
"GPBMetadata\\Google\\Protobuf\\": "src/GPBMetadata/Google/Protobuf"
}
}
}

View File

@@ -0,0 +1,95 @@
// Protocol Buffers - Google's data interchange format
// Copyright 2008 Google Inc. All rights reserved.
// https://developers.google.com/protocol-buffers/
//
// Redistribution and use in source and binary forms, with or without
// modification, are permitted provided that the following conditions are
// met:
//
// * Redistributions of source code must retain the above copyright
// notice, this list of conditions and the following disclaimer.
// * Redistributions in binary form must reproduce the above
// copyright notice, this list of conditions and the following disclaimer
// in the documentation and/or other materials provided with the
// distribution.
// * Neither the name of Google Inc. nor the names of its
// contributors may be used to endorse or promote products derived from
// this software without specific prior written permission.
//
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
#include <Zend/zend_API.h>
#include "php-upb.h"
// -----------------------------------------------------------------------------
// Arena
// -----------------------------------------------------------------------------
typedef struct Arena {
zend_object std;
upb_Arena* arena;
} Arena;
zend_class_entry *Arena_class_entry;
static zend_object_handlers Arena_object_handlers;
// PHP Object Handlers /////////////////////////////////////////////////////////
static zend_object* Arena_Create(zend_class_entry *class_type) {
Arena *intern = emalloc(sizeof(Arena));
zend_object_std_init(&intern->std, class_type);
intern->std.handlers = &Arena_object_handlers;
intern->arena = upb_Arena_New();
// Skip object_properties_init(), we don't allow derived classes.
return &intern->std;
}
static void Arena_Free(zend_object* obj) {
Arena* intern = (Arena*)obj;
upb_Arena_Free(intern->arena);
zend_object_std_dtor(&intern->std);
}
// C Functions from arena.h ////////////////////////////////////////////////////
void Arena_Init(zval* val) {
ZVAL_OBJ(val, Arena_Create(Arena_class_entry));
}
upb_Arena *Arena_Get(zval *val) {
Arena *a = (Arena*)Z_OBJ_P(val);
return a->arena;
}
// -----------------------------------------------------------------------------
// Module init.
// -----------------------------------------------------------------------------
// No public methods.
static const zend_function_entry Arena_methods[] = {
ZEND_FE_END
};
void Arena_ModuleInit() {
zend_class_entry tmp_ce;
INIT_CLASS_ENTRY(tmp_ce, "Google\\Protobuf\\Internal\\Arena", Arena_methods);
Arena_class_entry = zend_register_internal_class(&tmp_ce);
Arena_class_entry->create_object = Arena_Create;
Arena_class_entry->ce_flags |= ZEND_ACC_FINAL;
memcpy(&Arena_object_handlers, &std_object_handlers,
sizeof(zend_object_handlers));
Arena_object_handlers.free_obj = Arena_Free;
}

View File

@@ -0,0 +1,47 @@
// Protocol Buffers - Google's data interchange format
// Copyright 2008 Google Inc. All rights reserved.
// https://developers.google.com/protocol-buffers/
//
// Redistribution and use in source and binary forms, with or without
// modification, are permitted provided that the following conditions are
// met:
//
// * Redistributions of source code must retain the above copyright
// notice, this list of conditions and the following disclaimer.
// * Redistributions in binary form must reproduce the above
// copyright notice, this list of conditions and the following disclaimer
// in the documentation and/or other materials provided with the
// distribution.
// * Neither the name of Google Inc. nor the names of its
// contributors may be used to endorse or promote products derived from
// this software without specific prior written permission.
//
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
#ifndef PHP_PROTOBUF_ARENA_H_
#define PHP_PROTOBUF_ARENA_H_
#include <php.h>
#include "php-upb.h"
// Registers the PHP Arena class.
void Arena_ModuleInit();
// Creates and returns a new arena object that wraps a new upb_Arena*.
void Arena_Init(zval *val);
// Gets the underlying upb_Arena from this arena object.
upb_Arena *Arena_Get(zval *arena);
#endif // PHP_PROTOBUF_ARENA_H_

View File

@@ -0,0 +1,701 @@
// Protocol Buffers - Google's data interchange format
// Copyright 2008 Google Inc. All rights reserved.
// https://developers.google.com/protocol-buffers/
//
// Redistribution and use in source and binary forms, with or without
// modification, are permitted provided that the following conditions are
// met:
//
// * Redistributions of source code must retain the above copyright
// notice, this list of conditions and the following disclaimer.
// * Redistributions in binary form must reproduce the above
// copyright notice, this list of conditions and the following disclaimer
// in the documentation and/or other materials provided with the
// distribution.
// * Neither the name of Google Inc. nor the names of its
// contributors may be used to endorse or promote products derived from
// this software without specific prior written permission.
//
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
#include "array.h"
#include <Zend/zend_API.h>
#include <Zend/zend_interfaces.h>
#include <ext/spl/spl_iterators.h>
// This is not self-contained: it must be after other Zend includes.
#include <Zend/zend_exceptions.h>
#include "arena.h"
#include "convert.h"
#include "def.h"
#include "message.h"
#include "php-upb.h"
#include "protobuf.h"
static void RepeatedFieldIter_make(zval *val, zval *repeated_field);
// -----------------------------------------------------------------------------
// RepeatedField
// -----------------------------------------------------------------------------
typedef struct {
zend_object std;
zval arena;
upb_Array *array;
TypeInfo type;
} RepeatedField;
zend_class_entry *RepeatedField_class_entry;
static zend_object_handlers RepeatedField_object_handlers;
// PHP Object Handlers /////////////////////////////////////////////////////////
/**
* RepeatedField_create()
*
* PHP class entry function to allocate and initialize a new RepeatedField
* object.
*/
static zend_object* RepeatedField_create(zend_class_entry *class_type) {
RepeatedField *intern = emalloc(sizeof(RepeatedField));
zend_object_std_init(&intern->std, class_type);
intern->std.handlers = &RepeatedField_object_handlers;
Arena_Init(&intern->arena);
intern->array = NULL;
// Skip object_properties_init(), we don't allow derived classes.
return &intern->std;
}
/**
* RepeatedField_dtor()
*
* Object handler to destroy a RepeatedField. This releases all resources
* associated with the message. Note that it is possible to access a destroyed
* object from PHP in rare cases.
*/
static void RepeatedField_destructor(zend_object* obj) {
RepeatedField* intern = (RepeatedField*)obj;
ObjCache_Delete(intern->array);
zval_ptr_dtor(&intern->arena);
zend_object_std_dtor(&intern->std);
}
/**
* RepeatedField_compare_objects()
*
* Object handler for comparing two repeated field objects. Called whenever PHP
* code does:
*
* $rf1 == $rf2
*/
static int RepeatedField_compare_objects(zval *rf1, zval *rf2) {
RepeatedField* intern1 = (RepeatedField*)Z_OBJ_P(rf1);
RepeatedField* intern2 = (RepeatedField*)Z_OBJ_P(rf2);
return TypeInfo_Eq(intern1->type, intern2->type) &&
ArrayEq(intern1->array, intern2->array, intern1->type)
? 0
: 1;
}
/**
* RepeatedField_clone_obj()
*
* Object handler for cloning an object in PHP. Called when PHP code does:
*
* $rf2 = clone $rf1;
*/
static zend_object *RepeatedField_clone_obj(PROTO_VAL *object) {
RepeatedField* intern = PROTO_VAL_P(object);
upb_Arena *arena = Arena_Get(&intern->arena);
upb_Array *clone = upb_Array_New(arena, intern->type.type);
size_t n = upb_Array_Size(intern->array);
size_t i;
for (i = 0; i < n; i++) {
upb_MessageValue msgval = upb_Array_Get(intern->array, i);
upb_Array_Append(clone, msgval, arena);
}
zval ret;
RepeatedField_GetPhpWrapper(&ret, clone, intern->type, &intern->arena);
return Z_OBJ_P(&ret);
}
static HashTable *RepeatedField_GetProperties(PROTO_VAL *object) {
return NULL; // We do not have a properties table.
}
static zval *RepeatedField_GetPropertyPtrPtr(PROTO_VAL *object,
PROTO_STR *member,
int type, void **cache_slot) {
return NULL; // We don't offer direct references to our properties.
}
// C Functions from array.h ////////////////////////////////////////////////////
// These are documented in the header file.
void RepeatedField_GetPhpWrapper(zval *val, upb_Array *arr, TypeInfo type,
zval *arena) {
if (!arr) {
ZVAL_NULL(val);
return;
}
if (!ObjCache_Get(arr, val)) {
RepeatedField *intern = emalloc(sizeof(RepeatedField));
zend_object_std_init(&intern->std, RepeatedField_class_entry);
intern->std.handlers = &RepeatedField_object_handlers;
ZVAL_COPY(&intern->arena, arena);
intern->array = arr;
intern->type = type;
// Skip object_properties_init(), we don't allow derived classes.
ObjCache_Add(intern->array, &intern->std);
ZVAL_OBJ(val, &intern->std);
}
}
upb_Array *RepeatedField_GetUpbArray(zval *val, TypeInfo type,
upb_Arena *arena) {
if (Z_ISREF_P(val)) {
ZVAL_DEREF(val);
}
if (Z_TYPE_P(val) == IS_ARRAY) {
// Auto-construct, eg. [1, 2, 3] -> upb_Array([1, 2, 3]).
upb_Array *arr = upb_Array_New(arena, type.type);
HashTable *table = HASH_OF(val);
HashPosition pos;
zend_hash_internal_pointer_reset_ex(table, &pos);
while (true) {
zval *zv = zend_hash_get_current_data_ex(table, &pos);
upb_MessageValue val;
if (!zv) return arr;
if (!Convert_PhpToUpbAutoWrap(zv, &val, type, arena)) {
return NULL;
}
upb_Array_Append(arr, val, arena);
zend_hash_move_forward_ex(table, &pos);
}
} else if (Z_TYPE_P(val) == IS_OBJECT &&
Z_OBJCE_P(val) == RepeatedField_class_entry) {
// Unwrap existing RepeatedField object to get the upb_Array* inside.
RepeatedField *intern = (RepeatedField*)Z_OBJ_P(val);
if (!TypeInfo_Eq(intern->type, type)) {
php_error_docref(NULL, E_USER_ERROR,
"Wrong type for this repeated field.");
}
upb_Arena_Fuse(arena, Arena_Get(&intern->arena));
return intern->array;
} else {
php_error_docref(NULL, E_USER_ERROR, "Must be a repeated field");
return NULL;
}
}
bool ArrayEq(const upb_Array *a1, const upb_Array *a2, TypeInfo type) {
size_t i;
size_t n;
if ((a1 == NULL) != (a2 == NULL)) return false;
if (a1 == NULL) return true;
n = upb_Array_Size(a1);
if (n != upb_Array_Size(a2)) return false;
for (i = 0; i < n; i++) {
upb_MessageValue val1 = upb_Array_Get(a1, i);
upb_MessageValue val2 = upb_Array_Get(a2, i);
if (!ValueEq(val1, val2, type)) return false;
}
return true;
}
// RepeatedField PHP methods ///////////////////////////////////////////////////
/**
* RepeatedField::__construct()
*
* Constructs an instance of RepeatedField.
* @param long Type of the stored element.
* @param string Message/Enum class.
*/
PHP_METHOD(RepeatedField, __construct) {
RepeatedField *intern = (RepeatedField*)Z_OBJ_P(getThis());
upb_Arena *arena = Arena_Get(&intern->arena);
zend_long type;
zend_class_entry* klass = NULL;
if (zend_parse_parameters(ZEND_NUM_ARGS(), "l|C", &type, &klass) != SUCCESS) {
return;
}
intern->type.type = pbphp_dtype_to_type(type);
intern->type.desc = Descriptor_GetFromClassEntry(klass);
if (intern->type.type == kUpb_CType_Message && klass == NULL) {
php_error_docref(NULL, E_USER_ERROR,
"Message/enum type must have concrete class.");
return;
}
intern->array = upb_Array_New(arena, intern->type.type);
ObjCache_Add(intern->array, &intern->std);
}
/**
* RepeatedField::append()
*
* Append element to the end of the repeated field.
* @param object The element to be added.
*/
PHP_METHOD(RepeatedField, append) {
RepeatedField *intern = (RepeatedField*)Z_OBJ_P(getThis());
upb_Arena *arena = Arena_Get(&intern->arena);
zval *php_val;
upb_MessageValue msgval;
if (zend_parse_parameters(ZEND_NUM_ARGS(), "z", &php_val) != SUCCESS ||
!Convert_PhpToUpb(php_val, &msgval, intern->type, arena)) {
return;
}
upb_Array_Append(intern->array, msgval, arena);
}
/**
* RepeatedField::offsetExists(): bool
*
* Implements the ArrayAccess interface. Invoked when PHP code calls:
*
* isset($arr[$idx]);
* empty($arr[$idx]);
*
* @param long The index to be checked.
* @return bool True if the element at the given index exists.
*/
PHP_METHOD(RepeatedField, offsetExists) {
RepeatedField *intern = (RepeatedField*)Z_OBJ_P(getThis());
zend_long index;
if (zend_parse_parameters(ZEND_NUM_ARGS(), "l", &index) == FAILURE) {
return;
}
RETURN_BOOL(index >= 0 && index < upb_Array_Size(intern->array));
}
/**
* RepeatedField::offsetGet(): mixed
*
* Implements the ArrayAccess interface. Invoked when PHP code calls:
*
* $x = $arr[$idx];
*
* @param long The index of the element to be fetched.
* @return object The stored element at given index.
* @exception Invalid type for index.
* @exception Non-existing index.
*/
PHP_METHOD(RepeatedField, offsetGet) {
RepeatedField *intern = (RepeatedField*)Z_OBJ_P(getThis());
zend_long index;
upb_MessageValue msgval;
zval ret;
if (zend_parse_parameters(ZEND_NUM_ARGS(), "l", &index) == FAILURE) {
return;
}
if (index < 0 || index >= upb_Array_Size(intern->array)) {
zend_error(E_USER_ERROR, "Element at %ld doesn't exist.\n", index);
return;
}
msgval = upb_Array_Get(intern->array, index);
Convert_UpbToPhp(msgval, &ret, intern->type, &intern->arena);
RETURN_COPY_VALUE(&ret);
}
/**
* RepeatedField::offsetSet(): void
*
* Implements the ArrayAccess interface. Invoked when PHP code calls:
*
* $arr[$idx] = $x;
* $arr []= $x; // Append
*
* @param long The index of the element to be assigned.
* @param object The element to be assigned.
* @exception Invalid type for index.
* @exception Non-existing index.
* @exception Incorrect type of the element.
*/
PHP_METHOD(RepeatedField, offsetSet) {
RepeatedField *intern = (RepeatedField*)Z_OBJ_P(getThis());
upb_Arena *arena = Arena_Get(&intern->arena);
size_t size = upb_Array_Size(intern->array);
zval *offset, *val;
int64_t index;
upb_MessageValue msgval;
if (zend_parse_parameters(ZEND_NUM_ARGS(), "zz", &offset, &val) != SUCCESS) {
return;
}
if (Z_TYPE_P(offset) == IS_NULL) {
index = size;
} else if (!Convert_PhpToInt64(offset, &index)) {
return;
}
if (!Convert_PhpToUpb(val, &msgval, intern->type, arena)) {
return;
}
if (index > size) {
zend_error(E_USER_ERROR, "Element at index %ld doesn't exist.\n", index);
} else if (index == size) {
upb_Array_Append(intern->array, msgval, Arena_Get(&intern->arena));
} else {
upb_Array_Set(intern->array, index, msgval);
}
}
/**
* RepeatedField::offsetUnset(): void
*
* Implements the ArrayAccess interface. Invoked when PHP code calls:
*
* unset($arr[$idx]);
*
* @param long The index of the element to be removed.
* @exception Invalid type for index.
* @exception The element to be removed is not at the end of the RepeatedField.
*/
PHP_METHOD(RepeatedField, offsetUnset) {
RepeatedField *intern = (RepeatedField*)Z_OBJ_P(getThis());
zend_long index;
zend_long size = upb_Array_Size(intern->array);
// Only the element at the end of the array can be removed.
if (zend_parse_parameters(ZEND_NUM_ARGS(), "l", &index) != SUCCESS) {
return;
}
if (size == 0 || index != size - 1) {
php_error_docref(NULL, E_USER_ERROR, "Cannot remove element at %ld.\n",
index);
return;
}
upb_Array_Resize(intern->array, size - 1, Arena_Get(&intern->arena));
}
/**
* RepeatedField::count(): int
*
* Implements the Countable interface. Invoked when PHP code calls:
*
* $len = count($arr);
* Return the number of stored elements.
* This will also be called for: count($arr)
* @return long The number of stored elements.
*/
PHP_METHOD(RepeatedField, count) {
RepeatedField *intern = (RepeatedField*)Z_OBJ_P(getThis());
if (zend_parse_parameters_none() == FAILURE) {
return;
}
RETURN_LONG(upb_Array_Size(intern->array));
}
/**
* RepeatedField::getIterator(): Traversable
*
* Implements the IteratorAggregate interface. Invoked when PHP code calls:
*
* foreach ($arr) {}
*
* @return object Beginning iterator.
*/
PHP_METHOD(RepeatedField, getIterator) {
zval ret;
RepeatedFieldIter_make(&ret, getThis());
RETURN_COPY_VALUE(&ret);
}
ZEND_BEGIN_ARG_INFO_EX(arginfo_construct, 0, 0, 1)
ZEND_ARG_INFO(0, type)
ZEND_ARG_INFO(0, class)
ZEND_END_ARG_INFO()
ZEND_BEGIN_ARG_INFO_EX(arginfo_append, 0, 0, 1)
ZEND_ARG_INFO(0, newval)
ZEND_END_ARG_INFO()
PROTOBUF_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_offsetExists, 0, 0, _IS_BOOL, 0)
ZEND_ARG_INFO(0, index)
ZEND_END_ARG_INFO()
ZEND_BEGIN_ARG_WITH_TENTATIVE_RETURN_TYPE_INFO_EX(arginfo_offsetGet, 0, 0, IS_MIXED, 1)
ZEND_ARG_INFO(0, index)
ZEND_END_ARG_INFO()
PROTOBUF_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_offsetSet, 0, 2, IS_VOID, 0)
ZEND_ARG_INFO(0, index)
ZEND_ARG_INFO(0, newval)
ZEND_END_ARG_INFO()
PROTOBUF_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_offsetUnset, 0, 0, IS_VOID, 0)
ZEND_ARG_INFO(0, index)
ZEND_END_ARG_INFO()
PROTOBUF_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_count, 0, 0, IS_LONG, 0)
ZEND_END_ARG_INFO()
ZEND_BEGIN_ARG_WITH_RETURN_OBJ_INFO_EX(arginfo_getIterator, 0, 0, Traversable, 0)
ZEND_END_ARG_INFO()
static zend_function_entry repeated_field_methods[] = {
PHP_ME(RepeatedField, __construct, arginfo_construct, ZEND_ACC_PUBLIC)
PHP_ME(RepeatedField, append, arginfo_append, ZEND_ACC_PUBLIC)
PHP_ME(RepeatedField, offsetExists, arginfo_offsetExists, ZEND_ACC_PUBLIC)
PHP_ME(RepeatedField, offsetGet, arginfo_offsetGet, ZEND_ACC_PUBLIC)
PHP_ME(RepeatedField, offsetSet, arginfo_offsetSet, ZEND_ACC_PUBLIC)
PHP_ME(RepeatedField, offsetUnset, arginfo_offsetUnset, ZEND_ACC_PUBLIC)
PHP_ME(RepeatedField, count, arginfo_count, ZEND_ACC_PUBLIC)
PHP_ME(RepeatedField, getIterator, arginfo_getIterator, ZEND_ACC_PUBLIC)
ZEND_FE_END
};
// -----------------------------------------------------------------------------
// PHP RepeatedFieldIter
// -----------------------------------------------------------------------------
typedef struct {
zend_object std;
zval repeated_field;
zend_long position;
} RepeatedFieldIter;
zend_class_entry *RepeatedFieldIter_class_entry;
static zend_object_handlers repeated_field_iter_object_handlers;
/**
* RepeatedFieldIter_create()
*
* PHP class entry function to allocate and initialize a new RepeatedFieldIter
* object.
*/
zend_object* RepeatedFieldIter_create(zend_class_entry *class_type) {
RepeatedFieldIter *intern = emalloc(sizeof(RepeatedFieldIter));
zend_object_std_init(&intern->std, class_type);
intern->std.handlers = &repeated_field_iter_object_handlers;
ZVAL_NULL(&intern->repeated_field);
intern->position = 0;
// Skip object_properties_init(), we don't allow derived classes.
return &intern->std;
}
/**
* RepeatedFieldIter_dtor()
*
* Object handler to destroy a RepeatedFieldIter. This releases all resources
* associated with the message. Note that it is possible to access a destroyed
* object from PHP in rare cases.
*/
static void RepeatedFieldIter_dtor(zend_object* obj) {
RepeatedFieldIter* intern = (RepeatedFieldIter*)obj;
zval_ptr_dtor(&intern->repeated_field);
zend_object_std_dtor(&intern->std);
}
/**
* RepeatedFieldIter_make()
*
* C function to create a RepeatedFieldIter.
*/
static void RepeatedFieldIter_make(zval *val, zval *repeated_field) {
RepeatedFieldIter *iter;
ZVAL_OBJ(val, RepeatedFieldIter_class_entry->create_object(
RepeatedFieldIter_class_entry));
iter = (RepeatedFieldIter*)Z_OBJ_P(val);
ZVAL_COPY(&iter->repeated_field, repeated_field);
}
/*
* When a user writes:
*
* foreach($arr as $key => $val) {}
*
* PHP's iterator protocol is:
*
* $iter = $arr->getIterator();
* for ($iter->rewind(); $iter->valid(); $iter->next()) {
* $key = $iter->key();
* $val = $iter->current();
* }
*/
/**
* RepeatedFieldIter::rewind(): void
*
* Implements the Iterator interface. Sets the iterator to the first element.
*/
PHP_METHOD(RepeatedFieldIter, rewind) {
RepeatedFieldIter *intern = (RepeatedFieldIter*)Z_OBJ_P(getThis());
intern->position = 0;
}
/**
* RepeatedFieldIter::current(): mixed
*
* Implements the Iterator interface. Returns the current value.
*/
PHP_METHOD(RepeatedFieldIter, current) {
RepeatedFieldIter *intern = (RepeatedFieldIter*)Z_OBJ_P(getThis());
RepeatedField *field = (RepeatedField*)Z_OBJ_P(&intern->repeated_field);
upb_Array *array = field->array;
zend_long index = intern->position;
upb_MessageValue msgval;
zval ret;
if (index < 0 || index >= upb_Array_Size(array)) {
zend_error(E_USER_ERROR, "Element at %ld doesn't exist.\n", index);
}
msgval = upb_Array_Get(array, index);
Convert_UpbToPhp(msgval, &ret, field->type, &field->arena);
RETURN_COPY_VALUE(&ret);
}
/**
* RepeatedFieldIter::key(): mixed
*
* Implements the Iterator interface. Returns the current key.
*/
PHP_METHOD(RepeatedFieldIter, key) {
RepeatedFieldIter *intern = (RepeatedFieldIter*)Z_OBJ_P(getThis());
RETURN_LONG(intern->position);
}
/**
* RepeatedFieldIter::next(): void
*
* Implements the Iterator interface. Advances to the next element.
*/
PHP_METHOD(RepeatedFieldIter, next) {
RepeatedFieldIter *intern = (RepeatedFieldIter*)Z_OBJ_P(getThis());
++intern->position;
}
/**
* RepeatedFieldIter::valid(): bool
*
* Implements the Iterator interface. Returns true if this is a valid element.
*/
PHP_METHOD(RepeatedFieldIter, valid) {
RepeatedFieldIter *intern = (RepeatedFieldIter*)Z_OBJ_P(getThis());
RepeatedField *field = (RepeatedField*)Z_OBJ_P(&intern->repeated_field);
RETURN_BOOL(intern->position < upb_Array_Size(field->array));
}
ZEND_BEGIN_ARG_WITH_TENTATIVE_RETURN_TYPE_INFO_EX(arginfo_current, 0, 0, IS_MIXED, 0)
ZEND_END_ARG_INFO()
ZEND_BEGIN_ARG_WITH_TENTATIVE_RETURN_TYPE_INFO_EX(arginfo_key, 0, 0, IS_MIXED, 0)
ZEND_END_ARG_INFO()
PROTOBUF_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_next, 0, 0, IS_VOID, 0)
ZEND_END_ARG_INFO()
PROTOBUF_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_valid, 0, 0, _IS_BOOL, 0)
ZEND_END_ARG_INFO()
PROTOBUF_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_rewind, 0, 0, IS_VOID, 0)
ZEND_END_ARG_INFO()
static zend_function_entry repeated_field_iter_methods[] = {
PHP_ME(RepeatedFieldIter, rewind, arginfo_rewind, ZEND_ACC_PUBLIC)
PHP_ME(RepeatedFieldIter, current, arginfo_current, ZEND_ACC_PUBLIC)
PHP_ME(RepeatedFieldIter, key, arginfo_key, ZEND_ACC_PUBLIC)
PHP_ME(RepeatedFieldIter, next, arginfo_next, ZEND_ACC_PUBLIC)
PHP_ME(RepeatedFieldIter, valid, arginfo_valid, ZEND_ACC_PUBLIC)
ZEND_FE_END
};
// -----------------------------------------------------------------------------
// Module init.
// -----------------------------------------------------------------------------
/**
* Array_ModuleInit()
*
* Called when the C extension is loaded to register all types.
*/
void Array_ModuleInit() {
zend_class_entry tmp_ce;
zend_object_handlers *h;
// RepeatedField.
INIT_CLASS_ENTRY(tmp_ce, "Google\\Protobuf\\Internal\\RepeatedField",
repeated_field_methods);
RepeatedField_class_entry = zend_register_internal_class(&tmp_ce);
zend_class_implements(RepeatedField_class_entry, 3, zend_ce_arrayaccess,
zend_ce_aggregate, zend_ce_countable);
RepeatedField_class_entry->ce_flags |= ZEND_ACC_FINAL;
RepeatedField_class_entry->create_object = RepeatedField_create;
h = &RepeatedField_object_handlers;
memcpy(h, &std_object_handlers, sizeof(zend_object_handlers));
h->dtor_obj = RepeatedField_destructor;
#if PHP_VERSION_ID < 80000
h->compare_objects = RepeatedField_compare_objects;
#else
h->compare = RepeatedField_compare_objects;
#endif
h->clone_obj = RepeatedField_clone_obj;
h->get_properties = RepeatedField_GetProperties;
h->get_property_ptr_ptr = RepeatedField_GetPropertyPtrPtr;
// RepeatedFieldIter
INIT_CLASS_ENTRY(tmp_ce, "Google\\Protobuf\\Internal\\RepeatedFieldIter",
repeated_field_iter_methods);
RepeatedFieldIter_class_entry = zend_register_internal_class(&tmp_ce);
zend_class_implements(RepeatedFieldIter_class_entry, 1, zend_ce_iterator);
RepeatedFieldIter_class_entry->ce_flags |= ZEND_ACC_FINAL;
RepeatedFieldIter_class_entry->create_object = RepeatedFieldIter_create;
h = &repeated_field_iter_object_handlers;
memcpy(h, &std_object_handlers, sizeof(zend_object_handlers));
h->dtor_obj = RepeatedFieldIter_dtor;
}

View File

@@ -0,0 +1,67 @@
// Protocol Buffers - Google's data interchange format
// Copyright 2008 Google Inc. All rights reserved.
// https://developers.google.com/protocol-buffers/
//
// Redistribution and use in source and binary forms, with or without
// modification, are permitted provided that the following conditions are
// met:
//
// * Redistributions of source code must retain the above copyright
// notice, this list of conditions and the following disclaimer.
// * Redistributions in binary form must reproduce the above
// copyright notice, this list of conditions and the following disclaimer
// in the documentation and/or other materials provided with the
// distribution.
// * Neither the name of Google Inc. nor the names of its
// contributors may be used to endorse or promote products derived from
// this software without specific prior written permission.
//
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
#ifndef PHP_PROTOBUF_ARRAY_H_
#define PHP_PROTOBUF_ARRAY_H_
#include <php.h>
#include "def.h"
#include "php-upb.h"
// Registers PHP classes for RepeatedField.
void Array_ModuleInit();
// Gets a upb_Array* for the PHP object |val|:
// * If |val| is a RepeatedField object, we first check its type and verify
// that that the elements have the correct type for |type|. If so, we return
// the wrapped upb_Array*. We also make sure that this array's arena is fused
// to |arena|, so the returned upb_Array is guaranteed to live as long as
// |arena|.
// * If |val| is a PHP Array, we attempt to create a new upb_Array using
// |arena| and add all of the PHP elements to it.
//
// If an error occurs, we raise a PHP error and return NULL.
upb_Array *RepeatedField_GetUpbArray(zval *val, TypeInfo type,
upb_Arena *arena);
// Creates a PHP RepeatedField object for the given upb_Array* and |type| and
// returns it in |val|. The PHP object will keep a reference to this |arena| to
// ensure the underlying array data stays alive.
//
// If |arr| is NULL, this will return a PHP null object.
void RepeatedField_GetPhpWrapper(zval *val, upb_Array *arr, TypeInfo type,
zval *arena);
// Returns true if the given arrays are equal. Both arrays must be of this
// |type| and, if the type is |kUpb_CType_Message|, must have the same |m|.
bool ArrayEq(const upb_Array *a1, const upb_Array *a2, TypeInfo type);
#endif // PHP_PROTOBUF_ARRAY_H_

View File

@@ -0,0 +1,11 @@
PHP_ARG_ENABLE(protobuf, whether to enable Protobuf extension, [ --enable-protobuf Enable Protobuf extension])
if test "$PHP_PROTOBUF" != "no"; then
PHP_NEW_EXTENSION(
protobuf,
arena.c array.c convert.c def.c map.c message.c names.c php-upb.c protobuf.c third_party/utf8_range/naive.c third_party/utf8_range/range2-neon.c third_party/utf8_range/range2-sse.c,
$ext_shared, , -std=gnu99)
PHP_ADD_BUILD_DIR($ext_builddir/third_party/utf8_range)
fi

View File

@@ -0,0 +1,536 @@
// Protocol Buffers - Google's data interchange format
// Copyright 2008 Google Inc. All rights reserved.
// https://developers.google.com/protocol-buffers/
//
// Redistribution and use in source and binary forms, with or without
// modification, are permitted provided that the following conditions are
// met:
//
// * Redistributions of source code must retain the above copyright
// notice, this list of conditions and the following disclaimer.
// * Redistributions in binary form must reproduce the above
// copyright notice, this list of conditions and the following disclaimer
// in the documentation and/or other materials provided with the
// distribution.
// * Neither the name of Google Inc. nor the names of its
// contributors may be used to endorse or promote products derived from
// this software without specific prior written permission.
//
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
#include "convert.h"
#include <php.h>
// This is not self-contained: it must be after other Zend includes.
#include <Zend/zend_exceptions.h>
#include "array.h"
#include "map.h"
#include "message.h"
#include "php-upb.h"
#include "protobuf.h"
// -----------------------------------------------------------------------------
// GPBUtil
// -----------------------------------------------------------------------------
static zend_class_entry* GPBUtil_class_entry;
// The implementation of type checking for primitive fields is empty. This is
// because type checking is done when direct assigning message fields (e.g.,
// foo->a = 1). Functions defined here are place holders in generated code for
// pure PHP implementation (c extension and pure PHP share the same generated
// code).
PHP_METHOD(Util, checkInt32) {}
PHP_METHOD(Util, checkUint32) {}
PHP_METHOD(Util, checkInt64) {}
PHP_METHOD(Util, checkUint64) {}
PHP_METHOD(Util, checkEnum) {}
PHP_METHOD(Util, checkFloat) {}
PHP_METHOD(Util, checkDouble) {}
PHP_METHOD(Util, checkBool) {}
PHP_METHOD(Util, checkString) {}
PHP_METHOD(Util, checkBytes) {}
PHP_METHOD(Util, checkMessage) {}
// The result of checkMapField() is assigned, so we need to return the first
// param:
// $arr = GPBUtil::checkMapField($var,
// \Google\Protobuf\Internal\GPBType::INT64,
// \Google\Protobuf\Internal\GPBType::INT32);
PHP_METHOD(Util, checkMapField) {
zval *val, *key_type, *val_type, *klass;
if (zend_parse_parameters(ZEND_NUM_ARGS(), "zzz|z", &val, &key_type,
&val_type, &klass) == FAILURE) {
return;
}
RETURN_COPY(val);
}
// The result of checkRepeatedField() is assigned, so we need to return the
// first param:
// $arr = GPBUtil::checkRepeatedField(
// $var, \Google\Protobuf\Internal\GPBType::STRING);
PHP_METHOD(Util, checkRepeatedField) {
zval *val, *type, *klass;
if (zend_parse_parameters(ZEND_NUM_ARGS(), "zz|z", &val, &type, &klass) ==
FAILURE) {
return;
}
RETURN_COPY(val);
}
ZEND_BEGIN_ARG_INFO_EX(arginfo_checkPrimitive, 0, 0, 1)
ZEND_ARG_INFO(0, value)
ZEND_END_ARG_INFO()
ZEND_BEGIN_ARG_INFO_EX(arginfo_checkString, 0, 0, 1)
ZEND_ARG_INFO(0, value)
ZEND_ARG_INFO(0, check_utf8)
ZEND_END_ARG_INFO()
ZEND_BEGIN_ARG_INFO_EX(arginfo_checkMessage, 0, 0, 2)
ZEND_ARG_INFO(0, value)
ZEND_ARG_INFO(0, class)
ZEND_END_ARG_INFO()
ZEND_BEGIN_ARG_INFO_EX(arginfo_checkMapField, 0, 0, 3)
ZEND_ARG_INFO(0, value)
ZEND_ARG_INFO(0, key_type)
ZEND_ARG_INFO(0, value_type)
ZEND_ARG_INFO(0, value_class)
ZEND_END_ARG_INFO()
ZEND_BEGIN_ARG_INFO_EX(arginfo_checkRepeatedField, 0, 0, 2)
ZEND_ARG_INFO(0, value)
ZEND_ARG_INFO(0, type)
ZEND_ARG_INFO(0, class)
ZEND_END_ARG_INFO()
static zend_function_entry util_methods[] = {
PHP_ME(Util, checkInt32, arginfo_checkPrimitive,
ZEND_ACC_PUBLIC|ZEND_ACC_STATIC)
PHP_ME(Util, checkUint32, arginfo_checkPrimitive,
ZEND_ACC_PUBLIC|ZEND_ACC_STATIC)
PHP_ME(Util, checkInt64, arginfo_checkPrimitive,
ZEND_ACC_PUBLIC|ZEND_ACC_STATIC)
PHP_ME(Util, checkUint64, arginfo_checkPrimitive,
ZEND_ACC_PUBLIC|ZEND_ACC_STATIC)
PHP_ME(Util, checkEnum, arginfo_checkMessage,
ZEND_ACC_PUBLIC|ZEND_ACC_STATIC)
PHP_ME(Util, checkFloat, arginfo_checkPrimitive,
ZEND_ACC_PUBLIC|ZEND_ACC_STATIC)
PHP_ME(Util, checkDouble, arginfo_checkPrimitive,
ZEND_ACC_PUBLIC|ZEND_ACC_STATIC)
PHP_ME(Util, checkBool, arginfo_checkPrimitive,
ZEND_ACC_PUBLIC|ZEND_ACC_STATIC)
PHP_ME(Util, checkString, arginfo_checkString,
ZEND_ACC_PUBLIC|ZEND_ACC_STATIC)
PHP_ME(Util, checkBytes, arginfo_checkPrimitive,
ZEND_ACC_PUBLIC|ZEND_ACC_STATIC)
PHP_ME(Util, checkMessage, arginfo_checkMessage,
ZEND_ACC_PUBLIC|ZEND_ACC_STATIC)
PHP_ME(Util, checkMapField, arginfo_checkMapField,
ZEND_ACC_PUBLIC|ZEND_ACC_STATIC)
PHP_ME(Util, checkRepeatedField, arginfo_checkRepeatedField,
ZEND_ACC_PUBLIC|ZEND_ACC_STATIC)
ZEND_FE_END
};
// -----------------------------------------------------------------------------
// Conversion functions used from C
// -----------------------------------------------------------------------------
upb_CType pbphp_dtype_to_type(upb_FieldType type) {
switch (type) {
#define CASE(descriptor_type, type) \
case kUpb_FieldType_##descriptor_type: \
return kUpb_CType_##type;
CASE(Float, Float);
CASE(Double, Double);
CASE(Bool, Bool);
CASE(String, String);
CASE(Bytes, Bytes);
CASE(Message, Message);
CASE(Group, Message);
CASE(Enum, Enum);
CASE(Int32, Int32);
CASE(Int64, Int64);
CASE(UInt32, Int32);
CASE(UInt64, UInt64);
CASE(SInt32, Int32);
CASE(SInt64, Int64);
CASE(Fixed32, UInt32);
CASE(Fixed64, UInt64);
CASE(SFixed32, Int32);
CASE(SFixed64, Int64);
#undef CASE
}
zend_error(E_ERROR, "Unknown field type.");
return 0;
}
static bool buftouint64(const char *ptr, const char *end, uint64_t *val) {
uint64_t u64 = 0;
while (ptr < end) {
unsigned ch = (unsigned)(*ptr - '0');
if (ch >= 10) break;
if (u64 > UINT64_MAX / 10 || u64 * 10 > UINT64_MAX - ch) {
return false;
}
u64 *= 10;
u64 += ch;
ptr++;
}
if (ptr != end) {
// In PHP tradition, we allow truncation: "1.1" -> 1.
// But we don't allow 'e', eg. '1.1e2' or any other non-numeric chars.
if (*ptr++ != '.') return false;
for (;ptr < end; ptr++) {
if (*ptr < '0' || *ptr > '9') {
return false;
}
}
}
*val = u64;
return true;
}
static bool buftoint64(const char *ptr, const char *end, int64_t *val) {
bool neg = false;
uint64_t u64;
if (ptr != end && *ptr == '-') {
ptr++;
neg = true;
}
if (!buftouint64(ptr, end, &u64) ||
u64 > (uint64_t)INT64_MAX + neg) {
return false;
}
*val = neg ? -u64 : u64;
return true;
}
static void throw_conversion_exception(const char *to, const zval *zv) {
zval tmp;
ZVAL_COPY(&tmp, zv);
convert_to_string(&tmp);
zend_throw_exception_ex(NULL, 0, "Cannot convert '%s' to %s",
Z_STRVAL_P(&tmp), to);
zval_ptr_dtor(&tmp);
}
bool Convert_PhpToInt64(const zval *php_val, int64_t *i64) {
switch (Z_TYPE_P(php_val)) {
case IS_LONG:
*i64 = Z_LVAL_P(php_val);
return true;
case IS_DOUBLE: {
double dbl = Z_DVAL_P(php_val);
if (dbl > 9223372036854774784.0 || dbl < -9223372036854775808.0) {
zend_throw_exception_ex(NULL, 0, "Out of range");
return false;
}
*i64 = dbl; /* must be guarded, overflow here is UB */
return true;
}
case IS_STRING: {
const char *buf = Z_STRVAL_P(php_val);
// PHP would accept scientific notation here, but we're going to be a
// little more discerning and only accept pure integers.
bool ok = buftoint64(buf, buf + Z_STRLEN_P(php_val), i64);
if (!ok) {
throw_conversion_exception("integer", php_val);
}
return ok;
}
default:
throw_conversion_exception("integer", php_val);
return false;
}
}
static bool to_double(zval *php_val, double *dbl) {
switch (Z_TYPE_P(php_val)) {
case IS_LONG:
*dbl = Z_LVAL_P(php_val);
return true;
case IS_DOUBLE:
*dbl = Z_DVAL_P(php_val);
return true;
case IS_STRING: {
zend_long lval;
switch (is_numeric_string(Z_STRVAL_P(php_val), Z_STRLEN_P(php_val), &lval,
dbl, false)) {
case IS_LONG:
*dbl = lval;
return true;
case IS_DOUBLE:
return true;
default:
goto fail;
}
}
default:
fail:
throw_conversion_exception("double", php_val);
return false;
}
}
static bool to_bool(zval* from, bool* to) {
switch (Z_TYPE_P(from)) {
case IS_TRUE:
*to = true;
return true;
case IS_FALSE:
*to = false;
return true;
case IS_LONG:
*to = (Z_LVAL_P(from) != 0);
return true;
case IS_DOUBLE:
*to = (Z_LVAL_P(from) != 0);
return true;
case IS_STRING:
if (Z_STRLEN_P(from) == 0 ||
(Z_STRLEN_P(from) == 1 && Z_STRVAL_P(from)[0] == '0')) {
*to = false;
} else {
*to = true;
}
return true;
default:
throw_conversion_exception("bool", from);
return false;
}
}
static bool to_string(zval* from) {
if (Z_ISREF_P(from)) {
ZVAL_DEREF(from);
}
switch (Z_TYPE_P(from)) {
case IS_STRING:
return true;
case IS_TRUE:
case IS_FALSE:
case IS_LONG:
case IS_DOUBLE: {
zval tmp;
zend_make_printable_zval(from, &tmp);
ZVAL_COPY_VALUE(from, &tmp);
return true;
}
default:
throw_conversion_exception("string", from);
return false;
}
}
bool Convert_PhpToUpb(zval *php_val, upb_MessageValue *upb_val, TypeInfo type,
upb_Arena *arena) {
int64_t i64;
if (Z_ISREF_P(php_val)) {
ZVAL_DEREF(php_val);
}
switch (type.type) {
case kUpb_CType_Int64:
return Convert_PhpToInt64(php_val, &upb_val->int64_val);
case kUpb_CType_Int32:
case kUpb_CType_Enum:
if (!Convert_PhpToInt64(php_val, &i64)) {
return false;
}
upb_val->int32_val = i64;
return true;
case kUpb_CType_UInt64:
if (!Convert_PhpToInt64(php_val, &i64)) {
return false;
}
upb_val->uint64_val = i64;
return true;
case kUpb_CType_UInt32:
if (!Convert_PhpToInt64(php_val, &i64)) {
return false;
}
upb_val->uint32_val = i64;
return true;
case kUpb_CType_Double:
return to_double(php_val, &upb_val->double_val);
case kUpb_CType_Float:
if (!to_double(php_val, &upb_val->double_val)) return false;
upb_val->float_val = upb_val->double_val;
return true;
case kUpb_CType_Bool:
return to_bool(php_val, &upb_val->bool_val);
case kUpb_CType_String:
case kUpb_CType_Bytes: {
char *ptr;
size_t size;
if (!to_string(php_val)) return false;
size = Z_STRLEN_P(php_val);
// If arena is NULL we reference the input zval.
// The resulting upb_StringView will only be value while the zval is alive.
if (arena) {
ptr = upb_Arena_Malloc(arena, size);
memcpy(ptr, Z_STRVAL_P(php_val), size);
} else {
ptr = Z_STRVAL_P(php_val);
}
upb_val->str_val = upb_StringView_FromDataAndSize(ptr, size);
return true;
}
case kUpb_CType_Message:
PBPHP_ASSERT(type.desc);
return Message_GetUpbMessage(php_val, type.desc, arena,
(upb_Message **)&upb_val->msg_val);
}
return false;
}
void Convert_UpbToPhp(upb_MessageValue upb_val, zval *php_val, TypeInfo type,
zval *arena) {
switch (type.type) {
case kUpb_CType_Int64:
#if SIZEOF_ZEND_LONG == 8
ZVAL_LONG(php_val, upb_val.int64_val);
#else
{
char buf[20];
int size = sprintf(buf, "%lld", upb_val.int64_val);
ZVAL_NEW_STR(php_val, zend_string_init(buf, size, 0));
}
#endif
break;
case kUpb_CType_UInt64:
#if SIZEOF_ZEND_LONG == 8
ZVAL_LONG(php_val, upb_val.uint64_val);
#else
{
char buf[20];
int size = sprintf(buf, "%lld", (int64_t)upb_val.uint64_val);
ZVAL_NEW_STR(php_val, zend_string_init(buf, size, 0));
}
#endif
break;
case kUpb_CType_Int32:
case kUpb_CType_Enum:
ZVAL_LONG(php_val, upb_val.int32_val);
break;
case kUpb_CType_UInt32: {
// Sign-extend for consistency between 32/64-bit builds.
zend_long val = (int32_t)upb_val.uint32_val;
ZVAL_LONG(php_val, val);
break;
}
case kUpb_CType_Double:
ZVAL_DOUBLE(php_val, upb_val.double_val);
break;
case kUpb_CType_Float:
ZVAL_DOUBLE(php_val, upb_val.float_val);
break;
case kUpb_CType_Bool:
ZVAL_BOOL(php_val, upb_val.bool_val);
break;
case kUpb_CType_String:
case kUpb_CType_Bytes: {
upb_StringView str = upb_val.str_val;
ZVAL_NEW_STR(php_val, zend_string_init(str.data, str.size, 0));
break;
}
case kUpb_CType_Message:
PBPHP_ASSERT(type.desc);
Message_GetPhpWrapper(php_val, type.desc, (upb_Message *)upb_val.msg_val,
arena);
break;
}
}
// Check if the field is a well known wrapper type
static bool IsWrapper(const upb_MessageDef* m) {
if (!m) return false;
switch (upb_MessageDef_WellKnownType(m)) {
case kUpb_WellKnown_DoubleValue:
case kUpb_WellKnown_FloatValue:
case kUpb_WellKnown_Int64Value:
case kUpb_WellKnown_UInt64Value:
case kUpb_WellKnown_Int32Value:
case kUpb_WellKnown_UInt32Value:
case kUpb_WellKnown_StringValue:
case kUpb_WellKnown_BytesValue:
case kUpb_WellKnown_BoolValue:
return true;
default:
return false;
}
}
bool Convert_PhpToUpbAutoWrap(zval *val, upb_MessageValue *upb_val, TypeInfo type,
upb_Arena *arena) {
const upb_MessageDef *subm = type.desc ? type.desc->msgdef : NULL;
if (subm && IsWrapper(subm) && Z_TYPE_P(val) != IS_OBJECT) {
// Assigning a scalar to a wrapper-typed value. We will automatically wrap
// the value, so the user doesn't need to create a FooWrapper(['value': X])
// message manually.
upb_Message *wrapper = upb_Message_New(subm, arena);
const upb_FieldDef *val_f = upb_MessageDef_FindFieldByNumber(subm, 1);
upb_MessageValue msgval;
if (!Convert_PhpToUpb(val, &msgval, TypeInfo_Get(val_f), arena)) return false;
upb_Message_Set(wrapper, val_f, msgval, arena);
upb_val->msg_val = wrapper;
return true;
} else {
// Convert_PhpToUpb doesn't auto-construct messages. This means that we only
// allow:
// ['foo_submsg': new Foo(['a' => 1])]
// not:
// ['foo_submsg': ['a' => 1]]
return Convert_PhpToUpb(val, upb_val, type, arena);
}
}
void Convert_ModuleInit(void) {
const char *prefix_name = "TYPE_URL_PREFIX";
zend_class_entry class_type;
INIT_CLASS_ENTRY(class_type, "Google\\Protobuf\\Internal\\GPBUtil",
util_methods);
GPBUtil_class_entry = zend_register_internal_class(&class_type);
zend_declare_class_constant_string(GPBUtil_class_entry, prefix_name,
strlen(prefix_name),
"type.googleapis.com/");
}

View File

@@ -0,0 +1,73 @@
// Protocol Buffers - Google's data interchange format
// Copyright 2008 Google Inc. All rights reserved.
// https://developers.google.com/protocol-buffers/
//
// Redistribution and use in source and binary forms, with or without
// modification, are permitted provided that the following conditions are
// met:
//
// * Redistributions of source code must retain the above copyright
// notice, this list of conditions and the following disclaimer.
// * Redistributions in binary form must reproduce the above
// copyright notice, this list of conditions and the following disclaimer
// in the documentation and/or other materials provided with the
// distribution.
// * Neither the name of Google Inc. nor the names of its
// contributors may be used to endorse or promote products derived from
// this software without specific prior written permission.
//
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
#ifndef PHP_PROTOBUF_CONVERT_H_
#define PHP_PROTOBUF_CONVERT_H_
#include <php.h>
#include "php-upb.h"
#include "def.h"
upb_CType pbphp_dtype_to_type(upb_FieldType type);
// Converts |php_val| to an int64_t. Returns false if the value cannot be
// converted.
bool Convert_PhpToInt64(const zval *php_val, int64_t *i64);
// Converts |php_val| to a upb_MessageValue according to |type|. If type is
// kUpb_CType_Message, then |desc| must be the Descriptor for this message type.
// If type is string, message, or bytes, then |arena| will be used to copy
// string data or fuse this arena to the given message's arena.
bool Convert_PhpToUpb(zval *php_val, upb_MessageValue *upb_val, TypeInfo type,
upb_Arena *arena);
// Similar to Convert_PhpToUpb, but supports automatically wrapping the wrapper
// types if a primitive is specified:
//
// 5 -> Int64Wrapper(value=5)
//
// We currently allow this implicit conversion in initializers, but not for
// assignment.
bool Convert_PhpToUpbAutoWrap(zval *val, upb_MessageValue *upb_val, TypeInfo type,
upb_Arena *arena);
// Converts |upb_val| to a PHP zval according to |type|. This may involve
// creating a PHP wrapper object. Any newly created wrapper object
// will reference |arena|.
//
// The caller owns a reference to the returned value.
void Convert_UpbToPhp(upb_MessageValue upb_val, zval *php_val, TypeInfo type,
zval *arena);
// Registers the GPBUtil class.
void Convert_ModuleInit(void);
#endif // PHP_PROTOBUF_CONVERT_H_

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,90 @@
// Protocol Buffers - Google's data interchange format
// Copyright 2008 Google Inc. All rights reserved.
// https://developers.google.com/protocol-buffers/
//
// Redistribution and use in source and binary forms, with or without
// modification, are permitted provided that the following conditions are
// met:
//
// * Redistributions of source code must retain the above copyright
// notice, this list of conditions and the following disclaimer.
// * Redistributions in binary form must reproduce the above
// copyright notice, this list of conditions and the following disclaimer
// in the documentation and/or other materials provided with the
// distribution.
// * Neither the name of Google Inc. nor the names of its
// contributors may be used to endorse or promote products derived from
// this software without specific prior written permission.
//
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
#ifndef PHP_PROTOBUF_DEF_H_
#define PHP_PROTOBUF_DEF_H_
#include <php.h>
#include "php-upb.h"
// Initializes the Def module, which defines all of the descriptor classes.
void Def_ModuleInit();
// Creates a new DescriptorPool to wrap the given symtab, which must not be
// NULL.
void DescriptorPool_CreateWithSymbolTable(zval *zv, upb_DefPool *symtab);
upb_DefPool *DescriptorPool_GetSymbolTable();
// Returns true if the global descriptor pool already has the given filename.
bool DescriptorPool_HasFile(const char *filename);
// Adds the given descriptor with the given filename to the global pool.
void DescriptorPool_AddDescriptor(const char *filename, const char *data, int size);
typedef struct Descriptor {
zend_object std;
const upb_MessageDef *msgdef;
zend_class_entry *class_entry;
} Descriptor;
// Gets or creates a Descriptor* for the given class entry, upb_MessageDef, or
// upb_FieldDef. The returned Descriptor* will live for the entire request,
// so no ref is necessary to keep it alive. The caller does *not* own a ref
// on the returned object.
Descriptor* Descriptor_GetFromClassEntry(zend_class_entry *ce);
Descriptor* Descriptor_GetFromMessageDef(const upb_MessageDef *m);
Descriptor* Descriptor_GetFromFieldDef(const upb_FieldDef *f);
// Packages up a upb_CType with a Descriptor, since many functions need
// both.
typedef struct {
upb_CType type;
const Descriptor *desc; // When type == kUpb_CType_Message.
} TypeInfo;
static inline TypeInfo TypeInfo_Get(const upb_FieldDef *f) {
TypeInfo ret = {upb_FieldDef_CType(f), Descriptor_GetFromFieldDef(f)};
return ret;
}
static inline TypeInfo TypeInfo_FromType(upb_CType type) {
TypeInfo ret = {type};
return ret;
}
static inline bool TypeInfo_Eq(TypeInfo a, TypeInfo b) {
if (a.type != b.type) return false;
if (a.type == kUpb_CType_Message && a.desc != b.desc) return false;
return true;
}
#endif // PHP_PROTOBUF_DEF_H_

View File

@@ -0,0 +1,698 @@
// Protocol Buffers - Google's data interchange format
// Copyright 2008 Google Inc. All rights reserved.
// https://developers.google.com/protocol-buffers/
//
// Redistribution and use in source and binary forms, with or without
// modification, are permitted provided that the following conditions are
// met:
//
// * Redistributions of source code must retain the above copyright
// notice, this list of conditions and the following disclaimer.
// * Redistributions in binary form must reproduce the above
// copyright notice, this list of conditions and the following disclaimer
// in the documentation and/or other materials provided with the
// distribution.
// * Neither the name of Google Inc. nor the names of its
// contributors may be used to endorse or promote products derived from
// this software without specific prior written permission.
//
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
#include "map.h"
#include <Zend/zend_API.h>
#include <Zend/zend_interfaces.h>
#include <ext/spl/spl_iterators.h>
#include "arena.h"
#include "convert.h"
#include "message.h"
#include "php-upb.h"
#include "protobuf.h"
static void MapFieldIter_make(zval *val, zval *map_field);
// -----------------------------------------------------------------------------
// MapField
// -----------------------------------------------------------------------------
typedef struct {
zend_object std;
zval arena;
upb_Map *map;
MapField_Type type;
} MapField;
zend_class_entry *MapField_class_entry;
static zend_object_handlers MapField_object_handlers;
static bool MapType_Eq(MapField_Type a, MapField_Type b) {
return a.key_type == b.key_type && TypeInfo_Eq(a.val_type, b.val_type);
}
static TypeInfo KeyType(MapField_Type type) {
TypeInfo ret = {type.key_type};
return ret;
}
MapField_Type MapType_Get(const upb_FieldDef *f) {
const upb_MessageDef *ent = upb_FieldDef_MessageSubDef(f);
const upb_FieldDef *key_f = upb_MessageDef_FindFieldByNumber(ent, 1);
const upb_FieldDef *val_f = upb_MessageDef_FindFieldByNumber(ent, 2);
MapField_Type type = {
upb_FieldDef_CType(key_f),
{upb_FieldDef_CType(val_f), Descriptor_GetFromFieldDef(val_f)}};
return type;
}
// PHP Object Handlers /////////////////////////////////////////////////////////
/**
* MapField_create()
*
* PHP class entry function to allocate and initialize a new MapField
* object.
*/
static zend_object* MapField_create(zend_class_entry *class_type) {
MapField *intern = emalloc(sizeof(MapField));
zend_object_std_init(&intern->std, class_type);
intern->std.handlers = &MapField_object_handlers;
Arena_Init(&intern->arena);
intern->map = NULL;
// Skip object_properties_init(), we don't allow derived classes.
return &intern->std;
}
/**
* MapField_dtor()
*
* Object handler to destroy a MapField. This releases all resources
* associated with the message. Note that it is possible to access a destroyed
* object from PHP in rare cases.
*/
static void MapField_destructor(zend_object* obj) {
MapField* intern = (MapField*)obj;
ObjCache_Delete(intern->map);
zval_ptr_dtor(&intern->arena);
zend_object_std_dtor(&intern->std);
}
/**
* MapField_compare_objects()
*
* Object handler for comparing two repeated field objects. Called whenever PHP
* code does:
*
* $map1 == $map2
*/
static int MapField_compare_objects(zval *map1, zval *map2) {
MapField* intern1 = (MapField*)Z_OBJ_P(map1);
MapField* intern2 = (MapField*)Z_OBJ_P(map2);
return MapType_Eq(intern1->type, intern2->type) &&
MapEq(intern1->map, intern2->map, intern1->type)
? 0
: 1;
}
/**
* MapField_clone_obj()
*
* Object handler for cloning an object in PHP. Called when PHP code does:
*
* $map2 = clone $map1;
*/
static zend_object *MapField_clone_obj(PROTO_VAL *object) {
MapField* intern = PROTO_VAL_P(object);
upb_Arena *arena = Arena_Get(&intern->arena);
upb_Map *clone =
upb_Map_New(arena, intern->type.key_type, intern->type.val_type.type);
size_t iter = kUpb_Map_Begin;
while (upb_MapIterator_Next(intern->map, &iter)) {
upb_MessageValue key = upb_MapIterator_Key(intern->map, iter);
upb_MessageValue val = upb_MapIterator_Value(intern->map, iter);
upb_Map_Set(clone, key, val, arena);
}
zval ret;
MapField_GetPhpWrapper(&ret, clone, intern->type, &intern->arena);
return Z_OBJ_P(&ret);
}
static zval *Map_GetPropertyPtrPtr(PROTO_VAL *object, PROTO_STR *member,
int type, void **cache_slot) {
return NULL; // We don't offer direct references to our properties.
}
static HashTable *Map_GetProperties(PROTO_VAL *object) {
return NULL; // We do not have a properties table.
}
// C Functions from map.h //////////////////////////////////////////////////////
// These are documented in the header file.
void MapField_GetPhpWrapper(zval *val, upb_Map *map, MapField_Type type,
zval *arena) {
if (!map) {
ZVAL_NULL(val);
return;
}
if (!ObjCache_Get(map, val)) {
MapField *intern = emalloc(sizeof(MapField));
zend_object_std_init(&intern->std, MapField_class_entry);
intern->std.handlers = &MapField_object_handlers;
ZVAL_COPY(&intern->arena, arena);
intern->map = map;
intern->type = type;
// Skip object_properties_init(), we don't allow derived classes.
ObjCache_Add(intern->map, &intern->std);
ZVAL_OBJ(val, &intern->std);
}
}
upb_Map *MapField_GetUpbMap(zval *val, MapField_Type type, upb_Arena *arena) {
if (Z_ISREF_P(val)) {
ZVAL_DEREF(val);
}
if (Z_TYPE_P(val) == IS_ARRAY) {
upb_Map *map = upb_Map_New(arena, type.key_type, type.val_type.type);
HashTable *table = HASH_OF(val);
HashPosition pos;
zend_hash_internal_pointer_reset_ex(table, &pos);
while (true) {
zval php_key;
zval *php_val;
upb_MessageValue upb_key;
upb_MessageValue upb_val;
zend_hash_get_current_key_zval_ex(table, &php_key, &pos);
php_val = zend_hash_get_current_data_ex(table, &pos);
if (!php_val) return map;
if (!Convert_PhpToUpb(&php_key, &upb_key, KeyType(type), arena) ||
!Convert_PhpToUpbAutoWrap(php_val, &upb_val, type.val_type, arena)) {
return NULL;
}
upb_Map_Set(map, upb_key, upb_val, arena);
zend_hash_move_forward_ex(table, &pos);
zval_dtor(&php_key);
}
} else if (Z_TYPE_P(val) == IS_OBJECT &&
Z_OBJCE_P(val) == MapField_class_entry) {
MapField *intern = (MapField*)Z_OBJ_P(val);
if (!MapType_Eq(intern->type, type)) {
php_error_docref(NULL, E_USER_ERROR, "Wrong type for this map field.");
return NULL;
}
upb_Arena_Fuse(arena, Arena_Get(&intern->arena));
return intern->map;
} else {
php_error_docref(NULL, E_USER_ERROR, "Must be a map");
return NULL;
}
}
bool MapEq(const upb_Map *m1, const upb_Map *m2, MapField_Type type) {
size_t iter = kUpb_Map_Begin;
if ((m1 == NULL) != (m2 == NULL)) return false;
if (m1 == NULL) return true;
if (upb_Map_Size(m1) != upb_Map_Size(m2)) return false;
while (upb_MapIterator_Next(m1, &iter)) {
upb_MessageValue key = upb_MapIterator_Key(m1, iter);
upb_MessageValue val1 = upb_MapIterator_Value(m1, iter);
upb_MessageValue val2;
if (!upb_Map_Get(m2, key, &val2)) return false;
if (!ValueEq(val1, val2, type.val_type)) return false;
}
return true;
}
// MapField PHP methods ////////////////////////////////////////////////////////
/**
* MapField::__construct()
*
* Constructs an instance of MapField.
* @param long Key type.
* @param long Value type.
* @param string Message/Enum class (message/enum value types only).
*/
PHP_METHOD(MapField, __construct) {
MapField *intern = (MapField*)Z_OBJ_P(getThis());
upb_Arena *arena = Arena_Get(&intern->arena);
zend_long key_type, val_type;
zend_class_entry* klass = NULL;
if (zend_parse_parameters(ZEND_NUM_ARGS(), "ll|C", &key_type, &val_type,
&klass) != SUCCESS) {
return;
}
intern->type.key_type = pbphp_dtype_to_type(key_type);
intern->type.val_type.type = pbphp_dtype_to_type(val_type);
intern->type.val_type.desc = Descriptor_GetFromClassEntry(klass);
// Check that the key type is an allowed type.
switch (intern->type.key_type) {
case kUpb_CType_Int32:
case kUpb_CType_Int64:
case kUpb_CType_UInt32:
case kUpb_CType_UInt64:
case kUpb_CType_Bool:
case kUpb_CType_String:
case kUpb_CType_Bytes:
// These are OK.
break;
default:
zend_error(E_USER_ERROR, "Invalid key type for map.");
}
if (intern->type.val_type.type == kUpb_CType_Message && klass == NULL) {
php_error_docref(NULL, E_USER_ERROR,
"Message/enum type must have concrete class.");
return;
}
intern->map =
upb_Map_New(arena, intern->type.key_type, intern->type.val_type.type);
ObjCache_Add(intern->map, &intern->std);
}
/**
* MapField::offsetExists(): bool
*
* Implements the ArrayAccess interface. Invoked when PHP code calls:
*
* isset($map[$idx]);
* empty($map[$idx]);
*
* @param long The index to be checked.
* @return bool True if the element at the given index exists.
*/
PHP_METHOD(MapField, offsetExists) {
MapField *intern = (MapField*)Z_OBJ_P(getThis());
zval *key;
upb_MessageValue upb_key;
if (zend_parse_parameters(ZEND_NUM_ARGS(), "z", &key) != SUCCESS ||
!Convert_PhpToUpb(key, &upb_key, KeyType(intern->type), NULL)) {
return;
}
RETURN_BOOL(upb_Map_Get(intern->map, upb_key, NULL));
}
/**
* MapField::offsetGet(): mixed
*
* Implements the ArrayAccess interface. Invoked when PHP code calls:
*
* $x = $map[$idx];
*
* @param long The index of the element to be fetched.
* @return object The stored element at given index.
* @exception Invalid type for index.
* @exception Non-existing index.
*/
PHP_METHOD(MapField, offsetGet) {
MapField *intern = (MapField*)Z_OBJ_P(getThis());
zval *key;
zval ret;
upb_MessageValue upb_key, upb_val;
if (zend_parse_parameters(ZEND_NUM_ARGS(), "z", &key) != SUCCESS ||
!Convert_PhpToUpb(key, &upb_key, KeyType(intern->type), NULL)) {
return;
}
if (!upb_Map_Get(intern->map, upb_key, &upb_val)) {
zend_error(E_USER_ERROR, "Given key doesn't exist.");
return;
}
Convert_UpbToPhp(upb_val, &ret, intern->type.val_type, &intern->arena);
RETURN_COPY_VALUE(&ret);
}
/**
* MapField::offsetSet(): void
*
* Implements the ArrayAccess interface. Invoked when PHP code calls:
*
* $map[$idx] = $x;
*
* @param long The index of the element to be assigned.
* @param object The element to be assigned.
* @exception Invalid type for index.
* @exception Non-existing index.
* @exception Incorrect type of the element.
*/
PHP_METHOD(MapField, offsetSet) {
MapField *intern = (MapField*)Z_OBJ_P(getThis());
upb_Arena *arena = Arena_Get(&intern->arena);
zval *key, *val;
upb_MessageValue upb_key, upb_val;
if (zend_parse_parameters(ZEND_NUM_ARGS(), "zz", &key, &val) != SUCCESS ||
!Convert_PhpToUpb(key, &upb_key, KeyType(intern->type), NULL) ||
!Convert_PhpToUpb(val, &upb_val, intern->type.val_type, arena)) {
return;
}
upb_Map_Set(intern->map, upb_key, upb_val, arena);
}
/**
* MapField::offsetUnset(): void
*
* Implements the ArrayAccess interface. Invoked when PHP code calls:
*
* unset($map[$idx]);
*
* @param long The index of the element to be removed.
* @exception Invalid type for index.
* @exception The element to be removed is not at the end of the MapField.
*/
PHP_METHOD(MapField, offsetUnset) {
MapField *intern = (MapField*)Z_OBJ_P(getThis());
zval *key;
upb_MessageValue upb_key;
if (zend_parse_parameters(ZEND_NUM_ARGS(), "z", &key) != SUCCESS ||
!Convert_PhpToUpb(key, &upb_key, KeyType(intern->type), NULL)) {
return;
}
upb_Map_Delete(intern->map, upb_key);
}
/**
* MapField::count(): int
*
* Implements the Countable interface. Invoked when PHP code calls:
*
* $len = count($map);
* Return the number of stored elements.
* This will also be called for: count($map)
* @return long The number of stored elements.
*/
PHP_METHOD(MapField, count) {
MapField *intern = (MapField*)Z_OBJ_P(getThis());
if (zend_parse_parameters_none() == FAILURE) {
return;
}
RETURN_LONG(upb_Map_Size(intern->map));
}
/**
* MapField::getIterator(): Traversable
*
* Implements the IteratorAggregate interface. Invoked when PHP code calls:
*
* foreach ($arr) {}
*
* @return object Beginning iterator.
*/
PHP_METHOD(MapField, getIterator) {
zval ret;
MapFieldIter_make(&ret, getThis());
RETURN_COPY_VALUE(&ret);
}
ZEND_BEGIN_ARG_INFO_EX(arginfo_construct, 0, 0, 2)
ZEND_ARG_INFO(0, key_type)
ZEND_ARG_INFO(0, value_type)
ZEND_ARG_INFO(0, value_class)
ZEND_END_ARG_INFO()
ZEND_BEGIN_ARG_WITH_TENTATIVE_RETURN_TYPE_INFO_EX(arginfo_offsetGet, 0, 0, IS_MIXED, 1)
ZEND_ARG_INFO(0, index)
ZEND_END_ARG_INFO()
PROTOBUF_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_offsetSet, 0, 2, IS_VOID, 0)
ZEND_ARG_INFO(0, index)
ZEND_ARG_INFO(0, newval)
ZEND_END_ARG_INFO()
PROTOBUF_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_offsetUnset, 0, 0, IS_VOID, 0)
ZEND_ARG_INFO(0, index)
ZEND_END_ARG_INFO()
PROTOBUF_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_offsetExists, 0, 0, _IS_BOOL, 0)
ZEND_ARG_INFO(0, index)
ZEND_END_ARG_INFO()
ZEND_BEGIN_ARG_WITH_RETURN_OBJ_INFO_EX(arginfo_getIterator, 0, 0, Traversable, 0)
ZEND_END_ARG_INFO()
PROTOBUF_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_count, 0, 0, IS_LONG, 0)
ZEND_END_ARG_INFO()
static zend_function_entry MapField_methods[] = {
PHP_ME(MapField, __construct, arginfo_construct, ZEND_ACC_PUBLIC)
PHP_ME(MapField, offsetExists, arginfo_offsetExists, ZEND_ACC_PUBLIC)
PHP_ME(MapField, offsetGet, arginfo_offsetGet, ZEND_ACC_PUBLIC)
PHP_ME(MapField, offsetSet, arginfo_offsetSet, ZEND_ACC_PUBLIC)
PHP_ME(MapField, offsetUnset, arginfo_offsetUnset, ZEND_ACC_PUBLIC)
PHP_ME(MapField, count, arginfo_count, ZEND_ACC_PUBLIC)
PHP_ME(MapField, getIterator, arginfo_getIterator, ZEND_ACC_PUBLIC)
ZEND_FE_END
};
// -----------------------------------------------------------------------------
// MapFieldIter
// -----------------------------------------------------------------------------
typedef struct {
zend_object std;
zval map_field;
size_t position;
} MapFieldIter;
zend_class_entry *MapFieldIter_class_entry;
static zend_object_handlers MapFieldIter_object_handlers;
/**
* MapFieldIter_create()
*
* PHP class entry function to allocate and initialize a new MapFieldIter
* object.
*/
zend_object* MapFieldIter_create(zend_class_entry *class_type) {
MapFieldIter *intern = emalloc(sizeof(MapFieldIter));
zend_object_std_init(&intern->std, class_type);
intern->std.handlers = &MapFieldIter_object_handlers;
ZVAL_NULL(&intern->map_field);
intern->position = 0;
// Skip object_properties_init(), we don't allow derived classes.
return &intern->std;
}
/**
* MapFieldIter_dtor()
*
* Object handler to destroy a MapFieldIter. This releases all resources
* associated with the message. Note that it is possible to access a destroyed
* object from PHP in rare cases.
*/
static void map_field_iter_dtor(zend_object* obj) {
MapFieldIter* intern = (MapFieldIter*)obj;
zval_ptr_dtor(&intern->map_field);
zend_object_std_dtor(&intern->std);
}
/**
* MapFieldIter_make()
*
* Function to create a MapFieldIter directly from C.
*/
static void MapFieldIter_make(zval *val, zval *map_field) {
MapFieldIter *iter;
ZVAL_OBJ(val,
MapFieldIter_class_entry->create_object(MapFieldIter_class_entry));
iter = (MapFieldIter*)Z_OBJ_P(val);
ZVAL_COPY(&iter->map_field, map_field);
}
// -----------------------------------------------------------------------------
// PHP MapFieldIter Methods
// -----------------------------------------------------------------------------
/*
* When a user writes:
*
* foreach($arr as $key => $val) {}
*
* PHP translates this into:
*
* $iter = $arr->getIterator();
* for ($iter->rewind(); $iter->valid(); $iter->next()) {
* $key = $iter->key();
* $val = $iter->current();
* }
*/
/**
* MapFieldIter::rewind(): void
*
* Implements the Iterator interface. Sets the iterator to the first element.
*/
PHP_METHOD(MapFieldIter, rewind) {
MapFieldIter *intern = (MapFieldIter*)Z_OBJ_P(getThis());
MapField *map_field = (MapField*)Z_OBJ_P(&intern->map_field);
intern->position = kUpb_Map_Begin;
upb_MapIterator_Next(map_field->map, &intern->position);
}
/**
* MapFieldIter::current(): mixed
*
* Implements the Iterator interface. Returns the current value.
*/
PHP_METHOD(MapFieldIter, current) {
MapFieldIter *intern = (MapFieldIter*)Z_OBJ_P(getThis());
MapField *field = (MapField*)Z_OBJ_P(&intern->map_field);
upb_MessageValue upb_val = upb_MapIterator_Value(field->map, intern->position);
zval ret;
Convert_UpbToPhp(upb_val, &ret, field->type.val_type, &field->arena);
RETURN_COPY_VALUE(&ret);
}
/**
* MapFieldIter::key()
*
* Implements the Iterator interface. Returns the current key.
*/
PHP_METHOD(MapFieldIter, key) {
MapFieldIter *intern = (MapFieldIter*)Z_OBJ_P(getThis());
MapField *field = (MapField*)Z_OBJ_P(&intern->map_field);
upb_MessageValue upb_key = upb_MapIterator_Key(field->map, intern->position);
zval ret;
Convert_UpbToPhp(upb_key, &ret, KeyType(field->type), NULL);
RETURN_COPY_VALUE(&ret);
}
/**
* MapFieldIter::next(): void
*
* Implements the Iterator interface. Advances to the next element.
*/
PHP_METHOD(MapFieldIter, next) {
MapFieldIter *intern = (MapFieldIter*)Z_OBJ_P(getThis());
MapField *field = (MapField*)Z_OBJ_P(&intern->map_field);
upb_MapIterator_Next(field->map, &intern->position);
}
/**
* MapFieldIter::valid(): bool
*
* Implements the Iterator interface. Returns true if this is a valid element.
*/
PHP_METHOD(MapFieldIter, valid) {
MapFieldIter *intern = (MapFieldIter*)Z_OBJ_P(getThis());
MapField *field = (MapField*)Z_OBJ_P(&intern->map_field);
bool done = upb_MapIterator_Done(field->map, intern->position);
RETURN_BOOL(!done);
}
PROTOBUF_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_rewind, 0, 0, IS_VOID, 0)
ZEND_END_ARG_INFO()
ZEND_BEGIN_ARG_WITH_TENTATIVE_RETURN_TYPE_INFO_EX(arginfo_current, 0, 0, IS_MIXED, 0)
ZEND_END_ARG_INFO()
ZEND_BEGIN_ARG_WITH_TENTATIVE_RETURN_TYPE_INFO_EX(arginfo_key, 0, 0, IS_MIXED, 0)
ZEND_END_ARG_INFO()
PROTOBUF_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_next, 0, 0, IS_VOID, 0)
ZEND_END_ARG_INFO()
PROTOBUF_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_valid, 0, 0, _IS_BOOL, 0)
ZEND_END_ARG_INFO()
static zend_function_entry map_field_iter_methods[] = {
PHP_ME(MapFieldIter, rewind, arginfo_rewind, ZEND_ACC_PUBLIC)
PHP_ME(MapFieldIter, current, arginfo_current, ZEND_ACC_PUBLIC)
PHP_ME(MapFieldIter, key, arginfo_key, ZEND_ACC_PUBLIC)
PHP_ME(MapFieldIter, next, arginfo_next, ZEND_ACC_PUBLIC)
PHP_ME(MapFieldIter, valid, arginfo_valid, ZEND_ACC_PUBLIC)
ZEND_FE_END
};
// -----------------------------------------------------------------------------
// Module init.
// -----------------------------------------------------------------------------
/**
* Map_ModuleInit()
*
* Called when the C extension is loaded to register all types.
*/
void Map_ModuleInit() {
zend_class_entry tmp_ce;
zend_object_handlers *h;
INIT_CLASS_ENTRY(tmp_ce, "Google\\Protobuf\\Internal\\MapField",
MapField_methods);
MapField_class_entry = zend_register_internal_class(&tmp_ce);
zend_class_implements(MapField_class_entry, 3, zend_ce_arrayaccess,
zend_ce_aggregate, zend_ce_countable);
MapField_class_entry->ce_flags |= ZEND_ACC_FINAL;
MapField_class_entry->create_object = MapField_create;
h = &MapField_object_handlers;
memcpy(h, &std_object_handlers, sizeof(zend_object_handlers));
h->dtor_obj = MapField_destructor;
#if PHP_VERSION_ID < 80000
h->compare_objects = MapField_compare_objects;
#else
h->compare = MapField_compare_objects;
#endif
h->clone_obj = MapField_clone_obj;
h->get_properties = Map_GetProperties;
h->get_property_ptr_ptr = Map_GetPropertyPtrPtr;
INIT_CLASS_ENTRY(tmp_ce, "Google\\Protobuf\\Internal\\MapFieldIter",
map_field_iter_methods);
MapFieldIter_class_entry = zend_register_internal_class(&tmp_ce);
zend_class_implements(MapFieldIter_class_entry, 1, zend_ce_iterator);
MapFieldIter_class_entry->ce_flags |= ZEND_ACC_FINAL;
MapFieldIter_class_entry->ce_flags |= ZEND_ACC_FINAL;
MapFieldIter_class_entry->create_object = MapFieldIter_create;
h = &MapFieldIter_object_handlers;
memcpy(h, &std_object_handlers, sizeof(zend_object_handlers));
h->dtor_obj = map_field_iter_dtor;
}

View File

@@ -0,0 +1,70 @@
// Protocol Buffers - Google's data interchange format
// Copyright 2008 Google Inc. All rights reserved.
// https://developers.google.com/protocol-buffers/
//
// Redistribution and use in source and binary forms, with or without
// modification, are permitted provided that the following conditions are
// met:
//
// * Redistributions of source code must retain the above copyright
// notice, this list of conditions and the following disclaimer.
// * Redistributions in binary form must reproduce the above
// copyright notice, this list of conditions and the following disclaimer
// in the documentation and/or other materials provided with the
// distribution.
// * Neither the name of Google Inc. nor the names of its
// contributors may be used to endorse or promote products derived from
// this software without specific prior written permission.
//
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
#ifndef PHP_PROTOBUF_MAP_H_
#define PHP_PROTOBUF_MAP_H_
#include <php.h>
#include "def.h"
#include "php-upb.h"
void Map_ModuleInit();
typedef struct {
upb_CType key_type;
TypeInfo val_type;
} MapField_Type;
MapField_Type MapType_Get(const upb_FieldDef *f);
// Gets a upb_Map* for the PHP object |val|:
// * If |val| is a RepeatedField object, we first check its type and verify
// that that the elements have the correct type for |f|. If so, we return the
// wrapped upb_Map*. We also make sure that this map's arena is fused to
// |arena|, so the returned upb_Map is guaranteed to live as long as
// |arena|.
// * If |val| is a PHP Map, we attempt to create a new upb_Map using
// |arena| and add all of the PHP elements to it.
//
// If an error occurs, we raise a PHP error and return NULL.
upb_Map *MapField_GetUpbMap(zval *val, MapField_Type type, upb_Arena *arena);
// Creates a PHP MapField object for the given upb_Map* and |f| and returns it
// in |val|. The PHP object will keep a reference to this |arena| to ensure the
// underlying array data stays alive.
//
// If |map| is NULL, this will return a PHP null object.
void MapField_GetPhpWrapper(zval *val, upb_Map *arr, MapField_Type type,
zval *arena);
bool MapEq(const upb_Map *m1, const upb_Map *m2, MapField_Type type);
#endif // PHP_PROTOBUF_MAP_H_

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,61 @@
// Protocol Buffers - Google's data interchange format
// Copyright 2008 Google Inc. All rights reserved.
// https://developers.google.com/protocol-buffers/
//
// Redistribution and use in source and binary forms, with or without
// modification, are permitted provided that the following conditions are
// met:
//
// * Redistributions of source code must retain the above copyright
// notice, this list of conditions and the following disclaimer.
// * Redistributions in binary form must reproduce the above
// copyright notice, this list of conditions and the following disclaimer
// in the documentation and/or other materials provided with the
// distribution.
// * Neither the name of Google Inc. nor the names of its
// contributors may be used to endorse or promote products derived from
// this software without specific prior written permission.
//
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
#ifndef PHP_PROTOBUF_MESSAGE_H_
#define PHP_PROTOBUF_MESSAGE_H_
#include <stdbool.h>
#include "def.h"
// Registers the PHP Message class.
void Message_ModuleInit();
// Gets a upb_Message* for the PHP object |val|, which must either be a Message
// object or 'null'. Returns true and stores the message in |msg| if the
// conversion succeeded (we can't return upb_Message* because null->NULL is a valid
// conversion). Returns false and raises a PHP error if this isn't a Message
// object or null, or if the Message object doesn't match this Descriptor.
//
// The given |arena| will be fused to this message's arena.
bool Message_GetUpbMessage(zval *val, const Descriptor *desc, upb_Arena *arena,
upb_Message **msg);
// Gets or creates a PHP Message object to wrap the given upb_Message* and |desc|
// and returns it in |val|. The PHP object will keep a reference to this |arena|
// to ensure the underlying message data stays alive.
//
// If |msg| is NULL, this will return a PHP null.
void Message_GetPhpWrapper(zval *val, const Descriptor *desc, upb_Message *msg,
zval *arena);
bool ValueEq(upb_MessageValue val1, upb_MessageValue val2, TypeInfo type);
#endif // PHP_PROTOBUF_MESSAGE_H_

View File

@@ -0,0 +1,287 @@
// Protocol Buffers - Google's data interchange format
// Copyright 2008 Google Inc. All rights reserved.
// https://developers.google.com/protocol-buffers/
//
// Redistribution and use in source and binary forms, with or without
// modification, are permitted provided that the following conditions are
// met:
//
// * Redistributions of source code must retain the above copyright
// notice, this list of conditions and the following disclaimer.
// * Redistributions in binary form must reproduce the above
// copyright notice, this list of conditions and the following disclaimer
// in the documentation and/or other materials provided with the
// distribution.
// * Neither the name of Google Inc. nor the names of its
// contributors may be used to endorse or promote products derived from
// this software without specific prior written permission.
//
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
#include "names.h"
#include <stdlib.h>
#include "protobuf.h"
/* stringsink *****************************************************************/
typedef struct {
char *ptr;
size_t len, size;
} stringsink;
static size_t stringsink_string(stringsink *sink, const char *ptr, size_t len) {
size_t new_size = sink->size;
while (sink->len + len > new_size) {
new_size *= 2;
}
if (new_size != sink->size) {
sink->ptr = realloc(sink->ptr, new_size);
sink->size = new_size;
}
memcpy(sink->ptr + sink->len, ptr, len);
sink->len += len;
return len;
}
static void stringsink_init(stringsink *sink) {
sink->size = 32;
sink->ptr = malloc(sink->size);
PBPHP_ASSERT(sink->ptr != NULL);
sink->len = 0;
}
static void stringsink_uninit(stringsink *sink) { free(sink->ptr); }
/* def name -> classname ******************************************************/
const char *const kReservedNames[] = {
"abstract", "and", "array", "as", "break",
"callable", "case", "catch", "class", "clone",
"const", "continue", "declare", "default", "die",
"do", "echo", "else", "elseif", "empty",
"enddeclare", "endfor", "endforeach", "endif", "endswitch",
"endwhile", "eval", "exit", "extends", "final",
"finally", "fn", "for", "foreach", "function",
"if", "implements", "include", "include_once", "instanceof",
"global", "goto", "insteadof", "interface", "isset",
"list", "match", "namespace", "new", "object",
"or", "parent", "print", "private", "protected",
"public", "readonly", "require", "require_once", "return",
"self", "static", "switch", "throw", "trait",
"try", "unset", "use", "var", "while",
"xor", "yield", "int", "float", "bool",
"string", "true", "false", "null", "void",
"iterable", NULL};
const char *const kPreviouslyUnreservedNames[] = {
"readonly", NULL};
bool is_reserved_name(const char* name) {
int i;
for (i = 0; kReservedNames[i]; i++) {
if (strcmp(kReservedNames[i], name) == 0) {
return true;
}
}
return false;
}
bool is_previously_unreserved_name(const char* name) {
for (int i = 0; kPreviouslyUnreservedNames[i]; i++) {
if (strcmp(kPreviouslyUnreservedNames[i], name) == 0) {
return true;
}
}
return false;
}
static char nolocale_tolower(char ch) {
if (ch >= 'A' && ch <= 'Z') {
return ch - ('A' - 'a');
} else {
return ch;
}
}
static char nolocale_toupper(char ch) {
if (ch >= 'a' && ch <= 'z') {
return ch - ('a' - 'A');
} else {
return ch;
}
}
static char *strdup_nolocale_lower(char *str, int length) {
char* lower = malloc(length + 1);
lower[length] = '\0';
for(int i = 0; i < length; ++i) {
lower[i] = nolocale_tolower(str[i]);
}
return lower;
}
static bool is_reserved(const char *segment, int length, bool previous) {
bool result;
char* lower = strdup_nolocale_lower(segment, length);
result = is_reserved_name(lower);
if (result && previous && is_previously_unreserved_name(lower)) {
result = false;
}
free(lower);
return result;
}
static void fill_prefix(const char *segment, int length,
const char *prefix_given,
const char *package_name,
stringsink *classname,
bool previous) {
if (prefix_given != NULL && strcmp(prefix_given, "") != 0) {
stringsink_string(classname, prefix_given, strlen(prefix_given));
} else {
if (is_reserved(segment, length, previous)) {
if (package_name != NULL &&
strcmp("google.protobuf", package_name) == 0) {
stringsink_string(classname, "GPB", 3);
} else {
stringsink_string(classname, "PB", 2);
}
}
}
}
static void fill_segment(const char *segment, int length,
stringsink *classname, bool use_camel) {
if (use_camel && (segment[0] < 'A' || segment[0] > 'Z')) {
char first = nolocale_toupper(segment[0]);
stringsink_string(classname, &first, 1);
stringsink_string(classname, segment + 1, length - 1);
} else {
stringsink_string(classname, segment, length);
}
}
static void fill_namespace(const char *package, const char *php_namespace,
stringsink *classname, bool previous) {
if (php_namespace != NULL) {
if (strlen(php_namespace) != 0) {
stringsink_string(classname, php_namespace, strlen(php_namespace));
stringsink_string(classname, "\\", 1);
}
} else if (package != NULL) {
int i = 0, j = 0;
size_t package_len = strlen(package);
while (i < package_len) {
j = i;
while (j < package_len && package[j] != '.') {
j++;
}
fill_prefix(package + i, j - i, "", package, classname, previous);
fill_segment(package + i, j - i, classname, true);
stringsink_string(classname, "\\", 1);
i = j + 1;
}
}
}
static void fill_classname(const char *fullname,
const char *package,
const char *prefix,
stringsink *classname,
bool previous) {
int classname_start = 0;
if (package != NULL) {
size_t package_len = strlen(package);
classname_start = package_len == 0 ? 0 : package_len + 1;
}
size_t fullname_len = strlen(fullname);
int i = classname_start, j;
while (i < fullname_len) {
j = i;
while (j < fullname_len && fullname[j] != '.') {
j++;
}
fill_prefix(fullname + i, j - i, prefix, package, classname, previous);
fill_segment(fullname + i, j - i, classname, false);
if (j != fullname_len) {
stringsink_string(classname, "\\", 1);
}
i = j + 1;
}
}
char *str_view_dup(upb_StringView str) {
char *ret = malloc(str.size + 1);
memcpy(ret, str.data, str.size);
ret[str.size] = '\0';
return ret;
}
char *GetPhpClassname(const upb_FileDef *file, const char *fullname, bool previous) {
// Prepend '.' to package name to make it absolute. In the 5 additional
// bytes allocated, one for '.', one for trailing 0, and 3 for 'GPB' if
// given message is google.protobuf.Empty.
const google_protobuf_FileOptions* opts = upb_FileDef_Options(file);
const char *package = upb_FileDef_Package(file);
char *php_namespace =
google_protobuf_FileOptions_has_php_namespace(opts)
? str_view_dup(google_protobuf_FileOptions_php_namespace(opts))
: NULL;
char *prefix =
google_protobuf_FileOptions_has_php_class_prefix(opts)
? str_view_dup(google_protobuf_FileOptions_php_class_prefix(opts))
: NULL;
char *ret;
stringsink namesink;
stringsink_init(&namesink);
fill_namespace(package, php_namespace, &namesink, previous);
fill_classname(fullname, package, prefix, &namesink, previous);
stringsink_string(&namesink, "\0", 1);
ret = strdup(namesink.ptr);
stringsink_uninit(&namesink);
free(php_namespace);
free(prefix);
return ret;
}
bool IsPreviouslyUnreservedClassName(const char* fullname) {
const char *classname = strrchr(fullname, '\\');
if (classname) {
classname += 1;
} else {
classname = fullname;
}
if (strncmp(classname, "PB", 2) != 0) {
return false;
}
classname += 2;
int length = strlen(classname);
char* lower = strdup_nolocale_lower(classname, length);
for (int j = 0; kPreviouslyUnreservedNames[j]; j++) {
if (strcmp(kPreviouslyUnreservedNames[j], lower) == 0) {
free(lower);
return true;
}
}
free(lower);
return false;
}

View File

@@ -0,0 +1,41 @@
// Protocol Buffers - Google's data interchange format
// Copyright 2008 Google Inc. All rights reserved.
// https://developers.google.com/protocol-buffers/
//
// Redistribution and use in source and binary forms, with or without
// modification, are permitted provided that the following conditions are
// met:
//
// * Redistributions of source code must retain the above copyright
// notice, this list of conditions and the following disclaimer.
// * Redistributions in binary form must reproduce the above
// copyright notice, this list of conditions and the following disclaimer
// in the documentation and/or other materials provided with the
// distribution.
// * Neither the name of Google Inc. nor the names of its
// contributors may be used to endorse or promote products derived from
// this software without specific prior written permission.
//
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
#ifndef PHP_PROTOBUF_NAMES_H_
#define PHP_PROTOBUF_NAMES_H_
#include "php-upb.h"
// Translates a protobuf symbol name (eg. foo.bar.Baz) into a PHP class name
// (eg. \Foo\Bar\Baz).
char *GetPhpClassname(const upb_FileDef *file, const char *fullname, bool previous);
bool IsPreviouslyUnreservedClassName(const char* fullname);
#endif // PHP_PROTOBUF_NAMES_H_

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,45 @@
// Protocol Buffers - Google's data interchange format
// Copyright 2022 Google Inc. All rights reserved.
// https://developers.google.com/protocol-buffers/
//
// !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
// ! THIS FILE ONLY APPROACHING IN-TREE PHP EXTENSION BUILD !
// ! DOES NOT USE NORMALLY. !
// !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
//
// Redistribution and use in source and binary forms, with or without
// modification, are permitted provided that the following conditions are
// met:
//
// * Redistributions of source code must retain the above copyright
// notice, this list of conditions and the following disclaimer.
// * Redistributions in binary form must reproduce the above
// copyright notice, this list of conditions and the following disclaimer
// in the documentation and/or other materials provided with the
// distribution.
// * Neither the name of Google Inc. nor the names of its
// contributors may be used to endorse or promote products derived from
// this software without specific prior written permission.
//
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
#ifndef PHP_PROTOBUF_H
# define PHP_PROTOBUF_H
# ifdef HAVE_CONFIG_H
# include "config.h"
# endif
extern zend_module_entry protobuf_module_entry;
# define phpext_protobuf_ptr &protobuf_module_entry
#endif /* PHP_PROTOBUF_H */

View File

@@ -0,0 +1,357 @@
// Protocol Buffers - Google's data interchange format
// Copyright 2008 Google Inc. All rights reserved.
// https://developers.google.com/protocol-buffers/
//
// Redistribution and use in source and binary forms, with or without
// modification, are permitted provided that the following conditions are
// met:
//
// * Redistributions of source code must retain the above copyright
// notice, this list of conditions and the following disclaimer.
// * Redistributions in binary form must reproduce the above
// copyright notice, this list of conditions and the following disclaimer
// in the documentation and/or other materials provided with the
// distribution.
// * Neither the name of Google Inc. nor the names of its
// contributors may be used to endorse or promote products derived from
// this software without specific prior written permission.
//
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
#include "protobuf.h"
#include <php.h>
#include <Zend/zend_interfaces.h>
#include "arena.h"
#include "array.h"
#include "convert.h"
#include "def.h"
#include "map.h"
#include "message.h"
#include "names.h"
// -----------------------------------------------------------------------------
// Module "globals"
// -----------------------------------------------------------------------------
// Despite the name, module "globals" are really thread-locals:
// * PROTOBUF_G(var) accesses the thread-local variable for 'var'. Either:
// * PROTOBUF_G(var) -> protobuf_globals.var (Non-ZTS / non-thread-safe)
// * PROTOBUF_G(var) -> <Zend magic> (ZTS / thread-safe builds)
#define PROTOBUF_G(v) ZEND_MODULE_GLOBALS_ACCESSOR(protobuf, v)
ZEND_BEGIN_MODULE_GLOBALS(protobuf)
// Set by the user to make the descriptor pool persist between requests.
zend_bool keep_descriptor_pool_after_request;
// Set by the user to make the descriptor pool persist between requests.
zend_class_entry* constructing_class;
// A upb_DefPool that we are saving for the next request so that we don't have
// to rebuild it from scratch. When keep_descriptor_pool_after_request==true,
// we steal the upb_DefPool from the global DescriptorPool object just before
// destroying it.
upb_DefPool *global_symtab;
// Object cache (see interface in protobuf.h).
HashTable object_cache;
// Name cache (see interface in protobuf.h).
HashTable name_msg_cache;
HashTable name_enum_cache;
// An array of descriptor objects constructed during this request. These are
// logically referenced by the corresponding class entry, but since we can't
// actually write a class entry destructor, we reference them here, to be
// destroyed on request shutdown.
HashTable descriptors;
ZEND_END_MODULE_GLOBALS(protobuf)
void free_protobuf_globals(zend_protobuf_globals *globals) {
zend_hash_destroy(&globals->name_msg_cache);
zend_hash_destroy(&globals->name_enum_cache);
upb_DefPool_Free(globals->global_symtab);
globals->global_symtab = NULL;
}
ZEND_DECLARE_MODULE_GLOBALS(protobuf)
upb_DefPool *get_global_symtab() {
return PROTOBUF_G(global_symtab);
}
// This is a PHP extension (not a Zend extension). What follows is a summary of
// a PHP extension's lifetime and when various handlers are called.
//
// * PHP_GINIT_FUNCTION(protobuf) / PHP_GSHUTDOWN_FUNCTION(protobuf)
// are the constructor/destructor for the globals. The sequence over the
// course of a process lifetime is:
//
// # Process startup
// GINIT(<Main Thread Globals>)
// MINIT
//
// foreach request:
// RINIT
// # Request is processed here.
// RSHUTDOWN
//
// foreach thread:
// GINIT(<This Thread Globals>)
// # Code for the thread runs here.
// GSHUTDOWN(<This Thread Globals>)
//
// # Process Shutdown
// #
// # These should be running per the docs, but I have not been able to
// # actually get the process-wide shutdown functions to run.
// #
// # MSHUTDOWN
// # GSHUTDOWN(<Main Thread Globals>)
//
// * Threads can be created either explicitly by the user, inside a request,
// or implicitly by the runtime, to process multiple requests concurrently.
// If the latter is being used, then the "foreach thread" block above
// actually looks like this:
//
// foreach thread:
// GINIT(<This Thread Globals>)
// # A non-main thread will only receive requests when using a threaded
// # MPM with Apache
// foreach request:
// RINIT
// # Request is processed here.
// RSHUTDOWN
// GSHUTDOWN(<This Thread Globals>)
//
// That said, it appears that few people use threads with PHP:
// * The pthread package documented at
// https://www.php.net/manual/en/class.thread.php nas not been released
// since 2016, and the current release fails to compile against any PHP
// newer than 7.0.33.
// * The GitHub master branch supports 7.2+, but this has not been released
// to PECL.
// * Its owner has disavowed it as "broken by design" and "in an untenable
// position for the future": https://github.com/krakjoe/pthreads/issues/929
// * The only way to use PHP with requests in different threads is to use the
// Apache 2 mod_php with the "worker" MPM. But this is explicitly
// discouraged by the documentation: https://serverfault.com/a/231660
static PHP_GSHUTDOWN_FUNCTION(protobuf) {
if (protobuf_globals->global_symtab) {
free_protobuf_globals(protobuf_globals);
}
}
static PHP_GINIT_FUNCTION(protobuf) {
protobuf_globals->global_symtab = NULL;
}
/**
* PHP_RINIT_FUNCTION(protobuf)
*
* This function is run at the beginning of processing each request.
*/
static PHP_RINIT_FUNCTION(protobuf) {
// Create the global generated pool.
// Reuse the symtab (if any) left to us by the last request.
upb_DefPool *symtab = PROTOBUF_G(global_symtab);
if (!symtab) {
PROTOBUF_G(global_symtab) = symtab = upb_DefPool_New();
zend_hash_init(&PROTOBUF_G(name_msg_cache), 64, NULL, NULL, 0);
zend_hash_init(&PROTOBUF_G(name_enum_cache), 64, NULL, NULL, 0);
}
zend_hash_init(&PROTOBUF_G(object_cache), 64, NULL, NULL, 0);
zend_hash_init(&PROTOBUF_G(descriptors), 64, NULL, ZVAL_PTR_DTOR, 0);
PROTOBUF_G(constructing_class) = NULL;
return SUCCESS;
}
/**
* PHP_RSHUTDOWN_FUNCTION(protobuf)
*
* This function is run at the end of processing each request.
*/
static PHP_RSHUTDOWN_FUNCTION(protobuf) {
// Preserve the symtab if requested.
if (!PROTOBUF_G(keep_descriptor_pool_after_request)) {
free_protobuf_globals(ZEND_MODULE_GLOBALS_BULK(protobuf));
}
zend_hash_destroy(&PROTOBUF_G(object_cache));
zend_hash_destroy(&PROTOBUF_G(descriptors));
return SUCCESS;
}
// -----------------------------------------------------------------------------
// Object Cache.
// -----------------------------------------------------------------------------
void Descriptors_Add(zend_object *desc) {
// The hash table will own a ref (it will destroy it when the table is
// destroyed), but for some reason the insert operation does not add a ref, so
// we do that here with ZVAL_OBJ_COPY().
zval zv;
ZVAL_OBJ_COPY(&zv, desc);
zend_hash_next_index_insert(&PROTOBUF_G(descriptors), &zv);
}
void ObjCache_Add(const void *upb_obj, zend_object *php_obj) {
zend_ulong k = (zend_ulong)upb_obj;
zend_hash_index_add_ptr(&PROTOBUF_G(object_cache), k, php_obj);
}
void ObjCache_Delete(const void *upb_obj) {
if (upb_obj) {
zend_ulong k = (zend_ulong)upb_obj;
int ret = zend_hash_index_del(&PROTOBUF_G(object_cache), k);
PBPHP_ASSERT(ret == SUCCESS);
}
}
bool ObjCache_Get(const void *upb_obj, zval *val) {
zend_ulong k = (zend_ulong)upb_obj;
zend_object *obj = zend_hash_index_find_ptr(&PROTOBUF_G(object_cache), k);
if (obj) {
ZVAL_OBJ_COPY(val, obj);
return true;
} else {
ZVAL_NULL(val);
return false;
}
}
// -----------------------------------------------------------------------------
// Name Cache.
// -----------------------------------------------------------------------------
void NameMap_AddMessage(const upb_MessageDef *m) {
for (int i = 0; i < 2; ++i) {
char *k = GetPhpClassname(upb_MessageDef_File(m), upb_MessageDef_FullName(m), (bool)i);
zend_hash_str_add_ptr(&PROTOBUF_G(name_msg_cache), k, strlen(k), (void*)m);
if (!IsPreviouslyUnreservedClassName(k)) {
free(k);
return;
}
free(k);
}
}
void NameMap_AddEnum(const upb_EnumDef *e) {
char *k = GetPhpClassname(upb_EnumDef_File(e), upb_EnumDef_FullName(e), false);
zend_hash_str_add_ptr(&PROTOBUF_G(name_enum_cache), k, strlen(k), (void*)e);
free(k);
}
const upb_MessageDef *NameMap_GetMessage(zend_class_entry *ce) {
const upb_MessageDef *ret =
zend_hash_find_ptr(&PROTOBUF_G(name_msg_cache), ce->name);
if (!ret && ce->create_object && ce != PROTOBUF_G(constructing_class)) {
#if PHP_VERSION_ID < 80000
zval tmp;
zval zv;
ZVAL_OBJ(&tmp, ce->create_object(ce));
zend_call_method_with_0_params(&tmp, ce, NULL, "__construct", &zv);
zval_ptr_dtor(&tmp);
#else
zval zv;
zend_object *tmp = ce->create_object(ce);
zend_call_method_with_0_params(tmp, ce, NULL, "__construct", &zv);
OBJ_RELEASE(tmp);
#endif
zval_ptr_dtor(&zv);
ret = zend_hash_find_ptr(&PROTOBUF_G(name_msg_cache), ce->name);
}
return ret;
}
const upb_EnumDef *NameMap_GetEnum(zend_class_entry *ce) {
const upb_EnumDef *ret =
zend_hash_find_ptr(&PROTOBUF_G(name_enum_cache), ce->name);
return ret;
}
void NameMap_EnterConstructor(zend_class_entry* ce) {
assert(!PROTOBUF_G(constructing_class));
PROTOBUF_G(constructing_class) = ce;
}
void NameMap_ExitConstructor(zend_class_entry* ce) {
assert(PROTOBUF_G(constructing_class) == ce);
PROTOBUF_G(constructing_class) = NULL;
}
// -----------------------------------------------------------------------------
// Module init.
// -----------------------------------------------------------------------------
zend_function_entry protobuf_functions[] = {
ZEND_FE_END
};
static const zend_module_dep protobuf_deps[] = {
ZEND_MOD_OPTIONAL("date")
ZEND_MOD_END
};
PHP_INI_BEGIN()
STD_PHP_INI_ENTRY("protobuf.keep_descriptor_pool_after_request", "0",
PHP_INI_ALL, OnUpdateBool,
keep_descriptor_pool_after_request, zend_protobuf_globals,
protobuf_globals)
PHP_INI_END()
static PHP_MINIT_FUNCTION(protobuf) {
REGISTER_INI_ENTRIES();
Arena_ModuleInit();
Array_ModuleInit();
Convert_ModuleInit();
Def_ModuleInit();
Map_ModuleInit();
Message_ModuleInit();
return SUCCESS;
}
static PHP_MSHUTDOWN_FUNCTION(protobuf) {
UNREGISTER_INI_ENTRIES();
return SUCCESS;
}
zend_module_entry protobuf_module_entry = {
STANDARD_MODULE_HEADER_EX,
NULL,
protobuf_deps,
"protobuf", // extension name
protobuf_functions, // function list
PHP_MINIT(protobuf), // process startup
PHP_MSHUTDOWN(protobuf), // process shutdown
PHP_RINIT(protobuf), // request shutdown
PHP_RSHUTDOWN(protobuf), // request shutdown
NULL, // extension info
PHP_PROTOBUF_VERSION, // extension version
PHP_MODULE_GLOBALS(protobuf), // globals descriptor
PHP_GINIT(protobuf), // globals ctor
PHP_GSHUTDOWN(protobuf), // globals dtor
NULL, // post deactivate
STANDARD_MODULE_PROPERTIES_EX
};
ZEND_GET_MODULE(protobuf)

View File

@@ -0,0 +1,182 @@
// Protocol Buffers - Google's data interchange format
// Copyright 2008 Google Inc. All rights reserved.
// https://developers.google.com/protocol-buffers/
//
// Redistribution and use in source and binary forms, with or without
// modification, are permitted provided that the following conditions are
// met:
//
// * Redistributions of source code must retain the above copyright
// notice, this list of conditions and the following disclaimer.
// * Redistributions in binary form must reproduce the above
// copyright notice, this list of conditions and the following disclaimer
// in the documentation and/or other materials provided with the
// distribution.
// * Neither the name of Google Inc. nor the names of its
// contributors may be used to endorse or promote products derived from
// this software without specific prior written permission.
//
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
#ifndef PHP_PROTOBUF_H_
#define PHP_PROTOBUF_H_
#include <php.h>
#include <stdbool.h>
#include "php-upb.h"
upb_DefPool *get_global_symtab();
#if PHP_VERSION_ID < 70300
#define GC_ADDREF(h) ++GC_REFCOUNT(h)
#define GC_DELREF(h) --GC_REFCOUNT(h)
#endif
// Since php 7.4, the write_property() object handler now returns the assigned
// value (after possible type coercions) rather than void.
// https://github.com/php/php-src/blob/PHP-7.4.0/UPGRADING.INTERNALS#L171-L173
#if PHP_VERSION_ID < 70400
#define PROTO_RETURN_VAL void
#else
#define PROTO_RETURN_VAL zval*
#endif
// Since php 8.0, the Object Handlers API was changed to receive zend_object*
// instead of zval* and zend_string* instead of zval* for property names.
// https://github.com/php/php-src/blob/php-8.0.0beta1/UPGRADING.INTERNALS#L37-L39
#if PHP_VERSION_ID < 80000
#define PROTO_VAL zval
#define PROTO_STR zval
#define PROTO_VAL_P(obj) (void*)Z_OBJ_P(obj)
#define PROTO_STRVAL_P(obj) Z_STRVAL_P(obj)
#define PROTO_STRLEN_P(obj) Z_STRLEN_P(obj)
#define ZVAL_OBJ_COPY(z, o) do { ZVAL_OBJ(z, o); GC_ADDREF(o); } while (0)
#define RETVAL_OBJ_COPY(r) ZVAL_OBJ_COPY(return_value, r)
#define RETURN_OBJ_COPY(r) do { RETVAL_OBJ_COPY(r); return; } while (0)
#define RETURN_COPY(zv) do { ZVAL_COPY(return_value, zv); return; } while (0)
#define RETURN_COPY_VALUE(zv) do { ZVAL_COPY_VALUE(return_value, zv); return; } while (0)
#else
#define PROTO_VAL zend_object
#define PROTO_STR zend_string
#define PROTO_VAL_P(obj) (void*)(obj)
#define PROTO_STRVAL_P(obj) ZSTR_VAL(obj)
#define PROTO_STRLEN_P(obj) ZSTR_LEN(obj)
#endif
// In PHP 8.1, several old interfaces are removed:
// https://github.com/php/php-src/blob/14f599ea7def7c7a59c40aff763ce8b105573e7a/UPGRADING.INTERNALS#L27-L31
//
// We now use the new interfaces (zend_ce_arrayaccess and zend_ce_countable).
// However we have to polyfill zend_ce_countable, which was only introduced in
// PHP 7.2.0.
#if PHP_VERSION_ID < 70200
#define zend_ce_countable spl_ce_Countable
#define ZEND_BEGIN_ARG_WITH_RETURN_OBJ_INFO_EX(name, return_reference, required_num_args, class_name, allow_null) \
ZEND_BEGIN_ARG_INFO_EX(name, return_reference, required_num_args, allow_null)
#endif
// polyfill for ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX, which changes between 7.1 and 7.2
#if PHP_VERSION_ID < 70200
#define PROTOBUF_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(name, return_reference, required_num_args, type, allow_null) \
ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(name, return_reference, required_num_args, type, /*class_name*/ 0, allow_null)
#else
#define PROTOBUF_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(name, return_reference, required_num_args, type, allow_null) \
ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(name, return_reference, required_num_args, type, allow_null)
#endif
// In PHP 8.1, mismatched tentative return types emit a deprecation notice.
// https://wiki.php.net/rfc/internal_method_return_types
//
// When compiling for earlier php versions, the return type is dropped.
#if PHP_VERSION_ID < 80100
#define ZEND_BEGIN_ARG_WITH_TENTATIVE_RETURN_TYPE_INFO_EX(name, return_reference, required_num_args, type, allow_null) \
ZEND_BEGIN_ARG_INFO_EX(name, return_reference, required_num_args, allow_null)
#endif
#ifndef IS_VOID
#define IS_VOID 99
#endif
#ifndef IS_MIXED
#define IS_MIXED 99
#endif
#ifndef _IS_BOOL
#define _IS_BOOL 99
#endif
#ifndef IS_LONG
#define IS_LONG 99
#endif
ZEND_BEGIN_ARG_INFO(arginfo_void, 0)
ZEND_END_ARG_INFO()
ZEND_BEGIN_ARG_INFO_EX(arginfo_setter, 0, 0, 1)
ZEND_ARG_INFO(0, value)
ZEND_END_ARG_INFO()
#define PHP_PROTOBUF_VERSION "3.21.8"
// ptr -> PHP object cache. This is a weak map that caches lazily-created
// wrapper objects around upb types:
// * upb_Message* -> Message
// * upb_Array* -> RepeatedField
// * upb_Map*, -> MapField
// * upb_MessageDef* -> Descriptor
// * upb_EnumDef* -> EnumDescriptor
// * upb_MessageDef* -> Descriptor
//
// Each wrapped object should add itself to the map when it is constructed, and
// remove itself from the map when it is destroyed. This is how we ensure that
// the map only contains live objects. The map is weak so it does not actually
// take references to the cached objects.
void ObjCache_Add(const void *key, zend_object *php_obj);
void ObjCache_Delete(const void *key);
bool ObjCache_Get(const void *key, zval *val);
// PHP class name map. This is necessary because the pb_name->php_class_name
// transformation is non-reversible, so when we need to look up a msgdef or
// enumdef by PHP class, we can't turn the class name into a pb_name.
// * php_class_name -> upb_MessageDef*
// * php_class_name -> upb_EnumDef*
void NameMap_AddMessage(const upb_MessageDef *m);
void NameMap_AddEnum(const upb_EnumDef *m);
const upb_MessageDef *NameMap_GetMessage(zend_class_entry *ce);
const upb_EnumDef *NameMap_GetEnum(zend_class_entry *ce);
void NameMap_EnterConstructor(zend_class_entry* ce);
void NameMap_ExitConstructor(zend_class_entry* ce);
// Add this descriptor object to the global list of descriptors that will be
// kept alive for the duration of the request but destroyed when the request
// is ending.
void Descriptors_Add(zend_object *desc);
// We need our own assert() because PHP takes control of NDEBUG in its headers.
#ifdef PBPHP_ENABLE_ASSERTS
#define PBPHP_ASSERT(x) \
do { \
if (!(x)) { \
fprintf(stderr, "Assertion failure at %s:%d %s", __FILE__, __LINE__, \
#x); \
abort(); \
} \
} while (false)
#else
#define PBPHP_ASSERT(x) \
do { \
} while (false && (x))
#endif
#endif // PHP_PROTOBUF_H_

View File

@@ -0,0 +1,9 @@
--TEST--
unnecessary zval
--FILE--
<?php
var_dump(new \stdClass());
?>
--EXPECT--
object(stdClass)#1 (0) {
}

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,37 @@
#!/usr/bin/env bash
# Run this script to regenerate descriptor protos after the protocol compiler
# changes.
set -e
if [[ -z "${PROTOC}" ]]; then
PROTOC=$(realpath protoc)
fi
if [ ! -f $PROTOC ]; then
bazel build -c opt //:protoc
PROTOC=$(realpath bazel-bin/protoc)
fi
if test ! -e src/google/protobuf/stubs/common.h; then
cat >&2 << __EOF__
Could not find source code. Make sure you are running this script from the
root of the distribution tree.
__EOF__
exit 1
fi
pushd src
$PROTOC --php_out=internal:../php/src google/protobuf/descriptor.proto
$PROTOC --php_out=internal_generate_c_wkt:../php/src \
google/protobuf/any.proto \
google/protobuf/api.proto \
google/protobuf/duration.proto \
google/protobuf/empty.proto \
google/protobuf/field_mask.proto \
google/protobuf/source_context.proto \
google/protobuf/struct.proto \
google/protobuf/type.proto \
google/protobuf/timestamp.proto \
google/protobuf/wrappers.proto
popd

35
php/generate_test_protos.sh Executable file
View File

@@ -0,0 +1,35 @@
#!/bin/bash
set -ex
cd `dirname $0`/..
if [[ -z "${PROTOC}" ]]; then
PROTOC=$(pwd)/protoc
fi
if [ ! -f $PROTOC ]; then
bazel build -c opt //:protoc
PROTOC=$(pwd)/bazel-bin/protoc
fi
if [[ -d php/tmp && -z $(find php/tests/proto $PROTOC -newer php/tmp) ]]; then
# Generated protos are already present and up to date, so we can skip protoc.
#
# Protoc is very fast, but sometimes it is not available (like if we haven't
# built it in Docker). Skipping it helps us proceed in this case.
echo "Test protos are up-to-date, skipping protoc."
exit 0
fi
rm -rf php/tmp
mkdir -p php/tmp
find php/tests/proto -type f -name "*.proto"| xargs $PROTOC --php_out=php/tmp -Isrc -Iphp/tests
if [ "$1" = "--aggregate_metadata" ]; then
# Overwrite some of the files to use aggregation.
AGGREGATED_FILES="tests/proto/test.proto tests/proto/test_include.proto tests/proto/test_import_descriptor_proto.proto"
$PROTOC --php_out=aggregate_metadata=foo#bar:php/tmp -Isrc -Iphp/tests $AGGREGATED_FILES
fi
echo "Generated test protos from tests/proto -> tmp"

30
php/release.sh Executable file
View File

@@ -0,0 +1,30 @@
#!/bin/bash
set -ex
# Make sure we are in a protobuf source tree.
[ -f "php/release.sh" ] || {
echo "This script must be ran under root of protobuf source tree."
exit 1
}
VERSION=$1
rm -rf protobuf-php
git clone https://github.com/protocolbuffers/protobuf-php.git
# Clean old files
rm -rf protobuf-php/src
# Copy files
cp -r php/src protobuf-php
cp php/composer.json.dist protobuf-php/composer.json
cd protobuf-php
git add .
git commit -m "$VERSION"
if [ $(git tag -l "$VERSION") ]; then
echo "tag $VERSION already exists"
else
git tag "$VERSION"
fi

View File

@@ -0,0 +1,30 @@
<?php
# Generated by the protocol buffer compiler. DO NOT EDIT!
# source: google/protobuf/any.proto
namespace GPBMetadata\Google\Protobuf;
class Any
{
public static $is_initialized = false;
public static function initOnce() {
$pool = \Google\Protobuf\Internal\DescriptorPool::getGeneratedPool();
if (static::$is_initialized == true) {
return;
}
$pool->internalAddGeneratedFile(
'
Ô
google/protobuf/any.protogoogle.protobuf"&
Any
type_url ( 
value ( Bv
com.google.protobufBAnyProtoPZ,google.golang.org/protobuf/types/known/anypb˘GPBŞGoogle.Protobuf.WellKnownTypesbproto3'
, true);
static::$is_initialized = true;
}
}

View File

@@ -0,0 +1,48 @@
<?php
# Generated by the protocol buffer compiler. DO NOT EDIT!
# source: google/protobuf/api.proto
namespace GPBMetadata\Google\Protobuf;
class Api
{
public static $is_initialized = false;
public static function initOnce() {
$pool = \Google\Protobuf\Internal\DescriptorPool::getGeneratedPool();
if (static::$is_initialized == true) {
return;
}
\GPBMetadata\Google\Protobuf\SourceContext::initOnce();
\GPBMetadata\Google\Protobuf\Type::initOnce();
$pool->internalAddGeneratedFile(
'
É
google/protobuf/api.protogoogle.protobufgoogle/protobuf/type.proto"<22>
Api
name ( (
methods ( 2.google.protobuf.Method(
options ( 2.google.protobuf.Option
version ( 6
source_context ( 2.google.protobuf.SourceContext&
mixins ( 2.google.protobuf.Mixin\'
syntax (2.google.protobuf.Syntax"Ő
Method
name ( 
request_type_url ( 
request_streaming (
response_type_url ( 
response_streaming ((
options ( 2.google.protobuf.Option\'
syntax (2.google.protobuf.Syntax"#
Mixin
name ( 
root ( Bv
com.google.protobufBApiProtoPZ,google.golang.org/protobuf/types/known/apipb˘GPBŞGoogle.Protobuf.WellKnownTypesbproto3'
, true);
static::$is_initialized = true;
}
}

View File

@@ -0,0 +1,30 @@
<?php
# Generated by the protocol buffer compiler. DO NOT EDIT!
# source: google/protobuf/duration.proto
namespace GPBMetadata\Google\Protobuf;
class Duration
{
public static $is_initialized = false;
public static function initOnce() {
$pool = \Google\Protobuf\Internal\DescriptorPool::getGeneratedPool();
if (static::$is_initialized == true) {
return;
}
$pool->internalAddGeneratedFile(
'
ë
google/protobuf/duration.protogoogle.protobuf"*
Duration
seconds (
nanos (
com.google.protobufB
DurationProtoPZ1google.golang.org/protobuf/types/known/durationpbø¢GPBªGoogle.Protobuf.WellKnownTypesbproto3'
, true);
static::$is_initialized = true;
}
}

View File

@@ -0,0 +1,29 @@
<?php
# Generated by the protocol buffer compiler. DO NOT EDIT!
# source: google/protobuf/field_mask.proto
namespace GPBMetadata\Google\Protobuf;
class FieldMask
{
public static $is_initialized = false;
public static function initOnce() {
$pool = \Google\Protobuf\Internal\DescriptorPool::getGeneratedPool();
if (static::$is_initialized == true) {
return;
}
$pool->internalAddGeneratedFile(
'
ß
google/protobuf/field_mask.protogoogle.protobuf"
FieldMask
paths ( B…
com.google.protobufBFieldMaskProtoPZ2google.golang.org/protobuf/types/known/fieldmaskpbř˘GPBŞGoogle.Protobuf.WellKnownTypesbproto3'
, true);
static::$is_initialized = true;
}
}

View File

@@ -0,0 +1,29 @@
<?php
# Generated by the protocol buffer compiler. DO NOT EDIT!
# source: google/protobuf/empty.proto
namespace GPBMetadata\Google\Protobuf;
class GPBEmpty
{
public static $is_initialized = false;
public static function initOnce() {
$pool = \Google\Protobuf\Internal\DescriptorPool::getGeneratedPool();
if (static::$is_initialized == true) {
return;
}
$pool->internalAddGeneratedFile(
'
ž
google/protobuf/empty.protogoogle.protobuf"
EmptyB}
com.google.protobufB
EmptyProtoPZ.google.golang.org/protobuf/types/known/emptypbř˘GPBŞGoogle.Protobuf.WellKnownTypesbproto3'
, true);
static::$is_initialized = true;
}
}

View File

@@ -0,0 +1,280 @@
<?php
# Generated by the protocol buffer compiler. DO NOT EDIT!
# source: google/protobuf/descriptor.proto
namespace GPBMetadata\Google\Protobuf\Internal;
class Descriptor
{
public static $is_initialized = false;
public static function initOnce() {
$pool = \Google\Protobuf\Internal\DescriptorPool::getGeneratedPool();
if (static::$is_initialized == true) {
return;
}
$pool->addMessage('google.protobuf.internal.FileDescriptorSet', \Google\Protobuf\Internal\FileDescriptorSet::class)
->repeated('file', \Google\Protobuf\Internal\GPBType::MESSAGE, 1, 'google.protobuf.internal.FileDescriptorProto')
->finalizeToPool();
$pool->addMessage('google.protobuf.internal.FileDescriptorProto', \Google\Protobuf\Internal\FileDescriptorProto::class)
->optional('name', \Google\Protobuf\Internal\GPBType::STRING, 1)
->optional('package', \Google\Protobuf\Internal\GPBType::STRING, 2)
->repeated('dependency', \Google\Protobuf\Internal\GPBType::STRING, 3)
->repeated('public_dependency', \Google\Protobuf\Internal\GPBType::INT32, 10)
->repeated('weak_dependency', \Google\Protobuf\Internal\GPBType::INT32, 11)
->repeated('message_type', \Google\Protobuf\Internal\GPBType::MESSAGE, 4, 'google.protobuf.internal.DescriptorProto')
->repeated('enum_type', \Google\Protobuf\Internal\GPBType::MESSAGE, 5, 'google.protobuf.internal.EnumDescriptorProto')
->repeated('service', \Google\Protobuf\Internal\GPBType::MESSAGE, 6, 'google.protobuf.internal.ServiceDescriptorProto')
->repeated('extension', \Google\Protobuf\Internal\GPBType::MESSAGE, 7, 'google.protobuf.internal.FieldDescriptorProto')
->optional('options', \Google\Protobuf\Internal\GPBType::MESSAGE, 8, 'google.protobuf.internal.FileOptions')
->optional('source_code_info', \Google\Protobuf\Internal\GPBType::MESSAGE, 9, 'google.protobuf.internal.SourceCodeInfo')
->optional('syntax', \Google\Protobuf\Internal\GPBType::STRING, 12)
->optional('edition', \Google\Protobuf\Internal\GPBType::STRING, 13)
->finalizeToPool();
$pool->addMessage('google.protobuf.internal.DescriptorProto', \Google\Protobuf\Internal\DescriptorProto::class)
->optional('name', \Google\Protobuf\Internal\GPBType::STRING, 1)
->repeated('field', \Google\Protobuf\Internal\GPBType::MESSAGE, 2, 'google.protobuf.internal.FieldDescriptorProto')
->repeated('extension', \Google\Protobuf\Internal\GPBType::MESSAGE, 6, 'google.protobuf.internal.FieldDescriptorProto')
->repeated('nested_type', \Google\Protobuf\Internal\GPBType::MESSAGE, 3, 'google.protobuf.internal.DescriptorProto')
->repeated('enum_type', \Google\Protobuf\Internal\GPBType::MESSAGE, 4, 'google.protobuf.internal.EnumDescriptorProto')
->repeated('extension_range', \Google\Protobuf\Internal\GPBType::MESSAGE, 5, 'google.protobuf.internal.DescriptorProto.ExtensionRange')
->repeated('oneof_decl', \Google\Protobuf\Internal\GPBType::MESSAGE, 8, 'google.protobuf.internal.OneofDescriptorProto')
->optional('options', \Google\Protobuf\Internal\GPBType::MESSAGE, 7, 'google.protobuf.internal.MessageOptions')
->repeated('reserved_range', \Google\Protobuf\Internal\GPBType::MESSAGE, 9, 'google.protobuf.internal.DescriptorProto.ReservedRange')
->repeated('reserved_name', \Google\Protobuf\Internal\GPBType::STRING, 10)
->finalizeToPool();
$pool->addMessage('google.protobuf.internal.DescriptorProto.ExtensionRange', \Google\Protobuf\Internal\DescriptorProto\ExtensionRange::class)
->optional('start', \Google\Protobuf\Internal\GPBType::INT32, 1)
->optional('end', \Google\Protobuf\Internal\GPBType::INT32, 2)
->optional('options', \Google\Protobuf\Internal\GPBType::MESSAGE, 3, 'google.protobuf.internal.ExtensionRangeOptions')
->finalizeToPool();
$pool->addMessage('google.protobuf.internal.DescriptorProto.ReservedRange', \Google\Protobuf\Internal\DescriptorProto\ReservedRange::class)
->optional('start', \Google\Protobuf\Internal\GPBType::INT32, 1)
->optional('end', \Google\Protobuf\Internal\GPBType::INT32, 2)
->finalizeToPool();
$pool->addMessage('google.protobuf.internal.ExtensionRangeOptions', \Google\Protobuf\Internal\ExtensionRangeOptions::class)
->repeated('uninterpreted_option', \Google\Protobuf\Internal\GPBType::MESSAGE, 999, 'google.protobuf.internal.UninterpretedOption')
->finalizeToPool();
$pool->addMessage('google.protobuf.internal.FieldDescriptorProto', \Google\Protobuf\Internal\FieldDescriptorProto::class)
->optional('name', \Google\Protobuf\Internal\GPBType::STRING, 1)
->optional('number', \Google\Protobuf\Internal\GPBType::INT32, 3)
->optional('label', \Google\Protobuf\Internal\GPBType::ENUM, 4, 'google.protobuf.internal.FieldDescriptorProto.Label')
->optional('type', \Google\Protobuf\Internal\GPBType::ENUM, 5, 'google.protobuf.internal.FieldDescriptorProto.Type')
->optional('type_name', \Google\Protobuf\Internal\GPBType::STRING, 6)
->optional('extendee', \Google\Protobuf\Internal\GPBType::STRING, 2)
->optional('default_value', \Google\Protobuf\Internal\GPBType::STRING, 7)
->optional('oneof_index', \Google\Protobuf\Internal\GPBType::INT32, 9)
->optional('json_name', \Google\Protobuf\Internal\GPBType::STRING, 10)
->optional('options', \Google\Protobuf\Internal\GPBType::MESSAGE, 8, 'google.protobuf.internal.FieldOptions')
->optional('proto3_optional', \Google\Protobuf\Internal\GPBType::BOOL, 17)
->finalizeToPool();
$pool->addEnum('google.protobuf.internal.FieldDescriptorProto.Type', \Google\Protobuf\Internal\Type::class)
->value("TYPE_DOUBLE", 1)
->value("TYPE_FLOAT", 2)
->value("TYPE_INT64", 3)
->value("TYPE_UINT64", 4)
->value("TYPE_INT32", 5)
->value("TYPE_FIXED64", 6)
->value("TYPE_FIXED32", 7)
->value("TYPE_BOOL", 8)
->value("TYPE_STRING", 9)
->value("TYPE_GROUP", 10)
->value("TYPE_MESSAGE", 11)
->value("TYPE_BYTES", 12)
->value("TYPE_UINT32", 13)
->value("TYPE_ENUM", 14)
->value("TYPE_SFIXED32", 15)
->value("TYPE_SFIXED64", 16)
->value("TYPE_SINT32", 17)
->value("TYPE_SINT64", 18)
->finalizeToPool();
$pool->addEnum('google.protobuf.internal.FieldDescriptorProto.Label', \Google\Protobuf\Internal\Label::class)
->value("LABEL_OPTIONAL", 1)
->value("LABEL_REQUIRED", 2)
->value("LABEL_REPEATED", 3)
->finalizeToPool();
$pool->addMessage('google.protobuf.internal.OneofDescriptorProto', \Google\Protobuf\Internal\OneofDescriptorProto::class)
->optional('name', \Google\Protobuf\Internal\GPBType::STRING, 1)
->optional('options', \Google\Protobuf\Internal\GPBType::MESSAGE, 2, 'google.protobuf.internal.OneofOptions')
->finalizeToPool();
$pool->addMessage('google.protobuf.internal.EnumDescriptorProto', \Google\Protobuf\Internal\EnumDescriptorProto::class)
->optional('name', \Google\Protobuf\Internal\GPBType::STRING, 1)
->repeated('value', \Google\Protobuf\Internal\GPBType::MESSAGE, 2, 'google.protobuf.internal.EnumValueDescriptorProto')
->optional('options', \Google\Protobuf\Internal\GPBType::MESSAGE, 3, 'google.protobuf.internal.EnumOptions')
->repeated('reserved_range', \Google\Protobuf\Internal\GPBType::MESSAGE, 4, 'google.protobuf.internal.EnumDescriptorProto.EnumReservedRange')
->repeated('reserved_name', \Google\Protobuf\Internal\GPBType::STRING, 5)
->finalizeToPool();
$pool->addMessage('google.protobuf.internal.EnumDescriptorProto.EnumReservedRange', \Google\Protobuf\Internal\EnumDescriptorProto\EnumReservedRange::class)
->optional('start', \Google\Protobuf\Internal\GPBType::INT32, 1)
->optional('end', \Google\Protobuf\Internal\GPBType::INT32, 2)
->finalizeToPool();
$pool->addMessage('google.protobuf.internal.EnumValueDescriptorProto', \Google\Protobuf\Internal\EnumValueDescriptorProto::class)
->optional('name', \Google\Protobuf\Internal\GPBType::STRING, 1)
->optional('number', \Google\Protobuf\Internal\GPBType::INT32, 2)
->optional('options', \Google\Protobuf\Internal\GPBType::MESSAGE, 3, 'google.protobuf.internal.EnumValueOptions')
->finalizeToPool();
$pool->addMessage('google.protobuf.internal.ServiceDescriptorProto', \Google\Protobuf\Internal\ServiceDescriptorProto::class)
->optional('name', \Google\Protobuf\Internal\GPBType::STRING, 1)
->repeated('method', \Google\Protobuf\Internal\GPBType::MESSAGE, 2, 'google.protobuf.internal.MethodDescriptorProto')
->optional('options', \Google\Protobuf\Internal\GPBType::MESSAGE, 3, 'google.protobuf.internal.ServiceOptions')
->finalizeToPool();
$pool->addMessage('google.protobuf.internal.MethodDescriptorProto', \Google\Protobuf\Internal\MethodDescriptorProto::class)
->optional('name', \Google\Protobuf\Internal\GPBType::STRING, 1)
->optional('input_type', \Google\Protobuf\Internal\GPBType::STRING, 2)
->optional('output_type', \Google\Protobuf\Internal\GPBType::STRING, 3)
->optional('options', \Google\Protobuf\Internal\GPBType::MESSAGE, 4, 'google.protobuf.internal.MethodOptions')
->optional('client_streaming', \Google\Protobuf\Internal\GPBType::BOOL, 5)
->optional('server_streaming', \Google\Protobuf\Internal\GPBType::BOOL, 6)
->finalizeToPool();
$pool->addMessage('google.protobuf.internal.FileOptions', \Google\Protobuf\Internal\FileOptions::class)
->optional('java_package', \Google\Protobuf\Internal\GPBType::STRING, 1)
->optional('java_outer_classname', \Google\Protobuf\Internal\GPBType::STRING, 8)
->optional('java_multiple_files', \Google\Protobuf\Internal\GPBType::BOOL, 10)
->optional('java_generate_equals_and_hash', \Google\Protobuf\Internal\GPBType::BOOL, 20)
->optional('java_string_check_utf8', \Google\Protobuf\Internal\GPBType::BOOL, 27)
->optional('optimize_for', \Google\Protobuf\Internal\GPBType::ENUM, 9, 'google.protobuf.internal.FileOptions.OptimizeMode')
->optional('go_package', \Google\Protobuf\Internal\GPBType::STRING, 11)
->optional('cc_generic_services', \Google\Protobuf\Internal\GPBType::BOOL, 16)
->optional('java_generic_services', \Google\Protobuf\Internal\GPBType::BOOL, 17)
->optional('py_generic_services', \Google\Protobuf\Internal\GPBType::BOOL, 18)
->optional('php_generic_services', \Google\Protobuf\Internal\GPBType::BOOL, 42)
->optional('deprecated', \Google\Protobuf\Internal\GPBType::BOOL, 23)
->optional('cc_enable_arenas', \Google\Protobuf\Internal\GPBType::BOOL, 31)
->optional('objc_class_prefix', \Google\Protobuf\Internal\GPBType::STRING, 36)
->optional('csharp_namespace', \Google\Protobuf\Internal\GPBType::STRING, 37)
->optional('swift_prefix', \Google\Protobuf\Internal\GPBType::STRING, 39)
->optional('php_class_prefix', \Google\Protobuf\Internal\GPBType::STRING, 40)
->optional('php_namespace', \Google\Protobuf\Internal\GPBType::STRING, 41)
->optional('php_metadata_namespace', \Google\Protobuf\Internal\GPBType::STRING, 44)
->optional('ruby_package', \Google\Protobuf\Internal\GPBType::STRING, 45)
->repeated('uninterpreted_option', \Google\Protobuf\Internal\GPBType::MESSAGE, 999, 'google.protobuf.internal.UninterpretedOption')
->finalizeToPool();
$pool->addEnum('google.protobuf.internal.FileOptions.OptimizeMode', \Google\Protobuf\Internal\OptimizeMode::class)
->value("SPEED", 1)
->value("CODE_SIZE", 2)
->value("LITE_RUNTIME", 3)
->finalizeToPool();
$pool->addMessage('google.protobuf.internal.MessageOptions', \Google\Protobuf\Internal\MessageOptions::class)
->optional('message_set_wire_format', \Google\Protobuf\Internal\GPBType::BOOL, 1)
->optional('no_standard_descriptor_accessor', \Google\Protobuf\Internal\GPBType::BOOL, 2)
->optional('deprecated', \Google\Protobuf\Internal\GPBType::BOOL, 3)
->optional('map_entry', \Google\Protobuf\Internal\GPBType::BOOL, 7)
->repeated('uninterpreted_option', \Google\Protobuf\Internal\GPBType::MESSAGE, 999, 'google.protobuf.internal.UninterpretedOption')
->finalizeToPool();
$pool->addMessage('google.protobuf.internal.FieldOptions', \Google\Protobuf\Internal\FieldOptions::class)
->optional('ctype', \Google\Protobuf\Internal\GPBType::ENUM, 1, 'google.protobuf.internal.FieldOptions.CType')
->optional('packed', \Google\Protobuf\Internal\GPBType::BOOL, 2)
->optional('jstype', \Google\Protobuf\Internal\GPBType::ENUM, 6, 'google.protobuf.internal.FieldOptions.JSType')
->optional('lazy', \Google\Protobuf\Internal\GPBType::BOOL, 5)
->optional('unverified_lazy', \Google\Protobuf\Internal\GPBType::BOOL, 15)
->optional('deprecated', \Google\Protobuf\Internal\GPBType::BOOL, 3)
->optional('weak', \Google\Protobuf\Internal\GPBType::BOOL, 10)
->repeated('uninterpreted_option', \Google\Protobuf\Internal\GPBType::MESSAGE, 999, 'google.protobuf.internal.UninterpretedOption')
->finalizeToPool();
$pool->addEnum('google.protobuf.internal.FieldOptions.CType', \Google\Protobuf\Internal\CType::class)
->value("STRING", 0)
->value("CORD", 1)
->value("STRING_PIECE", 2)
->finalizeToPool();
$pool->addEnum('google.protobuf.internal.FieldOptions.JSType', \Google\Protobuf\Internal\JSType::class)
->value("JS_NORMAL", 0)
->value("JS_STRING", 1)
->value("JS_NUMBER", 2)
->finalizeToPool();
$pool->addMessage('google.protobuf.internal.OneofOptions', \Google\Protobuf\Internal\OneofOptions::class)
->repeated('uninterpreted_option', \Google\Protobuf\Internal\GPBType::MESSAGE, 999, 'google.protobuf.internal.UninterpretedOption')
->finalizeToPool();
$pool->addMessage('google.protobuf.internal.EnumOptions', \Google\Protobuf\Internal\EnumOptions::class)
->optional('allow_alias', \Google\Protobuf\Internal\GPBType::BOOL, 2)
->optional('deprecated', \Google\Protobuf\Internal\GPBType::BOOL, 3)
->repeated('uninterpreted_option', \Google\Protobuf\Internal\GPBType::MESSAGE, 999, 'google.protobuf.internal.UninterpretedOption')
->finalizeToPool();
$pool->addMessage('google.protobuf.internal.EnumValueOptions', \Google\Protobuf\Internal\EnumValueOptions::class)
->optional('deprecated', \Google\Protobuf\Internal\GPBType::BOOL, 1)
->repeated('uninterpreted_option', \Google\Protobuf\Internal\GPBType::MESSAGE, 999, 'google.protobuf.internal.UninterpretedOption')
->finalizeToPool();
$pool->addMessage('google.protobuf.internal.ServiceOptions', \Google\Protobuf\Internal\ServiceOptions::class)
->optional('deprecated', \Google\Protobuf\Internal\GPBType::BOOL, 33)
->repeated('uninterpreted_option', \Google\Protobuf\Internal\GPBType::MESSAGE, 999, 'google.protobuf.internal.UninterpretedOption')
->finalizeToPool();
$pool->addMessage('google.protobuf.internal.MethodOptions', \Google\Protobuf\Internal\MethodOptions::class)
->optional('deprecated', \Google\Protobuf\Internal\GPBType::BOOL, 33)
->optional('idempotency_level', \Google\Protobuf\Internal\GPBType::ENUM, 34, 'google.protobuf.internal.MethodOptions.IdempotencyLevel')
->repeated('uninterpreted_option', \Google\Protobuf\Internal\GPBType::MESSAGE, 999, 'google.protobuf.internal.UninterpretedOption')
->finalizeToPool();
$pool->addEnum('google.protobuf.internal.MethodOptions.IdempotencyLevel', \Google\Protobuf\Internal\IdempotencyLevel::class)
->value("IDEMPOTENCY_UNKNOWN", 0)
->value("NO_SIDE_EFFECTS", 1)
->value("IDEMPOTENT", 2)
->finalizeToPool();
$pool->addMessage('google.protobuf.internal.UninterpretedOption', \Google\Protobuf\Internal\UninterpretedOption::class)
->repeated('name', \Google\Protobuf\Internal\GPBType::MESSAGE, 2, 'google.protobuf.internal.UninterpretedOption.NamePart')
->optional('identifier_value', \Google\Protobuf\Internal\GPBType::STRING, 3)
->optional('positive_int_value', \Google\Protobuf\Internal\GPBType::UINT64, 4)
->optional('negative_int_value', \Google\Protobuf\Internal\GPBType::INT64, 5)
->optional('double_value', \Google\Protobuf\Internal\GPBType::DOUBLE, 6)
->optional('string_value', \Google\Protobuf\Internal\GPBType::BYTES, 7)
->optional('aggregate_value', \Google\Protobuf\Internal\GPBType::STRING, 8)
->finalizeToPool();
$pool->addMessage('google.protobuf.internal.UninterpretedOption.NamePart', \Google\Protobuf\Internal\UninterpretedOption\NamePart::class)
->required('name_part', \Google\Protobuf\Internal\GPBType::STRING, 1)
->required('is_extension', \Google\Protobuf\Internal\GPBType::BOOL, 2)
->finalizeToPool();
$pool->addMessage('google.protobuf.internal.SourceCodeInfo', \Google\Protobuf\Internal\SourceCodeInfo::class)
->repeated('location', \Google\Protobuf\Internal\GPBType::MESSAGE, 1, 'google.protobuf.internal.SourceCodeInfo.Location')
->finalizeToPool();
$pool->addMessage('google.protobuf.internal.SourceCodeInfo.Location', \Google\Protobuf\Internal\SourceCodeInfo\Location::class)
->repeated('path', \Google\Protobuf\Internal\GPBType::INT32, 1)
->repeated('span', \Google\Protobuf\Internal\GPBType::INT32, 2)
->optional('leading_comments', \Google\Protobuf\Internal\GPBType::STRING, 3)
->optional('trailing_comments', \Google\Protobuf\Internal\GPBType::STRING, 4)
->repeated('leading_detached_comments', \Google\Protobuf\Internal\GPBType::STRING, 6)
->finalizeToPool();
$pool->addMessage('google.protobuf.internal.GeneratedCodeInfo', \Google\Protobuf\Internal\GeneratedCodeInfo::class)
->repeated('annotation', \Google\Protobuf\Internal\GPBType::MESSAGE, 1, 'google.protobuf.internal.GeneratedCodeInfo.Annotation')
->finalizeToPool();
$pool->addMessage('google.protobuf.internal.GeneratedCodeInfo.Annotation', \Google\Protobuf\Internal\GeneratedCodeInfo\Annotation::class)
->repeated('path', \Google\Protobuf\Internal\GPBType::INT32, 1)
->optional('source_file', \Google\Protobuf\Internal\GPBType::STRING, 2)
->optional('begin', \Google\Protobuf\Internal\GPBType::INT32, 3)
->optional('end', \Google\Protobuf\Internal\GPBType::INT32, 4)
->finalizeToPool();
$pool->finish();
static::$is_initialized = true;
}
}

View File

@@ -0,0 +1,29 @@
<?php
# Generated by the protocol buffer compiler. DO NOT EDIT!
# source: google/protobuf/source_context.proto
namespace GPBMetadata\Google\Protobuf;
class SourceContext
{
public static $is_initialized = false;
public static function initOnce() {
$pool = \Google\Protobuf\Internal\DescriptorPool::getGeneratedPool();
if (static::$is_initialized == true) {
return;
}
$pool->internalAddGeneratedFile(
'
ð
$google/protobuf/source_context.protogoogle.protobuf""
SourceContext
file_name ( BŠ
com.google.protobufBSourceContextProtoPZ6google.golang.org/protobuf/types/known/sourcecontextpb¢GPBªGoogle.Protobuf.WellKnownTypesbproto3'
, true);
static::$is_initialized = true;
}
}

Binary file not shown.

View File

@@ -0,0 +1,30 @@
<?php
# Generated by the protocol buffer compiler. DO NOT EDIT!
# source: google/protobuf/timestamp.proto
namespace GPBMetadata\Google\Protobuf;
class Timestamp
{
public static $is_initialized = false;
public static function initOnce() {
$pool = \Google\Protobuf\Internal\DescriptorPool::getGeneratedPool();
if (static::$is_initialized == true) {
return;
}
$pool->internalAddGeneratedFile(
'
ď
google/protobuf/timestamp.protogoogle.protobuf"+
Timestamp
seconds (
nanos (B…
com.google.protobufBTimestampProtoPZ2google.golang.org/protobuf/types/known/timestamppbř˘GPBŞGoogle.Protobuf.WellKnownTypesbproto3'
, true);
static::$is_initialized = true;
}
}

Binary file not shown.

View File

@@ -0,0 +1,49 @@
<?php
# Generated by the protocol buffer compiler. DO NOT EDIT!
# source: google/protobuf/wrappers.proto
namespace GPBMetadata\Google\Protobuf;
class Wrappers
{
public static $is_initialized = false;
public static function initOnce() {
$pool = \Google\Protobuf\Internal\DescriptorPool::getGeneratedPool();
if (static::$is_initialized == true) {
return;
}
$pool->internalAddGeneratedFile(
'
Ç
google/protobuf/wrappers.protogoogle.protobuf"
DoubleValue
value ("
FloatValue
value ("
Int64Value
value ("
UInt64Value
value ("
Int32Value
value ("
UInt32Value
value (
"
BoolValue
value ("
StringValue
value ( "
BytesValue
value ( 
com.google.protobufB
WrappersProtoPZ1google.golang.org/protobuf/types/known/wrapperspbø¢GPBªGoogle.Protobuf.WellKnownTypesbproto3'
, true);
static::$is_initialized = true;
}

View File

@@ -0,0 +1,253 @@
<?php
# Generated by the protocol buffer compiler. DO NOT EDIT!
# source: google/protobuf/any.proto
namespace Google\Protobuf;
use Google\Protobuf\Internal\GPBType;
use Google\Protobuf\Internal\RepeatedField;
use Google\Protobuf\Internal\GPBUtil;
/**
* `Any` contains an arbitrary serialized protocol buffer message along with a
* URL that describes the type of the serialized message.
* Protobuf library provides support to pack/unpack Any values in the form
* of utility functions or additional generated methods of the Any type.
* Example 1: Pack and unpack a message in C++.
* Foo foo = ...;
* Any any;
* any.PackFrom(foo);
* ...
* if (any.UnpackTo(&foo)) {
* ...
* }
* Example 2: Pack and unpack a message in Java.
* Foo foo = ...;
* Any any = Any.pack(foo);
* ...
* if (any.is(Foo.class)) {
* foo = any.unpack(Foo.class);
* }
* Example 3: Pack and unpack a message in Python.
* foo = Foo(...)
* any = Any()
* any.Pack(foo)
* ...
* if any.Is(Foo.DESCRIPTOR):
* any.Unpack(foo)
* ...
* Example 4: Pack and unpack a message in Go
* foo := &pb.Foo{...}
* any, err := anypb.New(foo)
* if err != nil {
* ...
* }
* ...
* foo := &pb.Foo{}
* if err := any.UnmarshalTo(foo); err != nil {
* ...
* }
* The pack methods provided by protobuf library will by default use
* 'type.googleapis.com/full.type.name' as the type URL and the unpack
* methods only use the fully qualified type name after the last '/'
* in the type URL, for example "foo.bar.com/x/y.z" will yield type
* name "y.z".
* JSON
* The JSON representation of an `Any` value uses the regular
* representation of the deserialized, embedded message, with an
* additional field `&#64;type` which contains the type URL. Example:
* package google.profile;
* message Person {
* string first_name = 1;
* string last_name = 2;
* }
* {
* "&#64;type": "type.googleapis.com/google.profile.Person",
* "firstName": <string>,
* "lastName": <string>
* }
* If the embedded message type is well-known and has a custom JSON
* representation, that representation will be embedded adding a field
* `value` which holds the custom JSON in addition to the `&#64;type`
* field. Example (for message [google.protobuf.Duration][]):
* {
* "&#64;type": "type.googleapis.com/google.protobuf.Duration",
* "value": "1.212s"
* }
*
* Generated from protobuf message <code>google.protobuf.Any</code>
*/
class Any extends \Google\Protobuf\Internal\AnyBase
{
/**
* A URL/resource name that uniquely identifies the type of the serialized
* protocol buffer message. This string must contain at least
* one "/" character. The last segment of the URL's path must represent
* the fully qualified name of the type (as in
* `path/google.protobuf.Duration`). The name should be in a canonical form
* (e.g., leading "." is not accepted).
* In practice, teams usually precompile into the binary all types that they
* expect it to use in the context of Any. However, for URLs which use the
* scheme `http`, `https`, or no scheme, one can optionally set up a type
* server that maps type URLs to message definitions as follows:
* * If no scheme is provided, `https` is assumed.
* * An HTTP GET on the URL must yield a [google.protobuf.Type][]
* value in binary format, or produce an error.
* * Applications are allowed to cache lookup results based on the
* URL, or have them precompiled into a binary to avoid any
* lookup. Therefore, binary compatibility needs to be preserved
* on changes to types. (Use versioned type names to manage
* breaking changes.)
* Note: this functionality is not currently available in the official
* protobuf release, and it is not used for type URLs beginning with
* type.googleapis.com.
* Schemes other than `http`, `https` (or the empty scheme) might be
* used with implementation specific semantics.
*
* Generated from protobuf field <code>string type_url = 1;</code>
*/
protected $type_url = '';
/**
* Must be a valid serialized protocol buffer of the above specified type.
*
* Generated from protobuf field <code>bytes value = 2;</code>
*/
protected $value = '';
/**
* Constructor.
*
* @param array $data {
* Optional. Data for populating the Message object.
*
* @type string $type_url
* A URL/resource name that uniquely identifies the type of the serialized
* protocol buffer message. This string must contain at least
* one "/" character. The last segment of the URL's path must represent
* the fully qualified name of the type (as in
* `path/google.protobuf.Duration`). The name should be in a canonical form
* (e.g., leading "." is not accepted).
* In practice, teams usually precompile into the binary all types that they
* expect it to use in the context of Any. However, for URLs which use the
* scheme `http`, `https`, or no scheme, one can optionally set up a type
* server that maps type URLs to message definitions as follows:
* * If no scheme is provided, `https` is assumed.
* * An HTTP GET on the URL must yield a [google.protobuf.Type][]
* value in binary format, or produce an error.
* * Applications are allowed to cache lookup results based on the
* URL, or have them precompiled into a binary to avoid any
* lookup. Therefore, binary compatibility needs to be preserved
* on changes to types. (Use versioned type names to manage
* breaking changes.)
* Note: this functionality is not currently available in the official
* protobuf release, and it is not used for type URLs beginning with
* type.googleapis.com.
* Schemes other than `http`, `https` (or the empty scheme) might be
* used with implementation specific semantics.
* @type string $value
* Must be a valid serialized protocol buffer of the above specified type.
* }
*/
public function __construct($data = NULL) {
\GPBMetadata\Google\Protobuf\Any::initOnce();
parent::__construct($data);
}
/**
* A URL/resource name that uniquely identifies the type of the serialized
* protocol buffer message. This string must contain at least
* one "/" character. The last segment of the URL's path must represent
* the fully qualified name of the type (as in
* `path/google.protobuf.Duration`). The name should be in a canonical form
* (e.g., leading "." is not accepted).
* In practice, teams usually precompile into the binary all types that they
* expect it to use in the context of Any. However, for URLs which use the
* scheme `http`, `https`, or no scheme, one can optionally set up a type
* server that maps type URLs to message definitions as follows:
* * If no scheme is provided, `https` is assumed.
* * An HTTP GET on the URL must yield a [google.protobuf.Type][]
* value in binary format, or produce an error.
* * Applications are allowed to cache lookup results based on the
* URL, or have them precompiled into a binary to avoid any
* lookup. Therefore, binary compatibility needs to be preserved
* on changes to types. (Use versioned type names to manage
* breaking changes.)
* Note: this functionality is not currently available in the official
* protobuf release, and it is not used for type URLs beginning with
* type.googleapis.com.
* Schemes other than `http`, `https` (or the empty scheme) might be
* used with implementation specific semantics.
*
* Generated from protobuf field <code>string type_url = 1;</code>
* @return string
*/
public function getTypeUrl()
{
return $this->type_url;
}
/**
* A URL/resource name that uniquely identifies the type of the serialized
* protocol buffer message. This string must contain at least
* one "/" character. The last segment of the URL's path must represent
* the fully qualified name of the type (as in
* `path/google.protobuf.Duration`). The name should be in a canonical form
* (e.g., leading "." is not accepted).
* In practice, teams usually precompile into the binary all types that they
* expect it to use in the context of Any. However, for URLs which use the
* scheme `http`, `https`, or no scheme, one can optionally set up a type
* server that maps type URLs to message definitions as follows:
* * If no scheme is provided, `https` is assumed.
* * An HTTP GET on the URL must yield a [google.protobuf.Type][]
* value in binary format, or produce an error.
* * Applications are allowed to cache lookup results based on the
* URL, or have them precompiled into a binary to avoid any
* lookup. Therefore, binary compatibility needs to be preserved
* on changes to types. (Use versioned type names to manage
* breaking changes.)
* Note: this functionality is not currently available in the official
* protobuf release, and it is not used for type URLs beginning with
* type.googleapis.com.
* Schemes other than `http`, `https` (or the empty scheme) might be
* used with implementation specific semantics.
*
* Generated from protobuf field <code>string type_url = 1;</code>
* @param string $var
* @return $this
*/
public function setTypeUrl($var)
{
GPBUtil::checkString($var, True);
$this->type_url = $var;
return $this;
}
/**
* Must be a valid serialized protocol buffer of the above specified type.
*
* Generated from protobuf field <code>bytes value = 2;</code>
* @return string
*/
public function getValue()
{
return $this->value;
}
/**
* Must be a valid serialized protocol buffer of the above specified type.
*
* Generated from protobuf field <code>bytes value = 2;</code>
* @param string $var
* @return $this
*/
public function setValue($var)
{
GPBUtil::checkString($var, False);
$this->value = $var;
return $this;
}
}

View File

@@ -0,0 +1,360 @@
<?php
# Generated by the protocol buffer compiler. DO NOT EDIT!
# source: google/protobuf/api.proto
namespace Google\Protobuf;
use Google\Protobuf\Internal\GPBType;
use Google\Protobuf\Internal\RepeatedField;
use Google\Protobuf\Internal\GPBUtil;
/**
* Api is a light-weight descriptor for an API Interface.
* Interfaces are also described as "protocol buffer services" in some contexts,
* such as by the "service" keyword in a .proto file, but they are different
* from API Services, which represent a concrete implementation of an interface
* as opposed to simply a description of methods and bindings. They are also
* sometimes simply referred to as "APIs" in other contexts, such as the name of
* this message itself. See https://cloud.google.com/apis/design/glossary for
* detailed terminology.
*
* Generated from protobuf message <code>google.protobuf.Api</code>
*/
class Api extends \Google\Protobuf\Internal\Message
{
/**
* The fully qualified name of this interface, including package name
* followed by the interface's simple name.
*
* Generated from protobuf field <code>string name = 1;</code>
*/
protected $name = '';
/**
* The methods of this interface, in unspecified order.
*
* Generated from protobuf field <code>repeated .google.protobuf.Method methods = 2;</code>
*/
private $methods;
/**
* Any metadata attached to the interface.
*
* Generated from protobuf field <code>repeated .google.protobuf.Option options = 3;</code>
*/
private $options;
/**
* A version string for this interface. If specified, must have the form
* `major-version.minor-version`, as in `1.10`. If the minor version is
* omitted, it defaults to zero. If the entire version field is empty, the
* major version is derived from the package name, as outlined below. If the
* field is not empty, the version in the package name will be verified to be
* consistent with what is provided here.
* The versioning schema uses [semantic
* versioning](http://semver.org) where the major version number
* indicates a breaking change and the minor version an additive,
* non-breaking change. Both version numbers are signals to users
* what to expect from different versions, and should be carefully
* chosen based on the product plan.
* The major version is also reflected in the package name of the
* interface, which must end in `v<major-version>`, as in
* `google.feature.v1`. For major versions 0 and 1, the suffix can
* be omitted. Zero major versions must only be used for
* experimental, non-GA interfaces.
*
* Generated from protobuf field <code>string version = 4;</code>
*/
protected $version = '';
/**
* Source context for the protocol buffer service represented by this
* message.
*
* Generated from protobuf field <code>.google.protobuf.SourceContext source_context = 5;</code>
*/
protected $source_context = null;
/**
* Included interfaces. See [Mixin][].
*
* Generated from protobuf field <code>repeated .google.protobuf.Mixin mixins = 6;</code>
*/
private $mixins;
/**
* The source syntax of the service.
*
* Generated from protobuf field <code>.google.protobuf.Syntax syntax = 7;</code>
*/
protected $syntax = 0;
/**
* Constructor.
*
* @param array $data {
* Optional. Data for populating the Message object.
*
* @type string $name
* The fully qualified name of this interface, including package name
* followed by the interface's simple name.
* @type array<\Google\Protobuf\Method>|\Google\Protobuf\Internal\RepeatedField $methods
* The methods of this interface, in unspecified order.
* @type array<\Google\Protobuf\Option>|\Google\Protobuf\Internal\RepeatedField $options
* Any metadata attached to the interface.
* @type string $version
* A version string for this interface. If specified, must have the form
* `major-version.minor-version`, as in `1.10`. If the minor version is
* omitted, it defaults to zero. If the entire version field is empty, the
* major version is derived from the package name, as outlined below. If the
* field is not empty, the version in the package name will be verified to be
* consistent with what is provided here.
* The versioning schema uses [semantic
* versioning](http://semver.org) where the major version number
* indicates a breaking change and the minor version an additive,
* non-breaking change. Both version numbers are signals to users
* what to expect from different versions, and should be carefully
* chosen based on the product plan.
* The major version is also reflected in the package name of the
* interface, which must end in `v<major-version>`, as in
* `google.feature.v1`. For major versions 0 and 1, the suffix can
* be omitted. Zero major versions must only be used for
* experimental, non-GA interfaces.
* @type \Google\Protobuf\SourceContext $source_context
* Source context for the protocol buffer service represented by this
* message.
* @type array<\Google\Protobuf\Mixin>|\Google\Protobuf\Internal\RepeatedField $mixins
* Included interfaces. See [Mixin][].
* @type int $syntax
* The source syntax of the service.
* }
*/
public function __construct($data = NULL) {
\GPBMetadata\Google\Protobuf\Api::initOnce();
parent::__construct($data);
}
/**
* The fully qualified name of this interface, including package name
* followed by the interface's simple name.
*
* Generated from protobuf field <code>string name = 1;</code>
* @return string
*/
public function getName()
{
return $this->name;
}
/**
* The fully qualified name of this interface, including package name
* followed by the interface's simple name.
*
* Generated from protobuf field <code>string name = 1;</code>
* @param string $var
* @return $this
*/
public function setName($var)
{
GPBUtil::checkString($var, True);
$this->name = $var;
return $this;
}
/**
* The methods of this interface, in unspecified order.
*
* Generated from protobuf field <code>repeated .google.protobuf.Method methods = 2;</code>
* @return \Google\Protobuf\Internal\RepeatedField
*/
public function getMethods()
{
return $this->methods;
}
/**
* The methods of this interface, in unspecified order.
*
* Generated from protobuf field <code>repeated .google.protobuf.Method methods = 2;</code>
* @param array<\Google\Protobuf\Method>|\Google\Protobuf\Internal\RepeatedField $var
* @return $this
*/
public function setMethods($var)
{
$arr = GPBUtil::checkRepeatedField($var, \Google\Protobuf\Internal\GPBType::MESSAGE, \Google\Protobuf\Method::class);
$this->methods = $arr;
return $this;
}
/**
* Any metadata attached to the interface.
*
* Generated from protobuf field <code>repeated .google.protobuf.Option options = 3;</code>
* @return \Google\Protobuf\Internal\RepeatedField
*/
public function getOptions()
{
return $this->options;
}
/**
* Any metadata attached to the interface.
*
* Generated from protobuf field <code>repeated .google.protobuf.Option options = 3;</code>
* @param array<\Google\Protobuf\Option>|\Google\Protobuf\Internal\RepeatedField $var
* @return $this
*/
public function setOptions($var)
{
$arr = GPBUtil::checkRepeatedField($var, \Google\Protobuf\Internal\GPBType::MESSAGE, \Google\Protobuf\Option::class);
$this->options = $arr;
return $this;
}
/**
* A version string for this interface. If specified, must have the form
* `major-version.minor-version`, as in `1.10`. If the minor version is
* omitted, it defaults to zero. If the entire version field is empty, the
* major version is derived from the package name, as outlined below. If the
* field is not empty, the version in the package name will be verified to be
* consistent with what is provided here.
* The versioning schema uses [semantic
* versioning](http://semver.org) where the major version number
* indicates a breaking change and the minor version an additive,
* non-breaking change. Both version numbers are signals to users
* what to expect from different versions, and should be carefully
* chosen based on the product plan.
* The major version is also reflected in the package name of the
* interface, which must end in `v<major-version>`, as in
* `google.feature.v1`. For major versions 0 and 1, the suffix can
* be omitted. Zero major versions must only be used for
* experimental, non-GA interfaces.
*
* Generated from protobuf field <code>string version = 4;</code>
* @return string
*/
public function getVersion()
{
return $this->version;
}
/**
* A version string for this interface. If specified, must have the form
* `major-version.minor-version`, as in `1.10`. If the minor version is
* omitted, it defaults to zero. If the entire version field is empty, the
* major version is derived from the package name, as outlined below. If the
* field is not empty, the version in the package name will be verified to be
* consistent with what is provided here.
* The versioning schema uses [semantic
* versioning](http://semver.org) where the major version number
* indicates a breaking change and the minor version an additive,
* non-breaking change. Both version numbers are signals to users
* what to expect from different versions, and should be carefully
* chosen based on the product plan.
* The major version is also reflected in the package name of the
* interface, which must end in `v<major-version>`, as in
* `google.feature.v1`. For major versions 0 and 1, the suffix can
* be omitted. Zero major versions must only be used for
* experimental, non-GA interfaces.
*
* Generated from protobuf field <code>string version = 4;</code>
* @param string $var
* @return $this
*/
public function setVersion($var)
{
GPBUtil::checkString($var, True);
$this->version = $var;
return $this;
}
/**
* Source context for the protocol buffer service represented by this
* message.
*
* Generated from protobuf field <code>.google.protobuf.SourceContext source_context = 5;</code>
* @return \Google\Protobuf\SourceContext|null
*/
public function getSourceContext()
{
return $this->source_context;
}
public function hasSourceContext()
{
return isset($this->source_context);
}
public function clearSourceContext()
{
unset($this->source_context);
}
/**
* Source context for the protocol buffer service represented by this
* message.
*
* Generated from protobuf field <code>.google.protobuf.SourceContext source_context = 5;</code>
* @param \Google\Protobuf\SourceContext $var
* @return $this
*/
public function setSourceContext($var)
{
GPBUtil::checkMessage($var, \Google\Protobuf\SourceContext::class);
$this->source_context = $var;
return $this;
}
/**
* Included interfaces. See [Mixin][].
*
* Generated from protobuf field <code>repeated .google.protobuf.Mixin mixins = 6;</code>
* @return \Google\Protobuf\Internal\RepeatedField
*/
public function getMixins()
{
return $this->mixins;
}
/**
* Included interfaces. See [Mixin][].
*
* Generated from protobuf field <code>repeated .google.protobuf.Mixin mixins = 6;</code>
* @param array<\Google\Protobuf\Mixin>|\Google\Protobuf\Internal\RepeatedField $var
* @return $this
*/
public function setMixins($var)
{
$arr = GPBUtil::checkRepeatedField($var, \Google\Protobuf\Internal\GPBType::MESSAGE, \Google\Protobuf\Mixin::class);
$this->mixins = $arr;
return $this;
}
/**
* The source syntax of the service.
*
* Generated from protobuf field <code>.google.protobuf.Syntax syntax = 7;</code>
* @return int
*/
public function getSyntax()
{
return $this->syntax;
}
/**
* The source syntax of the service.
*
* Generated from protobuf field <code>.google.protobuf.Syntax syntax = 7;</code>
* @param int $var
* @return $this
*/
public function setSyntax($var)
{
GPBUtil::checkEnum($var, \Google\Protobuf\Syntax::class);
$this->syntax = $var;
return $this;
}
}

View File

@@ -0,0 +1,68 @@
<?php
# Generated by the protocol buffer compiler. DO NOT EDIT!
# source: google/protobuf/wrappers.proto
namespace Google\Protobuf;
use Google\Protobuf\Internal\GPBType;
use Google\Protobuf\Internal\RepeatedField;
use Google\Protobuf\Internal\GPBUtil;
/**
* Wrapper message for `bool`.
* The JSON representation for `BoolValue` is JSON `true` and `false`.
*
* Generated from protobuf message <code>google.protobuf.BoolValue</code>
*/
class BoolValue extends \Google\Protobuf\Internal\Message
{
/**
* The bool value.
*
* Generated from protobuf field <code>bool value = 1;</code>
*/
protected $value = false;
/**
* Constructor.
*
* @param array $data {
* Optional. Data for populating the Message object.
*
* @type bool $value
* The bool value.
* }
*/
public function __construct($data = NULL) {
\GPBMetadata\Google\Protobuf\Wrappers::initOnce();
parent::__construct($data);
}
/**
* The bool value.
*
* Generated from protobuf field <code>bool value = 1;</code>
* @return bool
*/
public function getValue()
{
return $this->value;
}
/**
* The bool value.
*
* Generated from protobuf field <code>bool value = 1;</code>
* @param bool $var
* @return $this
*/
public function setValue($var)
{
GPBUtil::checkBool($var);
$this->value = $var;
return $this;
}
}

View File

@@ -0,0 +1,68 @@
<?php
# Generated by the protocol buffer compiler. DO NOT EDIT!
# source: google/protobuf/wrappers.proto
namespace Google\Protobuf;
use Google\Protobuf\Internal\GPBType;
use Google\Protobuf\Internal\RepeatedField;
use Google\Protobuf\Internal\GPBUtil;
/**
* Wrapper message for `bytes`.
* The JSON representation for `BytesValue` is JSON string.
*
* Generated from protobuf message <code>google.protobuf.BytesValue</code>
*/
class BytesValue extends \Google\Protobuf\Internal\Message
{
/**
* The bytes value.
*
* Generated from protobuf field <code>bytes value = 1;</code>
*/
protected $value = '';
/**
* Constructor.
*
* @param array $data {
* Optional. Data for populating the Message object.
*
* @type string $value
* The bytes value.
* }
*/
public function __construct($data = NULL) {
\GPBMetadata\Google\Protobuf\Wrappers::initOnce();
parent::__construct($data);
}
/**
* The bytes value.
*
* Generated from protobuf field <code>bytes value = 1;</code>
* @return string
*/
public function getValue()
{
return $this->value;
}
/**
* The bytes value.
*
* Generated from protobuf field <code>bytes value = 1;</code>
* @param string $var
* @return $this
*/
public function setValue($var)
{
GPBUtil::checkString($var, False);
$this->value = $var;
return $this;
}
}

View File

@@ -0,0 +1,108 @@
<?php
// Protocol Buffers - Google's data interchange format
// Copyright 2017 Google Inc. All rights reserved.
// https://developers.google.com/protocol-buffers/
//
// Redistribution and use in source and binary forms, with or without
// modification, are permitted provided that the following conditions are
// met:
//
// * Redistributions of source code must retain the above copyright
// notice, this list of conditions and the following disclaimer.
// * Redistributions in binary form must reproduce the above
// copyright notice, this list of conditions and the following disclaimer
// in the documentation and/or other materials provided with the
// distribution.
// * Neither the name of Google Inc. nor the names of its
// contributors may be used to endorse or promote products derived from
// this software without specific prior written permission.
//
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
namespace Google\Protobuf;
use Google\Protobuf\Internal\GetPublicDescriptorTrait;
class Descriptor
{
use GetPublicDescriptorTrait;
private $internal_desc;
/**
* @internal
*/
public function __construct($internal_desc)
{
$this->internal_desc = $internal_desc;
}
/**
* @return string Full protobuf message name
*/
public function getFullName()
{
return trim($this->internal_desc->getFullName(), ".");
}
/**
* @return string PHP class name
*/
public function getClass()
{
return $this->internal_desc->getClass();
}
/**
* @param int $index Must be >= 0 and < getFieldCount()
* @return FieldDescriptor
*/
public function getField($index)
{
return $this->getPublicDescriptor($this->internal_desc->getFieldByIndex($index));
}
/**
* @return int Number of fields in message
*/
public function getFieldCount()
{
return count($this->internal_desc->getField());
}
/**
* @param int $index Must be >= 0 and < getOneofDeclCount()
* @return OneofDescriptor
*/
public function getOneofDecl($index)
{
return $this->getPublicDescriptor($this->internal_desc->getOneofDecl()[$index]);
}
/**
* @return int Number of oneofs in message
*/
public function getOneofDeclCount()
{
return count($this->internal_desc->getOneofDecl());
}
/**
* @return int Number of real oneofs in message
*/
public function getRealOneofDeclCount()
{
return $this->internal_desc->getRealOneofDeclCount();
}
}

View File

@@ -0,0 +1,76 @@
<?php
// Protocol Buffers - Google's data interchange format
// Copyright 2017 Google Inc. All rights reserved.
// https://developers.google.com/protocol-buffers/
//
// Redistribution and use in source and binary forms, with or without
// modification, are permitted provided that the following conditions are
// met:
//
// * Redistributions of source code must retain the above copyright
// notice, this list of conditions and the following disclaimer.
// * Redistributions in binary form must reproduce the above
// copyright notice, this list of conditions and the following disclaimer
// in the documentation and/or other materials provided with the
// distribution.
// * Neither the name of Google Inc. nor the names of its
// contributors may be used to endorse or promote products derived from
// this software without specific prior written permission.
//
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
namespace Google\Protobuf;
class DescriptorPool
{
private static $pool;
private $internal_pool;
/**
* @return DescriptorPool
*/
public static function getGeneratedPool()
{
if (!isset(self::$pool)) {
self::$pool = new DescriptorPool(\Google\Protobuf\Internal\DescriptorPool::getGeneratedPool());
}
return self::$pool;
}
private function __construct($internal_pool)
{
$this->internal_pool = $internal_pool;
}
/**
* @param string $className A fully qualified protobuf class name
* @return Descriptor
*/
public function getDescriptorByClassName($className)
{
$desc = $this->internal_pool->getDescriptorByClassName($className);
return is_null($desc) ? null : $desc->getPublicDescriptor();
}
/**
* @param string $className A fully qualified protobuf class name
* @return EnumDescriptor
*/
public function getEnumDescriptorByClassName($className)
{
$desc = $this->internal_pool->getEnumDescriptorByClassName($className);
return is_null($desc) ? null : $desc->getPublicDescriptor();
}
}

View File

@@ -0,0 +1,68 @@
<?php
# Generated by the protocol buffer compiler. DO NOT EDIT!
# source: google/protobuf/wrappers.proto
namespace Google\Protobuf;
use Google\Protobuf\Internal\GPBType;
use Google\Protobuf\Internal\RepeatedField;
use Google\Protobuf\Internal\GPBUtil;
/**
* Wrapper message for `double`.
* The JSON representation for `DoubleValue` is JSON number.
*
* Generated from protobuf message <code>google.protobuf.DoubleValue</code>
*/
class DoubleValue extends \Google\Protobuf\Internal\Message
{
/**
* The double value.
*
* Generated from protobuf field <code>double value = 1;</code>
*/
protected $value = 0.0;
/**
* Constructor.
*
* @param array $data {
* Optional. Data for populating the Message object.
*
* @type float $value
* The double value.
* }
*/
public function __construct($data = NULL) {
\GPBMetadata\Google\Protobuf\Wrappers::initOnce();
parent::__construct($data);
}
/**
* The double value.
*
* Generated from protobuf field <code>double value = 1;</code>
* @return float
*/
public function getValue()
{
return $this->value;
}
/**
* The double value.
*
* Generated from protobuf field <code>double value = 1;</code>
* @param float $var
* @return $this
*/
public function setValue($var)
{
GPBUtil::checkDouble($var);
$this->value = $var;
return $this;
}
}

View File

@@ -0,0 +1,173 @@
<?php
# Generated by the protocol buffer compiler. DO NOT EDIT!
# source: google/protobuf/duration.proto
namespace Google\Protobuf;
use Google\Protobuf\Internal\GPBType;
use Google\Protobuf\Internal\RepeatedField;
use Google\Protobuf\Internal\GPBUtil;
/**
* A Duration represents a signed, fixed-length span of time represented
* as a count of seconds and fractions of seconds at nanosecond
* resolution. It is independent of any calendar and concepts like "day"
* or "month". It is related to Timestamp in that the difference between
* two Timestamp values is a Duration and it can be added or subtracted
* from a Timestamp. Range is approximately +-10,000 years.
* # Examples
* Example 1: Compute Duration from two Timestamps in pseudo code.
* Timestamp start = ...;
* Timestamp end = ...;
* Duration duration = ...;
* duration.seconds = end.seconds - start.seconds;
* duration.nanos = end.nanos - start.nanos;
* if (duration.seconds < 0 && duration.nanos > 0) {
* duration.seconds += 1;
* duration.nanos -= 1000000000;
* } else if (duration.seconds > 0 && duration.nanos < 0) {
* duration.seconds -= 1;
* duration.nanos += 1000000000;
* }
* Example 2: Compute Timestamp from Timestamp + Duration in pseudo code.
* Timestamp start = ...;
* Duration duration = ...;
* Timestamp end = ...;
* end.seconds = start.seconds + duration.seconds;
* end.nanos = start.nanos + duration.nanos;
* if (end.nanos < 0) {
* end.seconds -= 1;
* end.nanos += 1000000000;
* } else if (end.nanos >= 1000000000) {
* end.seconds += 1;
* end.nanos -= 1000000000;
* }
* Example 3: Compute Duration from datetime.timedelta in Python.
* td = datetime.timedelta(days=3, minutes=10)
* duration = Duration()
* duration.FromTimedelta(td)
* # JSON Mapping
* In JSON format, the Duration type is encoded as a string rather than an
* object, where the string ends in the suffix "s" (indicating seconds) and
* is preceded by the number of seconds, with nanoseconds expressed as
* fractional seconds. For example, 3 seconds with 0 nanoseconds should be
* encoded in JSON format as "3s", while 3 seconds and 1 nanosecond should
* be expressed in JSON format as "3.000000001s", and 3 seconds and 1
* microsecond should be expressed in JSON format as "3.000001s".
*
* Generated from protobuf message <code>google.protobuf.Duration</code>
*/
class Duration extends \Google\Protobuf\Internal\Message
{
/**
* Signed seconds of the span of time. Must be from -315,576,000,000
* to +315,576,000,000 inclusive. Note: these bounds are computed from:
* 60 sec/min * 60 min/hr * 24 hr/day * 365.25 days/year * 10000 years
*
* Generated from protobuf field <code>int64 seconds = 1;</code>
*/
protected $seconds = 0;
/**
* Signed fractions of a second at nanosecond resolution of the span
* of time. Durations less than one second are represented with a 0
* `seconds` field and a positive or negative `nanos` field. For durations
* of one second or more, a non-zero value for the `nanos` field must be
* of the same sign as the `seconds` field. Must be from -999,999,999
* to +999,999,999 inclusive.
*
* Generated from protobuf field <code>int32 nanos = 2;</code>
*/
protected $nanos = 0;
/**
* Constructor.
*
* @param array $data {
* Optional. Data for populating the Message object.
*
* @type int|string $seconds
* Signed seconds of the span of time. Must be from -315,576,000,000
* to +315,576,000,000 inclusive. Note: these bounds are computed from:
* 60 sec/min * 60 min/hr * 24 hr/day * 365.25 days/year * 10000 years
* @type int $nanos
* Signed fractions of a second at nanosecond resolution of the span
* of time. Durations less than one second are represented with a 0
* `seconds` field and a positive or negative `nanos` field. For durations
* of one second or more, a non-zero value for the `nanos` field must be
* of the same sign as the `seconds` field. Must be from -999,999,999
* to +999,999,999 inclusive.
* }
*/
public function __construct($data = NULL) {
\GPBMetadata\Google\Protobuf\Duration::initOnce();
parent::__construct($data);
}
/**
* Signed seconds of the span of time. Must be from -315,576,000,000
* to +315,576,000,000 inclusive. Note: these bounds are computed from:
* 60 sec/min * 60 min/hr * 24 hr/day * 365.25 days/year * 10000 years
*
* Generated from protobuf field <code>int64 seconds = 1;</code>
* @return int|string
*/
public function getSeconds()
{
return $this->seconds;
}
/**
* Signed seconds of the span of time. Must be from -315,576,000,000
* to +315,576,000,000 inclusive. Note: these bounds are computed from:
* 60 sec/min * 60 min/hr * 24 hr/day * 365.25 days/year * 10000 years
*
* Generated from protobuf field <code>int64 seconds = 1;</code>
* @param int|string $var
* @return $this
*/
public function setSeconds($var)
{
GPBUtil::checkInt64($var);
$this->seconds = $var;
return $this;
}
/**
* Signed fractions of a second at nanosecond resolution of the span
* of time. Durations less than one second are represented with a 0
* `seconds` field and a positive or negative `nanos` field. For durations
* of one second or more, a non-zero value for the `nanos` field must be
* of the same sign as the `seconds` field. Must be from -999,999,999
* to +999,999,999 inclusive.
*
* Generated from protobuf field <code>int32 nanos = 2;</code>
* @return int
*/
public function getNanos()
{
return $this->nanos;
}
/**
* Signed fractions of a second at nanosecond resolution of the span
* of time. Durations less than one second are represented with a 0
* `seconds` field and a positive or negative `nanos` field. For durations
* of one second or more, a non-zero value for the `nanos` field must be
* of the same sign as the `seconds` field. Must be from -999,999,999
* to +999,999,999 inclusive.
*
* Generated from protobuf field <code>int32 nanos = 2;</code>
* @param int $var
* @return $this
*/
public function setNanos($var)
{
GPBUtil::checkInt32($var);
$this->nanos = $var;
return $this;
}
}

View File

@@ -0,0 +1,213 @@
<?php
# Generated by the protocol buffer compiler. DO NOT EDIT!
# source: google/protobuf/type.proto
namespace Google\Protobuf;
use Google\Protobuf\Internal\GPBType;
use Google\Protobuf\Internal\RepeatedField;
use Google\Protobuf\Internal\GPBUtil;
/**
* Enum type definition.
*
* Generated from protobuf message <code>google.protobuf.Enum</code>
*/
class Enum extends \Google\Protobuf\Internal\Message
{
/**
* Enum type name.
*
* Generated from protobuf field <code>string name = 1;</code>
*/
protected $name = '';
/**
* Enum value definitions.
*
* Generated from protobuf field <code>repeated .google.protobuf.EnumValue enumvalue = 2;</code>
*/
private $enumvalue;
/**
* Protocol buffer options.
*
* Generated from protobuf field <code>repeated .google.protobuf.Option options = 3;</code>
*/
private $options;
/**
* The source context.
*
* Generated from protobuf field <code>.google.protobuf.SourceContext source_context = 4;</code>
*/
protected $source_context = null;
/**
* The source syntax.
*
* Generated from protobuf field <code>.google.protobuf.Syntax syntax = 5;</code>
*/
protected $syntax = 0;
/**
* Constructor.
*
* @param array $data {
* Optional. Data for populating the Message object.
*
* @type string $name
* Enum type name.
* @type array<\Google\Protobuf\EnumValue>|\Google\Protobuf\Internal\RepeatedField $enumvalue
* Enum value definitions.
* @type array<\Google\Protobuf\Option>|\Google\Protobuf\Internal\RepeatedField $options
* Protocol buffer options.
* @type \Google\Protobuf\SourceContext $source_context
* The source context.
* @type int $syntax
* The source syntax.
* }
*/
public function __construct($data = NULL) {
\GPBMetadata\Google\Protobuf\Type::initOnce();
parent::__construct($data);
}
/**
* Enum type name.
*
* Generated from protobuf field <code>string name = 1;</code>
* @return string
*/
public function getName()
{
return $this->name;
}
/**
* Enum type name.
*
* Generated from protobuf field <code>string name = 1;</code>
* @param string $var
* @return $this
*/
public function setName($var)
{
GPBUtil::checkString($var, True);
$this->name = $var;
return $this;
}
/**
* Enum value definitions.
*
* Generated from protobuf field <code>repeated .google.protobuf.EnumValue enumvalue = 2;</code>
* @return \Google\Protobuf\Internal\RepeatedField
*/
public function getEnumvalue()
{
return $this->enumvalue;
}
/**
* Enum value definitions.
*
* Generated from protobuf field <code>repeated .google.protobuf.EnumValue enumvalue = 2;</code>
* @param array<\Google\Protobuf\EnumValue>|\Google\Protobuf\Internal\RepeatedField $var
* @return $this
*/
public function setEnumvalue($var)
{
$arr = GPBUtil::checkRepeatedField($var, \Google\Protobuf\Internal\GPBType::MESSAGE, \Google\Protobuf\EnumValue::class);
$this->enumvalue = $arr;
return $this;
}
/**
* Protocol buffer options.
*
* Generated from protobuf field <code>repeated .google.protobuf.Option options = 3;</code>
* @return \Google\Protobuf\Internal\RepeatedField
*/
public function getOptions()
{
return $this->options;
}
/**
* Protocol buffer options.
*
* Generated from protobuf field <code>repeated .google.protobuf.Option options = 3;</code>
* @param array<\Google\Protobuf\Option>|\Google\Protobuf\Internal\RepeatedField $var
* @return $this
*/
public function setOptions($var)
{
$arr = GPBUtil::checkRepeatedField($var, \Google\Protobuf\Internal\GPBType::MESSAGE, \Google\Protobuf\Option::class);
$this->options = $arr;
return $this;
}
/**
* The source context.
*
* Generated from protobuf field <code>.google.protobuf.SourceContext source_context = 4;</code>
* @return \Google\Protobuf\SourceContext|null
*/
public function getSourceContext()
{
return $this->source_context;
}
public function hasSourceContext()
{
return isset($this->source_context);
}
public function clearSourceContext()
{
unset($this->source_context);
}
/**
* The source context.
*
* Generated from protobuf field <code>.google.protobuf.SourceContext source_context = 4;</code>
* @param \Google\Protobuf\SourceContext $var
* @return $this
*/
public function setSourceContext($var)
{
GPBUtil::checkMessage($var, \Google\Protobuf\SourceContext::class);
$this->source_context = $var;
return $this;
}
/**
* The source syntax.
*
* Generated from protobuf field <code>.google.protobuf.Syntax syntax = 5;</code>
* @return int
*/
public function getSyntax()
{
return $this->syntax;
}
/**
* The source syntax.
*
* Generated from protobuf field <code>.google.protobuf.Syntax syntax = 5;</code>
* @param int $var
* @return $this
*/
public function setSyntax($var)
{
GPBUtil::checkEnum($var, \Google\Protobuf\Syntax::class);
$this->syntax = $var;
return $this;
}
}

View File

@@ -0,0 +1,79 @@
<?php
// Protocol Buffers - Google's data interchange format
// Copyright 2017 Google Inc. All rights reserved.
// https://developers.google.com/protocol-buffers/
//
// Redistribution and use in source and binary forms, with or without
// modification, are permitted provided that the following conditions are
// met:
//
// * Redistributions of source code must retain the above copyright
// notice, this list of conditions and the following disclaimer.
// * Redistributions in binary form must reproduce the above
// copyright notice, this list of conditions and the following disclaimer
// in the documentation and/or other materials provided with the
// distribution.
// * Neither the name of Google Inc. nor the names of its
// contributors may be used to endorse or promote products derived from
// this software without specific prior written permission.
//
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
namespace Google\Protobuf;
class EnumDescriptor
{
private $internal_desc;
/**
* @internal
*/
public function __construct($internal_desc)
{
$this->internal_desc = $internal_desc;
}
/**
* @return string Full protobuf message name
*/
public function getFullName()
{
return $this->internal_desc->getFullName();
}
/**
* @return string PHP class name
*/
public function getClass()
{
return $this->internal_desc->getClass();
}
/**
* @param int $index Must be >= 0 and < getValueCount()
* @return EnumValueDescriptor
*/
public function getValue($index)
{
return $this->internal_desc->getValueDescriptorByIndex($index);
}
/**
* @return int Number of values in enum
*/
public function getValueCount()
{
return $this->internal_desc->getValueCount();
}
}

View File

@@ -0,0 +1,135 @@
<?php
# Generated by the protocol buffer compiler. DO NOT EDIT!
# source: google/protobuf/type.proto
namespace Google\Protobuf;
use Google\Protobuf\Internal\GPBType;
use Google\Protobuf\Internal\RepeatedField;
use Google\Protobuf\Internal\GPBUtil;
/**
* Enum value definition.
*
* Generated from protobuf message <code>google.protobuf.EnumValue</code>
*/
class EnumValue extends \Google\Protobuf\Internal\Message
{
/**
* Enum value name.
*
* Generated from protobuf field <code>string name = 1;</code>
*/
protected $name = '';
/**
* Enum value number.
*
* Generated from protobuf field <code>int32 number = 2;</code>
*/
protected $number = 0;
/**
* Protocol buffer options.
*
* Generated from protobuf field <code>repeated .google.protobuf.Option options = 3;</code>
*/
private $options;
/**
* Constructor.
*
* @param array $data {
* Optional. Data for populating the Message object.
*
* @type string $name
* Enum value name.
* @type int $number
* Enum value number.
* @type array<\Google\Protobuf\Option>|\Google\Protobuf\Internal\RepeatedField $options
* Protocol buffer options.
* }
*/
public function __construct($data = NULL) {
\GPBMetadata\Google\Protobuf\Type::initOnce();
parent::__construct($data);
}
/**
* Enum value name.
*
* Generated from protobuf field <code>string name = 1;</code>
* @return string
*/
public function getName()
{
return $this->name;
}
/**
* Enum value name.
*
* Generated from protobuf field <code>string name = 1;</code>
* @param string $var
* @return $this
*/
public function setName($var)
{
GPBUtil::checkString($var, True);
$this->name = $var;
return $this;
}
/**
* Enum value number.
*
* Generated from protobuf field <code>int32 number = 2;</code>
* @return int
*/
public function getNumber()
{
return $this->number;
}
/**
* Enum value number.
*
* Generated from protobuf field <code>int32 number = 2;</code>
* @param int $var
* @return $this
*/
public function setNumber($var)
{
GPBUtil::checkInt32($var);
$this->number = $var;
return $this;
}
/**
* Protocol buffer options.
*
* Generated from protobuf field <code>repeated .google.protobuf.Option options = 3;</code>
* @return \Google\Protobuf\Internal\RepeatedField
*/
public function getOptions()
{
return $this->options;
}
/**
* Protocol buffer options.
*
* Generated from protobuf field <code>repeated .google.protobuf.Option options = 3;</code>
* @param array<\Google\Protobuf\Option>|\Google\Protobuf\Internal\RepeatedField $var
* @return $this
*/
public function setOptions($var)
{
$arr = GPBUtil::checkRepeatedField($var, \Google\Protobuf\Internal\GPBType::MESSAGE, \Google\Protobuf\Option::class);
$this->options = $arr;
return $this;
}
}

View File

@@ -0,0 +1,64 @@
<?php
// Protocol Buffers - Google's data interchange format
// Copyright 2008 Google Inc. All rights reserved.
// https://developers.google.com/protocol-buffers/
//
// Redistribution and use in source and binary forms, with or without
// modification, are permitted provided that the following conditions are
// met:
//
// * Redistributions of source code must retain the above copyright
// notice, this list of conditions and the following disclaimer.
// * Redistributions in binary form must reproduce the above
// copyright notice, this list of conditions and the following disclaimer
// in the documentation and/or other materials provided with the
// distribution.
// * Neither the name of Google Inc. nor the names of its
// contributors may be used to endorse or promote products derived from
// this software without specific prior written permission.
//
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
namespace Google\Protobuf;
class EnumValueDescriptor
{
private $name;
private $number;
/**
* @internal
*/
public function __construct($name, $number)
{
$this->name = $name;
$this->number = $number;
}
/**
* @return string
*/
public function getName()
{
return $this->name;
}
/**
* @return int
*/
public function getNumber()
{
return $this->number;
}
}

View File

@@ -0,0 +1,381 @@
<?php
# Generated by the protocol buffer compiler. DO NOT EDIT!
# source: google/protobuf/type.proto
namespace Google\Protobuf;
use Google\Protobuf\Internal\GPBType;
use Google\Protobuf\Internal\RepeatedField;
use Google\Protobuf\Internal\GPBUtil;
/**
* A single field of a message type.
*
* Generated from protobuf message <code>google.protobuf.Field</code>
*/
class Field extends \Google\Protobuf\Internal\Message
{
/**
* The field type.
*
* Generated from protobuf field <code>.google.protobuf.Field.Kind kind = 1;</code>
*/
protected $kind = 0;
/**
* The field cardinality.
*
* Generated from protobuf field <code>.google.protobuf.Field.Cardinality cardinality = 2;</code>
*/
protected $cardinality = 0;
/**
* The field number.
*
* Generated from protobuf field <code>int32 number = 3;</code>
*/
protected $number = 0;
/**
* The field name.
*
* Generated from protobuf field <code>string name = 4;</code>
*/
protected $name = '';
/**
* The field type URL, without the scheme, for message or enumeration
* types. Example: `"type.googleapis.com/google.protobuf.Timestamp"`.
*
* Generated from protobuf field <code>string type_url = 6;</code>
*/
protected $type_url = '';
/**
* The index of the field type in `Type.oneofs`, for message or enumeration
* types. The first type has index 1; zero means the type is not in the list.
*
* Generated from protobuf field <code>int32 oneof_index = 7;</code>
*/
protected $oneof_index = 0;
/**
* Whether to use alternative packed wire representation.
*
* Generated from protobuf field <code>bool packed = 8;</code>
*/
protected $packed = false;
/**
* The protocol buffer options.
*
* Generated from protobuf field <code>repeated .google.protobuf.Option options = 9;</code>
*/
private $options;
/**
* The field JSON name.
*
* Generated from protobuf field <code>string json_name = 10;</code>
*/
protected $json_name = '';
/**
* The string value of the default value of this field. Proto2 syntax only.
*
* Generated from protobuf field <code>string default_value = 11;</code>
*/
protected $default_value = '';
/**
* Constructor.
*
* @param array $data {
* Optional. Data for populating the Message object.
*
* @type int $kind
* The field type.
* @type int $cardinality
* The field cardinality.
* @type int $number
* The field number.
* @type string $name
* The field name.
* @type string $type_url
* The field type URL, without the scheme, for message or enumeration
* types. Example: `"type.googleapis.com/google.protobuf.Timestamp"`.
* @type int $oneof_index
* The index of the field type in `Type.oneofs`, for message or enumeration
* types. The first type has index 1; zero means the type is not in the list.
* @type bool $packed
* Whether to use alternative packed wire representation.
* @type array<\Google\Protobuf\Option>|\Google\Protobuf\Internal\RepeatedField $options
* The protocol buffer options.
* @type string $json_name
* The field JSON name.
* @type string $default_value
* The string value of the default value of this field. Proto2 syntax only.
* }
*/
public function __construct($data = NULL) {
\GPBMetadata\Google\Protobuf\Type::initOnce();
parent::__construct($data);
}
/**
* The field type.
*
* Generated from protobuf field <code>.google.protobuf.Field.Kind kind = 1;</code>
* @return int
*/
public function getKind()
{
return $this->kind;
}
/**
* The field type.
*
* Generated from protobuf field <code>.google.protobuf.Field.Kind kind = 1;</code>
* @param int $var
* @return $this
*/
public function setKind($var)
{
GPBUtil::checkEnum($var, \Google\Protobuf\Field\Kind::class);
$this->kind = $var;
return $this;
}
/**
* The field cardinality.
*
* Generated from protobuf field <code>.google.protobuf.Field.Cardinality cardinality = 2;</code>
* @return int
*/
public function getCardinality()
{
return $this->cardinality;
}
/**
* The field cardinality.
*
* Generated from protobuf field <code>.google.protobuf.Field.Cardinality cardinality = 2;</code>
* @param int $var
* @return $this
*/
public function setCardinality($var)
{
GPBUtil::checkEnum($var, \Google\Protobuf\Field\Cardinality::class);
$this->cardinality = $var;
return $this;
}
/**
* The field number.
*
* Generated from protobuf field <code>int32 number = 3;</code>
* @return int
*/
public function getNumber()
{
return $this->number;
}
/**
* The field number.
*
* Generated from protobuf field <code>int32 number = 3;</code>
* @param int $var
* @return $this
*/
public function setNumber($var)
{
GPBUtil::checkInt32($var);
$this->number = $var;
return $this;
}
/**
* The field name.
*
* Generated from protobuf field <code>string name = 4;</code>
* @return string
*/
public function getName()
{
return $this->name;
}
/**
* The field name.
*
* Generated from protobuf field <code>string name = 4;</code>
* @param string $var
* @return $this
*/
public function setName($var)
{
GPBUtil::checkString($var, True);
$this->name = $var;
return $this;
}
/**
* The field type URL, without the scheme, for message or enumeration
* types. Example: `"type.googleapis.com/google.protobuf.Timestamp"`.
*
* Generated from protobuf field <code>string type_url = 6;</code>
* @return string
*/
public function getTypeUrl()
{
return $this->type_url;
}
/**
* The field type URL, without the scheme, for message or enumeration
* types. Example: `"type.googleapis.com/google.protobuf.Timestamp"`.
*
* Generated from protobuf field <code>string type_url = 6;</code>
* @param string $var
* @return $this
*/
public function setTypeUrl($var)
{
GPBUtil::checkString($var, True);
$this->type_url = $var;
return $this;
}
/**
* The index of the field type in `Type.oneofs`, for message or enumeration
* types. The first type has index 1; zero means the type is not in the list.
*
* Generated from protobuf field <code>int32 oneof_index = 7;</code>
* @return int
*/
public function getOneofIndex()
{
return $this->oneof_index;
}
/**
* The index of the field type in `Type.oneofs`, for message or enumeration
* types. The first type has index 1; zero means the type is not in the list.
*
* Generated from protobuf field <code>int32 oneof_index = 7;</code>
* @param int $var
* @return $this
*/
public function setOneofIndex($var)
{
GPBUtil::checkInt32($var);
$this->oneof_index = $var;
return $this;
}
/**
* Whether to use alternative packed wire representation.
*
* Generated from protobuf field <code>bool packed = 8;</code>
* @return bool
*/
public function getPacked()
{
return $this->packed;
}
/**
* Whether to use alternative packed wire representation.
*
* Generated from protobuf field <code>bool packed = 8;</code>
* @param bool $var
* @return $this
*/
public function setPacked($var)
{
GPBUtil::checkBool($var);
$this->packed = $var;
return $this;
}
/**
* The protocol buffer options.
*
* Generated from protobuf field <code>repeated .google.protobuf.Option options = 9;</code>
* @return \Google\Protobuf\Internal\RepeatedField
*/
public function getOptions()
{
return $this->options;
}
/**
* The protocol buffer options.
*
* Generated from protobuf field <code>repeated .google.protobuf.Option options = 9;</code>
* @param array<\Google\Protobuf\Option>|\Google\Protobuf\Internal\RepeatedField $var
* @return $this
*/
public function setOptions($var)
{
$arr = GPBUtil::checkRepeatedField($var, \Google\Protobuf\Internal\GPBType::MESSAGE, \Google\Protobuf\Option::class);
$this->options = $arr;
return $this;
}
/**
* The field JSON name.
*
* Generated from protobuf field <code>string json_name = 10;</code>
* @return string
*/
public function getJsonName()
{
return $this->json_name;
}
/**
* The field JSON name.
*
* Generated from protobuf field <code>string json_name = 10;</code>
* @param string $var
* @return $this
*/
public function setJsonName($var)
{
GPBUtil::checkString($var, True);
$this->json_name = $var;
return $this;
}
/**
* The string value of the default value of this field. Proto2 syntax only.
*
* Generated from protobuf field <code>string default_value = 11;</code>
* @return string
*/
public function getDefaultValue()
{
return $this->default_value;
}
/**
* The string value of the default value of this field. Proto2 syntax only.
*
* Generated from protobuf field <code>string default_value = 11;</code>
* @param string $var
* @return $this
*/
public function setDefaultValue($var)
{
GPBUtil::checkString($var, True);
$this->default_value = $var;
return $this;
}
}

View File

@@ -0,0 +1,71 @@
<?php
# Generated by the protocol buffer compiler. DO NOT EDIT!
# source: google/protobuf/type.proto
namespace Google\Protobuf\Field;
use UnexpectedValueException;
/**
* Whether a field is optional, required, or repeated.
*
* Protobuf type <code>google.protobuf.Field.Cardinality</code>
*/
class Cardinality
{
/**
* For fields with unknown cardinality.
*
* Generated from protobuf enum <code>CARDINALITY_UNKNOWN = 0;</code>
*/
const CARDINALITY_UNKNOWN = 0;
/**
* For optional fields.
*
* Generated from protobuf enum <code>CARDINALITY_OPTIONAL = 1;</code>
*/
const CARDINALITY_OPTIONAL = 1;
/**
* For required fields. Proto2 syntax only.
*
* Generated from protobuf enum <code>CARDINALITY_REQUIRED = 2;</code>
*/
const CARDINALITY_REQUIRED = 2;
/**
* For repeated fields.
*
* Generated from protobuf enum <code>CARDINALITY_REPEATED = 3;</code>
*/
const CARDINALITY_REPEATED = 3;
private static $valueToName = [
self::CARDINALITY_UNKNOWN => 'CARDINALITY_UNKNOWN',
self::CARDINALITY_OPTIONAL => 'CARDINALITY_OPTIONAL',
self::CARDINALITY_REQUIRED => 'CARDINALITY_REQUIRED',
self::CARDINALITY_REPEATED => 'CARDINALITY_REPEATED',
];
public static function name($value)
{
if (!isset(self::$valueToName[$value])) {
throw new UnexpectedValueException(sprintf(
'Enum %s has no name defined for value %s', __CLASS__, $value));
}
return self::$valueToName[$value];
}
public static function value($name)
{
$const = __CLASS__ . '::' . strtoupper($name);
if (!defined($const)) {
throw new UnexpectedValueException(sprintf(
'Enum %s has no value defined for name %s', __CLASS__, $name));
}
return constant($const);
}
}
// Adding a class alias for backwards compatibility with the previous class name.
class_alias(Cardinality::class, \Google\Protobuf\Field_Cardinality::class);

View File

@@ -0,0 +1,176 @@
<?php
# Generated by the protocol buffer compiler. DO NOT EDIT!
# source: google/protobuf/type.proto
namespace Google\Protobuf\Field;
use UnexpectedValueException;
/**
* Basic field types.
*
* Protobuf type <code>google.protobuf.Field.Kind</code>
*/
class Kind
{
/**
* Field type unknown.
*
* Generated from protobuf enum <code>TYPE_UNKNOWN = 0;</code>
*/
const TYPE_UNKNOWN = 0;
/**
* Field type double.
*
* Generated from protobuf enum <code>TYPE_DOUBLE = 1;</code>
*/
const TYPE_DOUBLE = 1;
/**
* Field type float.
*
* Generated from protobuf enum <code>TYPE_FLOAT = 2;</code>
*/
const TYPE_FLOAT = 2;
/**
* Field type int64.
*
* Generated from protobuf enum <code>TYPE_INT64 = 3;</code>
*/
const TYPE_INT64 = 3;
/**
* Field type uint64.
*
* Generated from protobuf enum <code>TYPE_UINT64 = 4;</code>
*/
const TYPE_UINT64 = 4;
/**
* Field type int32.
*
* Generated from protobuf enum <code>TYPE_INT32 = 5;</code>
*/
const TYPE_INT32 = 5;
/**
* Field type fixed64.
*
* Generated from protobuf enum <code>TYPE_FIXED64 = 6;</code>
*/
const TYPE_FIXED64 = 6;
/**
* Field type fixed32.
*
* Generated from protobuf enum <code>TYPE_FIXED32 = 7;</code>
*/
const TYPE_FIXED32 = 7;
/**
* Field type bool.
*
* Generated from protobuf enum <code>TYPE_BOOL = 8;</code>
*/
const TYPE_BOOL = 8;
/**
* Field type string.
*
* Generated from protobuf enum <code>TYPE_STRING = 9;</code>
*/
const TYPE_STRING = 9;
/**
* Field type group. Proto2 syntax only, and deprecated.
*
* Generated from protobuf enum <code>TYPE_GROUP = 10;</code>
*/
const TYPE_GROUP = 10;
/**
* Field type message.
*
* Generated from protobuf enum <code>TYPE_MESSAGE = 11;</code>
*/
const TYPE_MESSAGE = 11;
/**
* Field type bytes.
*
* Generated from protobuf enum <code>TYPE_BYTES = 12;</code>
*/
const TYPE_BYTES = 12;
/**
* Field type uint32.
*
* Generated from protobuf enum <code>TYPE_UINT32 = 13;</code>
*/
const TYPE_UINT32 = 13;
/**
* Field type enum.
*
* Generated from protobuf enum <code>TYPE_ENUM = 14;</code>
*/
const TYPE_ENUM = 14;
/**
* Field type sfixed32.
*
* Generated from protobuf enum <code>TYPE_SFIXED32 = 15;</code>
*/
const TYPE_SFIXED32 = 15;
/**
* Field type sfixed64.
*
* Generated from protobuf enum <code>TYPE_SFIXED64 = 16;</code>
*/
const TYPE_SFIXED64 = 16;
/**
* Field type sint32.
*
* Generated from protobuf enum <code>TYPE_SINT32 = 17;</code>
*/
const TYPE_SINT32 = 17;
/**
* Field type sint64.
*
* Generated from protobuf enum <code>TYPE_SINT64 = 18;</code>
*/
const TYPE_SINT64 = 18;
private static $valueToName = [
self::TYPE_UNKNOWN => 'TYPE_UNKNOWN',
self::TYPE_DOUBLE => 'TYPE_DOUBLE',
self::TYPE_FLOAT => 'TYPE_FLOAT',
self::TYPE_INT64 => 'TYPE_INT64',
self::TYPE_UINT64 => 'TYPE_UINT64',
self::TYPE_INT32 => 'TYPE_INT32',
self::TYPE_FIXED64 => 'TYPE_FIXED64',
self::TYPE_FIXED32 => 'TYPE_FIXED32',
self::TYPE_BOOL => 'TYPE_BOOL',
self::TYPE_STRING => 'TYPE_STRING',
self::TYPE_GROUP => 'TYPE_GROUP',
self::TYPE_MESSAGE => 'TYPE_MESSAGE',
self::TYPE_BYTES => 'TYPE_BYTES',
self::TYPE_UINT32 => 'TYPE_UINT32',
self::TYPE_ENUM => 'TYPE_ENUM',
self::TYPE_SFIXED32 => 'TYPE_SFIXED32',
self::TYPE_SFIXED64 => 'TYPE_SFIXED64',
self::TYPE_SINT32 => 'TYPE_SINT32',
self::TYPE_SINT64 => 'TYPE_SINT64',
];
public static function name($value)
{
if (!isset(self::$valueToName[$value])) {
throw new UnexpectedValueException(sprintf(
'Enum %s has no name defined for value %s', __CLASS__, $value));
}
return self::$valueToName[$value];
}
public static function value($name)
{
$const = __CLASS__ . '::' . strtoupper($name);
if (!defined($const)) {
throw new UnexpectedValueException(sprintf(
'Enum %s has no value defined for name %s', __CLASS__, $name));
}
return constant($const);
}
}
// Adding a class alias for backwards compatibility with the previous class name.
class_alias(Kind::class, \Google\Protobuf\Field_Kind::class);

View File

@@ -0,0 +1,144 @@
<?php
// Protocol Buffers - Google's data interchange format
// Copyright 2017 Google Inc. All rights reserved.
// https://developers.google.com/protocol-buffers/
//
// Redistribution and use in source and binary forms, with or without
// modification, are permitted provided that the following conditions are
// met:
//
// * Redistributions of source code must retain the above copyright
// notice, this list of conditions and the following disclaimer.
// * Redistributions in binary form must reproduce the above
// copyright notice, this list of conditions and the following disclaimer
// in the documentation and/or other materials provided with the
// distribution.
// * Neither the name of Google Inc. nor the names of its
// contributors may be used to endorse or promote products derived from
// this software without specific prior written permission.
//
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
namespace Google\Protobuf;
use Google\Protobuf\Internal\GetPublicDescriptorTrait;
use Google\Protobuf\Internal\GPBType;
class FieldDescriptor
{
use GetPublicDescriptorTrait;
/** @var \Google\Protobuf\Internal\FieldDescriptor $internal_desc */
private $internal_desc;
/**
* @internal
*/
public function __construct($internal_desc)
{
$this->internal_desc = $internal_desc;
}
/**
* @return string Field name
*/
public function getName()
{
return $this->internal_desc->getName();
}
/**
* @return int Protobuf field number
*/
public function getNumber()
{
return $this->internal_desc->getNumber();
}
/**
* @return int
*/
public function getLabel()
{
return $this->internal_desc->getLabel();
}
/**
* @return int
*/
public function getType()
{
return $this->internal_desc->getType();
}
/**
* @return OneofDescriptor
*/
public function getContainingOneof()
{
return $this->getPublicDescriptor($this->internal_desc->getContainingOneof());
}
/**
* Gets the field's containing oneof, only if non-synthetic.
*
* @return null|OneofDescriptor
*/
public function getRealContainingOneof()
{
return $this->getPublicDescriptor($this->internal_desc->getRealContainingOneof());
}
/**
* @return boolean
*/
public function hasOptionalKeyword()
{
return $this->internal_desc->hasOptionalKeyword();
}
/**
* @return Descriptor Returns a descriptor for the field type if the field type is a message, otherwise throws \Exception
* @throws \Exception
*/
public function getMessageType()
{
if ($this->getType() == GPBType::MESSAGE) {
return $this->getPublicDescriptor($this->internal_desc->getMessageType());
} else {
throw new \Exception("Cannot get message type for non-message field '" . $this->getName() . "'");
}
}
/**
* @return EnumDescriptor Returns an enum descriptor if the field type is an enum, otherwise throws \Exception
* @throws \Exception
*/
public function getEnumType()
{
if ($this->getType() == GPBType::ENUM) {
return $this->getPublicDescriptor($this->internal_desc->getEnumType());
} else {
throw new \Exception("Cannot get enum type for non-enum field '" . $this->getName() . "'");
}
}
/**
* @return boolean
*/
public function isMap()
{
return $this->internal_desc->isMap();
}
}

View File

@@ -0,0 +1,217 @@
<?php
# Generated by the protocol buffer compiler. DO NOT EDIT!
# source: google/protobuf/field_mask.proto
namespace Google\Protobuf;
use Google\Protobuf\Internal\GPBType;
use Google\Protobuf\Internal\RepeatedField;
use Google\Protobuf\Internal\GPBUtil;
/**
* `FieldMask` represents a set of symbolic field paths, for example:
* paths: "f.a"
* paths: "f.b.d"
* Here `f` represents a field in some root message, `a` and `b`
* fields in the message found in `f`, and `d` a field found in the
* message in `f.b`.
* Field masks are used to specify a subset of fields that should be
* returned by a get operation or modified by an update operation.
* Field masks also have a custom JSON encoding (see below).
* # Field Masks in Projections
* When used in the context of a projection, a response message or
* sub-message is filtered by the API to only contain those fields as
* specified in the mask. For example, if the mask in the previous
* example is applied to a response message as follows:
* f {
* a : 22
* b {
* d : 1
* x : 2
* }
* y : 13
* }
* z: 8
* The result will not contain specific values for fields x,y and z
* (their value will be set to the default, and omitted in proto text
* output):
* f {
* a : 22
* b {
* d : 1
* }
* }
* A repeated field is not allowed except at the last position of a
* paths string.
* If a FieldMask object is not present in a get operation, the
* operation applies to all fields (as if a FieldMask of all fields
* had been specified).
* Note that a field mask does not necessarily apply to the
* top-level response message. In case of a REST get operation, the
* field mask applies directly to the response, but in case of a REST
* list operation, the mask instead applies to each individual message
* in the returned resource list. In case of a REST custom method,
* other definitions may be used. Where the mask applies will be
* clearly documented together with its declaration in the API. In
* any case, the effect on the returned resource/resources is required
* behavior for APIs.
* # Field Masks in Update Operations
* A field mask in update operations specifies which fields of the
* targeted resource are going to be updated. The API is required
* to only change the values of the fields as specified in the mask
* and leave the others untouched. If a resource is passed in to
* describe the updated values, the API ignores the values of all
* fields not covered by the mask.
* If a repeated field is specified for an update operation, new values will
* be appended to the existing repeated field in the target resource. Note that
* a repeated field is only allowed in the last position of a `paths` string.
* If a sub-message is specified in the last position of the field mask for an
* update operation, then new value will be merged into the existing sub-message
* in the target resource.
* For example, given the target message:
* f {
* b {
* d: 1
* x: 2
* }
* c: [1]
* }
* And an update message:
* f {
* b {
* d: 10
* }
* c: [2]
* }
* then if the field mask is:
* paths: ["f.b", "f.c"]
* then the result will be:
* f {
* b {
* d: 10
* x: 2
* }
* c: [1, 2]
* }
* An implementation may provide options to override this default behavior for
* repeated and message fields.
* In order to reset a field's value to the default, the field must
* be in the mask and set to the default value in the provided resource.
* Hence, in order to reset all fields of a resource, provide a default
* instance of the resource and set all fields in the mask, or do
* not provide a mask as described below.
* If a field mask is not present on update, the operation applies to
* all fields (as if a field mask of all fields has been specified).
* Note that in the presence of schema evolution, this may mean that
* fields the client does not know and has therefore not filled into
* the request will be reset to their default. If this is unwanted
* behavior, a specific service may require a client to always specify
* a field mask, producing an error if not.
* As with get operations, the location of the resource which
* describes the updated values in the request message depends on the
* operation kind. In any case, the effect of the field mask is
* required to be honored by the API.
* ## Considerations for HTTP REST
* The HTTP kind of an update operation which uses a field mask must
* be set to PATCH instead of PUT in order to satisfy HTTP semantics
* (PUT must only be used for full updates).
* # JSON Encoding of Field Masks
* In JSON, a field mask is encoded as a single string where paths are
* separated by a comma. Fields name in each path are converted
* to/from lower-camel naming conventions.
* As an example, consider the following message declarations:
* message Profile {
* User user = 1;
* Photo photo = 2;
* }
* message User {
* string display_name = 1;
* string address = 2;
* }
* In proto a field mask for `Profile` may look as such:
* mask {
* paths: "user.display_name"
* paths: "photo"
* }
* In JSON, the same mask is represented as below:
* {
* mask: "user.displayName,photo"
* }
* # Field Masks and Oneof Fields
* Field masks treat fields in oneofs just as regular fields. Consider the
* following message:
* message SampleMessage {
* oneof test_oneof {
* string name = 4;
* SubMessage sub_message = 9;
* }
* }
* The field mask can be:
* mask {
* paths: "name"
* }
* Or:
* mask {
* paths: "sub_message"
* }
* Note that oneof type names ("test_oneof" in this case) cannot be used in
* paths.
* ## Field Mask Verification
* The implementation of any API method which has a FieldMask type field in the
* request should verify the included field paths, and return an
* `INVALID_ARGUMENT` error if any path is unmappable.
*
* Generated from protobuf message <code>google.protobuf.FieldMask</code>
*/
class FieldMask extends \Google\Protobuf\Internal\Message
{
/**
* The set of field mask paths.
*
* Generated from protobuf field <code>repeated string paths = 1;</code>
*/
private $paths;
/**
* Constructor.
*
* @param array $data {
* Optional. Data for populating the Message object.
*
* @type array<string>|\Google\Protobuf\Internal\RepeatedField $paths
* The set of field mask paths.
* }
*/
public function __construct($data = NULL) {
\GPBMetadata\Google\Protobuf\FieldMask::initOnce();
parent::__construct($data);
}
/**
* The set of field mask paths.
*
* Generated from protobuf field <code>repeated string paths = 1;</code>
* @return \Google\Protobuf\Internal\RepeatedField
*/
public function getPaths()
{
return $this->paths;
}
/**
* The set of field mask paths.
*
* Generated from protobuf field <code>repeated string paths = 1;</code>
* @param array<string>|\Google\Protobuf\Internal\RepeatedField $var
* @return $this
*/
public function setPaths($var)
{
$arr = GPBUtil::checkRepeatedField($var, \Google\Protobuf\Internal\GPBType::STRING);
$this->paths = $arr;
return $this;
}
}

View File

@@ -0,0 +1,16 @@
<?php
# Generated by the protocol buffer compiler. DO NOT EDIT!
# source: google/protobuf/type.proto
namespace Google\Protobuf;
if (false) {
/**
* This class is deprecated. Use Google\Protobuf\Field\Cardinality instead.
* @deprecated
*/
class Field_Cardinality {}
}
class_exists(Field\Cardinality::class);
@trigger_error('Google\Protobuf\Field_Cardinality is deprecated and will be removed in the next major release. Use Google\Protobuf\Field\Cardinality instead', E_USER_DEPRECATED);

View File

@@ -0,0 +1,16 @@
<?php
# Generated by the protocol buffer compiler. DO NOT EDIT!
# source: google/protobuf/type.proto
namespace Google\Protobuf;
if (false) {
/**
* This class is deprecated. Use Google\Protobuf\Field\Kind instead.
* @deprecated
*/
class Field_Kind {}
}
class_exists(Field\Kind::class);
@trigger_error('Google\Protobuf\Field_Kind is deprecated and will be removed in the next major release. Use Google\Protobuf\Field\Kind instead', E_USER_DEPRECATED);

View File

@@ -0,0 +1,68 @@
<?php
# Generated by the protocol buffer compiler. DO NOT EDIT!
# source: google/protobuf/wrappers.proto
namespace Google\Protobuf;
use Google\Protobuf\Internal\GPBType;
use Google\Protobuf\Internal\RepeatedField;
use Google\Protobuf\Internal\GPBUtil;
/**
* Wrapper message for `float`.
* The JSON representation for `FloatValue` is JSON number.
*
* Generated from protobuf message <code>google.protobuf.FloatValue</code>
*/
class FloatValue extends \Google\Protobuf\Internal\Message
{
/**
* The float value.
*
* Generated from protobuf field <code>float value = 1;</code>
*/
protected $value = 0.0;
/**
* Constructor.
*
* @param array $data {
* Optional. Data for populating the Message object.
*
* @type float $value
* The float value.
* }
*/
public function __construct($data = NULL) {
\GPBMetadata\Google\Protobuf\Wrappers::initOnce();
parent::__construct($data);
}
/**
* The float value.
*
* Generated from protobuf field <code>float value = 1;</code>
* @return float
*/
public function getValue()
{
return $this->value;
}
/**
* The float value.
*
* Generated from protobuf field <code>float value = 1;</code>
* @param float $var
* @return $this
*/
public function setValue($var)
{
GPBUtil::checkFloat($var);
$this->value = $var;
return $this;
}
}

View File

@@ -0,0 +1,38 @@
<?php
# Generated by the protocol buffer compiler. DO NOT EDIT!
# source: google/protobuf/empty.proto
namespace Google\Protobuf;
use Google\Protobuf\Internal\GPBType;
use Google\Protobuf\Internal\RepeatedField;
use Google\Protobuf\Internal\GPBUtil;
/**
* A generic empty message that you can re-use to avoid defining duplicated
* empty messages in your APIs. A typical example is to use it as the request
* or the response type of an API method. For instance:
* service Foo {
* rpc Bar(google.protobuf.Empty) returns (google.protobuf.Empty);
* }
*
* Generated from protobuf message <code>google.protobuf.Empty</code>
*/
class GPBEmpty extends \Google\Protobuf\Internal\Message
{
/**
* Constructor.
*
* @param array $data {
* Optional. Data for populating the Message object.
*
* }
*/
public function __construct($data = NULL) {
\GPBMetadata\Google\Protobuf\GPBEmpty::initOnce();
parent::__construct($data);
}
}

View File

@@ -0,0 +1,68 @@
<?php
# Generated by the protocol buffer compiler. DO NOT EDIT!
# source: google/protobuf/wrappers.proto
namespace Google\Protobuf;
use Google\Protobuf\Internal\GPBType;
use Google\Protobuf\Internal\RepeatedField;
use Google\Protobuf\Internal\GPBUtil;
/**
* Wrapper message for `int32`.
* The JSON representation for `Int32Value` is JSON number.
*
* Generated from protobuf message <code>google.protobuf.Int32Value</code>
*/
class Int32Value extends \Google\Protobuf\Internal\Message
{
/**
* The int32 value.
*
* Generated from protobuf field <code>int32 value = 1;</code>
*/
protected $value = 0;
/**
* Constructor.
*
* @param array $data {
* Optional. Data for populating the Message object.
*
* @type int $value
* The int32 value.
* }
*/
public function __construct($data = NULL) {
\GPBMetadata\Google\Protobuf\Wrappers::initOnce();
parent::__construct($data);
}
/**
* The int32 value.
*
* Generated from protobuf field <code>int32 value = 1;</code>
* @return int
*/
public function getValue()
{
return $this->value;
}
/**
* The int32 value.
*
* Generated from protobuf field <code>int32 value = 1;</code>
* @param int $var
* @return $this
*/
public function setValue($var)
{
GPBUtil::checkInt32($var);
$this->value = $var;
return $this;
}
}

View File

@@ -0,0 +1,68 @@
<?php
# Generated by the protocol buffer compiler. DO NOT EDIT!
# source: google/protobuf/wrappers.proto
namespace Google\Protobuf;
use Google\Protobuf\Internal\GPBType;
use Google\Protobuf\Internal\RepeatedField;
use Google\Protobuf\Internal\GPBUtil;
/**
* Wrapper message for `int64`.
* The JSON representation for `Int64Value` is JSON string.
*
* Generated from protobuf message <code>google.protobuf.Int64Value</code>
*/
class Int64Value extends \Google\Protobuf\Internal\Message
{
/**
* The int64 value.
*
* Generated from protobuf field <code>int64 value = 1;</code>
*/
protected $value = 0;
/**
* Constructor.
*
* @param array $data {
* Optional. Data for populating the Message object.
*
* @type int|string $value
* The int64 value.
* }
*/
public function __construct($data = NULL) {
\GPBMetadata\Google\Protobuf\Wrappers::initOnce();
parent::__construct($data);
}
/**
* The int64 value.
*
* Generated from protobuf field <code>int64 value = 1;</code>
* @return int|string
*/
public function getValue()
{
return $this->value;
}
/**
* The int64 value.
*
* Generated from protobuf field <code>int64 value = 1;</code>
* @param int|string $var
* @return $this
*/
public function setValue($var)
{
GPBUtil::checkInt64($var);
$this->value = $var;
return $this;
}
}

View File

@@ -0,0 +1,86 @@
<?php
namespace Google\Protobuf\Internal;
/**
* Base class for Google\Protobuf\Any, this contains hand-written convenience
* methods like pack() and unpack().
*/
class AnyBase extends \Google\Protobuf\Internal\Message
{
const TYPE_URL_PREFIX = 'type.googleapis.com/';
/**
* This method will try to resolve the type_url in Any message to get the
* targeted message type. If failed, an error will be thrown. Otherwise,
* the method will create a message of the targeted type and fill it with
* the decoded value in Any.
* @return Message unpacked message
* @throws \Exception Type url needs to be type.googleapis.com/fully-qualified.
* @throws \Exception Class hasn't been added to descriptor pool.
* @throws \Exception cannot decode data in value field.
*/
public function unpack()
{
// Get fully qualified name from type url.
$url_prifix_len = strlen(GPBUtil::TYPE_URL_PREFIX);
if (substr($this->type_url, 0, $url_prifix_len) !=
GPBUtil::TYPE_URL_PREFIX) {
throw new \Exception(
"Type url needs to be type.googleapis.com/fully-qulified");
}
$fully_qualifed_name =
substr($this->type_url, $url_prifix_len);
// Create message according to fully qualified name.
$pool = \Google\Protobuf\Internal\DescriptorPool::getGeneratedPool();
$desc = $pool->getDescriptorByProtoName($fully_qualifed_name);
if (is_null($desc)) {
throw new \Exception("Class ".$fully_qualifed_name
." hasn't been added to descriptor pool");
}
$klass = $desc->getClass();
$msg = new $klass();
// Merge data into message.
$msg->mergeFromString($this->value);
return $msg;
}
/**
* The type_url will be created according to the given messages type and
* the value is encoded data from the given message..
* @param message: A proto message.
*/
public function pack($msg)
{
if (!$msg instanceof Message) {
trigger_error("Given parameter is not a message instance.",
E_USER_ERROR);
return;
}
// Set value using serialized message.
$this->value = $msg->serializeToString();
// Set type url.
$pool = \Google\Protobuf\Internal\DescriptorPool::getGeneratedPool();
$desc = $pool->getDescriptorByClassName(get_class($msg));
$fully_qualifed_name = $desc->getFullName();
$this->type_url = GPBUtil::TYPE_URL_PREFIX . $fully_qualifed_name;
}
/**
* This method returns whether the type_url in any_message is corresponded
* to the given class.
* @param klass: The fully qualified PHP class name of a proto message type.
*/
public function is($klass)
{
$pool = \Google\Protobuf\Internal\DescriptorPool::getGeneratedPool();
$desc = $pool->getDescriptorByClassName($klass);
$fully_qualifed_name = $desc->getFullName();
$type_url = GPBUtil::TYPE_URL_PREFIX . $fully_qualifed_name;
return $this->type_url === $type_url;
}
}

View File

@@ -0,0 +1,382 @@
<?php
// Protocol Buffers - Google's data interchange format
// Copyright 2008 Google Inc. All rights reserved.
// https://developers.google.com/protocol-buffers/
//
// Redistribution and use in source and binary forms, with or without
// modification, are permitted provided that the following conditions are
// met:
//
// * Redistributions of source code must retain the above copyright
// notice, this list of conditions and the following disclaimer.
// * Redistributions in binary form must reproduce the above
// copyright notice, this list of conditions and the following disclaimer
// in the documentation and/or other materials provided with the
// distribution.
// * Neither the name of Google Inc. nor the names of its
// contributors may be used to endorse or promote products derived from
// this software without specific prior written permission.
//
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
namespace Google\Protobuf\Internal;
use Google\Protobuf\Internal\Uint64;
class CodedInputStream
{
private $buffer;
private $buffer_size_after_limit;
private $buffer_end;
private $current;
private $current_limit;
private $legitimate_message_end;
private $recursion_budget;
private $recursion_limit;
private $total_bytes_limit;
private $total_bytes_read;
const MAX_VARINT_BYTES = 10;
const DEFAULT_RECURSION_LIMIT = 100;
const DEFAULT_TOTAL_BYTES_LIMIT = 33554432; // 32 << 20, 32MB
public function __construct($buffer)
{
$start = 0;
$end = strlen($buffer);
$this->buffer = $buffer;
$this->buffer_size_after_limit = 0;
$this->buffer_end = $end;
$this->current = $start;
$this->current_limit = $end;
$this->legitimate_message_end = false;
$this->recursion_budget = self::DEFAULT_RECURSION_LIMIT;
$this->recursion_limit = self::DEFAULT_RECURSION_LIMIT;
$this->total_bytes_limit = self::DEFAULT_TOTAL_BYTES_LIMIT;
$this->total_bytes_read = $end - $start;
}
private function advance($amount)
{
$this->current += $amount;
}
public function bufferSize()
{
return $this->buffer_end - $this->current;
}
public function current()
{
return $this->total_bytes_read -
($this->buffer_end - $this->current +
$this->buffer_size_after_limit);
}
public function substr($start, $end)
{
return substr($this->buffer, $start, $end - $start);
}
private function recomputeBufferLimits()
{
$this->buffer_end += $this->buffer_size_after_limit;
$closest_limit = min($this->current_limit, $this->total_bytes_limit);
if ($closest_limit < $this->total_bytes_read) {
// The limit position is in the current buffer. We must adjust the
// buffer size accordingly.
$this->buffer_size_after_limit = $this->total_bytes_read -
$closest_limit;
$this->buffer_end -= $this->buffer_size_after_limit;
} else {
$this->buffer_size_after_limit = 0;
}
}
private function consumedEntireMessage()
{
return $this->legitimate_message_end;
}
/**
* Read uint32 into $var. Advance buffer with consumed bytes. If the
* contained varint is larger than 32 bits, discard the high order bits.
* @param $var.
*/
public function readVarint32(&$var)
{
if (!$this->readVarint64($var)) {
return false;
}
if (PHP_INT_SIZE == 4) {
$var = bcmod($var, 4294967296);
} else {
$var &= 0xFFFFFFFF;
}
// Convert large uint32 to int32.
if ($var > 0x7FFFFFFF) {
if (PHP_INT_SIZE === 8) {
$var = $var | (0xFFFFFFFF << 32);
} else {
$var = bcsub($var, 4294967296);
}
}
$var = intval($var);
return true;
}
/**
* Read Uint64 into $var. Advance buffer with consumed bytes.
* @param $var.
*/
public function readVarint64(&$var)
{
$count = 0;
if (PHP_INT_SIZE == 4) {
$high = 0;
$low = 0;
$b = 0;
do {
if ($this->current === $this->buffer_end) {
return false;
}
if ($count === self::MAX_VARINT_BYTES) {
return false;
}
$b = ord($this->buffer[$this->current]);
$bits = 7 * $count;
if ($bits >= 32) {
$high |= (($b & 0x7F) << ($bits - 32));
} else if ($bits > 25){
// $bits is 28 in this case.
$low |= (($b & 0x7F) << 28);
$high = ($b & 0x7F) >> 4;
} else {
$low |= (($b & 0x7F) << $bits);
}
$this->advance(1);
$count += 1;
} while ($b & 0x80);
$var = GPBUtil::combineInt32ToInt64($high, $low);
if (bccomp($var, 0) < 0) {
$var = bcadd($var, "18446744073709551616");
}
} else {
$result = 0;
$shift = 0;
do {
if ($this->current === $this->buffer_end) {
return false;
}
if ($count === self::MAX_VARINT_BYTES) {
return false;
}
$byte = ord($this->buffer[$this->current]);
$result |= ($byte & 0x7f) << $shift;
$shift += 7;
$this->advance(1);
$count += 1;
} while ($byte > 0x7f);
$var = $result;
}
return true;
}
/**
* Read int into $var. If the result is larger than the largest integer, $var
* will be -1. Advance buffer with consumed bytes.
* @param $var.
*/
public function readVarintSizeAsInt(&$var)
{
if (!$this->readVarint64($var)) {
return false;
}
$var = (int)$var;
return true;
}
/**
* Read 32-bit unsigned integer to $var. If the buffer has less than 4 bytes,
* return false. Advance buffer with consumed bytes.
* @param $var.
*/
public function readLittleEndian32(&$var)
{
$data = null;
if (!$this->readRaw(4, $data)) {
return false;
}
$var = unpack('V', $data);
$var = $var[1];
return true;
}
/**
* Read 64-bit unsigned integer to $var. If the buffer has less than 8 bytes,
* return false. Advance buffer with consumed bytes.
* @param $var.
*/
public function readLittleEndian64(&$var)
{
$data = null;
if (!$this->readRaw(4, $data)) {
return false;
}
$low = unpack('V', $data)[1];
if (!$this->readRaw(4, $data)) {
return false;
}
$high = unpack('V', $data)[1];
if (PHP_INT_SIZE == 4) {
$var = GPBUtil::combineInt32ToInt64($high, $low);
} else {
$var = ($high << 32) | $low;
}
return true;
}
/**
* Read tag into $var. Advance buffer with consumed bytes.
* @param $var.
*/
public function readTag()
{
if ($this->current === $this->buffer_end) {
// Make sure that it failed due to EOF, not because we hit
// total_bytes_limit, which, unlike normal limits, is not a valid
// place to end a message.
$current_position = $this->total_bytes_read -
$this->buffer_size_after_limit;
if ($current_position >= $this->total_bytes_limit) {
// Hit total_bytes_limit_. But if we also hit the normal limit,
// we're still OK.
$this->legitimate_message_end =
($this->current_limit === $this->total_bytes_limit);
} else {
$this->legitimate_message_end = true;
}
return 0;
}
$result = 0;
// The largest tag is 2^29 - 1, which can be represented by int32.
$success = $this->readVarint32($result);
if ($success) {
return $result;
} else {
return 0;
}
}
public function readRaw($size, &$buffer)
{
$current_buffer_size = 0;
if ($this->bufferSize() < $size) {
return false;
}
if ($size === 0) {
$buffer = "";
} else {
$buffer = substr($this->buffer, $this->current, $size);
$this->advance($size);
}
return true;
}
/* Places a limit on the number of bytes that the stream may read, starting
* from the current position. Once the stream hits this limit, it will act
* like the end of the input has been reached until popLimit() is called.
*
* As the names imply, the stream conceptually has a stack of limits. The
* shortest limit on the stack is always enforced, even if it is not the top
* limit.
*
* The value returned by pushLimit() is opaque to the caller, and must be
* passed unchanged to the corresponding call to popLimit().
*
* @param integer $byte_limit
* @throws \Exception Fail to push limit.
*/
public function pushLimit($byte_limit)
{
// Current position relative to the beginning of the stream.
$current_position = $this->current();
$old_limit = $this->current_limit;
// security: byte_limit is possibly evil, so check for negative values
// and overflow.
if ($byte_limit >= 0 &&
$byte_limit <= PHP_INT_MAX - $current_position &&
$byte_limit <= $this->current_limit - $current_position) {
$this->current_limit = $current_position + $byte_limit;
$this->recomputeBufferLimits();
} else {
throw new GPBDecodeException("Fail to push limit.");
}
return $old_limit;
}
/* The limit passed in is actually the *old* limit, which we returned from
* PushLimit().
*
* @param integer $byte_limit
*/
public function popLimit($byte_limit)
{
$this->current_limit = $byte_limit;
$this->recomputeBufferLimits();
// We may no longer be at a legitimate message end. ReadTag() needs to
// be called again to find out.
$this->legitimate_message_end = false;
}
public function incrementRecursionDepthAndPushLimit(
$byte_limit, &$old_limit, &$recursion_budget)
{
$old_limit = $this->pushLimit($byte_limit);
$recursion_limit = --$this->recursion_limit;
}
public function decrementRecursionDepthAndPopLimit($byte_limit)
{
$result = $this->consumedEntireMessage();
$this->popLimit($byte_limit);
++$this->recursion_budget;
return $result;
}
public function bytesUntilLimit()
{
if ($this->current_limit === PHP_INT_MAX) {
return -1;
}
return $this->current_limit - $this->current;
}
}

View File

@@ -0,0 +1,159 @@
<?php
// Protocol Buffers - Google's data interchange format
// Copyright 2008 Google Inc. All rights reserved.
// https://developers.google.com/protocol-buffers/
//
// Redistribution and use in source and binary forms, with or without
// modification, are permitted provided that the following conditions are
// met:
//
// * Redistributions of source code must retain the above copyright
// notice, this list of conditions and the following disclaimer.
// * Redistributions in binary form must reproduce the above
// copyright notice, this list of conditions and the following disclaimer
// in the documentation and/or other materials provided with the
// distribution.
// * Neither the name of Google Inc. nor the names of its
// contributors may be used to endorse or promote products derived from
// this software without specific prior written permission.
//
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
namespace Google\Protobuf\Internal;
class CodedOutputStream
{
private $buffer;
private $buffer_size;
private $current;
const MAX_VARINT64_BYTES = 10;
public function __construct($size)
{
$this->current = 0;
$this->buffer_size = $size;
$this->buffer = str_repeat(chr(0), $this->buffer_size);
}
public function getData()
{
return $this->buffer;
}
public function writeVarint32($value, $trim)
{
$bytes = str_repeat(chr(0), self::MAX_VARINT64_BYTES);
$size = self::writeVarintToArray($value, $bytes, $trim);
return $this->writeRaw($bytes, $size);
}
public function writeVarint64($value)
{
$bytes = str_repeat(chr(0), self::MAX_VARINT64_BYTES);
$size = self::writeVarintToArray($value, $bytes);
return $this->writeRaw($bytes, $size);
}
public function writeLittleEndian32($value)
{
$bytes = str_repeat(chr(0), 4);
$size = self::writeLittleEndian32ToArray($value, $bytes);
return $this->writeRaw($bytes, $size);
}
public function writeLittleEndian64($value)
{
$bytes = str_repeat(chr(0), 8);
$size = self::writeLittleEndian64ToArray($value, $bytes);
return $this->writeRaw($bytes, $size);
}
public function writeTag($tag)
{
return $this->writeVarint32($tag, true);
}
public function writeRaw($data, $size)
{
if ($this->buffer_size < $size) {
trigger_error("Output stream doesn't have enough buffer.");
return false;
}
for ($i = 0; $i < $size; $i++) {
$this->buffer[$this->current] = $data[$i];
$this->current++;
$this->buffer_size--;
}
return true;
}
public static function writeVarintToArray($value, &$buffer, $trim = false)
{
$current = 0;
$high = 0;
$low = 0;
if (PHP_INT_SIZE == 4) {
GPBUtil::divideInt64ToInt32($value, $high, $low, $trim);
} else {
$low = $value;
}
while (($low >= 0x80 || $low < 0) || $high != 0) {
$buffer[$current] = chr($low | 0x80);
$value = ($value >> 7) & ~(0x7F << ((PHP_INT_SIZE << 3) - 7));
$carry = ($high & 0x7F) << ((PHP_INT_SIZE << 3) - 7);
$high = ($high >> 7) & ~(0x7F << ((PHP_INT_SIZE << 3) - 7));
$low = (($low >> 7) & ~(0x7F << ((PHP_INT_SIZE << 3) - 7)) | $carry);
$current++;
}
$buffer[$current] = chr($low);
return $current + 1;
}
private static function writeLittleEndian32ToArray($value, &$buffer)
{
$buffer[0] = chr($value & 0x000000FF);
$buffer[1] = chr(($value >> 8) & 0x000000FF);
$buffer[2] = chr(($value >> 16) & 0x000000FF);
$buffer[3] = chr(($value >> 24) & 0x000000FF);
return 4;
}
private static function writeLittleEndian64ToArray($value, &$buffer)
{
$high = 0;
$low = 0;
if (PHP_INT_SIZE == 4) {
GPBUtil::divideInt64ToInt32($value, $high, $low);
} else {
$low = $value & 0xFFFFFFFF;
$high = ($value >> 32) & 0xFFFFFFFF;
}
$buffer[0] = chr($low & 0x000000FF);
$buffer[1] = chr(($low >> 8) & 0x000000FF);
$buffer[2] = chr(($low >> 16) & 0x000000FF);
$buffer[3] = chr(($low >> 24) & 0x000000FF);
$buffer[4] = chr($high & 0x000000FF);
$buffer[5] = chr(($high >> 8) & 0x000000FF);
$buffer[6] = chr(($high >> 16) & 0x000000FF);
$buffer[7] = chr(($high >> 24) & 0x000000FF);
return 8;
}
}

View File

@@ -0,0 +1,236 @@
<?php
// Protocol Buffers - Google's data interchange format
// Copyright 2008 Google Inc. All rights reserved.
// https://developers.google.com/protocol-buffers/
//
// Redistribution and use in source and binary forms, with or without
// modification, are permitted provided that the following conditions are
// met:
//
// * Redistributions of source code must retain the above copyright
// notice, this list of conditions and the following disclaimer.
// * Redistributions in binary form must reproduce the above
// copyright notice, this list of conditions and the following disclaimer
// in the documentation and/or other materials provided with the
// distribution.
// * Neither the name of Google Inc. nor the names of its
// contributors may be used to endorse or promote products derived from
// this software without specific prior written permission.
//
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
namespace Google\Protobuf\Internal;
class Descriptor
{
use HasPublicDescriptorTrait;
private $full_name;
private $field = [];
private $json_to_field = [];
private $name_to_field = [];
private $index_to_field = [];
private $nested_type = [];
private $enum_type = [];
private $klass;
private $legacy_klass;
private $previous_klass;
private $options;
private $oneof_decl = [];
public function __construct()
{
$this->public_desc = new \Google\Protobuf\Descriptor($this);
}
public function addOneofDecl($oneof)
{
$this->oneof_decl[] = $oneof;
}
public function getOneofDecl()
{
return $this->oneof_decl;
}
public function setFullName($full_name)
{
$this->full_name = $full_name;
}
public function getFullName()
{
return $this->full_name;
}
public function addField($field)
{
$this->field[$field->getNumber()] = $field;
$this->json_to_field[$field->getJsonName()] = $field;
$this->name_to_field[$field->getName()] = $field;
$this->index_to_field[] = $field;
}
public function getField()
{
return $this->field;
}
public function addNestedType($desc)
{
$this->nested_type[] = $desc;
}
public function getNestedType()
{
return $this->nested_type;
}
public function addEnumType($desc)
{
$this->enum_type[] = $desc;
}
public function getEnumType()
{
return $this->enum_type;
}
public function getFieldByNumber($number)
{
if (!isset($this->field[$number])) {
return NULL;
} else {
return $this->field[$number];
}
}
public function getFieldByJsonName($json_name)
{
if (!isset($this->json_to_field[$json_name])) {
return NULL;
} else {
return $this->json_to_field[$json_name];
}
}
public function getFieldByName($name)
{
if (!isset($this->name_to_field[$name])) {
return NULL;
} else {
return $this->name_to_field[$name];
}
}
public function getFieldByIndex($index)
{
if (count($this->index_to_field) <= $index) {
return NULL;
} else {
return $this->index_to_field[$index];
}
}
public function setClass($klass)
{
$this->klass = $klass;
}
public function getClass()
{
return $this->klass;
}
public function setLegacyClass($klass)
{
$this->legacy_klass = $klass;
}
public function getLegacyClass()
{
return $this->legacy_klass;
}
public function setPreviouslyUnreservedClass($klass)
{
$this->previous_klass = $klass;
}
public function getPreviouslyUnreservedClass()
{
return $this->previous_klass;
}
public function setOptions($options)
{
$this->options = $options;
}
public function getOptions()
{
return $this->options;
}
public static function buildFromProto($proto, $file_proto, $containing)
{
$desc = new Descriptor();
$message_name_without_package = "";
$classname = "";
$legacy_classname = "";
$previous_classname = "";
$fullname = "";
GPBUtil::getFullClassName(
$proto,
$containing,
$file_proto,
$message_name_without_package,
$classname,
$legacy_classname,
$fullname,
$previous_classname);
$desc->setFullName($fullname);
$desc->setClass($classname);
$desc->setLegacyClass($legacy_classname);
$desc->setPreviouslyUnreservedClass($previous_classname);
$desc->setOptions($proto->getOptions());
foreach ($proto->getField() as $field_proto) {
$desc->addField(FieldDescriptor::buildFromProto($field_proto));
}
// Handle nested types.
foreach ($proto->getNestedType() as $nested_proto) {
$desc->addNestedType(Descriptor::buildFromProto(
$nested_proto, $file_proto, $message_name_without_package));
}
// Handle nested enum.
foreach ($proto->getEnumType() as $enum_proto) {
$desc->addEnumType(EnumDescriptor::buildFromProto(
$enum_proto, $file_proto, $message_name_without_package));
}
// Handle oneof fields.
$index = 0;
foreach ($proto->getOneofDecl() as $oneof_proto) {
$desc->addOneofDecl(
OneofDescriptor::buildFromProto($oneof_proto, $desc, $index));
$index++;
}
return $desc;
}
}

View File

@@ -0,0 +1,194 @@
<?php
// Protocol Buffers - Google's data interchange format
// Copyright 2008 Google Inc. All rights reserved.
// https://developers.google.com/protocol-buffers/
//
// Redistribution and use in source and binary forms, with or without
// modification, are permitted provided that the following conditions are
// met:
//
// * Redistributions of source code must retain the above copyright
// notice, this list of conditions and the following disclaimer.
// * Redistributions in binary form must reproduce the above
// copyright notice, this list of conditions and the following disclaimer
// in the documentation and/or other materials provided with the
// distribution.
// * Neither the name of Google Inc. nor the names of its
// contributors may be used to endorse or promote products derived from
// this software without specific prior written permission.
//
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
namespace Google\Protobuf\Internal;
use Google\Protobuf\Internal\Descriptor;
use Google\Protobuf\Internal\FileDescriptor;
use Google\Protobuf\Internal\FileDescriptorSet;
use Google\Protobuf\Internal\MessageBuilderContext;
use Google\Protobuf\Internal\EnumBuilderContext;
class DescriptorPool
{
private static $pool;
// Map from message names to sub-maps, which are maps from field numbers to
// field descriptors.
private $class_to_desc = [];
private $class_to_enum_desc = [];
private $proto_to_class = [];
public static function getGeneratedPool()
{
if (!isset(self::$pool)) {
self::$pool = new DescriptorPool();
}
return self::$pool;
}
public function internalAddGeneratedFile($data, $use_nested = false)
{
$files = new FileDescriptorSet();
$files->mergeFromString($data);
foreach($files->getFile() as $file_proto) {
$file = FileDescriptor::buildFromProto($file_proto);
foreach ($file->getMessageType() as $desc) {
$this->addDescriptor($desc);
}
unset($desc);
foreach ($file->getEnumType() as $desc) {
$this->addEnumDescriptor($desc);
}
unset($desc);
foreach ($file->getMessageType() as $desc) {
$this->crossLink($desc);
}
unset($desc);
}
}
public function addMessage($name, $klass)
{
return new MessageBuilderContext($name, $klass, $this);
}
public function addEnum($name, $klass)
{
return new EnumBuilderContext($name, $klass, $this);
}
public function addDescriptor($descriptor)
{
$this->proto_to_class[$descriptor->getFullName()] =
$descriptor->getClass();
$this->class_to_desc[$descriptor->getClass()] = $descriptor;
$this->class_to_desc[$descriptor->getLegacyClass()] = $descriptor;
$this->class_to_desc[$descriptor->getPreviouslyUnreservedClass()] = $descriptor;
foreach ($descriptor->getNestedType() as $nested_type) {
$this->addDescriptor($nested_type);
}
foreach ($descriptor->getEnumType() as $enum_type) {
$this->addEnumDescriptor($enum_type);
}
}
public function addEnumDescriptor($descriptor)
{
$this->proto_to_class[$descriptor->getFullName()] =
$descriptor->getClass();
$this->class_to_enum_desc[$descriptor->getClass()] = $descriptor;
$this->class_to_enum_desc[$descriptor->getLegacyClass()] = $descriptor;
}
public function getDescriptorByClassName($klass)
{
if (isset($this->class_to_desc[$klass])) {
return $this->class_to_desc[$klass];
} else {
return null;
}
}
public function getEnumDescriptorByClassName($klass)
{
if (isset($this->class_to_enum_desc[$klass])) {
return $this->class_to_enum_desc[$klass];
} else {
return null;
}
}
public function getDescriptorByProtoName($proto)
{
if (isset($this->proto_to_class[$proto])) {
$klass = $this->proto_to_class[$proto];
return $this->class_to_desc[$klass];
} else {
return null;
}
}
public function getEnumDescriptorByProtoName($proto)
{
$klass = $this->proto_to_class[$proto];
return $this->class_to_enum_desc[$klass];
}
private function crossLink(Descriptor $desc)
{
foreach ($desc->getField() as $field) {
switch ($field->getType()) {
case GPBType::MESSAGE:
$proto = $field->getMessageType();
if ($proto[0] == '.') {
$proto = substr($proto, 1);
}
$subdesc = $this->getDescriptorByProtoName($proto);
if (is_null($subdesc)) {
trigger_error(
'proto not added: ' . $proto
. " for " . $desc->getFullName(), E_USER_ERROR);
}
$field->setMessageType($subdesc);
break;
case GPBType::ENUM:
$proto = $field->getEnumType();
if ($proto[0] == '.') {
$proto = substr($proto, 1);
}
$field->setEnumType(
$this->getEnumDescriptorByProtoName($proto));
break;
default:
break;
}
}
unset($field);
foreach ($desc->getNestedType() as $nested_type) {
$this->crossLink($nested_type);
}
unset($nested_type);
}
public function finish()
{
foreach ($this->class_to_desc as $klass => $desc) {
$this->crossLink($desc);
}
unset($desc);
}
}

View File

@@ -0,0 +1,336 @@
<?php
# Generated by the protocol buffer compiler. DO NOT EDIT!
# source: google/protobuf/descriptor.proto
namespace Google\Protobuf\Internal;
use Google\Protobuf\Internal\GPBType;
use Google\Protobuf\Internal\GPBWire;
use Google\Protobuf\Internal\RepeatedField;
use Google\Protobuf\Internal\InputStream;
use Google\Protobuf\Internal\GPBUtil;
/**
* Describes a message type.
*
* Generated from protobuf message <code>google.protobuf.DescriptorProto</code>
*/
class DescriptorProto extends \Google\Protobuf\Internal\Message
{
/**
* Generated from protobuf field <code>optional string name = 1;</code>
*/
protected $name = null;
/**
* Generated from protobuf field <code>repeated .google.protobuf.FieldDescriptorProto field = 2;</code>
*/
private $field;
/**
* Generated from protobuf field <code>repeated .google.protobuf.FieldDescriptorProto extension = 6;</code>
*/
private $extension;
/**
* Generated from protobuf field <code>repeated .google.protobuf.DescriptorProto nested_type = 3;</code>
*/
private $nested_type;
/**
* Generated from protobuf field <code>repeated .google.protobuf.EnumDescriptorProto enum_type = 4;</code>
*/
private $enum_type;
/**
* Generated from protobuf field <code>repeated .google.protobuf.DescriptorProto.ExtensionRange extension_range = 5;</code>
*/
private $extension_range;
/**
* Generated from protobuf field <code>repeated .google.protobuf.OneofDescriptorProto oneof_decl = 8;</code>
*/
private $oneof_decl;
/**
* Generated from protobuf field <code>optional .google.protobuf.MessageOptions options = 7;</code>
*/
protected $options = null;
/**
* Generated from protobuf field <code>repeated .google.protobuf.DescriptorProto.ReservedRange reserved_range = 9;</code>
*/
private $reserved_range;
/**
* Reserved field names, which may not be used by fields in the same message.
* A given name may only be reserved once.
*
* Generated from protobuf field <code>repeated string reserved_name = 10;</code>
*/
private $reserved_name;
/**
* Constructor.
*
* @param array $data {
* Optional. Data for populating the Message object.
*
* @type string $name
* @type array<\Google\Protobuf\Internal\FieldDescriptorProto>|\Google\Protobuf\Internal\RepeatedField $field
* @type array<\Google\Protobuf\Internal\FieldDescriptorProto>|\Google\Protobuf\Internal\RepeatedField $extension
* @type array<\Google\Protobuf\Internal\DescriptorProto>|\Google\Protobuf\Internal\RepeatedField $nested_type
* @type array<\Google\Protobuf\Internal\EnumDescriptorProto>|\Google\Protobuf\Internal\RepeatedField $enum_type
* @type array<\Google\Protobuf\Internal\DescriptorProto\ExtensionRange>|\Google\Protobuf\Internal\RepeatedField $extension_range
* @type array<\Google\Protobuf\Internal\OneofDescriptorProto>|\Google\Protobuf\Internal\RepeatedField $oneof_decl
* @type \Google\Protobuf\Internal\MessageOptions $options
* @type array<\Google\Protobuf\Internal\DescriptorProto\ReservedRange>|\Google\Protobuf\Internal\RepeatedField $reserved_range
* @type array<string>|\Google\Protobuf\Internal\RepeatedField $reserved_name
* Reserved field names, which may not be used by fields in the same message.
* A given name may only be reserved once.
* }
*/
public function __construct($data = NULL) {
\GPBMetadata\Google\Protobuf\Internal\Descriptor::initOnce();
parent::__construct($data);
}
/**
* Generated from protobuf field <code>optional string name = 1;</code>
* @return string
*/
public function getName()
{
return isset($this->name) ? $this->name : '';
}
public function hasName()
{
return isset($this->name);
}
public function clearName()
{
unset($this->name);
}
/**
* Generated from protobuf field <code>optional string name = 1;</code>
* @param string $var
* @return $this
*/
public function setName($var)
{
GPBUtil::checkString($var, True);
$this->name = $var;
return $this;
}
/**
* Generated from protobuf field <code>repeated .google.protobuf.FieldDescriptorProto field = 2;</code>
* @return \Google\Protobuf\Internal\RepeatedField
*/
public function getField()
{
return $this->field;
}
/**
* Generated from protobuf field <code>repeated .google.protobuf.FieldDescriptorProto field = 2;</code>
* @param array<\Google\Protobuf\Internal\FieldDescriptorProto>|\Google\Protobuf\Internal\RepeatedField $var
* @return $this
*/
public function setField($var)
{
$arr = GPBUtil::checkRepeatedField($var, \Google\Protobuf\Internal\GPBType::MESSAGE, \Google\Protobuf\Internal\FieldDescriptorProto::class);
$this->field = $arr;
return $this;
}
/**
* Generated from protobuf field <code>repeated .google.protobuf.FieldDescriptorProto extension = 6;</code>
* @return \Google\Protobuf\Internal\RepeatedField
*/
public function getExtension()
{
return $this->extension;
}
/**
* Generated from protobuf field <code>repeated .google.protobuf.FieldDescriptorProto extension = 6;</code>
* @param array<\Google\Protobuf\Internal\FieldDescriptorProto>|\Google\Protobuf\Internal\RepeatedField $var
* @return $this
*/
public function setExtension($var)
{
$arr = GPBUtil::checkRepeatedField($var, \Google\Protobuf\Internal\GPBType::MESSAGE, \Google\Protobuf\Internal\FieldDescriptorProto::class);
$this->extension = $arr;
return $this;
}
/**
* Generated from protobuf field <code>repeated .google.protobuf.DescriptorProto nested_type = 3;</code>
* @return \Google\Protobuf\Internal\RepeatedField
*/
public function getNestedType()
{
return $this->nested_type;
}
/**
* Generated from protobuf field <code>repeated .google.protobuf.DescriptorProto nested_type = 3;</code>
* @param array<\Google\Protobuf\Internal\DescriptorProto>|\Google\Protobuf\Internal\RepeatedField $var
* @return $this
*/
public function setNestedType($var)
{
$arr = GPBUtil::checkRepeatedField($var, \Google\Protobuf\Internal\GPBType::MESSAGE, \Google\Protobuf\Internal\DescriptorProto::class);
$this->nested_type = $arr;
return $this;
}
/**
* Generated from protobuf field <code>repeated .google.protobuf.EnumDescriptorProto enum_type = 4;</code>
* @return \Google\Protobuf\Internal\RepeatedField
*/
public function getEnumType()
{
return $this->enum_type;
}
/**
* Generated from protobuf field <code>repeated .google.protobuf.EnumDescriptorProto enum_type = 4;</code>
* @param array<\Google\Protobuf\Internal\EnumDescriptorProto>|\Google\Protobuf\Internal\RepeatedField $var
* @return $this
*/
public function setEnumType($var)
{
$arr = GPBUtil::checkRepeatedField($var, \Google\Protobuf\Internal\GPBType::MESSAGE, \Google\Protobuf\Internal\EnumDescriptorProto::class);
$this->enum_type = $arr;
return $this;
}
/**
* Generated from protobuf field <code>repeated .google.protobuf.DescriptorProto.ExtensionRange extension_range = 5;</code>
* @return \Google\Protobuf\Internal\RepeatedField
*/
public function getExtensionRange()
{
return $this->extension_range;
}
/**
* Generated from protobuf field <code>repeated .google.protobuf.DescriptorProto.ExtensionRange extension_range = 5;</code>
* @param array<\Google\Protobuf\Internal\DescriptorProto\ExtensionRange>|\Google\Protobuf\Internal\RepeatedField $var
* @return $this
*/
public function setExtensionRange($var)
{
$arr = GPBUtil::checkRepeatedField($var, \Google\Protobuf\Internal\GPBType::MESSAGE, \Google\Protobuf\Internal\DescriptorProto\ExtensionRange::class);
$this->extension_range = $arr;
return $this;
}
/**
* Generated from protobuf field <code>repeated .google.protobuf.OneofDescriptorProto oneof_decl = 8;</code>
* @return \Google\Protobuf\Internal\RepeatedField
*/
public function getOneofDecl()
{
return $this->oneof_decl;
}
/**
* Generated from protobuf field <code>repeated .google.protobuf.OneofDescriptorProto oneof_decl = 8;</code>
* @param array<\Google\Protobuf\Internal\OneofDescriptorProto>|\Google\Protobuf\Internal\RepeatedField $var
* @return $this
*/
public function setOneofDecl($var)
{
$arr = GPBUtil::checkRepeatedField($var, \Google\Protobuf\Internal\GPBType::MESSAGE, \Google\Protobuf\Internal\OneofDescriptorProto::class);
$this->oneof_decl = $arr;
return $this;
}
/**
* Generated from protobuf field <code>optional .google.protobuf.MessageOptions options = 7;</code>
* @return \Google\Protobuf\Internal\MessageOptions|null
*/
public function getOptions()
{
return $this->options;
}
public function hasOptions()
{
return isset($this->options);
}
public function clearOptions()
{
unset($this->options);
}
/**
* Generated from protobuf field <code>optional .google.protobuf.MessageOptions options = 7;</code>
* @param \Google\Protobuf\Internal\MessageOptions $var
* @return $this
*/
public function setOptions($var)
{
GPBUtil::checkMessage($var, \Google\Protobuf\Internal\MessageOptions::class);
$this->options = $var;
return $this;
}
/**
* Generated from protobuf field <code>repeated .google.protobuf.DescriptorProto.ReservedRange reserved_range = 9;</code>
* @return \Google\Protobuf\Internal\RepeatedField
*/
public function getReservedRange()
{
return $this->reserved_range;
}
/**
* Generated from protobuf field <code>repeated .google.protobuf.DescriptorProto.ReservedRange reserved_range = 9;</code>
* @param array<\Google\Protobuf\Internal\DescriptorProto\ReservedRange>|\Google\Protobuf\Internal\RepeatedField $var
* @return $this
*/
public function setReservedRange($var)
{
$arr = GPBUtil::checkRepeatedField($var, \Google\Protobuf\Internal\GPBType::MESSAGE, \Google\Protobuf\Internal\DescriptorProto\ReservedRange::class);
$this->reserved_range = $arr;
return $this;
}
/**
* Reserved field names, which may not be used by fields in the same message.
* A given name may only be reserved once.
*
* Generated from protobuf field <code>repeated string reserved_name = 10;</code>
* @return \Google\Protobuf\Internal\RepeatedField
*/
public function getReservedName()
{
return $this->reserved_name;
}
/**
* Reserved field names, which may not be used by fields in the same message.
* A given name may only be reserved once.
*
* Generated from protobuf field <code>repeated string reserved_name = 10;</code>
* @param array<string>|\Google\Protobuf\Internal\RepeatedField $var
* @return $this
*/
public function setReservedName($var)
{
$arr = GPBUtil::checkRepeatedField($var, \Google\Protobuf\Internal\GPBType::STRING);
$this->reserved_name = $arr;
return $this;
}
}

View File

@@ -0,0 +1,161 @@
<?php
# Generated by the protocol buffer compiler. DO NOT EDIT!
# source: google/protobuf/descriptor.proto
namespace Google\Protobuf\Internal\DescriptorProto;
use Google\Protobuf\Internal\GPBType;
use Google\Protobuf\Internal\GPBWire;
use Google\Protobuf\Internal\RepeatedField;
use Google\Protobuf\Internal\InputStream;
use Google\Protobuf\Internal\GPBUtil;
/**
* Generated from protobuf message <code>google.protobuf.DescriptorProto.ExtensionRange</code>
*/
class ExtensionRange extends \Google\Protobuf\Internal\Message
{
/**
* Inclusive.
*
* Generated from protobuf field <code>optional int32 start = 1;</code>
*/
protected $start = null;
/**
* Exclusive.
*
* Generated from protobuf field <code>optional int32 end = 2;</code>
*/
protected $end = null;
/**
* Generated from protobuf field <code>optional .google.protobuf.ExtensionRangeOptions options = 3;</code>
*/
protected $options = null;
/**
* Constructor.
*
* @param array $data {
* Optional. Data for populating the Message object.
*
* @type int $start
* Inclusive.
* @type int $end
* Exclusive.
* @type \Google\Protobuf\Internal\ExtensionRangeOptions $options
* }
*/
public function __construct($data = NULL) {
\GPBMetadata\Google\Protobuf\Internal\Descriptor::initOnce();
parent::__construct($data);
}
/**
* Inclusive.
*
* Generated from protobuf field <code>optional int32 start = 1;</code>
* @return int
*/
public function getStart()
{
return isset($this->start) ? $this->start : 0;
}
public function hasStart()
{
return isset($this->start);
}
public function clearStart()
{
unset($this->start);
}
/**
* Inclusive.
*
* Generated from protobuf field <code>optional int32 start = 1;</code>
* @param int $var
* @return $this
*/
public function setStart($var)
{
GPBUtil::checkInt32($var);
$this->start = $var;
return $this;
}
/**
* Exclusive.
*
* Generated from protobuf field <code>optional int32 end = 2;</code>
* @return int
*/
public function getEnd()
{
return isset($this->end) ? $this->end : 0;
}
public function hasEnd()
{
return isset($this->end);
}
public function clearEnd()
{
unset($this->end);
}
/**
* Exclusive.
*
* Generated from protobuf field <code>optional int32 end = 2;</code>
* @param int $var
* @return $this
*/
public function setEnd($var)
{
GPBUtil::checkInt32($var);
$this->end = $var;
return $this;
}
/**
* Generated from protobuf field <code>optional .google.protobuf.ExtensionRangeOptions options = 3;</code>
* @return \Google\Protobuf\Internal\ExtensionRangeOptions|null
*/
public function getOptions()
{
return $this->options;
}
public function hasOptions()
{
return isset($this->options);
}
public function clearOptions()
{
unset($this->options);
}
/**
* Generated from protobuf field <code>optional .google.protobuf.ExtensionRangeOptions options = 3;</code>
* @param \Google\Protobuf\Internal\ExtensionRangeOptions $var
* @return $this
*/
public function setOptions($var)
{
GPBUtil::checkMessage($var, \Google\Protobuf\Internal\ExtensionRangeOptions::class);
$this->options = $var;
return $this;
}
}
// Adding a class alias for backwards compatibility with the previous class name.
class_alias(ExtensionRange::class, \Google\Protobuf\Internal\DescriptorProto_ExtensionRange::class);

View File

@@ -0,0 +1,128 @@
<?php
# Generated by the protocol buffer compiler. DO NOT EDIT!
# source: google/protobuf/descriptor.proto
namespace Google\Protobuf\Internal\DescriptorProto;
use Google\Protobuf\Internal\GPBType;
use Google\Protobuf\Internal\GPBWire;
use Google\Protobuf\Internal\RepeatedField;
use Google\Protobuf\Internal\InputStream;
use Google\Protobuf\Internal\GPBUtil;
/**
* Range of reserved tag numbers. Reserved tag numbers may not be used by
* fields or extension ranges in the same message. Reserved ranges may
* not overlap.
*
* Generated from protobuf message <code>google.protobuf.DescriptorProto.ReservedRange</code>
*/
class ReservedRange extends \Google\Protobuf\Internal\Message
{
/**
* Inclusive.
*
* Generated from protobuf field <code>optional int32 start = 1;</code>
*/
protected $start = null;
/**
* Exclusive.
*
* Generated from protobuf field <code>optional int32 end = 2;</code>
*/
protected $end = null;
/**
* Constructor.
*
* @param array $data {
* Optional. Data for populating the Message object.
*
* @type int $start
* Inclusive.
* @type int $end
* Exclusive.
* }
*/
public function __construct($data = NULL) {
\GPBMetadata\Google\Protobuf\Internal\Descriptor::initOnce();
parent::__construct($data);
}
/**
* Inclusive.
*
* Generated from protobuf field <code>optional int32 start = 1;</code>
* @return int
*/
public function getStart()
{
return isset($this->start) ? $this->start : 0;
}
public function hasStart()
{
return isset($this->start);
}
public function clearStart()
{
unset($this->start);
}
/**
* Inclusive.
*
* Generated from protobuf field <code>optional int32 start = 1;</code>
* @param int $var
* @return $this
*/
public function setStart($var)
{
GPBUtil::checkInt32($var);
$this->start = $var;
return $this;
}
/**
* Exclusive.
*
* Generated from protobuf field <code>optional int32 end = 2;</code>
* @return int
*/
public function getEnd()
{
return isset($this->end) ? $this->end : 0;
}
public function hasEnd()
{
return isset($this->end);
}
public function clearEnd()
{
unset($this->end);
}
/**
* Exclusive.
*
* Generated from protobuf field <code>optional int32 end = 2;</code>
* @param int $var
* @return $this
*/
public function setEnd($var)
{
GPBUtil::checkInt32($var);
$this->end = $var;
return $this;
}
}
// Adding a class alias for backwards compatibility with the previous class name.
class_alias(ReservedRange::class, \Google\Protobuf\Internal\DescriptorProto_ReservedRange::class);

View File

@@ -0,0 +1,16 @@
<?php
# Generated by the protocol buffer compiler. DO NOT EDIT!
# source: google/protobuf/descriptor.proto
namespace Google\Protobuf\Internal;
if (false) {
/**
* This class is deprecated. Use Google\Protobuf\Internal\DescriptorProto\ExtensionRange instead.
* @deprecated
*/
class DescriptorProto_ExtensionRange {}
}
class_exists(DescriptorProto\ExtensionRange::class);
@trigger_error('Google\Protobuf\Internal\DescriptorProto_ExtensionRange is deprecated and will be removed in the next major release. Use Google\Protobuf\Internal\DescriptorProto\ExtensionRange instead', E_USER_DEPRECATED);

View File

@@ -0,0 +1,16 @@
<?php
# Generated by the protocol buffer compiler. DO NOT EDIT!
# source: google/protobuf/descriptor.proto
namespace Google\Protobuf\Internal;
if (false) {
/**
* This class is deprecated. Use Google\Protobuf\Internal\DescriptorProto\ReservedRange instead.
* @deprecated
*/
class DescriptorProto_ReservedRange {}
}
class_exists(DescriptorProto\ReservedRange::class);
@trigger_error('Google\Protobuf\Internal\DescriptorProto_ReservedRange is deprecated and will be removed in the next major release. Use Google\Protobuf\Internal\DescriptorProto\ReservedRange instead', E_USER_DEPRECATED);

View File

@@ -0,0 +1,63 @@
<?php
// Protocol Buffers - Google's data interchange format
// Copyright 2008 Google Inc. All rights reserved.
// https://developers.google.com/protocol-buffers/
//
// Redistribution and use in source and binary forms, with or without
// modification, are permitted provided that the following conditions are
// met:
//
// * Redistributions of source code must retain the above copyright
// notice, this list of conditions and the following disclaimer.
// * Redistributions in binary form must reproduce the above
// copyright notice, this list of conditions and the following disclaimer
// in the documentation and/or other materials provided with the
// distribution.
// * Neither the name of Google Inc. nor the names of its
// contributors may be used to endorse or promote products derived from
// this software without specific prior written permission.
//
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
namespace Google\Protobuf\Internal;
use Google\Protobuf\Internal\EnumDescriptor;
use Google\Protobuf\EnumValueDescriptor;
class EnumBuilderContext
{
private $descriptor;
private $pool;
public function __construct($full_name, $klass, $pool)
{
$this->descriptor = new EnumDescriptor();
$this->descriptor->setFullName($full_name);
$this->descriptor->setClass($klass);
$this->pool = $pool;
}
public function value($name, $number)
{
$value = new EnumValueDescriptor($name, $number);
$this->descriptor->addValue($number, $value);
return $this;
}
public function finalizeToPool()
{
$this->pool->addEnumDescriptor($this->descriptor);
}
}

View File

@@ -0,0 +1,116 @@
<?php
namespace Google\Protobuf\Internal;
use Google\Protobuf\EnumValueDescriptor;
class EnumDescriptor
{
use HasPublicDescriptorTrait;
private $klass;
private $legacy_klass;
private $full_name;
private $value;
private $name_to_value;
private $value_descriptor = [];
public function __construct()
{
$this->public_desc = new \Google\Protobuf\EnumDescriptor($this);
}
public function setFullName($full_name)
{
$this->full_name = $full_name;
}
public function getFullName()
{
return $this->full_name;
}
public function addValue($number, $value)
{
$this->value[$number] = $value;
$this->name_to_value[$value->getName()] = $value;
$this->value_descriptor[] = new EnumValueDescriptor($value->getName(), $number);
}
public function getValueByNumber($number)
{
if (isset($this->value[$number])) {
return $this->value[$number];
}
return null;
}
public function getValueByName($name)
{
if (isset($this->name_to_value[$name])) {
return $this->name_to_value[$name];
}
return null;
}
public function getValueDescriptorByIndex($index)
{
if (isset($this->value_descriptor[$index])) {
return $this->value_descriptor[$index];
}
return null;
}
public function getValueCount()
{
return count($this->value);
}
public function setClass($klass)
{
$this->klass = $klass;
}
public function getClass()
{
return $this->klass;
}
public function setLegacyClass($klass)
{
$this->legacy_klass = $klass;
}
public function getLegacyClass()
{
return $this->legacy_klass;
}
public static function buildFromProto($proto, $file_proto, $containing)
{
$desc = new EnumDescriptor();
$enum_name_without_package = "";
$classname = "";
$legacy_classname = "";
$fullname = "";
GPBUtil::getFullClassName(
$proto,
$containing,
$file_proto,
$enum_name_without_package,
$classname,
$legacy_classname,
$fullname,
$unused_previous_classname);
$desc->setFullName($fullname);
$desc->setClass($classname);
$desc->setLegacyClass($legacy_classname);
$values = $proto->getValue();
foreach ($values as $value) {
$desc->addValue($value->getNumber(), $value);
}
return $desc;
}
}

View File

@@ -0,0 +1,216 @@
<?php
# Generated by the protocol buffer compiler. DO NOT EDIT!
# source: google/protobuf/descriptor.proto
namespace Google\Protobuf\Internal;
use Google\Protobuf\Internal\GPBType;
use Google\Protobuf\Internal\GPBWire;
use Google\Protobuf\Internal\RepeatedField;
use Google\Protobuf\Internal\InputStream;
use Google\Protobuf\Internal\GPBUtil;
/**
* Describes an enum type.
*
* Generated from protobuf message <code>google.protobuf.EnumDescriptorProto</code>
*/
class EnumDescriptorProto extends \Google\Protobuf\Internal\Message
{
/**
* Generated from protobuf field <code>optional string name = 1;</code>
*/
protected $name = null;
/**
* Generated from protobuf field <code>repeated .google.protobuf.EnumValueDescriptorProto value = 2;</code>
*/
private $value;
/**
* Generated from protobuf field <code>optional .google.protobuf.EnumOptions options = 3;</code>
*/
protected $options = null;
/**
* Range of reserved numeric values. Reserved numeric values may not be used
* by enum values in the same enum declaration. Reserved ranges may not
* overlap.
*
* Generated from protobuf field <code>repeated .google.protobuf.EnumDescriptorProto.EnumReservedRange reserved_range = 4;</code>
*/
private $reserved_range;
/**
* Reserved enum value names, which may not be reused. A given name may only
* be reserved once.
*
* Generated from protobuf field <code>repeated string reserved_name = 5;</code>
*/
private $reserved_name;
/**
* Constructor.
*
* @param array $data {
* Optional. Data for populating the Message object.
*
* @type string $name
* @type array<\Google\Protobuf\Internal\EnumValueDescriptorProto>|\Google\Protobuf\Internal\RepeatedField $value
* @type \Google\Protobuf\Internal\EnumOptions $options
* @type array<\Google\Protobuf\Internal\EnumDescriptorProto\EnumReservedRange>|\Google\Protobuf\Internal\RepeatedField $reserved_range
* Range of reserved numeric values. Reserved numeric values may not be used
* by enum values in the same enum declaration. Reserved ranges may not
* overlap.
* @type array<string>|\Google\Protobuf\Internal\RepeatedField $reserved_name
* Reserved enum value names, which may not be reused. A given name may only
* be reserved once.
* }
*/
public function __construct($data = NULL) {
\GPBMetadata\Google\Protobuf\Internal\Descriptor::initOnce();
parent::__construct($data);
}
/**
* Generated from protobuf field <code>optional string name = 1;</code>
* @return string
*/
public function getName()
{
return isset($this->name) ? $this->name : '';
}
public function hasName()
{
return isset($this->name);
}
public function clearName()
{
unset($this->name);
}
/**
* Generated from protobuf field <code>optional string name = 1;</code>
* @param string $var
* @return $this
*/
public function setName($var)
{
GPBUtil::checkString($var, True);
$this->name = $var;
return $this;
}
/**
* Generated from protobuf field <code>repeated .google.protobuf.EnumValueDescriptorProto value = 2;</code>
* @return \Google\Protobuf\Internal\RepeatedField
*/
public function getValue()
{
return $this->value;
}
/**
* Generated from protobuf field <code>repeated .google.protobuf.EnumValueDescriptorProto value = 2;</code>
* @param array<\Google\Protobuf\Internal\EnumValueDescriptorProto>|\Google\Protobuf\Internal\RepeatedField $var
* @return $this
*/
public function setValue($var)
{
$arr = GPBUtil::checkRepeatedField($var, \Google\Protobuf\Internal\GPBType::MESSAGE, \Google\Protobuf\Internal\EnumValueDescriptorProto::class);
$this->value = $arr;
return $this;
}
/**
* Generated from protobuf field <code>optional .google.protobuf.EnumOptions options = 3;</code>
* @return \Google\Protobuf\Internal\EnumOptions|null
*/
public function getOptions()
{
return $this->options;
}
public function hasOptions()
{
return isset($this->options);
}
public function clearOptions()
{
unset($this->options);
}
/**
* Generated from protobuf field <code>optional .google.protobuf.EnumOptions options = 3;</code>
* @param \Google\Protobuf\Internal\EnumOptions $var
* @return $this
*/
public function setOptions($var)
{
GPBUtil::checkMessage($var, \Google\Protobuf\Internal\EnumOptions::class);
$this->options = $var;
return $this;
}
/**
* Range of reserved numeric values. Reserved numeric values may not be used
* by enum values in the same enum declaration. Reserved ranges may not
* overlap.
*
* Generated from protobuf field <code>repeated .google.protobuf.EnumDescriptorProto.EnumReservedRange reserved_range = 4;</code>
* @return \Google\Protobuf\Internal\RepeatedField
*/
public function getReservedRange()
{
return $this->reserved_range;
}
/**
* Range of reserved numeric values. Reserved numeric values may not be used
* by enum values in the same enum declaration. Reserved ranges may not
* overlap.
*
* Generated from protobuf field <code>repeated .google.protobuf.EnumDescriptorProto.EnumReservedRange reserved_range = 4;</code>
* @param array<\Google\Protobuf\Internal\EnumDescriptorProto\EnumReservedRange>|\Google\Protobuf\Internal\RepeatedField $var
* @return $this
*/
public function setReservedRange($var)
{
$arr = GPBUtil::checkRepeatedField($var, \Google\Protobuf\Internal\GPBType::MESSAGE, \Google\Protobuf\Internal\EnumDescriptorProto\EnumReservedRange::class);
$this->reserved_range = $arr;
return $this;
}
/**
* Reserved enum value names, which may not be reused. A given name may only
* be reserved once.
*
* Generated from protobuf field <code>repeated string reserved_name = 5;</code>
* @return \Google\Protobuf\Internal\RepeatedField
*/
public function getReservedName()
{
return $this->reserved_name;
}
/**
* Reserved enum value names, which may not be reused. A given name may only
* be reserved once.
*
* Generated from protobuf field <code>repeated string reserved_name = 5;</code>
* @param array<string>|\Google\Protobuf\Internal\RepeatedField $var
* @return $this
*/
public function setReservedName($var)
{
$arr = GPBUtil::checkRepeatedField($var, \Google\Protobuf\Internal\GPBType::STRING);
$this->reserved_name = $arr;
return $this;
}
}

View File

@@ -0,0 +1,130 @@
<?php
# Generated by the protocol buffer compiler. DO NOT EDIT!
# source: google/protobuf/descriptor.proto
namespace Google\Protobuf\Internal\EnumDescriptorProto;
use Google\Protobuf\Internal\GPBType;
use Google\Protobuf\Internal\GPBWire;
use Google\Protobuf\Internal\RepeatedField;
use Google\Protobuf\Internal\InputStream;
use Google\Protobuf\Internal\GPBUtil;
/**
* Range of reserved numeric values. Reserved values may not be used by
* entries in the same enum. Reserved ranges may not overlap.
* Note that this is distinct from DescriptorProto.ReservedRange in that it
* is inclusive such that it can appropriately represent the entire int32
* domain.
*
* Generated from protobuf message <code>google.protobuf.EnumDescriptorProto.EnumReservedRange</code>
*/
class EnumReservedRange extends \Google\Protobuf\Internal\Message
{
/**
* Inclusive.
*
* Generated from protobuf field <code>optional int32 start = 1;</code>
*/
protected $start = null;
/**
* Inclusive.
*
* Generated from protobuf field <code>optional int32 end = 2;</code>
*/
protected $end = null;
/**
* Constructor.
*
* @param array $data {
* Optional. Data for populating the Message object.
*
* @type int $start
* Inclusive.
* @type int $end
* Inclusive.
* }
*/
public function __construct($data = NULL) {
\GPBMetadata\Google\Protobuf\Internal\Descriptor::initOnce();
parent::__construct($data);
}
/**
* Inclusive.
*
* Generated from protobuf field <code>optional int32 start = 1;</code>
* @return int
*/
public function getStart()
{
return isset($this->start) ? $this->start : 0;
}
public function hasStart()
{
return isset($this->start);
}
public function clearStart()
{
unset($this->start);
}
/**
* Inclusive.
*
* Generated from protobuf field <code>optional int32 start = 1;</code>
* @param int $var
* @return $this
*/
public function setStart($var)
{
GPBUtil::checkInt32($var);
$this->start = $var;
return $this;
}
/**
* Inclusive.
*
* Generated from protobuf field <code>optional int32 end = 2;</code>
* @return int
*/
public function getEnd()
{
return isset($this->end) ? $this->end : 0;
}
public function hasEnd()
{
return isset($this->end);
}
public function clearEnd()
{
unset($this->end);
}
/**
* Inclusive.
*
* Generated from protobuf field <code>optional int32 end = 2;</code>
* @param int $var
* @return $this
*/
public function setEnd($var)
{
GPBUtil::checkInt32($var);
$this->end = $var;
return $this;
}
}
// Adding a class alias for backwards compatibility with the previous class name.
class_alias(EnumReservedRange::class, \Google\Protobuf\Internal\EnumDescriptorProto_EnumReservedRange::class);

View File

@@ -0,0 +1,16 @@
<?php
# Generated by the protocol buffer compiler. DO NOT EDIT!
# source: google/protobuf/descriptor.proto
namespace Google\Protobuf\Internal;
if (false) {
/**
* This class is deprecated. Use Google\Protobuf\Internal\EnumDescriptorProto\EnumReservedRange instead.
* @deprecated
*/
class EnumDescriptorProto_EnumReservedRange {}
}
class_exists(EnumDescriptorProto\EnumReservedRange::class);
@trigger_error('Google\Protobuf\Internal\EnumDescriptorProto_EnumReservedRange is deprecated and will be removed in the next major release. Use Google\Protobuf\Internal\EnumDescriptorProto\EnumReservedRange instead', E_USER_DEPRECATED);

View File

@@ -0,0 +1,171 @@
<?php
# Generated by the protocol buffer compiler. DO NOT EDIT!
# source: google/protobuf/descriptor.proto
namespace Google\Protobuf\Internal;
use Google\Protobuf\Internal\GPBType;
use Google\Protobuf\Internal\GPBWire;
use Google\Protobuf\Internal\RepeatedField;
use Google\Protobuf\Internal\InputStream;
use Google\Protobuf\Internal\GPBUtil;
/**
* Generated from protobuf message <code>google.protobuf.EnumOptions</code>
*/
class EnumOptions extends \Google\Protobuf\Internal\Message
{
/**
* Set this option to true to allow mapping different tag names to the same
* value.
*
* Generated from protobuf field <code>optional bool allow_alias = 2;</code>
*/
protected $allow_alias = null;
/**
* Is this enum deprecated?
* Depending on the target platform, this can emit Deprecated annotations
* for the enum, or it will be completely ignored; in the very least, this
* is a formalization for deprecating enums.
*
* Generated from protobuf field <code>optional bool deprecated = 3 [default = false];</code>
*/
protected $deprecated = null;
/**
* The parser stores options it doesn't recognize here. See above.
*
* Generated from protobuf field <code>repeated .google.protobuf.UninterpretedOption uninterpreted_option = 999;</code>
*/
private $uninterpreted_option;
/**
* Constructor.
*
* @param array $data {
* Optional. Data for populating the Message object.
*
* @type bool $allow_alias
* Set this option to true to allow mapping different tag names to the same
* value.
* @type bool $deprecated
* Is this enum deprecated?
* Depending on the target platform, this can emit Deprecated annotations
* for the enum, or it will be completely ignored; in the very least, this
* is a formalization for deprecating enums.
* @type array<\Google\Protobuf\Internal\UninterpretedOption>|\Google\Protobuf\Internal\RepeatedField $uninterpreted_option
* The parser stores options it doesn't recognize here. See above.
* }
*/
public function __construct($data = NULL) {
\GPBMetadata\Google\Protobuf\Internal\Descriptor::initOnce();
parent::__construct($data);
}
/**
* Set this option to true to allow mapping different tag names to the same
* value.
*
* Generated from protobuf field <code>optional bool allow_alias = 2;</code>
* @return bool
*/
public function getAllowAlias()
{
return isset($this->allow_alias) ? $this->allow_alias : false;
}
public function hasAllowAlias()
{
return isset($this->allow_alias);
}
public function clearAllowAlias()
{
unset($this->allow_alias);
}
/**
* Set this option to true to allow mapping different tag names to the same
* value.
*
* Generated from protobuf field <code>optional bool allow_alias = 2;</code>
* @param bool $var
* @return $this
*/
public function setAllowAlias($var)
{
GPBUtil::checkBool($var);
$this->allow_alias = $var;
return $this;
}
/**
* Is this enum deprecated?
* Depending on the target platform, this can emit Deprecated annotations
* for the enum, or it will be completely ignored; in the very least, this
* is a formalization for deprecating enums.
*
* Generated from protobuf field <code>optional bool deprecated = 3 [default = false];</code>
* @return bool
*/
public function getDeprecated()
{
return isset($this->deprecated) ? $this->deprecated : false;
}
public function hasDeprecated()
{
return isset($this->deprecated);
}
public function clearDeprecated()
{
unset($this->deprecated);
}
/**
* Is this enum deprecated?
* Depending on the target platform, this can emit Deprecated annotations
* for the enum, or it will be completely ignored; in the very least, this
* is a formalization for deprecating enums.
*
* Generated from protobuf field <code>optional bool deprecated = 3 [default = false];</code>
* @param bool $var
* @return $this
*/
public function setDeprecated($var)
{
GPBUtil::checkBool($var);
$this->deprecated = $var;
return $this;
}
/**
* The parser stores options it doesn't recognize here. See above.
*
* Generated from protobuf field <code>repeated .google.protobuf.UninterpretedOption uninterpreted_option = 999;</code>
* @return \Google\Protobuf\Internal\RepeatedField
*/
public function getUninterpretedOption()
{
return $this->uninterpreted_option;
}
/**
* The parser stores options it doesn't recognize here. See above.
*
* Generated from protobuf field <code>repeated .google.protobuf.UninterpretedOption uninterpreted_option = 999;</code>
* @param array<\Google\Protobuf\Internal\UninterpretedOption>|\Google\Protobuf\Internal\RepeatedField $var
* @return $this
*/
public function setUninterpretedOption($var)
{
$arr = GPBUtil::checkRepeatedField($var, \Google\Protobuf\Internal\GPBType::MESSAGE, \Google\Protobuf\Internal\UninterpretedOption::class);
$this->uninterpreted_option = $arr;
return $this;
}
}

View File

@@ -0,0 +1,146 @@
<?php
# Generated by the protocol buffer compiler. DO NOT EDIT!
# source: google/protobuf/descriptor.proto
namespace Google\Protobuf\Internal;
use Google\Protobuf\Internal\GPBType;
use Google\Protobuf\Internal\GPBWire;
use Google\Protobuf\Internal\RepeatedField;
use Google\Protobuf\Internal\InputStream;
use Google\Protobuf\Internal\GPBUtil;
/**
* Describes a value within an enum.
*
* Generated from protobuf message <code>google.protobuf.EnumValueDescriptorProto</code>
*/
class EnumValueDescriptorProto extends \Google\Protobuf\Internal\Message
{
/**
* Generated from protobuf field <code>optional string name = 1;</code>
*/
protected $name = null;
/**
* Generated from protobuf field <code>optional int32 number = 2;</code>
*/
protected $number = null;
/**
* Generated from protobuf field <code>optional .google.protobuf.EnumValueOptions options = 3;</code>
*/
protected $options = null;
/**
* Constructor.
*
* @param array $data {
* Optional. Data for populating the Message object.
*
* @type string $name
* @type int $number
* @type \Google\Protobuf\Internal\EnumValueOptions $options
* }
*/
public function __construct($data = NULL) {
\GPBMetadata\Google\Protobuf\Internal\Descriptor::initOnce();
parent::__construct($data);
}
/**
* Generated from protobuf field <code>optional string name = 1;</code>
* @return string
*/
public function getName()
{
return isset($this->name) ? $this->name : '';
}
public function hasName()
{
return isset($this->name);
}
public function clearName()
{
unset($this->name);
}
/**
* Generated from protobuf field <code>optional string name = 1;</code>
* @param string $var
* @return $this
*/
public function setName($var)
{
GPBUtil::checkString($var, True);
$this->name = $var;
return $this;
}
/**
* Generated from protobuf field <code>optional int32 number = 2;</code>
* @return int
*/
public function getNumber()
{
return isset($this->number) ? $this->number : 0;
}
public function hasNumber()
{
return isset($this->number);
}
public function clearNumber()
{
unset($this->number);
}
/**
* Generated from protobuf field <code>optional int32 number = 2;</code>
* @param int $var
* @return $this
*/
public function setNumber($var)
{
GPBUtil::checkInt32($var);
$this->number = $var;
return $this;
}
/**
* Generated from protobuf field <code>optional .google.protobuf.EnumValueOptions options = 3;</code>
* @return \Google\Protobuf\Internal\EnumValueOptions|null
*/
public function getOptions()
{
return $this->options;
}
public function hasOptions()
{
return isset($this->options);
}
public function clearOptions()
{
unset($this->options);
}
/**
* Generated from protobuf field <code>optional .google.protobuf.EnumValueOptions options = 3;</code>
* @param \Google\Protobuf\Internal\EnumValueOptions $var
* @return $this
*/
public function setOptions($var)
{
GPBUtil::checkMessage($var, \Google\Protobuf\Internal\EnumValueOptions::class);
$this->options = $var;
return $this;
}
}

View File

@@ -0,0 +1,123 @@
<?php
# Generated by the protocol buffer compiler. DO NOT EDIT!
# source: google/protobuf/descriptor.proto
namespace Google\Protobuf\Internal;
use Google\Protobuf\Internal\GPBType;
use Google\Protobuf\Internal\GPBWire;
use Google\Protobuf\Internal\RepeatedField;
use Google\Protobuf\Internal\InputStream;
use Google\Protobuf\Internal\GPBUtil;
/**
* Generated from protobuf message <code>google.protobuf.EnumValueOptions</code>
*/
class EnumValueOptions extends \Google\Protobuf\Internal\Message
{
/**
* Is this enum value deprecated?
* Depending on the target platform, this can emit Deprecated annotations
* for the enum value, or it will be completely ignored; in the very least,
* this is a formalization for deprecating enum values.
*
* Generated from protobuf field <code>optional bool deprecated = 1 [default = false];</code>
*/
protected $deprecated = null;
/**
* The parser stores options it doesn't recognize here. See above.
*
* Generated from protobuf field <code>repeated .google.protobuf.UninterpretedOption uninterpreted_option = 999;</code>
*/
private $uninterpreted_option;
/**
* Constructor.
*
* @param array $data {
* Optional. Data for populating the Message object.
*
* @type bool $deprecated
* Is this enum value deprecated?
* Depending on the target platform, this can emit Deprecated annotations
* for the enum value, or it will be completely ignored; in the very least,
* this is a formalization for deprecating enum values.
* @type array<\Google\Protobuf\Internal\UninterpretedOption>|\Google\Protobuf\Internal\RepeatedField $uninterpreted_option
* The parser stores options it doesn't recognize here. See above.
* }
*/
public function __construct($data = NULL) {
\GPBMetadata\Google\Protobuf\Internal\Descriptor::initOnce();
parent::__construct($data);
}
/**
* Is this enum value deprecated?
* Depending on the target platform, this can emit Deprecated annotations
* for the enum value, or it will be completely ignored; in the very least,
* this is a formalization for deprecating enum values.
*
* Generated from protobuf field <code>optional bool deprecated = 1 [default = false];</code>
* @return bool
*/
public function getDeprecated()
{
return isset($this->deprecated) ? $this->deprecated : false;
}
public function hasDeprecated()
{
return isset($this->deprecated);
}
public function clearDeprecated()
{
unset($this->deprecated);
}
/**
* Is this enum value deprecated?
* Depending on the target platform, this can emit Deprecated annotations
* for the enum value, or it will be completely ignored; in the very least,
* this is a formalization for deprecating enum values.
*
* Generated from protobuf field <code>optional bool deprecated = 1 [default = false];</code>
* @param bool $var
* @return $this
*/
public function setDeprecated($var)
{
GPBUtil::checkBool($var);
$this->deprecated = $var;
return $this;
}
/**
* The parser stores options it doesn't recognize here. See above.
*
* Generated from protobuf field <code>repeated .google.protobuf.UninterpretedOption uninterpreted_option = 999;</code>
* @return \Google\Protobuf\Internal\RepeatedField
*/
public function getUninterpretedOption()
{
return $this->uninterpreted_option;
}
/**
* The parser stores options it doesn't recognize here. See above.
*
* Generated from protobuf field <code>repeated .google.protobuf.UninterpretedOption uninterpreted_option = 999;</code>
* @param array<\Google\Protobuf\Internal\UninterpretedOption>|\Google\Protobuf\Internal\RepeatedField $var
* @return $this
*/
public function setUninterpretedOption($var)
{
$arr = GPBUtil::checkRepeatedField($var, \Google\Protobuf\Internal\GPBType::MESSAGE, \Google\Protobuf\Internal\UninterpretedOption::class);
$this->uninterpreted_option = $arr;
return $this;
}
}

View File

@@ -0,0 +1,67 @@
<?php
# Generated by the protocol buffer compiler. DO NOT EDIT!
# source: google/protobuf/descriptor.proto
namespace Google\Protobuf\Internal;
use Google\Protobuf\Internal\GPBType;
use Google\Protobuf\Internal\GPBWire;
use Google\Protobuf\Internal\RepeatedField;
use Google\Protobuf\Internal\InputStream;
use Google\Protobuf\Internal\GPBUtil;
/**
* Generated from protobuf message <code>google.protobuf.ExtensionRangeOptions</code>
*/
class ExtensionRangeOptions extends \Google\Protobuf\Internal\Message
{
/**
* The parser stores options it doesn't recognize here. See above.
*
* Generated from protobuf field <code>repeated .google.protobuf.UninterpretedOption uninterpreted_option = 999;</code>
*/
private $uninterpreted_option;
/**
* Constructor.
*
* @param array $data {
* Optional. Data for populating the Message object.
*
* @type array<\Google\Protobuf\Internal\UninterpretedOption>|\Google\Protobuf\Internal\RepeatedField $uninterpreted_option
* The parser stores options it doesn't recognize here. See above.
* }
*/
public function __construct($data = NULL) {
\GPBMetadata\Google\Protobuf\Internal\Descriptor::initOnce();
parent::__construct($data);
}
/**
* The parser stores options it doesn't recognize here. See above.
*
* Generated from protobuf field <code>repeated .google.protobuf.UninterpretedOption uninterpreted_option = 999;</code>
* @return \Google\Protobuf\Internal\RepeatedField
*/
public function getUninterpretedOption()
{
return $this->uninterpreted_option;
}
/**
* The parser stores options it doesn't recognize here. See above.
*
* Generated from protobuf field <code>repeated .google.protobuf.UninterpretedOption uninterpreted_option = 999;</code>
* @param array<\Google\Protobuf\Internal\UninterpretedOption>|\Google\Protobuf\Internal\RepeatedField $var
* @return $this
*/
public function setUninterpretedOption($var)
{
$arr = GPBUtil::checkRepeatedField($var, \Google\Protobuf\Internal\GPBType::MESSAGE, \Google\Protobuf\Internal\UninterpretedOption::class);
$this->uninterpreted_option = $arr;
return $this;
}
}

View File

@@ -0,0 +1,326 @@
<?php
// Protocol Buffers - Google's data interchange format
// Copyright 2008 Google Inc. All rights reserved.
// https://developers.google.com/protocol-buffers/
//
// Redistribution and use in source and binary forms, with or without
// modification, are permitted provided that the following conditions are
// met:
//
// * Redistributions of source code must retain the above copyright
// notice, this list of conditions and the following disclaimer.
// * Redistributions in binary form must reproduce the above
// copyright notice, this list of conditions and the following disclaimer
// in the documentation and/or other materials provided with the
// distribution.
// * Neither the name of Google Inc. nor the names of its
// contributors may be used to endorse or promote products derived from
// this software without specific prior written permission.
//
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
namespace Google\Protobuf\Internal;
class FieldDescriptor
{
use HasPublicDescriptorTrait;
private $name;
private $json_name;
private $setter;
private $getter;
private $number;
private $label;
private $type;
private $message_type;
private $enum_type;
private $packed;
private $oneof_index = -1;
private $proto3_optional;
/** @var OneofDescriptor $containing_oneof */
private $containing_oneof;
public function __construct()
{
$this->public_desc = new \Google\Protobuf\FieldDescriptor($this);
}
public function setOneofIndex($index)
{
$this->oneof_index = $index;
}
public function getOneofIndex()
{
return $this->oneof_index;
}
public function setName($name)
{
$this->name = $name;
}
public function getName()
{
return $this->name;
}
public function setJsonName($json_name)
{
$this->json_name = $json_name;
}
public function getJsonName()
{
return $this->json_name;
}
public function setSetter($setter)
{
$this->setter = $setter;
}
public function getSetter()
{
return $this->setter;
}
public function setGetter($getter)
{
$this->getter = $getter;
}
public function getGetter()
{
return $this->getter;
}
public function setNumber($number)
{
$this->number = $number;
}
public function getNumber()
{
return $this->number;
}
public function setLabel($label)
{
$this->label = $label;
}
public function getLabel()
{
return $this->label;
}
public function isRepeated()
{
return $this->label === GPBLabel::REPEATED;
}
public function setType($type)
{
$this->type = $type;
}
public function getType()
{
return $this->type;
}
public function setMessageType($message_type)
{
$this->message_type = $message_type;
}
public function getMessageType()
{
return $this->message_type;
}
public function setEnumType($enum_type)
{
$this->enum_type = $enum_type;
}
public function getEnumType()
{
return $this->enum_type;
}
public function setPacked($packed)
{
$this->packed = $packed;
}
public function getPacked()
{
return $this->packed;
}
public function getProto3Optional()
{
return $this->proto3_optional;
}
public function setProto3Optional($proto3_optional)
{
$this->proto3_optional = $proto3_optional;
}
public function getContainingOneof()
{
return $this->containing_oneof;
}
public function setContainingOneof($containing_oneof)
{
$this->containing_oneof = $containing_oneof;
}
public function getRealContainingOneof()
{
return !is_null($this->containing_oneof) && !$this->containing_oneof->isSynthetic()
? $this->containing_oneof : null;
}
public function isPackable()
{
return $this->isRepeated() && self::isTypePackable($this->type);
}
public function isMap()
{
return $this->getType() == GPBType::MESSAGE &&
!is_null($this->getMessageType()->getOptions()) &&
$this->getMessageType()->getOptions()->getMapEntry();
}
public function isTimestamp()
{
return $this->getType() == GPBType::MESSAGE &&
$this->getMessageType()->getClass() === "Google\Protobuf\Timestamp";
}
public function isWrapperType()
{
if ($this->getType() == GPBType::MESSAGE) {
$class = $this->getMessageType()->getClass();
return in_array($class, [
"Google\Protobuf\DoubleValue",
"Google\Protobuf\FloatValue",
"Google\Protobuf\Int64Value",
"Google\Protobuf\UInt64Value",
"Google\Protobuf\Int32Value",
"Google\Protobuf\UInt32Value",
"Google\Protobuf\BoolValue",
"Google\Protobuf\StringValue",
"Google\Protobuf\BytesValue",
]);
}
return false;
}
private static function isTypePackable($field_type)
{
return ($field_type !== GPBType::STRING &&
$field_type !== GPBType::GROUP &&
$field_type !== GPBType::MESSAGE &&
$field_type !== GPBType::BYTES);
}
/**
* @param FieldDescriptorProto $proto
* @return FieldDescriptor
*/
public static function getFieldDescriptor($proto)
{
$type_name = null;
$type = $proto->getType();
switch ($type) {
case GPBType::MESSAGE:
case GPBType::GROUP:
case GPBType::ENUM:
$type_name = $proto->getTypeName();
break;
default:
break;
}
$oneof_index = $proto->hasOneofIndex() ? $proto->getOneofIndex() : -1;
// TODO: once proto2 is supported, this default should be false
// for proto2.
if ($proto->getLabel() === GPBLabel::REPEATED &&
$proto->getType() !== GPBType::MESSAGE &&
$proto->getType() !== GPBType::GROUP &&
$proto->getType() !== GPBType::STRING &&
$proto->getType() !== GPBType::BYTES) {
$packed = true;
} else {
$packed = false;
}
$options = $proto->getOptions();
if ($options !== null) {
$packed = $options->getPacked();
}
$field = new FieldDescriptor();
$field->setName($proto->getName());
if ($proto->hasJsonName()) {
$json_name = $proto->getJsonName();
} else {
$proto_name = $proto->getName();
$json_name = implode('', array_map('ucwords', explode('_', $proto_name)));
if ($proto_name[0] !== "_" && !ctype_upper($proto_name[0])) {
$json_name = lcfirst($json_name);
}
}
$field->setJsonName($json_name);
$camel_name = implode('', array_map('ucwords', explode('_', $proto->getName())));
$field->setGetter('get' . $camel_name);
$field->setSetter('set' . $camel_name);
$field->setType($proto->getType());
$field->setNumber($proto->getNumber());
$field->setLabel($proto->getLabel());
$field->setPacked($packed);
$field->setOneofIndex($oneof_index);
$field->setProto3Optional($proto->getProto3Optional());
// At this time, the message/enum type may have not been added to pool.
// So we use the type name as place holder and will replace it with the
// actual descriptor in cross building.
switch ($type) {
case GPBType::MESSAGE:
$field->setMessageType($type_name);
break;
case GPBType::ENUM:
$field->setEnumType($type_name);
break;
default:
break;
}
return $field;
}
public static function buildFromProto($proto)
{
return FieldDescriptor::getFieldDescriptor($proto);
}
}

View File

@@ -0,0 +1,611 @@
<?php
# Generated by the protocol buffer compiler. DO NOT EDIT!
# source: google/protobuf/descriptor.proto
namespace Google\Protobuf\Internal;
use Google\Protobuf\Internal\GPBType;
use Google\Protobuf\Internal\GPBWire;
use Google\Protobuf\Internal\RepeatedField;
use Google\Protobuf\Internal\InputStream;
use Google\Protobuf\Internal\GPBUtil;
/**
* Describes a field within a message.
*
* Generated from protobuf message <code>google.protobuf.FieldDescriptorProto</code>
*/
class FieldDescriptorProto extends \Google\Protobuf\Internal\Message
{
/**
* Generated from protobuf field <code>optional string name = 1;</code>
*/
protected $name = null;
/**
* Generated from protobuf field <code>optional int32 number = 3;</code>
*/
protected $number = null;
/**
* Generated from protobuf field <code>optional .google.protobuf.FieldDescriptorProto.Label label = 4;</code>
*/
protected $label = null;
/**
* If type_name is set, this need not be set. If both this and type_name
* are set, this must be one of TYPE_ENUM, TYPE_MESSAGE or TYPE_GROUP.
*
* Generated from protobuf field <code>optional .google.protobuf.FieldDescriptorProto.Type type = 5;</code>
*/
protected $type = null;
/**
* For message and enum types, this is the name of the type. If the name
* starts with a '.', it is fully-qualified. Otherwise, C++-like scoping
* rules are used to find the type (i.e. first the nested types within this
* message are searched, then within the parent, on up to the root
* namespace).
*
* Generated from protobuf field <code>optional string type_name = 6;</code>
*/
protected $type_name = null;
/**
* For extensions, this is the name of the type being extended. It is
* resolved in the same manner as type_name.
*
* Generated from protobuf field <code>optional string extendee = 2;</code>
*/
protected $extendee = null;
/**
* For numeric types, contains the original text representation of the value.
* For booleans, "true" or "false".
* For strings, contains the default text contents (not escaped in any way).
* For bytes, contains the C escaped value. All bytes >= 128 are escaped.
*
* Generated from protobuf field <code>optional string default_value = 7;</code>
*/
protected $default_value = null;
/**
* If set, gives the index of a oneof in the containing type's oneof_decl
* list. This field is a member of that oneof.
*
* Generated from protobuf field <code>optional int32 oneof_index = 9;</code>
*/
protected $oneof_index = null;
/**
* JSON name of this field. The value is set by protocol compiler. If the
* user has set a "json_name" option on this field, that option's value
* will be used. Otherwise, it's deduced from the field's name by converting
* it to camelCase.
*
* Generated from protobuf field <code>optional string json_name = 10;</code>
*/
protected $json_name = null;
/**
* Generated from protobuf field <code>optional .google.protobuf.FieldOptions options = 8;</code>
*/
protected $options = null;
/**
* If true, this is a proto3 "optional". When a proto3 field is optional, it
* tracks presence regardless of field type.
* When proto3_optional is true, this field must be belong to a oneof to
* signal to old proto3 clients that presence is tracked for this field. This
* oneof is known as a "synthetic" oneof, and this field must be its sole
* member (each proto3 optional field gets its own synthetic oneof). Synthetic
* oneofs exist in the descriptor only, and do not generate any API. Synthetic
* oneofs must be ordered after all "real" oneofs.
* For message fields, proto3_optional doesn't create any semantic change,
* since non-repeated message fields always track presence. However it still
* indicates the semantic detail of whether the user wrote "optional" or not.
* This can be useful for round-tripping the .proto file. For consistency we
* give message fields a synthetic oneof also, even though it is not required
* to track presence. This is especially important because the parser can't
* tell if a field is a message or an enum, so it must always create a
* synthetic oneof.
* Proto2 optional fields do not set this flag, because they already indicate
* optional with `LABEL_OPTIONAL`.
*
* Generated from protobuf field <code>optional bool proto3_optional = 17;</code>
*/
protected $proto3_optional = null;
/**
* Constructor.
*
* @param array $data {
* Optional. Data for populating the Message object.
*
* @type string $name
* @type int $number
* @type int $label
* @type int $type
* If type_name is set, this need not be set. If both this and type_name
* are set, this must be one of TYPE_ENUM, TYPE_MESSAGE or TYPE_GROUP.
* @type string $type_name
* For message and enum types, this is the name of the type. If the name
* starts with a '.', it is fully-qualified. Otherwise, C++-like scoping
* rules are used to find the type (i.e. first the nested types within this
* message are searched, then within the parent, on up to the root
* namespace).
* @type string $extendee
* For extensions, this is the name of the type being extended. It is
* resolved in the same manner as type_name.
* @type string $default_value
* For numeric types, contains the original text representation of the value.
* For booleans, "true" or "false".
* For strings, contains the default text contents (not escaped in any way).
* For bytes, contains the C escaped value. All bytes >= 128 are escaped.
* @type int $oneof_index
* If set, gives the index of a oneof in the containing type's oneof_decl
* list. This field is a member of that oneof.
* @type string $json_name
* JSON name of this field. The value is set by protocol compiler. If the
* user has set a "json_name" option on this field, that option's value
* will be used. Otherwise, it's deduced from the field's name by converting
* it to camelCase.
* @type \Google\Protobuf\Internal\FieldOptions $options
* @type bool $proto3_optional
* If true, this is a proto3 "optional". When a proto3 field is optional, it
* tracks presence regardless of field type.
* When proto3_optional is true, this field must be belong to a oneof to
* signal to old proto3 clients that presence is tracked for this field. This
* oneof is known as a "synthetic" oneof, and this field must be its sole
* member (each proto3 optional field gets its own synthetic oneof). Synthetic
* oneofs exist in the descriptor only, and do not generate any API. Synthetic
* oneofs must be ordered after all "real" oneofs.
* For message fields, proto3_optional doesn't create any semantic change,
* since non-repeated message fields always track presence. However it still
* indicates the semantic detail of whether the user wrote "optional" or not.
* This can be useful for round-tripping the .proto file. For consistency we
* give message fields a synthetic oneof also, even though it is not required
* to track presence. This is especially important because the parser can't
* tell if a field is a message or an enum, so it must always create a
* synthetic oneof.
* Proto2 optional fields do not set this flag, because they already indicate
* optional with `LABEL_OPTIONAL`.
* }
*/
public function __construct($data = NULL) {
\GPBMetadata\Google\Protobuf\Internal\Descriptor::initOnce();
parent::__construct($data);
}
/**
* Generated from protobuf field <code>optional string name = 1;</code>
* @return string
*/
public function getName()
{
return isset($this->name) ? $this->name : '';
}
public function hasName()
{
return isset($this->name);
}
public function clearName()
{
unset($this->name);
}
/**
* Generated from protobuf field <code>optional string name = 1;</code>
* @param string $var
* @return $this
*/
public function setName($var)
{
GPBUtil::checkString($var, True);
$this->name = $var;
return $this;
}
/**
* Generated from protobuf field <code>optional int32 number = 3;</code>
* @return int
*/
public function getNumber()
{
return isset($this->number) ? $this->number : 0;
}
public function hasNumber()
{
return isset($this->number);
}
public function clearNumber()
{
unset($this->number);
}
/**
* Generated from protobuf field <code>optional int32 number = 3;</code>
* @param int $var
* @return $this
*/
public function setNumber($var)
{
GPBUtil::checkInt32($var);
$this->number = $var;
return $this;
}
/**
* Generated from protobuf field <code>optional .google.protobuf.FieldDescriptorProto.Label label = 4;</code>
* @return int
*/
public function getLabel()
{
return isset($this->label) ? $this->label : 0;
}
public function hasLabel()
{
return isset($this->label);
}
public function clearLabel()
{
unset($this->label);
}
/**
* Generated from protobuf field <code>optional .google.protobuf.FieldDescriptorProto.Label label = 4;</code>
* @param int $var
* @return $this
*/
public function setLabel($var)
{
GPBUtil::checkEnum($var, \Google\Protobuf\Internal\FieldDescriptorProto\Label::class);
$this->label = $var;
return $this;
}
/**
* If type_name is set, this need not be set. If both this and type_name
* are set, this must be one of TYPE_ENUM, TYPE_MESSAGE or TYPE_GROUP.
*
* Generated from protobuf field <code>optional .google.protobuf.FieldDescriptorProto.Type type = 5;</code>
* @return int
*/
public function getType()
{
return isset($this->type) ? $this->type : 0;
}
public function hasType()
{
return isset($this->type);
}
public function clearType()
{
unset($this->type);
}
/**
* If type_name is set, this need not be set. If both this and type_name
* are set, this must be one of TYPE_ENUM, TYPE_MESSAGE or TYPE_GROUP.
*
* Generated from protobuf field <code>optional .google.protobuf.FieldDescriptorProto.Type type = 5;</code>
* @param int $var
* @return $this
*/
public function setType($var)
{
GPBUtil::checkEnum($var, \Google\Protobuf\Internal\FieldDescriptorProto\Type::class);
$this->type = $var;
return $this;
}
/**
* For message and enum types, this is the name of the type. If the name
* starts with a '.', it is fully-qualified. Otherwise, C++-like scoping
* rules are used to find the type (i.e. first the nested types within this
* message are searched, then within the parent, on up to the root
* namespace).
*
* Generated from protobuf field <code>optional string type_name = 6;</code>
* @return string
*/
public function getTypeName()
{
return isset($this->type_name) ? $this->type_name : '';
}
public function hasTypeName()
{
return isset($this->type_name);
}
public function clearTypeName()
{
unset($this->type_name);
}
/**
* For message and enum types, this is the name of the type. If the name
* starts with a '.', it is fully-qualified. Otherwise, C++-like scoping
* rules are used to find the type (i.e. first the nested types within this
* message are searched, then within the parent, on up to the root
* namespace).
*
* Generated from protobuf field <code>optional string type_name = 6;</code>
* @param string $var
* @return $this
*/
public function setTypeName($var)
{
GPBUtil::checkString($var, True);
$this->type_name = $var;
return $this;
}
/**
* For extensions, this is the name of the type being extended. It is
* resolved in the same manner as type_name.
*
* Generated from protobuf field <code>optional string extendee = 2;</code>
* @return string
*/
public function getExtendee()
{
return isset($this->extendee) ? $this->extendee : '';
}
public function hasExtendee()
{
return isset($this->extendee);
}
public function clearExtendee()
{
unset($this->extendee);
}
/**
* For extensions, this is the name of the type being extended. It is
* resolved in the same manner as type_name.
*
* Generated from protobuf field <code>optional string extendee = 2;</code>
* @param string $var
* @return $this
*/
public function setExtendee($var)
{
GPBUtil::checkString($var, True);
$this->extendee = $var;
return $this;
}
/**
* For numeric types, contains the original text representation of the value.
* For booleans, "true" or "false".
* For strings, contains the default text contents (not escaped in any way).
* For bytes, contains the C escaped value. All bytes >= 128 are escaped.
*
* Generated from protobuf field <code>optional string default_value = 7;</code>
* @return string
*/
public function getDefaultValue()
{
return isset($this->default_value) ? $this->default_value : '';
}
public function hasDefaultValue()
{
return isset($this->default_value);
}
public function clearDefaultValue()
{
unset($this->default_value);
}
/**
* For numeric types, contains the original text representation of the value.
* For booleans, "true" or "false".
* For strings, contains the default text contents (not escaped in any way).
* For bytes, contains the C escaped value. All bytes >= 128 are escaped.
*
* Generated from protobuf field <code>optional string default_value = 7;</code>
* @param string $var
* @return $this
*/
public function setDefaultValue($var)
{
GPBUtil::checkString($var, True);
$this->default_value = $var;
return $this;
}
/**
* If set, gives the index of a oneof in the containing type's oneof_decl
* list. This field is a member of that oneof.
*
* Generated from protobuf field <code>optional int32 oneof_index = 9;</code>
* @return int
*/
public function getOneofIndex()
{
return isset($this->oneof_index) ? $this->oneof_index : 0;
}
public function hasOneofIndex()
{
return isset($this->oneof_index);
}
public function clearOneofIndex()
{
unset($this->oneof_index);
}
/**
* If set, gives the index of a oneof in the containing type's oneof_decl
* list. This field is a member of that oneof.
*
* Generated from protobuf field <code>optional int32 oneof_index = 9;</code>
* @param int $var
* @return $this
*/
public function setOneofIndex($var)
{
GPBUtil::checkInt32($var);
$this->oneof_index = $var;
return $this;
}
/**
* JSON name of this field. The value is set by protocol compiler. If the
* user has set a "json_name" option on this field, that option's value
* will be used. Otherwise, it's deduced from the field's name by converting
* it to camelCase.
*
* Generated from protobuf field <code>optional string json_name = 10;</code>
* @return string
*/
public function getJsonName()
{
return isset($this->json_name) ? $this->json_name : '';
}
public function hasJsonName()
{
return isset($this->json_name);
}
public function clearJsonName()
{
unset($this->json_name);
}
/**
* JSON name of this field. The value is set by protocol compiler. If the
* user has set a "json_name" option on this field, that option's value
* will be used. Otherwise, it's deduced from the field's name by converting
* it to camelCase.
*
* Generated from protobuf field <code>optional string json_name = 10;</code>
* @param string $var
* @return $this
*/
public function setJsonName($var)
{
GPBUtil::checkString($var, True);
$this->json_name = $var;
return $this;
}
/**
* Generated from protobuf field <code>optional .google.protobuf.FieldOptions options = 8;</code>
* @return \Google\Protobuf\Internal\FieldOptions|null
*/
public function getOptions()
{
return $this->options;
}
public function hasOptions()
{
return isset($this->options);
}
public function clearOptions()
{
unset($this->options);
}
/**
* Generated from protobuf field <code>optional .google.protobuf.FieldOptions options = 8;</code>
* @param \Google\Protobuf\Internal\FieldOptions $var
* @return $this
*/
public function setOptions($var)
{
GPBUtil::checkMessage($var, \Google\Protobuf\Internal\FieldOptions::class);
$this->options = $var;
return $this;
}
/**
* If true, this is a proto3 "optional". When a proto3 field is optional, it
* tracks presence regardless of field type.
* When proto3_optional is true, this field must be belong to a oneof to
* signal to old proto3 clients that presence is tracked for this field. This
* oneof is known as a "synthetic" oneof, and this field must be its sole
* member (each proto3 optional field gets its own synthetic oneof). Synthetic
* oneofs exist in the descriptor only, and do not generate any API. Synthetic
* oneofs must be ordered after all "real" oneofs.
* For message fields, proto3_optional doesn't create any semantic change,
* since non-repeated message fields always track presence. However it still
* indicates the semantic detail of whether the user wrote "optional" or not.
* This can be useful for round-tripping the .proto file. For consistency we
* give message fields a synthetic oneof also, even though it is not required
* to track presence. This is especially important because the parser can't
* tell if a field is a message or an enum, so it must always create a
* synthetic oneof.
* Proto2 optional fields do not set this flag, because they already indicate
* optional with `LABEL_OPTIONAL`.
*
* Generated from protobuf field <code>optional bool proto3_optional = 17;</code>
* @return bool
*/
public function getProto3Optional()
{
return isset($this->proto3_optional) ? $this->proto3_optional : false;
}
public function hasProto3Optional()
{
return isset($this->proto3_optional);
}
public function clearProto3Optional()
{
unset($this->proto3_optional);
}
/**
* If true, this is a proto3 "optional". When a proto3 field is optional, it
* tracks presence regardless of field type.
* When proto3_optional is true, this field must be belong to a oneof to
* signal to old proto3 clients that presence is tracked for this field. This
* oneof is known as a "synthetic" oneof, and this field must be its sole
* member (each proto3 optional field gets its own synthetic oneof). Synthetic
* oneofs exist in the descriptor only, and do not generate any API. Synthetic
* oneofs must be ordered after all "real" oneofs.
* For message fields, proto3_optional doesn't create any semantic change,
* since non-repeated message fields always track presence. However it still
* indicates the semantic detail of whether the user wrote "optional" or not.
* This can be useful for round-tripping the .proto file. For consistency we
* give message fields a synthetic oneof also, even though it is not required
* to track presence. This is especially important because the parser can't
* tell if a field is a message or an enum, so it must always create a
* synthetic oneof.
* Proto2 optional fields do not set this flag, because they already indicate
* optional with `LABEL_OPTIONAL`.
*
* Generated from protobuf field <code>optional bool proto3_optional = 17;</code>
* @param bool $var
* @return $this
*/
public function setProto3Optional($var)
{
GPBUtil::checkBool($var);
$this->proto3_optional = $var;
return $this;
}
}

View File

@@ -0,0 +1,58 @@
<?php
# Generated by the protocol buffer compiler. DO NOT EDIT!
# source: google/protobuf/descriptor.proto
namespace Google\Protobuf\Internal\FieldDescriptorProto;
use UnexpectedValueException;
/**
* Protobuf type <code>google.protobuf.FieldDescriptorProto.Label</code>
*/
class Label
{
/**
* 0 is reserved for errors
*
* Generated from protobuf enum <code>LABEL_OPTIONAL = 1;</code>
*/
const LABEL_OPTIONAL = 1;
/**
* Generated from protobuf enum <code>LABEL_REQUIRED = 2;</code>
*/
const LABEL_REQUIRED = 2;
/**
* Generated from protobuf enum <code>LABEL_REPEATED = 3;</code>
*/
const LABEL_REPEATED = 3;
private static $valueToName = [
self::LABEL_OPTIONAL => 'LABEL_OPTIONAL',
self::LABEL_REQUIRED => 'LABEL_REQUIRED',
self::LABEL_REPEATED => 'LABEL_REPEATED',
];
public static function name($value)
{
if (!isset(self::$valueToName[$value])) {
throw new UnexpectedValueException(sprintf(
'Enum %s has no name defined for value %s', __CLASS__, $value));
}
return self::$valueToName[$value];
}
public static function value($name)
{
$const = __CLASS__ . '::' . strtoupper($name);
if (!defined($const)) {
throw new UnexpectedValueException(sprintf(
'Enum %s has no value defined for name %s', __CLASS__, $name));
}
return constant($const);
}
}
// Adding a class alias for backwards compatibility with the previous class name.
class_alias(Label::class, \Google\Protobuf\Internal\FieldDescriptorProto_Label::class);

View File

@@ -0,0 +1,153 @@
<?php
# Generated by the protocol buffer compiler. DO NOT EDIT!
# source: google/protobuf/descriptor.proto
namespace Google\Protobuf\Internal\FieldDescriptorProto;
use UnexpectedValueException;
/**
* Protobuf type <code>google.protobuf.FieldDescriptorProto.Type</code>
*/
class Type
{
/**
* 0 is reserved for errors.
* Order is weird for historical reasons.
*
* Generated from protobuf enum <code>TYPE_DOUBLE = 1;</code>
*/
const TYPE_DOUBLE = 1;
/**
* Generated from protobuf enum <code>TYPE_FLOAT = 2;</code>
*/
const TYPE_FLOAT = 2;
/**
* Not ZigZag encoded. Negative numbers take 10 bytes. Use TYPE_SINT64 if
* negative values are likely.
*
* Generated from protobuf enum <code>TYPE_INT64 = 3;</code>
*/
const TYPE_INT64 = 3;
/**
* Generated from protobuf enum <code>TYPE_UINT64 = 4;</code>
*/
const TYPE_UINT64 = 4;
/**
* Not ZigZag encoded. Negative numbers take 10 bytes. Use TYPE_SINT32 if
* negative values are likely.
*
* Generated from protobuf enum <code>TYPE_INT32 = 5;</code>
*/
const TYPE_INT32 = 5;
/**
* Generated from protobuf enum <code>TYPE_FIXED64 = 6;</code>
*/
const TYPE_FIXED64 = 6;
/**
* Generated from protobuf enum <code>TYPE_FIXED32 = 7;</code>
*/
const TYPE_FIXED32 = 7;
/**
* Generated from protobuf enum <code>TYPE_BOOL = 8;</code>
*/
const TYPE_BOOL = 8;
/**
* Generated from protobuf enum <code>TYPE_STRING = 9;</code>
*/
const TYPE_STRING = 9;
/**
* Tag-delimited aggregate.
* Group type is deprecated and not supported in proto3. However, Proto3
* implementations should still be able to parse the group wire format and
* treat group fields as unknown fields.
*
* Generated from protobuf enum <code>TYPE_GROUP = 10;</code>
*/
const TYPE_GROUP = 10;
/**
* Length-delimited aggregate.
*
* Generated from protobuf enum <code>TYPE_MESSAGE = 11;</code>
*/
const TYPE_MESSAGE = 11;
/**
* New in version 2.
*
* Generated from protobuf enum <code>TYPE_BYTES = 12;</code>
*/
const TYPE_BYTES = 12;
/**
* Generated from protobuf enum <code>TYPE_UINT32 = 13;</code>
*/
const TYPE_UINT32 = 13;
/**
* Generated from protobuf enum <code>TYPE_ENUM = 14;</code>
*/
const TYPE_ENUM = 14;
/**
* Generated from protobuf enum <code>TYPE_SFIXED32 = 15;</code>
*/
const TYPE_SFIXED32 = 15;
/**
* Generated from protobuf enum <code>TYPE_SFIXED64 = 16;</code>
*/
const TYPE_SFIXED64 = 16;
/**
* Uses ZigZag encoding.
*
* Generated from protobuf enum <code>TYPE_SINT32 = 17;</code>
*/
const TYPE_SINT32 = 17;
/**
* Uses ZigZag encoding.
*
* Generated from protobuf enum <code>TYPE_SINT64 = 18;</code>
*/
const TYPE_SINT64 = 18;
private static $valueToName = [
self::TYPE_DOUBLE => 'TYPE_DOUBLE',
self::TYPE_FLOAT => 'TYPE_FLOAT',
self::TYPE_INT64 => 'TYPE_INT64',
self::TYPE_UINT64 => 'TYPE_UINT64',
self::TYPE_INT32 => 'TYPE_INT32',
self::TYPE_FIXED64 => 'TYPE_FIXED64',
self::TYPE_FIXED32 => 'TYPE_FIXED32',
self::TYPE_BOOL => 'TYPE_BOOL',
self::TYPE_STRING => 'TYPE_STRING',
self::TYPE_GROUP => 'TYPE_GROUP',
self::TYPE_MESSAGE => 'TYPE_MESSAGE',
self::TYPE_BYTES => 'TYPE_BYTES',
self::TYPE_UINT32 => 'TYPE_UINT32',
self::TYPE_ENUM => 'TYPE_ENUM',
self::TYPE_SFIXED32 => 'TYPE_SFIXED32',
self::TYPE_SFIXED64 => 'TYPE_SFIXED64',
self::TYPE_SINT32 => 'TYPE_SINT32',
self::TYPE_SINT64 => 'TYPE_SINT64',
];
public static function name($value)
{
if (!isset(self::$valueToName[$value])) {
throw new UnexpectedValueException(sprintf(
'Enum %s has no name defined for value %s', __CLASS__, $value));
}
return self::$valueToName[$value];
}
public static function value($name)
{
$const = __CLASS__ . '::' . strtoupper($name);
if (!defined($const)) {
throw new UnexpectedValueException(sprintf(
'Enum %s has no value defined for name %s', __CLASS__, $name));
}
return constant($const);
}
}
// Adding a class alias for backwards compatibility with the previous class name.
class_alias(Type::class, \Google\Protobuf\Internal\FieldDescriptorProto_Type::class);

View File

@@ -0,0 +1,16 @@
<?php
# Generated by the protocol buffer compiler. DO NOT EDIT!
# source: google/protobuf/descriptor.proto
namespace Google\Protobuf\Internal;
if (false) {
/**
* This class is deprecated. Use Google\Protobuf\Internal\FieldDescriptorProto\Label instead.
* @deprecated
*/
class FieldDescriptorProto_Label {}
}
class_exists(FieldDescriptorProto\Label::class);
@trigger_error('Google\Protobuf\Internal\FieldDescriptorProto_Label is deprecated and will be removed in the next major release. Use Google\Protobuf\Internal\FieldDescriptorProto\Label instead', E_USER_DEPRECATED);

View File

@@ -0,0 +1,16 @@
<?php
# Generated by the protocol buffer compiler. DO NOT EDIT!
# source: google/protobuf/descriptor.proto
namespace Google\Protobuf\Internal;
if (false) {
/**
* This class is deprecated. Use Google\Protobuf\Internal\FieldDescriptorProto\Type instead.
* @deprecated
*/
class FieldDescriptorProto_Type {}
}
class_exists(FieldDescriptorProto\Type::class);
@trigger_error('Google\Protobuf\Internal\FieldDescriptorProto_Type is deprecated and will be removed in the next major release. Use Google\Protobuf\Internal\FieldDescriptorProto\Type instead', E_USER_DEPRECATED);

View File

@@ -0,0 +1,559 @@
<?php
# Generated by the protocol buffer compiler. DO NOT EDIT!
# source: google/protobuf/descriptor.proto
namespace Google\Protobuf\Internal;
use Google\Protobuf\Internal\GPBType;
use Google\Protobuf\Internal\GPBWire;
use Google\Protobuf\Internal\RepeatedField;
use Google\Protobuf\Internal\InputStream;
use Google\Protobuf\Internal\GPBUtil;
/**
* Generated from protobuf message <code>google.protobuf.FieldOptions</code>
*/
class FieldOptions extends \Google\Protobuf\Internal\Message
{
/**
* The ctype option instructs the C++ code generator to use a different
* representation of the field than it normally would. See the specific
* options below. This option is not yet implemented in the open source
* release -- sorry, we'll try to include it in a future version!
*
* Generated from protobuf field <code>optional .google.protobuf.FieldOptions.CType ctype = 1 [default = STRING];</code>
*/
protected $ctype = null;
/**
* The packed option can be enabled for repeated primitive fields to enable
* a more efficient representation on the wire. Rather than repeatedly
* writing the tag and type for each element, the entire array is encoded as
* a single length-delimited blob. In proto3, only explicit setting it to
* false will avoid using packed encoding.
*
* Generated from protobuf field <code>optional bool packed = 2;</code>
*/
protected $packed = null;
/**
* The jstype option determines the JavaScript type used for values of the
* field. The option is permitted only for 64 bit integral and fixed types
* (int64, uint64, sint64, fixed64, sfixed64). A field with jstype JS_STRING
* is represented as JavaScript string, which avoids loss of precision that
* can happen when a large value is converted to a floating point JavaScript.
* Specifying JS_NUMBER for the jstype causes the generated JavaScript code to
* use the JavaScript "number" type. The behavior of the default option
* JS_NORMAL is implementation dependent.
* This option is an enum to permit additional types to be added, e.g.
* goog.math.Integer.
*
* Generated from protobuf field <code>optional .google.protobuf.FieldOptions.JSType jstype = 6 [default = JS_NORMAL];</code>
*/
protected $jstype = null;
/**
* Should this field be parsed lazily? Lazy applies only to message-type
* fields. It means that when the outer message is initially parsed, the
* inner message's contents will not be parsed but instead stored in encoded
* form. The inner message will actually be parsed when it is first accessed.
* This is only a hint. Implementations are free to choose whether to use
* eager or lazy parsing regardless of the value of this option. However,
* setting this option true suggests that the protocol author believes that
* using lazy parsing on this field is worth the additional bookkeeping
* overhead typically needed to implement it.
* This option does not affect the public interface of any generated code;
* all method signatures remain the same. Furthermore, thread-safety of the
* interface is not affected by this option; const methods remain safe to
* call from multiple threads concurrently, while non-const methods continue
* to require exclusive access.
* Note that implementations may choose not to check required fields within
* a lazy sub-message. That is, calling IsInitialized() on the outer message
* may return true even if the inner message has missing required fields.
* This is necessary because otherwise the inner message would have to be
* parsed in order to perform the check, defeating the purpose of lazy
* parsing. An implementation which chooses not to check required fields
* must be consistent about it. That is, for any particular sub-message, the
* implementation must either *always* check its required fields, or *never*
* check its required fields, regardless of whether or not the message has
* been parsed.
* As of May 2022, lazy verifies the contents of the byte stream during
* parsing. An invalid byte stream will cause the overall parsing to fail.
*
* Generated from protobuf field <code>optional bool lazy = 5 [default = false];</code>
*/
protected $lazy = null;
/**
* unverified_lazy does no correctness checks on the byte stream. This should
* only be used where lazy with verification is prohibitive for performance
* reasons.
*
* Generated from protobuf field <code>optional bool unverified_lazy = 15 [default = false];</code>
*/
protected $unverified_lazy = null;
/**
* Is this field deprecated?
* Depending on the target platform, this can emit Deprecated annotations
* for accessors, or it will be completely ignored; in the very least, this
* is a formalization for deprecating fields.
*
* Generated from protobuf field <code>optional bool deprecated = 3 [default = false];</code>
*/
protected $deprecated = null;
/**
* For Google-internal migration only. Do not use.
*
* Generated from protobuf field <code>optional bool weak = 10 [default = false];</code>
*/
protected $weak = null;
/**
* The parser stores options it doesn't recognize here. See above.
*
* Generated from protobuf field <code>repeated .google.protobuf.UninterpretedOption uninterpreted_option = 999;</code>
*/
private $uninterpreted_option;
/**
* Constructor.
*
* @param array $data {
* Optional. Data for populating the Message object.
*
* @type int $ctype
* The ctype option instructs the C++ code generator to use a different
* representation of the field than it normally would. See the specific
* options below. This option is not yet implemented in the open source
* release -- sorry, we'll try to include it in a future version!
* @type bool $packed
* The packed option can be enabled for repeated primitive fields to enable
* a more efficient representation on the wire. Rather than repeatedly
* writing the tag and type for each element, the entire array is encoded as
* a single length-delimited blob. In proto3, only explicit setting it to
* false will avoid using packed encoding.
* @type int $jstype
* The jstype option determines the JavaScript type used for values of the
* field. The option is permitted only for 64 bit integral and fixed types
* (int64, uint64, sint64, fixed64, sfixed64). A field with jstype JS_STRING
* is represented as JavaScript string, which avoids loss of precision that
* can happen when a large value is converted to a floating point JavaScript.
* Specifying JS_NUMBER for the jstype causes the generated JavaScript code to
* use the JavaScript "number" type. The behavior of the default option
* JS_NORMAL is implementation dependent.
* This option is an enum to permit additional types to be added, e.g.
* goog.math.Integer.
* @type bool $lazy
* Should this field be parsed lazily? Lazy applies only to message-type
* fields. It means that when the outer message is initially parsed, the
* inner message's contents will not be parsed but instead stored in encoded
* form. The inner message will actually be parsed when it is first accessed.
* This is only a hint. Implementations are free to choose whether to use
* eager or lazy parsing regardless of the value of this option. However,
* setting this option true suggests that the protocol author believes that
* using lazy parsing on this field is worth the additional bookkeeping
* overhead typically needed to implement it.
* This option does not affect the public interface of any generated code;
* all method signatures remain the same. Furthermore, thread-safety of the
* interface is not affected by this option; const methods remain safe to
* call from multiple threads concurrently, while non-const methods continue
* to require exclusive access.
* Note that implementations may choose not to check required fields within
* a lazy sub-message. That is, calling IsInitialized() on the outer message
* may return true even if the inner message has missing required fields.
* This is necessary because otherwise the inner message would have to be
* parsed in order to perform the check, defeating the purpose of lazy
* parsing. An implementation which chooses not to check required fields
* must be consistent about it. That is, for any particular sub-message, the
* implementation must either *always* check its required fields, or *never*
* check its required fields, regardless of whether or not the message has
* been parsed.
* As of May 2022, lazy verifies the contents of the byte stream during
* parsing. An invalid byte stream will cause the overall parsing to fail.
* @type bool $unverified_lazy
* unverified_lazy does no correctness checks on the byte stream. This should
* only be used where lazy with verification is prohibitive for performance
* reasons.
* @type bool $deprecated
* Is this field deprecated?
* Depending on the target platform, this can emit Deprecated annotations
* for accessors, or it will be completely ignored; in the very least, this
* is a formalization for deprecating fields.
* @type bool $weak
* For Google-internal migration only. Do not use.
* @type array<\Google\Protobuf\Internal\UninterpretedOption>|\Google\Protobuf\Internal\RepeatedField $uninterpreted_option
* The parser stores options it doesn't recognize here. See above.
* }
*/
public function __construct($data = NULL) {
\GPBMetadata\Google\Protobuf\Internal\Descriptor::initOnce();
parent::__construct($data);
}
/**
* The ctype option instructs the C++ code generator to use a different
* representation of the field than it normally would. See the specific
* options below. This option is not yet implemented in the open source
* release -- sorry, we'll try to include it in a future version!
*
* Generated from protobuf field <code>optional .google.protobuf.FieldOptions.CType ctype = 1 [default = STRING];</code>
* @return int
*/
public function getCtype()
{
return isset($this->ctype) ? $this->ctype : 0;
}
public function hasCtype()
{
return isset($this->ctype);
}
public function clearCtype()
{
unset($this->ctype);
}
/**
* The ctype option instructs the C++ code generator to use a different
* representation of the field than it normally would. See the specific
* options below. This option is not yet implemented in the open source
* release -- sorry, we'll try to include it in a future version!
*
* Generated from protobuf field <code>optional .google.protobuf.FieldOptions.CType ctype = 1 [default = STRING];</code>
* @param int $var
* @return $this
*/
public function setCtype($var)
{
GPBUtil::checkEnum($var, \Google\Protobuf\Internal\FieldOptions\CType::class);
$this->ctype = $var;
return $this;
}
/**
* The packed option can be enabled for repeated primitive fields to enable
* a more efficient representation on the wire. Rather than repeatedly
* writing the tag and type for each element, the entire array is encoded as
* a single length-delimited blob. In proto3, only explicit setting it to
* false will avoid using packed encoding.
*
* Generated from protobuf field <code>optional bool packed = 2;</code>
* @return bool
*/
public function getPacked()
{
return isset($this->packed) ? $this->packed : false;
}
public function hasPacked()
{
return isset($this->packed);
}
public function clearPacked()
{
unset($this->packed);
}
/**
* The packed option can be enabled for repeated primitive fields to enable
* a more efficient representation on the wire. Rather than repeatedly
* writing the tag and type for each element, the entire array is encoded as
* a single length-delimited blob. In proto3, only explicit setting it to
* false will avoid using packed encoding.
*
* Generated from protobuf field <code>optional bool packed = 2;</code>
* @param bool $var
* @return $this
*/
public function setPacked($var)
{
GPBUtil::checkBool($var);
$this->packed = $var;
return $this;
}
/**
* The jstype option determines the JavaScript type used for values of the
* field. The option is permitted only for 64 bit integral and fixed types
* (int64, uint64, sint64, fixed64, sfixed64). A field with jstype JS_STRING
* is represented as JavaScript string, which avoids loss of precision that
* can happen when a large value is converted to a floating point JavaScript.
* Specifying JS_NUMBER for the jstype causes the generated JavaScript code to
* use the JavaScript "number" type. The behavior of the default option
* JS_NORMAL is implementation dependent.
* This option is an enum to permit additional types to be added, e.g.
* goog.math.Integer.
*
* Generated from protobuf field <code>optional .google.protobuf.FieldOptions.JSType jstype = 6 [default = JS_NORMAL];</code>
* @return int
*/
public function getJstype()
{
return isset($this->jstype) ? $this->jstype : 0;
}
public function hasJstype()
{
return isset($this->jstype);
}
public function clearJstype()
{
unset($this->jstype);
}
/**
* The jstype option determines the JavaScript type used for values of the
* field. The option is permitted only for 64 bit integral and fixed types
* (int64, uint64, sint64, fixed64, sfixed64). A field with jstype JS_STRING
* is represented as JavaScript string, which avoids loss of precision that
* can happen when a large value is converted to a floating point JavaScript.
* Specifying JS_NUMBER for the jstype causes the generated JavaScript code to
* use the JavaScript "number" type. The behavior of the default option
* JS_NORMAL is implementation dependent.
* This option is an enum to permit additional types to be added, e.g.
* goog.math.Integer.
*
* Generated from protobuf field <code>optional .google.protobuf.FieldOptions.JSType jstype = 6 [default = JS_NORMAL];</code>
* @param int $var
* @return $this
*/
public function setJstype($var)
{
GPBUtil::checkEnum($var, \Google\Protobuf\Internal\FieldOptions\JSType::class);
$this->jstype = $var;
return $this;
}
/**
* Should this field be parsed lazily? Lazy applies only to message-type
* fields. It means that when the outer message is initially parsed, the
* inner message's contents will not be parsed but instead stored in encoded
* form. The inner message will actually be parsed when it is first accessed.
* This is only a hint. Implementations are free to choose whether to use
* eager or lazy parsing regardless of the value of this option. However,
* setting this option true suggests that the protocol author believes that
* using lazy parsing on this field is worth the additional bookkeeping
* overhead typically needed to implement it.
* This option does not affect the public interface of any generated code;
* all method signatures remain the same. Furthermore, thread-safety of the
* interface is not affected by this option; const methods remain safe to
* call from multiple threads concurrently, while non-const methods continue
* to require exclusive access.
* Note that implementations may choose not to check required fields within
* a lazy sub-message. That is, calling IsInitialized() on the outer message
* may return true even if the inner message has missing required fields.
* This is necessary because otherwise the inner message would have to be
* parsed in order to perform the check, defeating the purpose of lazy
* parsing. An implementation which chooses not to check required fields
* must be consistent about it. That is, for any particular sub-message, the
* implementation must either *always* check its required fields, or *never*
* check its required fields, regardless of whether or not the message has
* been parsed.
* As of May 2022, lazy verifies the contents of the byte stream during
* parsing. An invalid byte stream will cause the overall parsing to fail.
*
* Generated from protobuf field <code>optional bool lazy = 5 [default = false];</code>
* @return bool
*/
public function getLazy()
{
return isset($this->lazy) ? $this->lazy : false;
}
public function hasLazy()
{
return isset($this->lazy);
}
public function clearLazy()
{
unset($this->lazy);
}
/**
* Should this field be parsed lazily? Lazy applies only to message-type
* fields. It means that when the outer message is initially parsed, the
* inner message's contents will not be parsed but instead stored in encoded
* form. The inner message will actually be parsed when it is first accessed.
* This is only a hint. Implementations are free to choose whether to use
* eager or lazy parsing regardless of the value of this option. However,
* setting this option true suggests that the protocol author believes that
* using lazy parsing on this field is worth the additional bookkeeping
* overhead typically needed to implement it.
* This option does not affect the public interface of any generated code;
* all method signatures remain the same. Furthermore, thread-safety of the
* interface is not affected by this option; const methods remain safe to
* call from multiple threads concurrently, while non-const methods continue
* to require exclusive access.
* Note that implementations may choose not to check required fields within
* a lazy sub-message. That is, calling IsInitialized() on the outer message
* may return true even if the inner message has missing required fields.
* This is necessary because otherwise the inner message would have to be
* parsed in order to perform the check, defeating the purpose of lazy
* parsing. An implementation which chooses not to check required fields
* must be consistent about it. That is, for any particular sub-message, the
* implementation must either *always* check its required fields, or *never*
* check its required fields, regardless of whether or not the message has
* been parsed.
* As of May 2022, lazy verifies the contents of the byte stream during
* parsing. An invalid byte stream will cause the overall parsing to fail.
*
* Generated from protobuf field <code>optional bool lazy = 5 [default = false];</code>
* @param bool $var
* @return $this
*/
public function setLazy($var)
{
GPBUtil::checkBool($var);
$this->lazy = $var;
return $this;
}
/**
* unverified_lazy does no correctness checks on the byte stream. This should
* only be used where lazy with verification is prohibitive for performance
* reasons.
*
* Generated from protobuf field <code>optional bool unverified_lazy = 15 [default = false];</code>
* @return bool
*/
public function getUnverifiedLazy()
{
return isset($this->unverified_lazy) ? $this->unverified_lazy : false;
}
public function hasUnverifiedLazy()
{
return isset($this->unverified_lazy);
}
public function clearUnverifiedLazy()
{
unset($this->unverified_lazy);
}
/**
* unverified_lazy does no correctness checks on the byte stream. This should
* only be used where lazy with verification is prohibitive for performance
* reasons.
*
* Generated from protobuf field <code>optional bool unverified_lazy = 15 [default = false];</code>
* @param bool $var
* @return $this
*/
public function setUnverifiedLazy($var)
{
GPBUtil::checkBool($var);
$this->unverified_lazy = $var;
return $this;
}
/**
* Is this field deprecated?
* Depending on the target platform, this can emit Deprecated annotations
* for accessors, or it will be completely ignored; in the very least, this
* is a formalization for deprecating fields.
*
* Generated from protobuf field <code>optional bool deprecated = 3 [default = false];</code>
* @return bool
*/
public function getDeprecated()
{
return isset($this->deprecated) ? $this->deprecated : false;
}
public function hasDeprecated()
{
return isset($this->deprecated);
}
public function clearDeprecated()
{
unset($this->deprecated);
}
/**
* Is this field deprecated?
* Depending on the target platform, this can emit Deprecated annotations
* for accessors, or it will be completely ignored; in the very least, this
* is a formalization for deprecating fields.
*
* Generated from protobuf field <code>optional bool deprecated = 3 [default = false];</code>
* @param bool $var
* @return $this
*/
public function setDeprecated($var)
{
GPBUtil::checkBool($var);
$this->deprecated = $var;
return $this;
}
/**
* For Google-internal migration only. Do not use.
*
* Generated from protobuf field <code>optional bool weak = 10 [default = false];</code>
* @return bool
*/
public function getWeak()
{
return isset($this->weak) ? $this->weak : false;
}
public function hasWeak()
{
return isset($this->weak);
}
public function clearWeak()
{
unset($this->weak);
}
/**
* For Google-internal migration only. Do not use.
*
* Generated from protobuf field <code>optional bool weak = 10 [default = false];</code>
* @param bool $var
* @return $this
*/
public function setWeak($var)
{
GPBUtil::checkBool($var);
$this->weak = $var;
return $this;
}
/**
* The parser stores options it doesn't recognize here. See above.
*
* Generated from protobuf field <code>repeated .google.protobuf.UninterpretedOption uninterpreted_option = 999;</code>
* @return \Google\Protobuf\Internal\RepeatedField
*/
public function getUninterpretedOption()
{
return $this->uninterpreted_option;
}
/**
* The parser stores options it doesn't recognize here. See above.
*
* Generated from protobuf field <code>repeated .google.protobuf.UninterpretedOption uninterpreted_option = 999;</code>
* @param array<\Google\Protobuf\Internal\UninterpretedOption>|\Google\Protobuf\Internal\RepeatedField $var
* @return $this
*/
public function setUninterpretedOption($var)
{
$arr = GPBUtil::checkRepeatedField($var, \Google\Protobuf\Internal\GPBType::MESSAGE, \Google\Protobuf\Internal\UninterpretedOption::class);
$this->uninterpreted_option = $arr;
return $this;
}
}

View File

@@ -0,0 +1,58 @@
<?php
# Generated by the protocol buffer compiler. DO NOT EDIT!
# source: google/protobuf/descriptor.proto
namespace Google\Protobuf\Internal\FieldOptions;
use UnexpectedValueException;
/**
* Protobuf type <code>google.protobuf.FieldOptions.CType</code>
*/
class CType
{
/**
* Default mode.
*
* Generated from protobuf enum <code>STRING = 0;</code>
*/
const STRING = 0;
/**
* Generated from protobuf enum <code>CORD = 1;</code>
*/
const CORD = 1;
/**
* Generated from protobuf enum <code>STRING_PIECE = 2;</code>
*/
const STRING_PIECE = 2;
private static $valueToName = [
self::STRING => 'STRING',
self::CORD => 'CORD',
self::STRING_PIECE => 'STRING_PIECE',
];
public static function name($value)
{
if (!isset(self::$valueToName[$value])) {
throw new UnexpectedValueException(sprintf(
'Enum %s has no name defined for value %s', __CLASS__, $value));
}
return self::$valueToName[$value];
}
public static function value($name)
{
$const = __CLASS__ . '::' . strtoupper($name);
if (!defined($const)) {
throw new UnexpectedValueException(sprintf(
'Enum %s has no value defined for name %s', __CLASS__, $name));
}
return constant($const);
}
}
// Adding a class alias for backwards compatibility with the previous class name.
class_alias(CType::class, \Google\Protobuf\Internal\FieldOptions_CType::class);

View File

@@ -0,0 +1,62 @@
<?php
# Generated by the protocol buffer compiler. DO NOT EDIT!
# source: google/protobuf/descriptor.proto
namespace Google\Protobuf\Internal\FieldOptions;
use UnexpectedValueException;
/**
* Protobuf type <code>google.protobuf.FieldOptions.JSType</code>
*/
class JSType
{
/**
* Use the default type.
*
* Generated from protobuf enum <code>JS_NORMAL = 0;</code>
*/
const JS_NORMAL = 0;
/**
* Use JavaScript strings.
*
* Generated from protobuf enum <code>JS_STRING = 1;</code>
*/
const JS_STRING = 1;
/**
* Use JavaScript numbers.
*
* Generated from protobuf enum <code>JS_NUMBER = 2;</code>
*/
const JS_NUMBER = 2;
private static $valueToName = [
self::JS_NORMAL => 'JS_NORMAL',
self::JS_STRING => 'JS_STRING',
self::JS_NUMBER => 'JS_NUMBER',
];
public static function name($value)
{
if (!isset(self::$valueToName[$value])) {
throw new UnexpectedValueException(sprintf(
'Enum %s has no name defined for value %s', __CLASS__, $value));
}
return self::$valueToName[$value];
}
public static function value($name)
{
$const = __CLASS__ . '::' . strtoupper($name);
if (!defined($const)) {
throw new UnexpectedValueException(sprintf(
'Enum %s has no value defined for name %s', __CLASS__, $name));
}
return constant($const);
}
}
// Adding a class alias for backwards compatibility with the previous class name.
class_alias(JSType::class, \Google\Protobuf\Internal\FieldOptions_JSType::class);

View File

@@ -0,0 +1,16 @@
<?php
# Generated by the protocol buffer compiler. DO NOT EDIT!
# source: google/protobuf/descriptor.proto
namespace Google\Protobuf\Internal;
if (false) {
/**
* This class is deprecated. Use Google\Protobuf\Internal\FieldOptions\CType instead.
* @deprecated
*/
class FieldOptions_CType {}
}
class_exists(FieldOptions\CType::class);
@trigger_error('Google\Protobuf\Internal\FieldOptions_CType is deprecated and will be removed in the next major release. Use Google\Protobuf\Internal\FieldOptions\CType instead', E_USER_DEPRECATED);

View File

@@ -0,0 +1,16 @@
<?php
# Generated by the protocol buffer compiler. DO NOT EDIT!
# source: google/protobuf/descriptor.proto
namespace Google\Protobuf\Internal;
if (false) {
/**
* This class is deprecated. Use Google\Protobuf\Internal\FieldOptions\JSType instead.
* @deprecated
*/
class FieldOptions_JSType {}
}
class_exists(FieldOptions\JSType::class);
@trigger_error('Google\Protobuf\Internal\FieldOptions_JSType is deprecated and will be removed in the next major release. Use Google\Protobuf\Internal\FieldOptions\JSType instead', E_USER_DEPRECATED);

View File

@@ -0,0 +1,89 @@
<?php
// Protocol Buffers - Google's data interchange format
// Copyright 2008 Google Inc. All rights reserved.
// https://developers.google.com/protocol-buffers/
//
// Redistribution and use in source and binary forms, with or without
// modification, are permitted provided that the following conditions are
// met:
//
// * Redistributions of source code must retain the above copyright
// notice, this list of conditions and the following disclaimer.
// * Redistributions in binary form must reproduce the above
// copyright notice, this list of conditions and the following disclaimer
// in the documentation and/or other materials provided with the
// distribution.
// * Neither the name of Google Inc. nor the names of its
// contributors may be used to endorse or promote products derived from
// this software without specific prior written permission.
//
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
namespace Google\Protobuf\Internal;
class FileDescriptor
{
private $package;
private $message_type = [];
private $enum_type = [];
public function setPackage($package)
{
$this->package = $package;
}
public function getPackage()
{
return $this->package;
}
public function getMessageType()
{
return $this->message_type;
}
public function addMessageType($desc)
{
$this->message_type[] = $desc;
}
public function getEnumType()
{
return $this->enum_type;
}
public function addEnumType($desc)
{
$this->enum_type[]= $desc;
}
public static function buildFromProto($proto)
{
$file = new FileDescriptor();
$file->setPackage($proto->getPackage());
foreach ($proto->getMessageType() as $message_proto) {
$file->addMessageType(Descriptor::buildFromProto(
$message_proto, $proto, ""));
}
foreach ($proto->getEnumType() as $enum_proto) {
$file->addEnumType(
EnumDescriptor::buildFromProto(
$enum_proto,
$proto,
""));
}
return $file;
}
}

View File

@@ -0,0 +1,533 @@
<?php
# Generated by the protocol buffer compiler. DO NOT EDIT!
# source: google/protobuf/descriptor.proto
namespace Google\Protobuf\Internal;
use Google\Protobuf\Internal\GPBType;
use Google\Protobuf\Internal\GPBWire;
use Google\Protobuf\Internal\RepeatedField;
use Google\Protobuf\Internal\InputStream;
use Google\Protobuf\Internal\GPBUtil;
/**
* Describes a complete .proto file.
*
* Generated from protobuf message <code>google.protobuf.FileDescriptorProto</code>
*/
class FileDescriptorProto extends \Google\Protobuf\Internal\Message
{
/**
* file name, relative to root of source tree
*
* Generated from protobuf field <code>optional string name = 1;</code>
*/
protected $name = null;
/**
* e.g. "foo", "foo.bar", etc.
*
* Generated from protobuf field <code>optional string package = 2;</code>
*/
protected $package = null;
/**
* Names of files imported by this file.
*
* Generated from protobuf field <code>repeated string dependency = 3;</code>
*/
private $dependency;
/**
* Indexes of the public imported files in the dependency list above.
*
* Generated from protobuf field <code>repeated int32 public_dependency = 10;</code>
*/
private $public_dependency;
/**
* Indexes of the weak imported files in the dependency list.
* For Google-internal migration only. Do not use.
*
* Generated from protobuf field <code>repeated int32 weak_dependency = 11;</code>
*/
private $weak_dependency;
/**
* All top-level definitions in this file.
*
* Generated from protobuf field <code>repeated .google.protobuf.DescriptorProto message_type = 4;</code>
*/
private $message_type;
/**
* Generated from protobuf field <code>repeated .google.protobuf.EnumDescriptorProto enum_type = 5;</code>
*/
private $enum_type;
/**
* Generated from protobuf field <code>repeated .google.protobuf.ServiceDescriptorProto service = 6;</code>
*/
private $service;
/**
* Generated from protobuf field <code>repeated .google.protobuf.FieldDescriptorProto extension = 7;</code>
*/
private $extension;
/**
* Generated from protobuf field <code>optional .google.protobuf.FileOptions options = 8;</code>
*/
protected $options = null;
/**
* This field contains optional information about the original source code.
* You may safely remove this entire field without harming runtime
* functionality of the descriptors -- the information is needed only by
* development tools.
*
* Generated from protobuf field <code>optional .google.protobuf.SourceCodeInfo source_code_info = 9;</code>
*/
protected $source_code_info = null;
/**
* The syntax of the proto file.
* The supported values are "proto2", "proto3", and "editions".
* If `edition` is present, this value must be "editions".
*
* Generated from protobuf field <code>optional string syntax = 12;</code>
*/
protected $syntax = null;
/**
* The edition of the proto file, which is an opaque string.
*
* Generated from protobuf field <code>optional string edition = 13;</code>
*/
protected $edition = null;
/**
* Constructor.
*
* @param array $data {
* Optional. Data for populating the Message object.
*
* @type string $name
* file name, relative to root of source tree
* @type string $package
* e.g. "foo", "foo.bar", etc.
* @type array<string>|\Google\Protobuf\Internal\RepeatedField $dependency
* Names of files imported by this file.
* @type array<int>|\Google\Protobuf\Internal\RepeatedField $public_dependency
* Indexes of the public imported files in the dependency list above.
* @type array<int>|\Google\Protobuf\Internal\RepeatedField $weak_dependency
* Indexes of the weak imported files in the dependency list.
* For Google-internal migration only. Do not use.
* @type array<\Google\Protobuf\Internal\DescriptorProto>|\Google\Protobuf\Internal\RepeatedField $message_type
* All top-level definitions in this file.
* @type array<\Google\Protobuf\Internal\EnumDescriptorProto>|\Google\Protobuf\Internal\RepeatedField $enum_type
* @type array<\Google\Protobuf\Internal\ServiceDescriptorProto>|\Google\Protobuf\Internal\RepeatedField $service
* @type array<\Google\Protobuf\Internal\FieldDescriptorProto>|\Google\Protobuf\Internal\RepeatedField $extension
* @type \Google\Protobuf\Internal\FileOptions $options
* @type \Google\Protobuf\Internal\SourceCodeInfo $source_code_info
* This field contains optional information about the original source code.
* You may safely remove this entire field without harming runtime
* functionality of the descriptors -- the information is needed only by
* development tools.
* @type string $syntax
* The syntax of the proto file.
* The supported values are "proto2", "proto3", and "editions".
* If `edition` is present, this value must be "editions".
* @type string $edition
* The edition of the proto file, which is an opaque string.
* }
*/
public function __construct($data = NULL) {
\GPBMetadata\Google\Protobuf\Internal\Descriptor::initOnce();
parent::__construct($data);
}
/**
* file name, relative to root of source tree
*
* Generated from protobuf field <code>optional string name = 1;</code>
* @return string
*/
public function getName()
{
return isset($this->name) ? $this->name : '';
}
public function hasName()
{
return isset($this->name);
}
public function clearName()
{
unset($this->name);
}
/**
* file name, relative to root of source tree
*
* Generated from protobuf field <code>optional string name = 1;</code>
* @param string $var
* @return $this
*/
public function setName($var)
{
GPBUtil::checkString($var, True);
$this->name = $var;
return $this;
}
/**
* e.g. "foo", "foo.bar", etc.
*
* Generated from protobuf field <code>optional string package = 2;</code>
* @return string
*/
public function getPackage()
{
return isset($this->package) ? $this->package : '';
}
public function hasPackage()
{
return isset($this->package);
}
public function clearPackage()
{
unset($this->package);
}
/**
* e.g. "foo", "foo.bar", etc.
*
* Generated from protobuf field <code>optional string package = 2;</code>
* @param string $var
* @return $this
*/
public function setPackage($var)
{
GPBUtil::checkString($var, True);
$this->package = $var;
return $this;
}
/**
* Names of files imported by this file.
*
* Generated from protobuf field <code>repeated string dependency = 3;</code>
* @return \Google\Protobuf\Internal\RepeatedField
*/
public function getDependency()
{
return $this->dependency;
}
/**
* Names of files imported by this file.
*
* Generated from protobuf field <code>repeated string dependency = 3;</code>
* @param array<string>|\Google\Protobuf\Internal\RepeatedField $var
* @return $this
*/
public function setDependency($var)
{
$arr = GPBUtil::checkRepeatedField($var, \Google\Protobuf\Internal\GPBType::STRING);
$this->dependency = $arr;
return $this;
}
/**
* Indexes of the public imported files in the dependency list above.
*
* Generated from protobuf field <code>repeated int32 public_dependency = 10;</code>
* @return \Google\Protobuf\Internal\RepeatedField
*/
public function getPublicDependency()
{
return $this->public_dependency;
}
/**
* Indexes of the public imported files in the dependency list above.
*
* Generated from protobuf field <code>repeated int32 public_dependency = 10;</code>
* @param array<int>|\Google\Protobuf\Internal\RepeatedField $var
* @return $this
*/
public function setPublicDependency($var)
{
$arr = GPBUtil::checkRepeatedField($var, \Google\Protobuf\Internal\GPBType::INT32);
$this->public_dependency = $arr;
return $this;
}
/**
* Indexes of the weak imported files in the dependency list.
* For Google-internal migration only. Do not use.
*
* Generated from protobuf field <code>repeated int32 weak_dependency = 11;</code>
* @return \Google\Protobuf\Internal\RepeatedField
*/
public function getWeakDependency()
{
return $this->weak_dependency;
}
/**
* Indexes of the weak imported files in the dependency list.
* For Google-internal migration only. Do not use.
*
* Generated from protobuf field <code>repeated int32 weak_dependency = 11;</code>
* @param array<int>|\Google\Protobuf\Internal\RepeatedField $var
* @return $this
*/
public function setWeakDependency($var)
{
$arr = GPBUtil::checkRepeatedField($var, \Google\Protobuf\Internal\GPBType::INT32);
$this->weak_dependency = $arr;
return $this;
}
/**
* All top-level definitions in this file.
*
* Generated from protobuf field <code>repeated .google.protobuf.DescriptorProto message_type = 4;</code>
* @return \Google\Protobuf\Internal\RepeatedField
*/
public function getMessageType()
{
return $this->message_type;
}
/**
* All top-level definitions in this file.
*
* Generated from protobuf field <code>repeated .google.protobuf.DescriptorProto message_type = 4;</code>
* @param array<\Google\Protobuf\Internal\DescriptorProto>|\Google\Protobuf\Internal\RepeatedField $var
* @return $this
*/
public function setMessageType($var)
{
$arr = GPBUtil::checkRepeatedField($var, \Google\Protobuf\Internal\GPBType::MESSAGE, \Google\Protobuf\Internal\DescriptorProto::class);
$this->message_type = $arr;
return $this;
}
/**
* Generated from protobuf field <code>repeated .google.protobuf.EnumDescriptorProto enum_type = 5;</code>
* @return \Google\Protobuf\Internal\RepeatedField
*/
public function getEnumType()
{
return $this->enum_type;
}
/**
* Generated from protobuf field <code>repeated .google.protobuf.EnumDescriptorProto enum_type = 5;</code>
* @param array<\Google\Protobuf\Internal\EnumDescriptorProto>|\Google\Protobuf\Internal\RepeatedField $var
* @return $this
*/
public function setEnumType($var)
{
$arr = GPBUtil::checkRepeatedField($var, \Google\Protobuf\Internal\GPBType::MESSAGE, \Google\Protobuf\Internal\EnumDescriptorProto::class);
$this->enum_type = $arr;
return $this;
}
/**
* Generated from protobuf field <code>repeated .google.protobuf.ServiceDescriptorProto service = 6;</code>
* @return \Google\Protobuf\Internal\RepeatedField
*/
public function getService()
{
return $this->service;
}
/**
* Generated from protobuf field <code>repeated .google.protobuf.ServiceDescriptorProto service = 6;</code>
* @param array<\Google\Protobuf\Internal\ServiceDescriptorProto>|\Google\Protobuf\Internal\RepeatedField $var
* @return $this
*/
public function setService($var)
{
$arr = GPBUtil::checkRepeatedField($var, \Google\Protobuf\Internal\GPBType::MESSAGE, \Google\Protobuf\Internal\ServiceDescriptorProto::class);
$this->service = $arr;
return $this;
}
/**
* Generated from protobuf field <code>repeated .google.protobuf.FieldDescriptorProto extension = 7;</code>
* @return \Google\Protobuf\Internal\RepeatedField
*/
public function getExtension()
{
return $this->extension;
}
/**
* Generated from protobuf field <code>repeated .google.protobuf.FieldDescriptorProto extension = 7;</code>
* @param array<\Google\Protobuf\Internal\FieldDescriptorProto>|\Google\Protobuf\Internal\RepeatedField $var
* @return $this
*/
public function setExtension($var)
{
$arr = GPBUtil::checkRepeatedField($var, \Google\Protobuf\Internal\GPBType::MESSAGE, \Google\Protobuf\Internal\FieldDescriptorProto::class);
$this->extension = $arr;
return $this;
}
/**
* Generated from protobuf field <code>optional .google.protobuf.FileOptions options = 8;</code>
* @return \Google\Protobuf\Internal\FileOptions|null
*/
public function getOptions()
{
return $this->options;
}
public function hasOptions()
{
return isset($this->options);
}
public function clearOptions()
{
unset($this->options);
}
/**
* Generated from protobuf field <code>optional .google.protobuf.FileOptions options = 8;</code>
* @param \Google\Protobuf\Internal\FileOptions $var
* @return $this
*/
public function setOptions($var)
{
GPBUtil::checkMessage($var, \Google\Protobuf\Internal\FileOptions::class);
$this->options = $var;
return $this;
}
/**
* This field contains optional information about the original source code.
* You may safely remove this entire field without harming runtime
* functionality of the descriptors -- the information is needed only by
* development tools.
*
* Generated from protobuf field <code>optional .google.protobuf.SourceCodeInfo source_code_info = 9;</code>
* @return \Google\Protobuf\Internal\SourceCodeInfo|null
*/
public function getSourceCodeInfo()
{
return $this->source_code_info;
}
public function hasSourceCodeInfo()
{
return isset($this->source_code_info);
}
public function clearSourceCodeInfo()
{
unset($this->source_code_info);
}
/**
* This field contains optional information about the original source code.
* You may safely remove this entire field without harming runtime
* functionality of the descriptors -- the information is needed only by
* development tools.
*
* Generated from protobuf field <code>optional .google.protobuf.SourceCodeInfo source_code_info = 9;</code>
* @param \Google\Protobuf\Internal\SourceCodeInfo $var
* @return $this
*/
public function setSourceCodeInfo($var)
{
GPBUtil::checkMessage($var, \Google\Protobuf\Internal\SourceCodeInfo::class);
$this->source_code_info = $var;
return $this;
}
/**
* The syntax of the proto file.
* The supported values are "proto2", "proto3", and "editions".
* If `edition` is present, this value must be "editions".
*
* Generated from protobuf field <code>optional string syntax = 12;</code>
* @return string
*/
public function getSyntax()
{
return isset($this->syntax) ? $this->syntax : '';
}
public function hasSyntax()
{
return isset($this->syntax);
}
public function clearSyntax()
{
unset($this->syntax);
}
/**
* The syntax of the proto file.
* The supported values are "proto2", "proto3", and "editions".
* If `edition` is present, this value must be "editions".
*
* Generated from protobuf field <code>optional string syntax = 12;</code>
* @param string $var
* @return $this
*/
public function setSyntax($var)
{
GPBUtil::checkString($var, True);
$this->syntax = $var;
return $this;
}
/**
* The edition of the proto file, which is an opaque string.
*
* Generated from protobuf field <code>optional string edition = 13;</code>
* @return string
*/
public function getEdition()
{
return isset($this->edition) ? $this->edition : '';
}
public function hasEdition()
{
return isset($this->edition);
}
public function clearEdition()
{
unset($this->edition);
}
/**
* The edition of the proto file, which is an opaque string.
*
* Generated from protobuf field <code>optional string edition = 13;</code>
* @param string $var
* @return $this
*/
public function setEdition($var)
{
GPBUtil::checkString($var, True);
$this->edition = $var;
return $this;
}
}

View File

@@ -0,0 +1,63 @@
<?php
# Generated by the protocol buffer compiler. DO NOT EDIT!
# source: google/protobuf/descriptor.proto
namespace Google\Protobuf\Internal;
use Google\Protobuf\Internal\GPBType;
use Google\Protobuf\Internal\GPBWire;
use Google\Protobuf\Internal\RepeatedField;
use Google\Protobuf\Internal\InputStream;
use Google\Protobuf\Internal\GPBUtil;
/**
* The protocol compiler can output a FileDescriptorSet containing the .proto
* files it parses.
*
* Generated from protobuf message <code>google.protobuf.FileDescriptorSet</code>
*/
class FileDescriptorSet extends \Google\Protobuf\Internal\Message
{
/**
* Generated from protobuf field <code>repeated .google.protobuf.FileDescriptorProto file = 1;</code>
*/
private $file;
/**
* Constructor.
*
* @param array $data {
* Optional. Data for populating the Message object.
*
* @type array<\Google\Protobuf\Internal\FileDescriptorProto>|\Google\Protobuf\Internal\RepeatedField $file
* }
*/
public function __construct($data = NULL) {
\GPBMetadata\Google\Protobuf\Internal\Descriptor::initOnce();
parent::__construct($data);
}
/**
* Generated from protobuf field <code>repeated .google.protobuf.FileDescriptorProto file = 1;</code>
* @return \Google\Protobuf\Internal\RepeatedField
*/
public function getFile()
{
return $this->file;
}
/**
* Generated from protobuf field <code>repeated .google.protobuf.FileDescriptorProto file = 1;</code>
* @param array<\Google\Protobuf\Internal\FileDescriptorProto>|\Google\Protobuf\Internal\RepeatedField $var
* @return $this
*/
public function setFile($var)
{
$arr = GPBUtil::checkRepeatedField($var, \Google\Protobuf\Internal\GPBType::MESSAGE, \Google\Protobuf\Internal\FileDescriptorProto::class);
$this->file = $arr;
return $this;
}
}

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,64 @@
<?php
# Generated by the protocol buffer compiler. DO NOT EDIT!
# source: google/protobuf/descriptor.proto
namespace Google\Protobuf\Internal\FileOptions;
use UnexpectedValueException;
/**
* Generated classes can be optimized for speed or code size.
*
* Protobuf type <code>google.protobuf.FileOptions.OptimizeMode</code>
*/
class OptimizeMode
{
/**
* Generate complete code for parsing, serialization,
*
* Generated from protobuf enum <code>SPEED = 1;</code>
*/
const SPEED = 1;
/**
* etc.
*
* Generated from protobuf enum <code>CODE_SIZE = 2;</code>
*/
const CODE_SIZE = 2;
/**
* Generate code using MessageLite and the lite runtime.
*
* Generated from protobuf enum <code>LITE_RUNTIME = 3;</code>
*/
const LITE_RUNTIME = 3;
private static $valueToName = [
self::SPEED => 'SPEED',
self::CODE_SIZE => 'CODE_SIZE',
self::LITE_RUNTIME => 'LITE_RUNTIME',
];
public static function name($value)
{
if (!isset(self::$valueToName[$value])) {
throw new UnexpectedValueException(sprintf(
'Enum %s has no name defined for value %s', __CLASS__, $value));
}
return self::$valueToName[$value];
}
public static function value($name)
{
$const = __CLASS__ . '::' . strtoupper($name);
if (!defined($const)) {
throw new UnexpectedValueException(sprintf(
'Enum %s has no value defined for name %s', __CLASS__, $name));
}
return constant($const);
}
}
// Adding a class alias for backwards compatibility with the previous class name.
class_alias(OptimizeMode::class, \Google\Protobuf\Internal\FileOptions_OptimizeMode::class);

Some files were not shown because too many files have changed in this diff Show More