diff --git a/composer.json b/composer.json new file mode 100644 index 00000000..f0079b89 --- /dev/null +++ b/composer.json @@ -0,0 +1,43 @@ +{ + "name": "aelf/aelf-sdk", + "type": "library", + "description": "AElf php SDK", + "keywords": ["aelf-sdk","aelf","AElf php SDK"], + "license": "MIT", + "authors": [ + + ], + "homepage": "https://github.com/AElfProject/aelf-sdk.php", + "require": { + "php": ">=5.6", + "ext-gmp": "*", + "ext-curl": "*", + "kornrunner/secp256k1": "^0.1.2" + }, + "require-dev": { + "phpunit/phpunit": "^6.2" + }, + "autoload": { + "classmap": [ + "src/helper" + ], + "files":["src/helper/Sha.php"], + "psr-4": { + "Aelf\\": "src/", + "Aelf\\Api\\":"src/sdk/", + "Hhxsv5\\PhpMultiCurl\\": "src/helper", + "StephenHill\\": "src/helper", + "StephenHill\\Benchmarks\\": "benchmarks/", + "Aelf\\AelfECDSA\\": "src/helper/", + "Google\\Protobuf\\": "src/pro/Google/Protobuf", + "GPBMetadata\\Google\\Protobuf\\": "src/GPBMetadata/Google/Protobuf", + "Aelf\\Protobuf\\Generated\\": "src/pro/Aelf/Protobuf/Generated/", + "GPBMetadata\\": "src/pro/GPBMetadata/" + } + }, + "autoload-dev": { + "psr-4": { + "Aelf\\example\\": "example/" + } + } +} \ No newline at end of file diff --git a/composer.lock b/composer.lock new file mode 100644 index 00000000..1a9ad29b --- /dev/null +++ b/composer.lock @@ -0,0 +1,1921 @@ +{ + "_readme": [ + "This file locks the dependencies of your project to a known state", + "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies", + "This file is @generated automatically" + ], + "content-hash": "14b9a3c3ee78aff5dd359b9b33d39294", + "packages": [ + { + "name": "fgrosse/phpasn1", + "version": "v2.1.1", + "source": { + "type": "git", + "url": "https://github.com/fgrosse/PHPASN1.git", + "reference": "7ebf2a09084a7bbdb7b879c66fdf7ad80461bbe8" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/fgrosse/PHPASN1/zipball/7ebf2a09084a7bbdb7b879c66fdf7ad80461bbe8", + "reference": "7ebf2a09084a7bbdb7b879c66fdf7ad80461bbe8", + "shasum": "", + "mirrors": [ + { + "url": "https://mirrors.cloud.tencent.com/composer/dists/%package%/%reference%.%type%", + "preferred": true + } + ] + }, + "require": { + "php": ">=7.0.0" + }, + "require-dev": { + "phpunit/phpunit": "~6.3", + "satooshi/php-coveralls": "~2.0" + }, + "suggest": { + "ext-gmp": "GMP is the preferred extension for big integer calculations", + "php-curl": "For loading OID information from the web if they have not bee defined statically" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "2.0.x-dev" + } + }, + "autoload": { + "psr-4": { + "FG\\": "lib/" + } + }, + "notification-url": "https://packagist.jp/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Friedrich Große", + "email": "friedrich.grosse@gmail.com", + "homepage": "https://github.com/FGrosse", + "role": "Author" + }, + { + "name": "All contributors", + "homepage": "https://github.com/FGrosse/PHPASN1/contributors" + } + ], + "description": "A PHP Framework that allows you to encode and decode arbitrary ASN.1 structures using the ITU-T X.690 Encoding Rules.", + "homepage": "https://github.com/FGrosse/PHPASN1", + "keywords": [ + "DER", + "asn.1", + "asn1", + "ber", + "binary", + "decoding", + "encoding", + "x.509", + "x.690", + "x509", + "x690" + ], + "time": "2018-12-02T01:34:34+00:00" + }, + { + "name": "kornrunner/secp256k1", + "version": "0.1.2", + "source": { + "type": "git", + "url": "https://github.com/kornrunner/php-secp256k1.git", + "reference": "915f0ef1ec748606a1117b171093266de349b058" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/kornrunner/php-secp256k1/zipball/915f0ef1ec748606a1117b171093266de349b058", + "reference": "915f0ef1ec748606a1117b171093266de349b058", + "shasum": "", + "mirrors": [ + { + "url": "https://mirrors.cloud.tencent.com/composer/dists/%package%/%reference%.%type%", + "preferred": true + } + ] + }, + "require": { + "mdanter/ecc": "^0.5", + "php": ">=7.1" + }, + "require-dev": { + "php-coveralls/php-coveralls": "^2.1", + "phpunit/phpunit": "^7" + }, + "type": "library", + "autoload": { + "psr-4": { + "kornrunner\\": "src/" + } + }, + "notification-url": "https://packagist.jp/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Boris Momčilović", + "email": "boris.momcilovic@gmail.com" + } + ], + "description": "Pure PHP secp256k1", + "keywords": [ + "curve", + "ecc", + "elliptic", + "secp256k1" + ], + "time": "2019-01-16T17:01:51+00:00" + }, + { + "name": "mdanter/ecc", + "version": "v0.5.2", + "source": { + "type": "git", + "url": "https://github.com/phpecc/phpecc.git", + "reference": "b95f25cc1bacc83a9f0ccd375900b7cfd343029e" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/phpecc/phpecc/zipball/b95f25cc1bacc83a9f0ccd375900b7cfd343029e", + "reference": "b95f25cc1bacc83a9f0ccd375900b7cfd343029e", + "shasum": "", + "mirrors": [ + { + "url": "https://mirrors.cloud.tencent.com/composer/dists/%package%/%reference%.%type%", + "preferred": true + } + ] + }, + "require": { + "ext-gmp": "*", + "fgrosse/phpasn1": "^2.0", + "php": "^7.0" + }, + "require-dev": { + "phpunit/phpunit": "^6.0", + "squizlabs/php_codesniffer": "^2.0", + "symfony/yaml": "^2.6|^3.0" + }, + "type": "library", + "autoload": { + "psr-4": { + "Mdanter\\Ecc\\": "src/" + } + }, + "notification-url": "https://packagist.jp/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Matyas Danter", + "homepage": "http://matejdanter.com/", + "role": "Author" + }, + { + "name": "Thibaud Fabre", + "email": "thibaud@aztech.io", + "homepage": "http://aztech.io", + "role": "Maintainer" + }, + { + "name": "Thomas Kerin", + "email": "afk11@users.noreply.github.com", + "role": "Maintainer" + } + ], + "description": "PHP Elliptic Curve Cryptography library", + "homepage": "https://github.com/phpecc/phpecc", + "keywords": [ + "Diffie", + "ECDSA", + "Hellman", + "curve", + "ecdh", + "elliptic", + "nistp192", + "nistp224", + "nistp256", + "nistp384", + "nistp521", + "phpecc", + "secp256k1", + "secp256r1" + ], + "time": "2018-12-03T18:17:01+00:00" + } + ], + "packages-dev": [ + { + "name": "doctrine/instantiator", + "version": "1.3.0", + "source": { + "type": "git", + "url": "https://github.com/doctrine/instantiator.git", + "reference": "ae466f726242e637cebdd526a7d991b9433bacf1" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/doctrine/instantiator/zipball/ae466f726242e637cebdd526a7d991b9433bacf1", + "reference": "ae466f726242e637cebdd526a7d991b9433bacf1", + "shasum": "", + "mirrors": [ + { + "url": "https://mirrors.cloud.tencent.com/composer/dists/%package%/%reference%.%type%", + "preferred": true + } + ] + }, + "require": { + "php": "^7.1" + }, + "require-dev": { + "doctrine/coding-standard": "^6.0", + "ext-pdo": "*", + "ext-phar": "*", + "phpbench/phpbench": "^0.13", + "phpstan/phpstan-phpunit": "^0.11", + "phpstan/phpstan-shim": "^0.11", + "phpunit/phpunit": "^7.0" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "1.2.x-dev" + } + }, + "autoload": { + "psr-4": { + "Doctrine\\Instantiator\\": "src/Doctrine/Instantiator/" + } + }, + "notification-url": "https://packagist.jp/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Marco Pivetta", + "email": "ocramius@gmail.com", + "homepage": "http://ocramius.github.com/" + } + ], + "description": "A small, lightweight utility to instantiate objects in PHP without invoking their constructors", + "homepage": "https://www.doctrine-project.org/projects/instantiator.html", + "keywords": [ + "constructor", + "instantiate" + ], + "time": "2019-10-21T16:45:58+00:00" + }, + { + "name": "myclabs/deep-copy", + "version": "1.9.5", + "source": { + "type": "git", + "url": "https://github.com/myclabs/DeepCopy.git", + "reference": "b2c28789e80a97badd14145fda39b545d83ca3ef" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/myclabs/DeepCopy/zipball/b2c28789e80a97badd14145fda39b545d83ca3ef", + "reference": "b2c28789e80a97badd14145fda39b545d83ca3ef", + "shasum": "", + "mirrors": [ + { + "url": "https://mirrors.cloud.tencent.com/composer/dists/%package%/%reference%.%type%", + "preferred": true + } + ] + }, + "require": { + "php": "^7.1" + }, + "replace": { + "myclabs/deep-copy": "self.version" + }, + "require-dev": { + "doctrine/collections": "^1.0", + "doctrine/common": "^2.6", + "phpunit/phpunit": "^7.1" + }, + "type": "library", + "autoload": { + "psr-4": { + "DeepCopy\\": "src/DeepCopy/" + }, + "files": [ + "src/DeepCopy/deep_copy.php" + ] + }, + "notification-url": "https://packagist.jp/downloads/", + "license": [ + "MIT" + ], + "description": "Create deep copies (clones) of your objects", + "keywords": [ + "clone", + "copy", + "duplicate", + "object", + "object graph" + ], + "time": "2020-01-17T21:11:47+00:00" + }, + { + "name": "phar-io/manifest", + "version": "1.0.1", + "source": { + "type": "git", + "url": "https://github.com/phar-io/manifest.git", + "reference": "2df402786ab5368a0169091f61a7c1e0eb6852d0" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/phar-io/manifest/zipball/2df402786ab5368a0169091f61a7c1e0eb6852d0", + "reference": "2df402786ab5368a0169091f61a7c1e0eb6852d0", + "shasum": "", + "mirrors": [ + { + "url": "https://mirrors.cloud.tencent.com/composer/dists/%package%/%reference%.%type%", + "preferred": true + } + ] + }, + "require": { + "ext-dom": "*", + "ext-phar": "*", + "phar-io/version": "^1.0.1", + "php": "^5.6 || ^7.0" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "1.0.x-dev" + } + }, + "autoload": { + "classmap": [ + "src/" + ] + }, + "notification-url": "https://packagist.jp/downloads/", + "license": [ + "BSD-3-Clause" + ], + "authors": [ + { + "name": "Arne Blankerts", + "email": "arne@blankerts.de", + "role": "Developer" + }, + { + "name": "Sebastian Heuer", + "email": "sebastian@phpeople.de", + "role": "Developer" + }, + { + "name": "Sebastian Bergmann", + "email": "sebastian@phpunit.de", + "role": "Developer" + } + ], + "description": "Component for reading phar.io manifest information from a PHP Archive (PHAR)", + "time": "2017-03-05T18:14:27+00:00" + }, + { + "name": "phar-io/version", + "version": "1.0.1", + "source": { + "type": "git", + "url": "https://github.com/phar-io/version.git", + "reference": "a70c0ced4be299a63d32fa96d9281d03e94041df" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/phar-io/version/zipball/a70c0ced4be299a63d32fa96d9281d03e94041df", + "reference": "a70c0ced4be299a63d32fa96d9281d03e94041df", + "shasum": "", + "mirrors": [ + { + "url": "https://mirrors.cloud.tencent.com/composer/dists/%package%/%reference%.%type%", + "preferred": true + } + ] + }, + "require": { + "php": "^5.6 || ^7.0" + }, + "type": "library", + "autoload": { + "classmap": [ + "src/" + ] + }, + "notification-url": "https://packagist.jp/downloads/", + "license": [ + "BSD-3-Clause" + ], + "authors": [ + { + "name": "Arne Blankerts", + "email": "arne@blankerts.de", + "role": "Developer" + }, + { + "name": "Sebastian Heuer", + "email": "sebastian@phpeople.de", + "role": "Developer" + }, + { + "name": "Sebastian Bergmann", + "email": "sebastian@phpunit.de", + "role": "Developer" + } + ], + "description": "Library for handling version information and constraints", + "time": "2017-03-05T17:38:23+00:00" + }, + { + "name": "phpdocumentor/reflection-common", + "version": "2.0.0", + "source": { + "type": "git", + "url": "https://github.com/phpDocumentor/ReflectionCommon.git", + "reference": "63a995caa1ca9e5590304cd845c15ad6d482a62a" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/phpDocumentor/ReflectionCommon/zipball/63a995caa1ca9e5590304cd845c15ad6d482a62a", + "reference": "63a995caa1ca9e5590304cd845c15ad6d482a62a", + "shasum": "", + "mirrors": [ + { + "url": "https://mirrors.cloud.tencent.com/composer/dists/%package%/%reference%.%type%", + "preferred": true + } + ] + }, + "require": { + "php": ">=7.1" + }, + "require-dev": { + "phpunit/phpunit": "~6" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "2.x-dev" + } + }, + "autoload": { + "psr-4": { + "phpDocumentor\\Reflection\\": "src/" + } + }, + "notification-url": "https://packagist.jp/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Jaap van Otterdijk", + "email": "opensource@ijaap.nl" + } + ], + "description": "Common reflection classes used by phpdocumentor to reflect the code structure", + "homepage": "http://www.phpdoc.org", + "keywords": [ + "FQSEN", + "phpDocumentor", + "phpdoc", + "reflection", + "static analysis" + ], + "time": "2018-08-07T13:53:10+00:00" + }, + { + "name": "phpdocumentor/reflection-docblock", + "version": "5.1.0", + "source": { + "type": "git", + "url": "https://github.com/phpDocumentor/ReflectionDocBlock.git", + "reference": "cd72d394ca794d3466a3b2fc09d5a6c1dc86b47e" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/phpDocumentor/ReflectionDocBlock/zipball/cd72d394ca794d3466a3b2fc09d5a6c1dc86b47e", + "reference": "cd72d394ca794d3466a3b2fc09d5a6c1dc86b47e", + "shasum": "", + "mirrors": [ + { + "url": "https://mirrors.cloud.tencent.com/composer/dists/%package%/%reference%.%type%", + "preferred": true + } + ] + }, + "require": { + "ext-filter": "^7.1", + "php": "^7.2", + "phpdocumentor/reflection-common": "^2.0", + "phpdocumentor/type-resolver": "^1.0", + "webmozart/assert": "^1" + }, + "require-dev": { + "doctrine/instantiator": "^1", + "mockery/mockery": "^1" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "5.x-dev" + } + }, + "autoload": { + "psr-4": { + "phpDocumentor\\Reflection\\": "src" + } + }, + "notification-url": "https://packagist.jp/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Mike van Riel", + "email": "me@mikevanriel.com" + }, + { + "name": "Jaap van Otterdijk", + "email": "account@ijaap.nl" + } + ], + "description": "With this component, a library can provide support for annotations via DocBlocks or otherwise retrieve information that is embedded in a DocBlock.", + "time": "2020-02-22T12:28:44+00:00" + }, + { + "name": "phpdocumentor/type-resolver", + "version": "1.1.0", + "source": { + "type": "git", + "url": "https://github.com/phpDocumentor/TypeResolver.git", + "reference": "7462d5f123dfc080dfdf26897032a6513644fc95" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/phpDocumentor/TypeResolver/zipball/7462d5f123dfc080dfdf26897032a6513644fc95", + "reference": "7462d5f123dfc080dfdf26897032a6513644fc95", + "shasum": "", + "mirrors": [ + { + "url": "https://mirrors.cloud.tencent.com/composer/dists/%package%/%reference%.%type%", + "preferred": true + } + ] + }, + "require": { + "php": "^7.2", + "phpdocumentor/reflection-common": "^2.0" + }, + "require-dev": { + "ext-tokenizer": "^7.2", + "mockery/mockery": "~1" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "1.x-dev" + } + }, + "autoload": { + "psr-4": { + "phpDocumentor\\Reflection\\": "src" + } + }, + "notification-url": "https://packagist.jp/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Mike van Riel", + "email": "me@mikevanriel.com" + } + ], + "description": "A PSR-5 based resolver of Class names, Types and Structural Element Names", + "time": "2020-02-18T18:59:58+00:00" + }, + { + "name": "phpspec/prophecy", + "version": "v1.10.3", + "source": { + "type": "git", + "url": "https://github.com/phpspec/prophecy.git", + "reference": "451c3cd1418cf640de218914901e51b064abb093" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/phpspec/prophecy/zipball/451c3cd1418cf640de218914901e51b064abb093", + "reference": "451c3cd1418cf640de218914901e51b064abb093", + "shasum": "", + "mirrors": [ + { + "url": "https://mirrors.cloud.tencent.com/composer/dists/%package%/%reference%.%type%", + "preferred": true + } + ] + }, + "require": { + "doctrine/instantiator": "^1.0.2", + "php": "^5.3|^7.0", + "phpdocumentor/reflection-docblock": "^2.0|^3.0.2|^4.0|^5.0", + "sebastian/comparator": "^1.2.3|^2.0|^3.0|^4.0", + "sebastian/recursion-context": "^1.0|^2.0|^3.0|^4.0" + }, + "require-dev": { + "phpspec/phpspec": "^2.5 || ^3.2", + "phpunit/phpunit": "^4.8.35 || ^5.7 || ^6.5 || ^7.1" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "1.10.x-dev" + } + }, + "autoload": { + "psr-4": { + "Prophecy\\": "src/Prophecy" + } + }, + "notification-url": "https://packagist.jp/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Konstantin Kudryashov", + "email": "ever.zet@gmail.com", + "homepage": "http://everzet.com" + }, + { + "name": "Marcello Duarte", + "email": "marcello.duarte@gmail.com" + } + ], + "description": "Highly opinionated mocking framework for PHP 5.3+", + "homepage": "https://github.com/phpspec/prophecy", + "keywords": [ + "Double", + "Dummy", + "fake", + "mock", + "spy", + "stub" + ], + "time": "2020-03-05T15:02:03+00:00" + }, + { + "name": "phpunit/php-code-coverage", + "version": "5.3.2", + "source": { + "type": "git", + "url": "https://github.com/sebastianbergmann/php-code-coverage.git", + "reference": "c89677919c5dd6d3b3852f230a663118762218ac" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/sebastianbergmann/php-code-coverage/zipball/c89677919c5dd6d3b3852f230a663118762218ac", + "reference": "c89677919c5dd6d3b3852f230a663118762218ac", + "shasum": "", + "mirrors": [ + { + "url": "https://mirrors.cloud.tencent.com/composer/dists/%package%/%reference%.%type%", + "preferred": true + } + ] + }, + "require": { + "ext-dom": "*", + "ext-xmlwriter": "*", + "php": "^7.0", + "phpunit/php-file-iterator": "^1.4.2", + "phpunit/php-text-template": "^1.2.1", + "phpunit/php-token-stream": "^2.0.1", + "sebastian/code-unit-reverse-lookup": "^1.0.1", + "sebastian/environment": "^3.0", + "sebastian/version": "^2.0.1", + "theseer/tokenizer": "^1.1" + }, + "require-dev": { + "phpunit/phpunit": "^6.0" + }, + "suggest": { + "ext-xdebug": "^2.5.5" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "5.3.x-dev" + } + }, + "autoload": { + "classmap": [ + "src/" + ] + }, + "notification-url": "https://packagist.jp/downloads/", + "license": [ + "BSD-3-Clause" + ], + "authors": [ + { + "name": "Sebastian Bergmann", + "email": "sebastian@phpunit.de", + "role": "lead" + } + ], + "description": "Library that provides collection, processing, and rendering functionality for PHP code coverage information.", + "homepage": "https://github.com/sebastianbergmann/php-code-coverage", + "keywords": [ + "coverage", + "testing", + "xunit" + ], + "time": "2018-04-06T15:36:58+00:00" + }, + { + "name": "phpunit/php-file-iterator", + "version": "1.4.5", + "source": { + "type": "git", + "url": "https://github.com/sebastianbergmann/php-file-iterator.git", + "reference": "730b01bc3e867237eaac355e06a36b85dd93a8b4" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/sebastianbergmann/php-file-iterator/zipball/730b01bc3e867237eaac355e06a36b85dd93a8b4", + "reference": "730b01bc3e867237eaac355e06a36b85dd93a8b4", + "shasum": "", + "mirrors": [ + { + "url": "https://mirrors.cloud.tencent.com/composer/dists/%package%/%reference%.%type%", + "preferred": true + } + ] + }, + "require": { + "php": ">=5.3.3" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "1.4.x-dev" + } + }, + "autoload": { + "classmap": [ + "src/" + ] + }, + "notification-url": "https://packagist.jp/downloads/", + "license": [ + "BSD-3-Clause" + ], + "authors": [ + { + "name": "Sebastian Bergmann", + "email": "sb@sebastian-bergmann.de", + "role": "lead" + } + ], + "description": "FilterIterator implementation that filters files based on a list of suffixes.", + "homepage": "https://github.com/sebastianbergmann/php-file-iterator/", + "keywords": [ + "filesystem", + "iterator" + ], + "time": "2017-11-27T13:52:08+00:00" + }, + { + "name": "phpunit/php-text-template", + "version": "1.2.1", + "source": { + "type": "git", + "url": "https://github.com/sebastianbergmann/php-text-template.git", + "reference": "31f8b717e51d9a2afca6c9f046f5d69fc27c8686" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/sebastianbergmann/php-text-template/zipball/31f8b717e51d9a2afca6c9f046f5d69fc27c8686", + "reference": "31f8b717e51d9a2afca6c9f046f5d69fc27c8686", + "shasum": "", + "mirrors": [ + { + "url": "https://mirrors.cloud.tencent.com/composer/dists/%package%/%reference%.%type%", + "preferred": true + } + ] + }, + "require": { + "php": ">=5.3.3" + }, + "type": "library", + "autoload": { + "classmap": [ + "src/" + ] + }, + "notification-url": "https://packagist.jp/downloads/", + "license": [ + "BSD-3-Clause" + ], + "authors": [ + { + "name": "Sebastian Bergmann", + "email": "sebastian@phpunit.de", + "role": "lead" + } + ], + "description": "Simple template engine.", + "homepage": "https://github.com/sebastianbergmann/php-text-template/", + "keywords": [ + "template" + ], + "time": "2015-06-21T13:50:34+00:00" + }, + { + "name": "phpunit/php-timer", + "version": "1.0.9", + "source": { + "type": "git", + "url": "https://github.com/sebastianbergmann/php-timer.git", + "reference": "3dcf38ca72b158baf0bc245e9184d3fdffa9c46f" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/sebastianbergmann/php-timer/zipball/3dcf38ca72b158baf0bc245e9184d3fdffa9c46f", + "reference": "3dcf38ca72b158baf0bc245e9184d3fdffa9c46f", + "shasum": "", + "mirrors": [ + { + "url": "https://mirrors.cloud.tencent.com/composer/dists/%package%/%reference%.%type%", + "preferred": true + } + ] + }, + "require": { + "php": "^5.3.3 || ^7.0" + }, + "require-dev": { + "phpunit/phpunit": "^4.8.35 || ^5.7 || ^6.0" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "1.0-dev" + } + }, + "autoload": { + "classmap": [ + "src/" + ] + }, + "notification-url": "https://packagist.jp/downloads/", + "license": [ + "BSD-3-Clause" + ], + "authors": [ + { + "name": "Sebastian Bergmann", + "email": "sb@sebastian-bergmann.de", + "role": "lead" + } + ], + "description": "Utility class for timing", + "homepage": "https://github.com/sebastianbergmann/php-timer/", + "keywords": [ + "timer" + ], + "time": "2017-02-26T11:10:40+00:00" + }, + { + "name": "phpunit/php-token-stream", + "version": "2.0.2", + "source": { + "type": "git", + "url": "https://github.com/sebastianbergmann/php-token-stream.git", + "reference": "791198a2c6254db10131eecfe8c06670700904db" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/sebastianbergmann/php-token-stream/zipball/791198a2c6254db10131eecfe8c06670700904db", + "reference": "791198a2c6254db10131eecfe8c06670700904db", + "shasum": "", + "mirrors": [ + { + "url": "https://mirrors.cloud.tencent.com/composer/dists/%package%/%reference%.%type%", + "preferred": true + } + ] + }, + "require": { + "ext-tokenizer": "*", + "php": "^7.0" + }, + "require-dev": { + "phpunit/phpunit": "^6.2.4" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "2.0-dev" + } + }, + "autoload": { + "classmap": [ + "src/" + ] + }, + "notification-url": "https://packagist.jp/downloads/", + "license": [ + "BSD-3-Clause" + ], + "authors": [ + { + "name": "Sebastian Bergmann", + "email": "sebastian@phpunit.de" + } + ], + "description": "Wrapper around PHP's tokenizer extension.", + "homepage": "https://github.com/sebastianbergmann/php-token-stream/", + "keywords": [ + "tokenizer" + ], + "time": "2017-11-27T05:48:46+00:00" + }, + { + "name": "phpunit/phpunit", + "version": "6.5.14", + "source": { + "type": "git", + "url": "https://github.com/sebastianbergmann/phpunit.git", + "reference": "bac23fe7ff13dbdb461481f706f0e9fe746334b7" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/sebastianbergmann/phpunit/zipball/bac23fe7ff13dbdb461481f706f0e9fe746334b7", + "reference": "bac23fe7ff13dbdb461481f706f0e9fe746334b7", + "shasum": "", + "mirrors": [ + { + "url": "https://mirrors.cloud.tencent.com/composer/dists/%package%/%reference%.%type%", + "preferred": true + } + ] + }, + "require": { + "ext-dom": "*", + "ext-json": "*", + "ext-libxml": "*", + "ext-mbstring": "*", + "ext-xml": "*", + "myclabs/deep-copy": "^1.6.1", + "phar-io/manifest": "^1.0.1", + "phar-io/version": "^1.0", + "php": "^7.0", + "phpspec/prophecy": "^1.7", + "phpunit/php-code-coverage": "^5.3", + "phpunit/php-file-iterator": "^1.4.3", + "phpunit/php-text-template": "^1.2.1", + "phpunit/php-timer": "^1.0.9", + "phpunit/phpunit-mock-objects": "^5.0.9", + "sebastian/comparator": "^2.1", + "sebastian/diff": "^2.0", + "sebastian/environment": "^3.1", + "sebastian/exporter": "^3.1", + "sebastian/global-state": "^2.0", + "sebastian/object-enumerator": "^3.0.3", + "sebastian/resource-operations": "^1.0", + "sebastian/version": "^2.0.1" + }, + "conflict": { + "phpdocumentor/reflection-docblock": "3.0.2", + "phpunit/dbunit": "<3.0" + }, + "require-dev": { + "ext-pdo": "*" + }, + "suggest": { + "ext-xdebug": "*", + "phpunit/php-invoker": "^1.1" + }, + "bin": [ + "phpunit" + ], + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "6.5.x-dev" + } + }, + "autoload": { + "classmap": [ + "src/" + ] + }, + "notification-url": "https://packagist.jp/downloads/", + "license": [ + "BSD-3-Clause" + ], + "authors": [ + { + "name": "Sebastian Bergmann", + "email": "sebastian@phpunit.de", + "role": "lead" + } + ], + "description": "The PHP Unit Testing framework.", + "homepage": "https://phpunit.de/", + "keywords": [ + "phpunit", + "testing", + "xunit" + ], + "time": "2019-02-01T05:22:47+00:00" + }, + { + "name": "phpunit/phpunit-mock-objects", + "version": "5.0.10", + "source": { + "type": "git", + "url": "https://github.com/sebastianbergmann/phpunit-mock-objects.git", + "reference": "cd1cf05c553ecfec36b170070573e540b67d3f1f" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/sebastianbergmann/phpunit-mock-objects/zipball/cd1cf05c553ecfec36b170070573e540b67d3f1f", + "reference": "cd1cf05c553ecfec36b170070573e540b67d3f1f", + "shasum": "", + "mirrors": [ + { + "url": "https://mirrors.cloud.tencent.com/composer/dists/%package%/%reference%.%type%", + "preferred": true + } + ] + }, + "require": { + "doctrine/instantiator": "^1.0.5", + "php": "^7.0", + "phpunit/php-text-template": "^1.2.1", + "sebastian/exporter": "^3.1" + }, + "conflict": { + "phpunit/phpunit": "<6.0" + }, + "require-dev": { + "phpunit/phpunit": "^6.5.11" + }, + "suggest": { + "ext-soap": "*" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "5.0.x-dev" + } + }, + "autoload": { + "classmap": [ + "src/" + ] + }, + "notification-url": "https://packagist.jp/downloads/", + "license": [ + "BSD-3-Clause" + ], + "authors": [ + { + "name": "Sebastian Bergmann", + "email": "sebastian@phpunit.de", + "role": "lead" + } + ], + "description": "Mock Object library for PHPUnit", + "homepage": "https://github.com/sebastianbergmann/phpunit-mock-objects/", + "keywords": [ + "mock", + "xunit" + ], + "abandoned": true, + "time": "2018-08-09T05:50:03+00:00" + }, + { + "name": "sebastian/code-unit-reverse-lookup", + "version": "1.0.1", + "source": { + "type": "git", + "url": "https://github.com/sebastianbergmann/code-unit-reverse-lookup.git", + "reference": "4419fcdb5eabb9caa61a27c7a1db532a6b55dd18" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/sebastianbergmann/code-unit-reverse-lookup/zipball/4419fcdb5eabb9caa61a27c7a1db532a6b55dd18", + "reference": "4419fcdb5eabb9caa61a27c7a1db532a6b55dd18", + "shasum": "", + "mirrors": [ + { + "url": "https://mirrors.cloud.tencent.com/composer/dists/%package%/%reference%.%type%", + "preferred": true + } + ] + }, + "require": { + "php": "^5.6 || ^7.0" + }, + "require-dev": { + "phpunit/phpunit": "^5.7 || ^6.0" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "1.0.x-dev" + } + }, + "autoload": { + "classmap": [ + "src/" + ] + }, + "notification-url": "https://packagist.jp/downloads/", + "license": [ + "BSD-3-Clause" + ], + "authors": [ + { + "name": "Sebastian Bergmann", + "email": "sebastian@phpunit.de" + } + ], + "description": "Looks up which function or method a line of code belongs to", + "homepage": "https://github.com/sebastianbergmann/code-unit-reverse-lookup/", + "time": "2017-03-04T06:30:41+00:00" + }, + { + "name": "sebastian/comparator", + "version": "2.1.3", + "source": { + "type": "git", + "url": "https://github.com/sebastianbergmann/comparator.git", + "reference": "34369daee48eafb2651bea869b4b15d75ccc35f9" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/sebastianbergmann/comparator/zipball/34369daee48eafb2651bea869b4b15d75ccc35f9", + "reference": "34369daee48eafb2651bea869b4b15d75ccc35f9", + "shasum": "", + "mirrors": [ + { + "url": "https://mirrors.cloud.tencent.com/composer/dists/%package%/%reference%.%type%", + "preferred": true + } + ] + }, + "require": { + "php": "^7.0", + "sebastian/diff": "^2.0 || ^3.0", + "sebastian/exporter": "^3.1" + }, + "require-dev": { + "phpunit/phpunit": "^6.4" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "2.1.x-dev" + } + }, + "autoload": { + "classmap": [ + "src/" + ] + }, + "notification-url": "https://packagist.jp/downloads/", + "license": [ + "BSD-3-Clause" + ], + "authors": [ + { + "name": "Jeff Welch", + "email": "whatthejeff@gmail.com" + }, + { + "name": "Volker Dusch", + "email": "github@wallbash.com" + }, + { + "name": "Bernhard Schussek", + "email": "bschussek@2bepublished.at" + }, + { + "name": "Sebastian Bergmann", + "email": "sebastian@phpunit.de" + } + ], + "description": "Provides the functionality to compare PHP values for equality", + "homepage": "https://github.com/sebastianbergmann/comparator", + "keywords": [ + "comparator", + "compare", + "equality" + ], + "time": "2018-02-01T13:46:46+00:00" + }, + { + "name": "sebastian/diff", + "version": "2.0.1", + "source": { + "type": "git", + "url": "https://github.com/sebastianbergmann/diff.git", + "reference": "347c1d8b49c5c3ee30c7040ea6fc446790e6bddd" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/sebastianbergmann/diff/zipball/347c1d8b49c5c3ee30c7040ea6fc446790e6bddd", + "reference": "347c1d8b49c5c3ee30c7040ea6fc446790e6bddd", + "shasum": "", + "mirrors": [ + { + "url": "https://mirrors.cloud.tencent.com/composer/dists/%package%/%reference%.%type%", + "preferred": true + } + ] + }, + "require": { + "php": "^7.0" + }, + "require-dev": { + "phpunit/phpunit": "^6.2" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "2.0-dev" + } + }, + "autoload": { + "classmap": [ + "src/" + ] + }, + "notification-url": "https://packagist.jp/downloads/", + "license": [ + "BSD-3-Clause" + ], + "authors": [ + { + "name": "Kore Nordmann", + "email": "mail@kore-nordmann.de" + }, + { + "name": "Sebastian Bergmann", + "email": "sebastian@phpunit.de" + } + ], + "description": "Diff implementation", + "homepage": "https://github.com/sebastianbergmann/diff", + "keywords": [ + "diff" + ], + "time": "2017-08-03T08:09:46+00:00" + }, + { + "name": "sebastian/environment", + "version": "3.1.0", + "source": { + "type": "git", + "url": "https://github.com/sebastianbergmann/environment.git", + "reference": "cd0871b3975fb7fc44d11314fd1ee20925fce4f5" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/sebastianbergmann/environment/zipball/cd0871b3975fb7fc44d11314fd1ee20925fce4f5", + "reference": "cd0871b3975fb7fc44d11314fd1ee20925fce4f5", + "shasum": "", + "mirrors": [ + { + "url": "https://mirrors.cloud.tencent.com/composer/dists/%package%/%reference%.%type%", + "preferred": true + } + ] + }, + "require": { + "php": "^7.0" + }, + "require-dev": { + "phpunit/phpunit": "^6.1" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "3.1.x-dev" + } + }, + "autoload": { + "classmap": [ + "src/" + ] + }, + "notification-url": "https://packagist.jp/downloads/", + "license": [ + "BSD-3-Clause" + ], + "authors": [ + { + "name": "Sebastian Bergmann", + "email": "sebastian@phpunit.de" + } + ], + "description": "Provides functionality to handle HHVM/PHP environments", + "homepage": "http://www.github.com/sebastianbergmann/environment", + "keywords": [ + "Xdebug", + "environment", + "hhvm" + ], + "time": "2017-07-01T08:51:00+00:00" + }, + { + "name": "sebastian/exporter", + "version": "3.1.2", + "source": { + "type": "git", + "url": "https://github.com/sebastianbergmann/exporter.git", + "reference": "68609e1261d215ea5b21b7987539cbfbe156ec3e" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/sebastianbergmann/exporter/zipball/68609e1261d215ea5b21b7987539cbfbe156ec3e", + "reference": "68609e1261d215ea5b21b7987539cbfbe156ec3e", + "shasum": "", + "mirrors": [ + { + "url": "https://mirrors.cloud.tencent.com/composer/dists/%package%/%reference%.%type%", + "preferred": true + } + ] + }, + "require": { + "php": "^7.0", + "sebastian/recursion-context": "^3.0" + }, + "require-dev": { + "ext-mbstring": "*", + "phpunit/phpunit": "^6.0" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "3.1.x-dev" + } + }, + "autoload": { + "classmap": [ + "src/" + ] + }, + "notification-url": "https://packagist.jp/downloads/", + "license": [ + "BSD-3-Clause" + ], + "authors": [ + { + "name": "Sebastian Bergmann", + "email": "sebastian@phpunit.de" + }, + { + "name": "Jeff Welch", + "email": "whatthejeff@gmail.com" + }, + { + "name": "Volker Dusch", + "email": "github@wallbash.com" + }, + { + "name": "Adam Harvey", + "email": "aharvey@php.net" + }, + { + "name": "Bernhard Schussek", + "email": "bschussek@gmail.com" + } + ], + "description": "Provides the functionality to export PHP variables for visualization", + "homepage": "http://www.github.com/sebastianbergmann/exporter", + "keywords": [ + "export", + "exporter" + ], + "time": "2019-09-14T09:02:43+00:00" + }, + { + "name": "sebastian/global-state", + "version": "2.0.0", + "source": { + "type": "git", + "url": "https://github.com/sebastianbergmann/global-state.git", + "reference": "e8ba02eed7bbbb9e59e43dedd3dddeff4a56b0c4" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/sebastianbergmann/global-state/zipball/e8ba02eed7bbbb9e59e43dedd3dddeff4a56b0c4", + "reference": "e8ba02eed7bbbb9e59e43dedd3dddeff4a56b0c4", + "shasum": "", + "mirrors": [ + { + "url": "https://mirrors.cloud.tencent.com/composer/dists/%package%/%reference%.%type%", + "preferred": true + } + ] + }, + "require": { + "php": "^7.0" + }, + "require-dev": { + "phpunit/phpunit": "^6.0" + }, + "suggest": { + "ext-uopz": "*" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "2.0-dev" + } + }, + "autoload": { + "classmap": [ + "src/" + ] + }, + "notification-url": "https://packagist.jp/downloads/", + "license": [ + "BSD-3-Clause" + ], + "authors": [ + { + "name": "Sebastian Bergmann", + "email": "sebastian@phpunit.de" + } + ], + "description": "Snapshotting of global state", + "homepage": "http://www.github.com/sebastianbergmann/global-state", + "keywords": [ + "global state" + ], + "time": "2017-04-27T15:39:26+00:00" + }, + { + "name": "sebastian/object-enumerator", + "version": "3.0.3", + "source": { + "type": "git", + "url": "https://github.com/sebastianbergmann/object-enumerator.git", + "reference": "7cfd9e65d11ffb5af41198476395774d4c8a84c5" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/sebastianbergmann/object-enumerator/zipball/7cfd9e65d11ffb5af41198476395774d4c8a84c5", + "reference": "7cfd9e65d11ffb5af41198476395774d4c8a84c5", + "shasum": "", + "mirrors": [ + { + "url": "https://mirrors.cloud.tencent.com/composer/dists/%package%/%reference%.%type%", + "preferred": true + } + ] + }, + "require": { + "php": "^7.0", + "sebastian/object-reflector": "^1.1.1", + "sebastian/recursion-context": "^3.0" + }, + "require-dev": { + "phpunit/phpunit": "^6.0" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "3.0.x-dev" + } + }, + "autoload": { + "classmap": [ + "src/" + ] + }, + "notification-url": "https://packagist.jp/downloads/", + "license": [ + "BSD-3-Clause" + ], + "authors": [ + { + "name": "Sebastian Bergmann", + "email": "sebastian@phpunit.de" + } + ], + "description": "Traverses array structures and object graphs to enumerate all referenced objects", + "homepage": "https://github.com/sebastianbergmann/object-enumerator/", + "time": "2017-08-03T12:35:26+00:00" + }, + { + "name": "sebastian/object-reflector", + "version": "1.1.1", + "source": { + "type": "git", + "url": "https://github.com/sebastianbergmann/object-reflector.git", + "reference": "773f97c67f28de00d397be301821b06708fca0be" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/sebastianbergmann/object-reflector/zipball/773f97c67f28de00d397be301821b06708fca0be", + "reference": "773f97c67f28de00d397be301821b06708fca0be", + "shasum": "", + "mirrors": [ + { + "url": "https://mirrors.cloud.tencent.com/composer/dists/%package%/%reference%.%type%", + "preferred": true + } + ] + }, + "require": { + "php": "^7.0" + }, + "require-dev": { + "phpunit/phpunit": "^6.0" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "1.1-dev" + } + }, + "autoload": { + "classmap": [ + "src/" + ] + }, + "notification-url": "https://packagist.jp/downloads/", + "license": [ + "BSD-3-Clause" + ], + "authors": [ + { + "name": "Sebastian Bergmann", + "email": "sebastian@phpunit.de" + } + ], + "description": "Allows reflection of object attributes, including inherited and non-public ones", + "homepage": "https://github.com/sebastianbergmann/object-reflector/", + "time": "2017-03-29T09:07:27+00:00" + }, + { + "name": "sebastian/recursion-context", + "version": "3.0.0", + "source": { + "type": "git", + "url": "https://github.com/sebastianbergmann/recursion-context.git", + "reference": "5b0cd723502bac3b006cbf3dbf7a1e3fcefe4fa8" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/sebastianbergmann/recursion-context/zipball/5b0cd723502bac3b006cbf3dbf7a1e3fcefe4fa8", + "reference": "5b0cd723502bac3b006cbf3dbf7a1e3fcefe4fa8", + "shasum": "", + "mirrors": [ + { + "url": "https://mirrors.cloud.tencent.com/composer/dists/%package%/%reference%.%type%", + "preferred": true + } + ] + }, + "require": { + "php": "^7.0" + }, + "require-dev": { + "phpunit/phpunit": "^6.0" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "3.0.x-dev" + } + }, + "autoload": { + "classmap": [ + "src/" + ] + }, + "notification-url": "https://packagist.jp/downloads/", + "license": [ + "BSD-3-Clause" + ], + "authors": [ + { + "name": "Jeff Welch", + "email": "whatthejeff@gmail.com" + }, + { + "name": "Sebastian Bergmann", + "email": "sebastian@phpunit.de" + }, + { + "name": "Adam Harvey", + "email": "aharvey@php.net" + } + ], + "description": "Provides functionality to recursively process PHP variables", + "homepage": "http://www.github.com/sebastianbergmann/recursion-context", + "time": "2017-03-03T06:23:57+00:00" + }, + { + "name": "sebastian/resource-operations", + "version": "1.0.0", + "source": { + "type": "git", + "url": "https://github.com/sebastianbergmann/resource-operations.git", + "reference": "ce990bb21759f94aeafd30209e8cfcdfa8bc3f52" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/sebastianbergmann/resource-operations/zipball/ce990bb21759f94aeafd30209e8cfcdfa8bc3f52", + "reference": "ce990bb21759f94aeafd30209e8cfcdfa8bc3f52", + "shasum": "", + "mirrors": [ + { + "url": "https://mirrors.cloud.tencent.com/composer/dists/%package%/%reference%.%type%", + "preferred": true + } + ] + }, + "require": { + "php": ">=5.6.0" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "1.0.x-dev" + } + }, + "autoload": { + "classmap": [ + "src/" + ] + }, + "notification-url": "https://packagist.jp/downloads/", + "license": [ + "BSD-3-Clause" + ], + "authors": [ + { + "name": "Sebastian Bergmann", + "email": "sebastian@phpunit.de" + } + ], + "description": "Provides a list of PHP built-in functions that operate on resources", + "homepage": "https://www.github.com/sebastianbergmann/resource-operations", + "time": "2015-07-28T20:34:47+00:00" + }, + { + "name": "sebastian/version", + "version": "2.0.1", + "source": { + "type": "git", + "url": "https://github.com/sebastianbergmann/version.git", + "reference": "99732be0ddb3361e16ad77b68ba41efc8e979019" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/sebastianbergmann/version/zipball/99732be0ddb3361e16ad77b68ba41efc8e979019", + "reference": "99732be0ddb3361e16ad77b68ba41efc8e979019", + "shasum": "", + "mirrors": [ + { + "url": "https://mirrors.cloud.tencent.com/composer/dists/%package%/%reference%.%type%", + "preferred": true + } + ] + }, + "require": { + "php": ">=5.6" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "2.0.x-dev" + } + }, + "autoload": { + "classmap": [ + "src/" + ] + }, + "notification-url": "https://packagist.jp/downloads/", + "license": [ + "BSD-3-Clause" + ], + "authors": [ + { + "name": "Sebastian Bergmann", + "email": "sebastian@phpunit.de", + "role": "lead" + } + ], + "description": "Library that helps with managing the version number of Git-hosted PHP projects", + "homepage": "https://github.com/sebastianbergmann/version", + "time": "2016-10-03T07:35:21+00:00" + }, + { + "name": "symfony/polyfill-ctype", + "version": "v1.14.0", + "source": { + "type": "git", + "url": "https://github.com/symfony/polyfill-ctype.git", + "reference": "fbdeaec0df06cf3d51c93de80c7eb76e271f5a38" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/symfony/polyfill-ctype/zipball/fbdeaec0df06cf3d51c93de80c7eb76e271f5a38", + "reference": "fbdeaec0df06cf3d51c93de80c7eb76e271f5a38", + "shasum": "", + "mirrors": [ + { + "url": "https://mirrors.cloud.tencent.com/composer/dists/%package%/%reference%.%type%", + "preferred": true + } + ] + }, + "require": { + "php": ">=5.3.3" + }, + "suggest": { + "ext-ctype": "For best performance" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "1.14-dev" + } + }, + "autoload": { + "psr-4": { + "Symfony\\Polyfill\\Ctype\\": "" + }, + "files": [ + "bootstrap.php" + ] + }, + "notification-url": "https://packagist.jp/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Gert de Pagter", + "email": "BackEndTea@gmail.com" + }, + { + "name": "Symfony Community", + "homepage": "https://symfony.com/contributors" + } + ], + "description": "Symfony polyfill for ctype functions", + "homepage": "https://symfony.com", + "keywords": [ + "compatibility", + "ctype", + "polyfill", + "portable" + ], + "time": "2020-01-13T11:15:53+00:00" + }, + { + "name": "theseer/tokenizer", + "version": "1.1.3", + "source": { + "type": "git", + "url": "https://github.com/theseer/tokenizer.git", + "reference": "11336f6f84e16a720dae9d8e6ed5019efa85a0f9" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/theseer/tokenizer/zipball/11336f6f84e16a720dae9d8e6ed5019efa85a0f9", + "reference": "11336f6f84e16a720dae9d8e6ed5019efa85a0f9", + "shasum": "", + "mirrors": [ + { + "url": "https://mirrors.cloud.tencent.com/composer/dists/%package%/%reference%.%type%", + "preferred": true + } + ] + }, + "require": { + "ext-dom": "*", + "ext-tokenizer": "*", + "ext-xmlwriter": "*", + "php": "^7.0" + }, + "type": "library", + "autoload": { + "classmap": [ + "src/" + ] + }, + "notification-url": "https://packagist.jp/downloads/", + "license": [ + "BSD-3-Clause" + ], + "authors": [ + { + "name": "Arne Blankerts", + "email": "arne@blankerts.de", + "role": "Developer" + } + ], + "description": "A small library for converting tokenized PHP source code into XML and potentially other formats", + "time": "2019-06-13T22:48:21+00:00" + }, + { + "name": "webmozart/assert", + "version": "1.7.0", + "source": { + "type": "git", + "url": "https://github.com/webmozart/assert.git", + "reference": "aed98a490f9a8f78468232db345ab9cf606cf598" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/webmozart/assert/zipball/aed98a490f9a8f78468232db345ab9cf606cf598", + "reference": "aed98a490f9a8f78468232db345ab9cf606cf598", + "shasum": "", + "mirrors": [ + { + "url": "https://mirrors.cloud.tencent.com/composer/dists/%package%/%reference%.%type%", + "preferred": true + } + ] + }, + "require": { + "php": "^5.3.3 || ^7.0", + "symfony/polyfill-ctype": "^1.8" + }, + "conflict": { + "vimeo/psalm": "<3.6.0" + }, + "require-dev": { + "phpunit/phpunit": "^4.8.36 || ^7.5.13" + }, + "type": "library", + "autoload": { + "psr-4": { + "Webmozart\\Assert\\": "src/" + } + }, + "notification-url": "https://packagist.jp/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Bernhard Schussek", + "email": "bschussek@gmail.com" + } + ], + "description": "Assertions to validate method input/output with nice error messages.", + "keywords": [ + "assert", + "check", + "validate" + ], + "time": "2020-02-14T12:15:55+00:00" + } + ], + "aliases": [], + "minimum-stability": "stable", + "stability-flags": [], + "prefer-stable": false, + "prefer-lowest": false, + "platform": { + "php": ">=5.6", + "ext-gmp": "*", + "ext-curl": "*" + }, + "platform-dev": [] +} diff --git a/example/AelfTest.php b/example/AelfTest.php new file mode 100644 index 00000000..eca0cc3b --- /dev/null +++ b/example/AelfTest.php @@ -0,0 +1,221 @@ +Aelf = new Aelf($url); + $this->OPREATIONADDRESS ='18.223.158.83:7003'; + + $AelfECDSA = new AelfECDSA(); + $this->private_key = 'be3abe5c1439899ac2efd0001e15715fd989a3ae11f09e1cb95d320cd4993e2a'; + $AelfECDSA->setPrivateKey($this->private_key); + $this->public_key = $AelfECDSA->getUncompressedPubKey(); + $this->address= $this->Aelf->getAddressFromPrivateKey($this->private_key); + $this->base58 = new Base58(); + } + + + public function testgetChainStatus(){ + $chain_status =$this->Aelf->getChainStatus(); + print_r($chain_status); + $this->assertTrue($chain_status['BestChainHeight'] > 0); + $chain_id = $this->Aelf->getChainId(); + print_r($chain_id); + $this->assertTrue($chain_id == 9992731); + + } + + public function testBlockapi(){ + $blockHeight = $this->Aelf->getBlockHeight(); + print_r('# getBlockHeight'); + echo '
'; + print_r($blockHeight); + $this->assertTrue($blockHeight > 0); + $block = $this->Aelf->getBlockByHeight(1,true); + + $this->assertTrue($block['Header']['Height'] ==1 ); + + $block2 = $this->Aelf->getBlockByHash($block['BlockHash'],false); + + + $this->assertTrue($block2['Header']['Height'] == 1); + return $block2['Header']['Height']; + + } + + public function testgetTransactionResultApi(){ + $block = $this->Aelf->getBlockByHeight(1,true); + + $transaction_result = $this->Aelf->getTransactionResult($block['Body']['Transactions'][0]); + print_r('# get_transaction_result' ); + print_r($transaction_result); + $this->assertTrue($transaction_result['Status'] == 'MINED'); + $transaction_results = $this->Aelf->getTransactionResults($block['BlockHash']); + print_r('# get_transaction_results'); + print_r($transaction_results); + $merkle_path = $this->Aelf->getMerklePathByTransactionId($block['Body']['Transactions'][0]); + $this->assertTrue(is_array($merkle_path['MerklePathNodes'])); + } + public function testexecuteTransaction(){ + $toAddress = $this->Aelf->getGenesisContractAddress(); + $methodName = "GetContractAddressByName"; + $bytes =hex2bin(hash('sha256','AElf.ContractNames.TokenConverter')); + $transaction = $this->Aelf->generateTransaction($this->address, $toAddress, $methodName, $bytes); + + $signature = $this->Aelf->signTransaction($this->private_key, $transaction); + + $transaction->setSignature(hex2bin($signature)); + + $executeTransactionDtoObj =['RawTransaction'=>bin2hex($transaction->serializeToString())]; + $response = $this->Aelf->executeTransaction($executeTransactionDtoObj); + $address = new Address(); + $address->mergeFromString(hex2bin($response)); + $base58Str = $this->base58->encodeChecked($address->getValue()); + $aa = $this->Aelf->getContractAddressByName($this->private_key,$bytes); + + $this->assertTrue($aa == $base58Str); + + } + public function testRawTransactionApi(){ + $status = $this->Aelf->getChainStatus(); + $Params = base64_encode(hex2bin(hash('sha256', 'AElf.ContractNames.Consensus'))); + $param = array('value'=>$Params); + $transaction = [ + "from" =>$this->Aelf->getAddressFromPrivateKey($this->private_key), + "to"=>$this->Aelf->getGenesisContractAddress(), + "refBlockNumber"=>$status['BestChainHeight'], + "refBlockHash"=> $status['BestChainHash'], + "methodName"=> "GetContractAddressByName", + "params"=> json_encode($param) + ]; + $raw_transaction = $this->Aelf->createRawTransaction($transaction); + print_r($raw_transaction.'
'); + $transactionId =hash('sha256',hex2bin($raw_transaction['RawTransaction'])); + + $sign = $this->Aelf->getSignatureWithPrivateKey($this->private_key,$transactionId); + + $transaction1 = array('RawTransaction'=>$raw_transaction['RawTransaction'],'signature'=>$sign); + $execute = $this->Aelf->executeRawTransaction($transaction1); + print_r($execute); + $transaction2 = array('Transaction'=>$raw_transaction['RawTransaction'],'signature'=>$sign,'returnTransaction'=>true); + $execute1 = $this->Aelf->sendRawTransaction($transaction2); + print_r($execute1); + } + public function testgetAddressFromPubKeyTest(){ + //$pubKeyAddress = $this->Aelf->getAddressFromPubKey($this->public_key); + $pubKeyAddress = $this->Aelf->getAddressFromPubKey('04166cf4be901dee1c21f3d97b9e4818f229bec72a5ecd56b5c4d6ce7abfc3c87e25c36fd279db721acf4258fb489b4a4406e6e6e467935d06990be9d134e5741c'); + + print_r($pubKeyAddress); + $this->assertTrue($pubKeyAddress == 'SD6BXDrKT2syNd1WehtPyRo3dPBiXqfGUj8UJym7YP9W9RynM'); + } + + public function testSendTransactionApi(){ + $currentHeight = $this->Aelf->getBlockHeight(); + $block = $this->Aelf->getBlockByHeight($currentHeight,False); + $params = hex2bin(hash('sha256','AElf.ContractNames.Vote')); + $transaction = $this->buildTransaction($this->Aelf->getGenesisContractAddress(),'GetContractAddressByName',$params); + $Transactioninput = new TransferInput(); + $executeTransactionDtoObj =['RawTransaction'=>bin2hex($transaction->serializeToString())]; + $result = $this->Aelf->sendTransaction($executeTransactionDtoObj); + print_r($result); + $this->assertTrue($result['TransactionId'] != ""); + } + public function testsendTransactions() { + $toAddress = $this->Aelf->getGenesisContractAddress(); + $param1 =hex2bin(hash('sha256','AElf.ContractNames.Token')); + $param2 =hex2bin(hash('sha256','AElf.ContractNames.Vote')); + $methodName = "GetContractAddressByName"; + $tmp = [$param1,$param2]; + foreach($tmp as $k){ + $transactionObj = $this->buildTransaction($toAddress,$methodName,$k); + $rawTransactions = bin2hex($transactionObj->serializeToString()); + $sendTransactionsInputs = ['RawTransactions'=>$rawTransactions]; + $listString = $this->Aelf->sendTransactions($sendTransactionsInputs); + print_r($listString); + } + + } + public function testTxPoolApi(){ + $txPoolStatus = $this->Aelf->getTransactionPoolStatus(); + print_r('# get_transaction_pool_status:'); + print_r($txPoolStatus); + $this->assertTrue($txPoolStatus['Queued'] >= 0); + } + + public function testTaskQueueApi(){ + $task_queue_status = $this->Aelf->getTaskQueueStatus(); + print_r($task_queue_status); + $this->assertTrue(count($task_queue_status) > 0); + } + + public function testNetworkApi(){ + print('getNetworkInfo'); + echo "
"; + print_r($this->Aelf->getNetworkInfo()); + echo "
"; + print('remove_peer'); + echo "
"; + var_dump($this->Aelf->removePeer($this->OPREATIONADDRESS)); + echo "
"; + print('add_peer'); + print_r($this->Aelf->addPeer($this->OPREATIONADDRESS)); + print_r($this->Aelf->getPeers(true)); + echo "
"; + + } + + public function testGetContractFilCeDescriptorSet(){ + $blockHeight = $this->Aelf->getBlockHeight(); + $this->assertTrue($blockHeight > 0); + $blockDto = $this->Aelf->getBlockByHeight($blockHeight, false); + $transactionResultDtoList = $this->Aelf->getTransactionResults($blockDto['BlockHash'],0,10); + + foreach($transactionResultDtoList as $v){ + + $this->Aelf->getContractFilCeDescriptorSet($v['Transaction']['To']); + } + + } + + + + public function testHelpers(){ + $is_connected =$this->Aelf->isConnected(); + $this->assertTrue($is_connected); + } + + public function testgetFormattedAddress(){ + $addressVal = $this->Aelf->getFormattedAddress($this->private_key, $this->address); + $this->assertTrue(("ELF_".$this->address."_AELF")==$addressVal); + } + + private function buildTransaction($toaddress,$methodName,$params){ + + $transactionObj = $this->Aelf->generateTransaction($this->address,$toaddress,$methodName,$params); + + $signature = $this->Aelf->signTransaction($this->private_key,$transactionObj); + $transactionObj->setSignature(hex2bin($signature)); + + return $transactionObj; + } +} +$r= new AelfTest(); +$r->setUp(); +$r->testgetChainStatus(); +?> \ No newline at end of file diff --git a/src/Aelf.php b/src/Aelf.php new file mode 100644 index 00000000..df0f7bd5 --- /dev/null +++ b/src/Aelf.php @@ -0,0 +1,402 @@ +url= $url; + + if($version != null){ + $this-$version = $version; + } + $this->getBlockChainSdkObj(); + $this->getNetSdkObj(); + $this->base58 = new Base58(); + } + + public function getBlockChainSdkObj(){ + + if($this->blockChainSdk==NULL){ + return $this->blockChainSdk = new BlockChainSdk($this->url,$this->version); + }else{ + return $this->blockChainSdk; + } + } + + public function getNetSdkObj(){ + if($this->netSdk == NULL ){ + $this->netSdk = new NetSdk($this->url,$this->version); + }else { + return $this->netSdk; + } + } + + /** + * Get the height of the current chain. wa:/api/blockChain/blockHeight + */ + public function getBlockHeight(){ + + return $this->getBlockChainSdkObj()->getBlockHeight(); + } + + + /** + * Get information about a given block by block hash. Otionally with the list of its transactions. + * wa://api/blockChain/block?includeTransactions={includeTransactions} + */ + public function getBlockByHash($blockHash,$includeTransactions = false){ + return $this->getBlockChainSdkObj()->getBlockByHash($blockHash, $includeTransactions); + } + + /** + * Get information of a block by specified height. Optional whether to include transaction + * information. wa://api/blockChain/blockByHeight?includeTransactions={includeTransactions} + */ + public function getBlockByHeight($blockHeight,$includeTransactions = false){ + //$includeTransactions The default is false + return $this->getBlockChainSdkObj()->getBlockByHeight($blockHeight, $includeTransactions); + } + + /** + * Get the current status of the block chain. wa:/api/blockChain/chainStatus + */ + public function getChainStatus(){ + return $this->getBlockChainSdkObj()->getChainStatus(); + } + + /** + * Get the protobuf definitions related to a contract /api/blockChain/contractFileDescriptorSet. + */ + public function getContractFilCeDescriptorSet($address){ + return $this->getBlockChainSdkObj()->getContractFilCeDescriptorSet($address); + } + + /** + * Gets the status information of the task queue wa:/api/blockChain/taskQueueStatus. + */ + public function getTaskQueueStatus(){ + return $this->getBlockChainSdkObj()->getTaskQueueStatus(); + } + + /** + * Gets information about the current transaction pool.wa:/api/blockChain/transactionPoolStatus + */ + public function getTransactionPoolStatus(){ + return $this->getBlockChainSdkObj()->getTransactionPoolStatus(); + } + + /** + * Call a read-only method of a contract. wa:/api/blockChain/executeTransaction + */ + public function executeTransaction($input){ + return $this->getBlockChainSdkObj()->executeTransaction($input); + } + + /** + * Creates an unsigned serialized transaction wa:/api/blockChain/rawTransaction. + */ + public function createRawTransaction($input) + { + return $this->getBlockChainSdkObj()->createRawTransaction($input); + } + + /** + * Call a method of a contract by given serialized str wa:/api/blockChain/executeRawTransaction. + */ + public function executeRawTransaction($input){ + return $this->getBlockChainSdkObj()->executeRawTransaction($input); + } + + /** + * Broadcast a serialized transaction. wa:/api/blockChain/sendRawTransaction + */ + public function sendRawTransaction($input){ + return $this->getBlockChainSdkObj()->sendRawTransaction($input); + } + + /** + * Broadcast a transaction wa:/api/blockChain/sendTransaction. + */ + public function sendTransaction($input){ + return $this->getBlockChainSdkObj()->sendTransaction($input); + } + + /** + * Broadcast volume transactions wa:/api/blockChain/sendTransactions. + */ + public function sendTransactions($input){ + return $this->getBlockChainSdkObj()->sendTransactions($input); + } + + /** + * Get the current status of a transaction wa:/api/blockChain/transactionResult. + */ + public function getTransactionResult($transactionId){ + return $this->getBlockChainSdkObj()->getTransactionResult($transactionId); + } + + + /** + * Get multiple transaction results. wa:/api/blockChain/transactionResults + */ + public function getTransactionResults($blockHash,$offset = 0,$limit = 10) + { + return $this->getBlockChainSdkObj()->getTransactionResults($blockHash,$offset,$limit); + } + + /** + * Get merkle path of a transaction. wa:/api/blockChain/merklePathByTransactionId + */ + public function getMerklePathByTransactionId($transactionId) { + return $this->getBlockChainSdkObj()->getMerklePathByTransactionId($transactionId); + } + + /** + * Get id of the chain. + */ + public function getChainId(){ + return $this->getBlockChainSdkObj()->getChainId(); + } + + /** + * Attempts to add a node to the connected network nodes wa:/api/net/peer. + */ + public function addPeer($input){ + return $this->getNetSdkObj()->addPeer($input); + } + + /** + * Attempts to remove a node from the connected network nodes wa:/api/net/peer. + */ + public function removePeer($address){ + return $this->getNetSdkObj()->removePeer($address); + } + + /** + * Gets information about the peer nodes of the current node.Optional whether to include metrics. + * wa:/api/net/peers?withMetrics=false + */ + public function getPeers($withMetrics){ + return $this->getNetSdkObj()->getPeers($withMetrics); + } + + /** + * Get information about the node’s connection to the network. wa:/api/net/networkInfo + */ + public function getNetworkInfo(){ + return $this->getNetSdkObj()->getNetworkInfo(); + } + + /** + * Build a transaction from the input parameters. + */ + public function generateTransaction($from,$to,$methodName,$params){ + $chainStatus = $this->getBlockChainSdkObj()->getChainStatus(); + + $Bit = new AelfECDSA(); + $from = $Bit->decodeChecked($from); + $to = $Bit->decodeChecked($to); + $transaction = new Transaction(); + $Faddress = new Address(); + $Taddress = new Address(); + $Faddress->setValue($from); + $Taddress->setValue($to); + $transaction->setFromAddress($Faddress); + $transaction->setToAddress($Taddress); + $transaction->setMethodName($methodName); + $Hash = new Hash(); + $Hash->setValue($params); + $transaction->setParams($Hash->serializeToString()); + $transaction->setRefBlockNumber($chainStatus['BestChainHeight']); + $transaction->setRefBlockPrefix(substr(hex2bin($chainStatus['BestChainHash']),0,4)); + return $transaction; + + } + + /** + * Sign a transaction using private key. + */ + public function signTransaction($privateKeyHex,$transaction) + { + $transactionData = sha256($transaction->serializeToString()); + + return $this->getSignatureWithPrivateKey($privateKeyHex,$transactionData); + } + + /** + * Get the address of genesis contract. + * + * @return address + */ + public function getGenesisContractAddress(){ + $chainstatusDto = $this->getBlockChainSdkObj()->getChainStatus(); + return $chainstatusDto['GenesisContractAddress']; + } + + /** + * Get the account address through the public key. + * + * @param pubKey pubKey hex + * @return Str + */ + public function getAddressFromPubKey($pubKey = null) { + $aelfkey = new AelfECDSA(); + $address = $aelfkey->hash256(hex2bin($pubKey)); + //checksum + $address = $address.substr($aelfkey->hash256(hex2bin($address)), 0, 8); + $address = $aelfkey->base58_encode($address); + return $address; + } + /** + * Convert the Address to the displayed string:symbol_base58-string_base58-string-chain-id. + */ + public function getFormattedAddress($privateKey,$address){ + $chainIdString = $this->getBlockChainSdkObj()->getChainStatus()['ChainId']; + $fromAddress = $this->getAddressFromPrivateKey($privateKey); + + $toAddress = $this->getContractAddressByName($privateKey,hex2bin(sha256('AElf.ContractNames.Token'))); + + $methodName = "GetPrimaryTokenSymbol"; + $bytes = ''; + $transaction = $this->generateTransaction($fromAddress,$toAddress,$methodName,$bytes); + $signature = $this->signTransaction($privateKey,$transaction); + $transaction->setSignature(hex2bin($signature)); + $executeTransactionDto = ['RawTransaction'=>bin2hex($transaction->serializeToString())]; + $response = $this->getBlockChainSdkObj()->executeTransaction($executeTransactionDto); + $symbol = new StringInput(); + $symbol->mergeFromString(hex2bin($response)); + $symbolstr = $symbol->getStringValue(); + return $symbolstr."_". $address. "_" .$chainIdString; + } + + /** + * new generateKeyPairInfo; + */ + public function generateKeyPairInfo() + { + $keyPair = new AelfECDSA(); + $keyPair->generateRandomPrivateKey(); + $privateKey = $keyPair->getPrivateKey(); + $publicKey = $keyPair->getUncompressedPubKey(); + $address = $keyPair->getUncompressedAddress(); + $keyPairInfo=array('privateKey'=>$privateKey,'publicKey'=>$publicKey,'address'=>$address); + return $keyPairInfo; + } + + /** + * Get address of a contract by given contractNameHash. + */ + public function getContractAddressByName($privateKey,$contractNameHash) + { + $from = $this->getAddressFromPrivateKey($privateKey); + $to = $this->getGenesisContractAddress(); + $methodName = 'GetContractAddressByName'; + + $transaction = $this->generateTransaction($from,$to,$methodName,$contractNameHash); + + $signature = $this->signTransaction($privateKey, $transaction); + + $transaction->setSignature(hex2bin($signature)); + + $executeTransactionDto = ['RawTransaction'=>bin2hex($transaction->serializeToString())]; + + $response = $this->getBlockChainSdkObj()->executeTransaction($executeTransactionDto); + $address = new Address(); + $address->mergeFromString(hex2bin($response)); + + $base58Str = $this->base58->encodeChecked($address->getValue()); + + return $base58Str; + } + + /** + * Get address of a contract by given contractNameHash. + */ + public function getAddressFromPrivateKey($privateKey) { + $aelfkey = new AelfECDSA(); + $aelfkey->setPrivateKey($privateKey); + $address = $aelfkey->getUncompressedAddress(); + return $address; + } + + /** + * Get the private sha256 signature. + */ + public function getSignatureWithPrivateKey($privateKey,$txData){ + $secp256k1 = new Secp256k1(); + + $signature = $secp256k1->sign($txData, $privateKey); + // get r + $r = $signature->getR(); + // get s + $s = $signature->getS(); + // get recovery param + $v = $signature->getRecoveryParam(); + // encode to hex + $serializer = new HexSignatureSerializer(); + $signatureString = $serializer->serialize($signature); + + // or you can call toHex + $signatureString = $signature->toHex(); + + if(strlen((string)$v)==1){ + $v = "0".$v; + } + return $signatureString.$v; + } + + /** + * Verify whether $this sdk successfully connects the chain. + * + * @return IsConnected or not + */ + public function isConnected() { + + + try { + $this->getBlockChainSdkObj()->getChainStatus(); + return true; + + } catch (Exception $e){ + return false; + + } + } + + +} diff --git a/src/GPBMetadata/Google/Protobuf/Any.php b/src/GPBMetadata/Google/Protobuf/Any.php new file mode 100644 index 00000000..22cc2500 --- /dev/null +++ b/src/GPBMetadata/Google/Protobuf/Any.php @@ -0,0 +1,30 @@ +internalAddGeneratedFile(hex2bin( + "0acd010a19676f6f676c652f70726f746f6275662f616e792e70726f746f" . + "120f676f6f676c652e70726f746f62756622260a03416e7912100a087479" . + "70655f75726c180120012809120d0a0576616c756518022001280c426f0a" . + "13636f6d2e676f6f676c652e70726f746f6275664208416e7950726f746f" . + "50015a256769746875622e636f6d2f676f6c616e672f70726f746f627566" . + "2f7074797065732f616e79a20203475042aa021e476f6f676c652e50726f" . + "746f6275662e57656c6c4b6e6f776e5479706573620670726f746f33" + )); + + static::$is_initialized = true; + } +} + diff --git a/src/GPBMetadata/Google/Protobuf/Api.php b/src/GPBMetadata/Google/Protobuf/Api.php new file mode 100644 index 00000000..b18e0d33 --- /dev/null +++ b/src/GPBMetadata/Google/Protobuf/Api.php @@ -0,0 +1,49 @@ +internalAddGeneratedFile(hex2bin( + "0ac8050a19676f6f676c652f70726f746f6275662f6170692e70726f746f" . + "120f676f6f676c652e70726f746f6275661a1a676f6f676c652f70726f74" . + "6f6275662f747970652e70726f746f2281020a03417069120c0a046e616d" . + "6518012001280912280a076d6574686f647318022003280b32172e676f6f" . + "676c652e70726f746f6275662e4d6574686f6412280a076f7074696f6e73" . + "18032003280b32172e676f6f676c652e70726f746f6275662e4f7074696f" . + "6e120f0a0776657273696f6e18042001280912360a0e736f757263655f63" . + "6f6e7465787418052001280b321e2e676f6f676c652e70726f746f627566" . + "2e536f75726365436f6e7465787412260a066d6978696e7318062003280b" . + "32162e676f6f676c652e70726f746f6275662e4d6978696e12270a067379" . + "6e74617818072001280e32172e676f6f676c652e70726f746f6275662e53" . + "796e74617822d5010a064d6574686f64120c0a046e616d65180120012809" . + "12180a10726571756573745f747970655f75726c18022001280912190a11" . + "726571756573745f73747265616d696e6718032001280812190a11726573" . + "706f6e73655f747970655f75726c180420012809121a0a12726573706f6e" . + "73655f73747265616d696e6718052001280812280a076f7074696f6e7318" . + "062003280b32172e676f6f676c652e70726f746f6275662e4f7074696f6e" . + "12270a0673796e74617818072001280e32172e676f6f676c652e70726f74" . + "6f6275662e53796e74617822230a054d6978696e120c0a046e616d651801" . + "20012809120c0a04726f6f7418022001280942750a13636f6d2e676f6f67" . + "6c652e70726f746f627566420841706950726f746f50015a2b676f6f676c" . + "652e676f6c616e672e6f72672f67656e70726f746f2f70726f746f627566" . + "2f6170693b617069a20203475042aa021e476f6f676c652e50726f746f62" . + "75662e57656c6c4b6e6f776e5479706573620670726f746f33" + )); + + static::$is_initialized = true; + } +} + diff --git a/src/GPBMetadata/Google/Protobuf/Duration.php b/src/GPBMetadata/Google/Protobuf/Duration.php new file mode 100644 index 00000000..b1c85ad8 --- /dev/null +++ b/src/GPBMetadata/Google/Protobuf/Duration.php @@ -0,0 +1,31 @@ +internalAddGeneratedFile(hex2bin( + "0ae3010a1e676f6f676c652f70726f746f6275662f6475726174696f6e2e" . + "70726f746f120f676f6f676c652e70726f746f627566222a0a0844757261" . + "74696f6e120f0a077365636f6e6473180120012803120d0a056e616e6f73" . + "180220012805427c0a13636f6d2e676f6f676c652e70726f746f62756642" . + "0d4475726174696f6e50726f746f50015a2a6769746875622e636f6d2f67" . + "6f6c616e672f70726f746f6275662f7074797065732f6475726174696f6e" . + "f80101a20203475042aa021e476f6f676c652e50726f746f6275662e5765" . + "6c6c4b6e6f776e5479706573620670726f746f33" + )); + + static::$is_initialized = true; + } +} + diff --git a/src/GPBMetadata/Google/Protobuf/FieldMask.php b/src/GPBMetadata/Google/Protobuf/FieldMask.php new file mode 100644 index 00000000..5812be1e --- /dev/null +++ b/src/GPBMetadata/Google/Protobuf/FieldMask.php @@ -0,0 +1,31 @@ +internalAddGeneratedFile(hex2bin( + "0ae3010a20676f6f676c652f70726f746f6275662f6669656c645f6d6173" . + "6b2e70726f746f120f676f6f676c652e70726f746f627566221a0a094669" . + "656c644d61736b120d0a0570617468731801200328094289010a13636f6d" . + "2e676f6f676c652e70726f746f627566420e4669656c644d61736b50726f" . + "746f50015a39676f6f676c652e676f6c616e672e6f72672f67656e70726f" . + "746f2f70726f746f6275662f6669656c645f6d61736b3b6669656c645f6d" . + "61736ba20203475042aa021e476f6f676c652e50726f746f6275662e5765" . + "6c6c4b6e6f776e5479706573620670726f746f33" + )); + + static::$is_initialized = true; + } +} + diff --git a/src/GPBMetadata/Google/Protobuf/GPBEmpty.php b/src/GPBMetadata/Google/Protobuf/GPBEmpty.php new file mode 100644 index 00000000..88f42a11 --- /dev/null +++ b/src/GPBMetadata/Google/Protobuf/GPBEmpty.php @@ -0,0 +1,30 @@ +internalAddGeneratedFile(hex2bin( + "0ab7010a1b676f6f676c652f70726f746f6275662f656d7074792e70726f" . + "746f120f676f6f676c652e70726f746f62756622070a05456d7074794276" . + "0a13636f6d2e676f6f676c652e70726f746f627566420a456d7074795072" . + "6f746f50015a276769746875622e636f6d2f676f6c616e672f70726f746f" . + "6275662f7074797065732f656d707479f80101a20203475042aa021e476f" . + "6f676c652e50726f746f6275662e57656c6c4b6e6f776e54797065736206" . + "70726f746f33" + )); + + static::$is_initialized = true; + } +} + diff --git a/src/GPBMetadata/Google/Protobuf/Internal/Descriptor.php b/src/GPBMetadata/Google/Protobuf/Internal/Descriptor.php new file mode 100644 index 00000000..e6362f2b --- /dev/null +++ b/src/GPBMetadata/Google/Protobuf/Internal/Descriptor.php @@ -0,0 +1,277 @@ +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) + ->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') + ->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('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; + } +} + diff --git a/src/GPBMetadata/Google/Protobuf/SourceContext.php b/src/GPBMetadata/Google/Protobuf/SourceContext.php new file mode 100644 index 00000000..495c6de4 --- /dev/null +++ b/src/GPBMetadata/Google/Protobuf/SourceContext.php @@ -0,0 +1,32 @@ +internalAddGeneratedFile(hex2bin( + "0afb010a24676f6f676c652f70726f746f6275662f736f757263655f636f" . + "6e746578742e70726f746f120f676f6f676c652e70726f746f6275662222" . + "0a0d536f75726365436f6e7465787412110a0966696c655f6e616d651801" . + "200128094295010a13636f6d2e676f6f676c652e70726f746f6275664212" . + "536f75726365436f6e7465787450726f746f50015a41676f6f676c652e67" . + "6f6c616e672e6f72672f67656e70726f746f2f70726f746f6275662f736f" . + "757263655f636f6e746578743b736f757263655f636f6e74657874a20203" . + "475042aa021e476f6f676c652e50726f746f6275662e57656c6c4b6e6f77" . + "6e5479706573620670726f746f33" + )); + + static::$is_initialized = true; + } +} + diff --git a/src/GPBMetadata/Google/Protobuf/Struct.php b/src/GPBMetadata/Google/Protobuf/Struct.php new file mode 100644 index 00000000..96b42af4 --- /dev/null +++ b/src/GPBMetadata/Google/Protobuf/Struct.php @@ -0,0 +1,45 @@ +internalAddGeneratedFile(hex2bin( + "0a81050a1c676f6f676c652f70726f746f6275662f7374727563742e7072" . + "6f746f120f676f6f676c652e70726f746f6275662284010a065374727563" . + "7412330a066669656c647318012003280b32232e676f6f676c652e70726f" . + "746f6275662e5374727563742e4669656c6473456e7472791a450a0b4669" . + "656c6473456e747279120b0a036b657918012001280912250a0576616c75" . + "6518022001280b32162e676f6f676c652e70726f746f6275662e56616c75" . + "653a02380122ea010a0556616c756512300a0a6e756c6c5f76616c756518" . + "012001280e321a2e676f6f676c652e70726f746f6275662e4e756c6c5661" . + "6c7565480012160a0c6e756d6265725f76616c7565180220012801480012" . + "160a0c737472696e675f76616c7565180320012809480012140a0a626f6f" . + "6c5f76616c75651804200128084800122f0a0c7374727563745f76616c75" . + "6518052001280b32172e676f6f676c652e70726f746f6275662e53747275" . + "6374480012300a0a6c6973745f76616c756518062001280b321a2e676f6f" . + "676c652e70726f746f6275662e4c69737456616c7565480042060a046b69" . + "6e6422330a094c69737456616c756512260a0676616c7565731801200328" . + "0b32162e676f6f676c652e70726f746f6275662e56616c75652a1b0a094e" . + "756c6c56616c7565120e0a0a4e554c4c5f56414c554510004281010a1363" . + "6f6d2e676f6f676c652e70726f746f627566420b53747275637450726f74" . + "6f50015a316769746875622e636f6d2f676f6c616e672f70726f746f6275" . + "662f7074797065732f7374727563743b7374727563747062f80101a20203" . + "475042aa021e476f6f676c652e50726f746f6275662e57656c6c4b6e6f77" . + "6e5479706573620670726f746f33" + )); + + static::$is_initialized = true; + } +} + diff --git a/src/GPBMetadata/Google/Protobuf/Timestamp.php b/src/GPBMetadata/Google/Protobuf/Timestamp.php new file mode 100644 index 00000000..373665c9 --- /dev/null +++ b/src/GPBMetadata/Google/Protobuf/Timestamp.php @@ -0,0 +1,31 @@ +internalAddGeneratedFile(hex2bin( + "0ae7010a1f676f6f676c652f70726f746f6275662f74696d657374616d70" . + "2e70726f746f120f676f6f676c652e70726f746f627566222b0a0954696d" . + "657374616d70120f0a077365636f6e6473180120012803120d0a056e616e" . + "6f73180220012805427e0a13636f6d2e676f6f676c652e70726f746f6275" . + "66420e54696d657374616d7050726f746f50015a2b6769746875622e636f" . + "6d2f676f6c616e672f70726f746f6275662f7074797065732f74696d6573" . + "74616d70f80101a20203475042aa021e476f6f676c652e50726f746f6275" . + "662e57656c6c4b6e6f776e5479706573620670726f746f33" + )); + + static::$is_initialized = true; + } +} + diff --git a/src/GPBMetadata/Google/Protobuf/Type.php b/src/GPBMetadata/Google/Protobuf/Type.php new file mode 100644 index 00000000..8fbe8cbf --- /dev/null +++ b/src/GPBMetadata/Google/Protobuf/Type.php @@ -0,0 +1,78 @@ +internalAddGeneratedFile(hex2bin( + "0a9f0c0a1a676f6f676c652f70726f746f6275662f747970652e70726f74" . + "6f120f676f6f676c652e70726f746f6275661a24676f6f676c652f70726f" . + "746f6275662f736f757263655f636f6e746578742e70726f746f22d7010a" . + "0454797065120c0a046e616d6518012001280912260a066669656c647318" . + "022003280b32162e676f6f676c652e70726f746f6275662e4669656c6412" . + "0e0a066f6e656f667318032003280912280a076f7074696f6e7318042003" . + "280b32172e676f6f676c652e70726f746f6275662e4f7074696f6e12360a" . + "0e736f757263655f636f6e7465787418052001280b321e2e676f6f676c65" . + "2e70726f746f6275662e536f75726365436f6e7465787412270a0673796e" . + "74617818062001280e32172e676f6f676c652e70726f746f6275662e5379" . + "6e74617822d5050a054669656c6412290a046b696e6418012001280e321b" . + "2e676f6f676c652e70726f746f6275662e4669656c642e4b696e6412370a" . + "0b63617264696e616c69747918022001280e32222e676f6f676c652e7072" . + "6f746f6275662e4669656c642e43617264696e616c697479120e0a066e75" . + "6d626572180320012805120c0a046e616d6518042001280912100a087479" . + "70655f75726c18062001280912130a0b6f6e656f665f696e646578180720" . + "012805120e0a067061636b656418082001280812280a076f7074696f6e73" . + "18092003280b32172e676f6f676c652e70726f746f6275662e4f7074696f" . + "6e12110a096a736f6e5f6e616d65180a2001280912150a0d64656661756c" . + "745f76616c7565180b2001280922c8020a044b696e6412100a0c54595045" . + "5f554e4b4e4f574e1000120f0a0b545950455f444f55424c451001120e0a" . + "0a545950455f464c4f41541002120e0a0a545950455f494e543634100312" . + "0f0a0b545950455f55494e5436341004120e0a0a545950455f494e543332" . + "100512100a0c545950455f46495845443634100612100a0c545950455f46" . + "4958454433321007120d0a09545950455f424f4f4c1008120f0a0b545950" . + "455f535452494e471009120e0a0a545950455f47524f5550100a12100a0c" . + "545950455f4d455353414745100b120e0a0a545950455f4259544553100c" . + "120f0a0b545950455f55494e543332100d120d0a09545950455f454e554d" . + "100e12110a0d545950455f5346495845443332100f12110a0d545950455f" . + "53464958454436341010120f0a0b545950455f53494e5433321011120f0a" . + "0b545950455f53494e543634101222740a0b43617264696e616c69747912" . + "170a1343415244494e414c4954595f554e4b4e4f574e100012180a144341" . + "5244494e414c4954595f4f5054494f4e414c100112180a1443415244494e" . + "414c4954595f5245515549524544100212180a1443415244494e414c4954" . + "595f5245504541544544100322ce010a04456e756d120c0a046e616d6518" . + "0120012809122d0a09656e756d76616c756518022003280b321a2e676f6f" . + "676c652e70726f746f6275662e456e756d56616c756512280a076f707469" . + "6f6e7318032003280b32172e676f6f676c652e70726f746f6275662e4f70" . + "74696f6e12360a0e736f757263655f636f6e7465787418042001280b321e" . + "2e676f6f676c652e70726f746f6275662e536f75726365436f6e74657874" . + "12270a0673796e74617818052001280e32172e676f6f676c652e70726f74" . + "6f6275662e53796e74617822530a09456e756d56616c7565120c0a046e61" . + "6d65180120012809120e0a066e756d62657218022001280512280a076f70" . + "74696f6e7318032003280b32172e676f6f676c652e70726f746f6275662e" . + "4f7074696f6e223b0a064f7074696f6e120c0a046e616d65180120012809" . + "12230a0576616c756518022001280b32142e676f6f676c652e70726f746f" . + "6275662e416e792a2e0a0653796e74617812110a0d53594e5441585f5052" . + "4f544f32100012110a0d53594e5441585f50524f544f331001427d0a1363" . + "6f6d2e676f6f676c652e70726f746f62756642095479706550726f746f50" . + "015a2f676f6f676c652e676f6c616e672e6f72672f67656e70726f746f2f" . + "70726f746f6275662f70747970653b7074797065f80101a20203475042aa" . + "021e476f6f676c652e50726f746f6275662e57656c6c4b6e6f776e547970" . + "6573620670726f746f33" + )); + + static::$is_initialized = true; + } +} + diff --git a/src/GPBMetadata/Google/Protobuf/Wrappers.php b/src/GPBMetadata/Google/Protobuf/Wrappers.php new file mode 100644 index 00000000..dd72ff48 --- /dev/null +++ b/src/GPBMetadata/Google/Protobuf/Wrappers.php @@ -0,0 +1,38 @@ +internalAddGeneratedFile(hex2bin( + "0abf030a1e676f6f676c652f70726f746f6275662f77726170706572732e" . + "70726f746f120f676f6f676c652e70726f746f627566221c0a0b446f7562" . + "6c6556616c7565120d0a0576616c7565180120012801221b0a0a466c6f61" . + "7456616c7565120d0a0576616c7565180120012802221b0a0a496e743634" . + "56616c7565120d0a0576616c7565180120012803221c0a0b55496e743634" . + "56616c7565120d0a0576616c7565180120012804221b0a0a496e74333256" . + "616c7565120d0a0576616c7565180120012805221c0a0b55496e74333256" . + "616c7565120d0a0576616c756518012001280d221a0a09426f6f6c56616c" . + "7565120d0a0576616c7565180120012808221c0a0b537472696e6756616c" . + "7565120d0a0576616c7565180120012809221b0a0a427974657356616c75" . + "65120d0a0576616c756518012001280c427c0a13636f6d2e676f6f676c65" . + "2e70726f746f627566420d577261707065727350726f746f50015a2a6769" . + "746875622e636f6d2f676f6c616e672f70726f746f6275662f7074797065" . + "732f7772617070657273f80101a20203475042aa021e476f6f676c652e50" . + "726f746f6275662e57656c6c4b6e6f776e5479706573620670726f746f33" + )); + + static::$is_initialized = true; + } +} + diff --git a/src/Google/Protobuf/Any.php b/src/Google/Protobuf/Any.php new file mode 100644 index 00000000..166c66a4 --- /dev/null +++ b/src/Google/Protobuf/Any.php @@ -0,0 +1,325 @@ +, + * "lastName": + * } + * 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 `@type` + * field. Example (for message [google.protobuf.Duration][]): + * { + * "@type": "type.googleapis.com/google.protobuf.Duration", + * "value": "1.212s" + * } + * + * Generated from protobuf message google.protobuf.Any + */ +class Any extends \Google\Protobuf\Internal\Message +{ + /** + * A URL/resource name that uniquely identifies the type of the serialized + * protocol buffer message. 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 string type_url = 1; + */ + private $type_url = ''; + /** + * Must be a valid serialized protocol buffer of the above specified type. + * + * Generated from protobuf field bytes value = 2; + */ + private $value = ''; + + const TYPE_URL_PREFIX = 'type.googleapis.com/'; + + /** + * 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. 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. 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 string type_url = 1; + * @return string + */ + public function getTypeUrl() + { + return $this->type_url; + } + + /** + * A URL/resource name that uniquely identifies the type of the serialized + * protocol buffer message. 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 string type_url = 1; + * @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 bytes value = 2; + * @return string + */ + public function getValue() + { + return $this->value; + } + + /** + * Must be a valid serialized protocol buffer of the above specified type. + * + * Generated from protobuf field bytes value = 2; + * @param string $var + * @return $this + */ + public function setValue($var) + { + GPBUtil::checkString($var, False); + $this->value = $var; + + return $this; + } + + /** + * 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 message’s 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.substr( + $fully_qualifed_name, 1, strlen($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.substr( + $fully_qualifed_name, 1, strlen($fully_qualifed_name)); + return $this->type_url === $type_url; + } +} + diff --git a/src/Google/Protobuf/Api.php b/src/Google/Protobuf/Api.php new file mode 100644 index 00000000..db37ffb0 --- /dev/null +++ b/src/Google/Protobuf/Api.php @@ -0,0 +1,350 @@ +google.protobuf.Api + */ +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 string name = 1; + */ + private $name = ''; + /** + * The methods of this interface, in unspecified order. + * + * Generated from protobuf field repeated .google.protobuf.Method methods = 2; + */ + private $methods; + /** + * Any metadata attached to the interface. + * + * Generated from protobuf field repeated .google.protobuf.Option options = 3; + */ + 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`, 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 string version = 4; + */ + private $version = ''; + /** + * Source context for the protocol buffer service represented by this + * message. + * + * Generated from protobuf field .google.protobuf.SourceContext source_context = 5; + */ + private $source_context = null; + /** + * Included interfaces. See [Mixin][]. + * + * Generated from protobuf field repeated .google.protobuf.Mixin mixins = 6; + */ + private $mixins; + /** + * The source syntax of the service. + * + * Generated from protobuf field .google.protobuf.Syntax syntax = 7; + */ + private $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 \Google\Protobuf\Method[]|\Google\Protobuf\Internal\RepeatedField $methods + * The methods of this interface, in unspecified order. + * @type \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`, 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 \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 string name = 1; + * @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 string name = 1; + * @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 repeated .google.protobuf.Method methods = 2; + * @return \Google\Protobuf\Internal\RepeatedField + */ + public function getMethods() + { + return $this->methods; + } + + /** + * The methods of this interface, in unspecified order. + * + * Generated from protobuf field repeated .google.protobuf.Method methods = 2; + * @param \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 repeated .google.protobuf.Option options = 3; + * @return \Google\Protobuf\Internal\RepeatedField + */ + public function getOptions() + { + return $this->options; + } + + /** + * Any metadata attached to the interface. + * + * Generated from protobuf field repeated .google.protobuf.Option options = 3; + * @param \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`, 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 string version = 4; + * @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`, 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 string version = 4; + * @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 .google.protobuf.SourceContext source_context = 5; + * @return \Google\Protobuf\SourceContext + */ + public function getSourceContext() + { + return $this->source_context; + } + + /** + * Source context for the protocol buffer service represented by this + * message. + * + * Generated from protobuf field .google.protobuf.SourceContext source_context = 5; + * @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 repeated .google.protobuf.Mixin mixins = 6; + * @return \Google\Protobuf\Internal\RepeatedField + */ + public function getMixins() + { + return $this->mixins; + } + + /** + * Included interfaces. See [Mixin][]. + * + * Generated from protobuf field repeated .google.protobuf.Mixin mixins = 6; + * @param \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 .google.protobuf.Syntax syntax = 7; + * @return int + */ + public function getSyntax() + { + return $this->syntax; + } + + /** + * The source syntax of the service. + * + * Generated from protobuf field .google.protobuf.Syntax syntax = 7; + * @param int $var + * @return $this + */ + public function setSyntax($var) + { + GPBUtil::checkEnum($var, \Google\Protobuf\Syntax::class); + $this->syntax = $var; + + return $this; + } + +} + diff --git a/src/Google/Protobuf/BoolValue.php b/src/Google/Protobuf/BoolValue.php new file mode 100644 index 00000000..13872eb1 --- /dev/null +++ b/src/Google/Protobuf/BoolValue.php @@ -0,0 +1,68 @@ +google.protobuf.BoolValue + */ +class BoolValue extends \Google\Protobuf\Internal\Message +{ + /** + * The bool value. + * + * Generated from protobuf field bool value = 1; + */ + private $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 bool value = 1; + * @return bool + */ + public function getValue() + { + return $this->value; + } + + /** + * The bool value. + * + * Generated from protobuf field bool value = 1; + * @param bool $var + * @return $this + */ + public function setValue($var) + { + GPBUtil::checkBool($var); + $this->value = $var; + + return $this; + } + +} + diff --git a/src/Google/Protobuf/BytesValue.php b/src/Google/Protobuf/BytesValue.php new file mode 100644 index 00000000..f1b38171 --- /dev/null +++ b/src/Google/Protobuf/BytesValue.php @@ -0,0 +1,68 @@ +google.protobuf.BytesValue + */ +class BytesValue extends \Google\Protobuf\Internal\Message +{ + /** + * The bytes value. + * + * Generated from protobuf field bytes value = 1; + */ + private $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 bytes value = 1; + * @return string + */ + public function getValue() + { + return $this->value; + } + + /** + * The bytes value. + * + * Generated from protobuf field bytes value = 1; + * @param string $var + * @return $this + */ + public function setValue($var) + { + GPBUtil::checkString($var, False); + $this->value = $var; + + return $this; + } + +} + diff --git a/src/Google/Protobuf/Descriptor.php b/src/Google/Protobuf/Descriptor.php new file mode 100644 index 00000000..986b81e1 --- /dev/null +++ b/src/Google/Protobuf/Descriptor.php @@ -0,0 +1,100 @@ +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()); + } +} diff --git a/src/Google/Protobuf/DescriptorPool.php b/src/Google/Protobuf/DescriptorPool.php new file mode 100644 index 00000000..119f0e2e --- /dev/null +++ b/src/Google/Protobuf/DescriptorPool.php @@ -0,0 +1,76 @@ +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(); + } +} diff --git a/src/Google/Protobuf/DoubleValue.php b/src/Google/Protobuf/DoubleValue.php new file mode 100644 index 00000000..236d9182 --- /dev/null +++ b/src/Google/Protobuf/DoubleValue.php @@ -0,0 +1,68 @@ +google.protobuf.DoubleValue + */ +class DoubleValue extends \Google\Protobuf\Internal\Message +{ + /** + * The double value. + * + * Generated from protobuf field double value = 1; + */ + private $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 double value = 1; + * @return float + */ + public function getValue() + { + return $this->value; + } + + /** + * The double value. + * + * Generated from protobuf field double value = 1; + * @param float $var + * @return $this + */ + public function setValue($var) + { + GPBUtil::checkDouble($var); + $this->value = $var; + + return $this; + } + +} + diff --git a/src/Google/Protobuf/Duration.php b/src/Google/Protobuf/Duration.php new file mode 100644 index 00000000..414a1868 --- /dev/null +++ b/src/Google/Protobuf/Duration.php @@ -0,0 +1,173 @@ + 0) { + * duration.seconds += 1; + * duration.nanos -= 1000000000; + * } else if (durations.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 google.protobuf.Duration + */ +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 int64 seconds = 1; + */ + private $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 int32 nanos = 2; + */ + private $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 int64 seconds = 1; + * @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 int64 seconds = 1; + * @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 int32 nanos = 2; + * @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 int32 nanos = 2; + * @param int $var + * @return $this + */ + public function setNanos($var) + { + GPBUtil::checkInt32($var); + $this->nanos = $var; + + return $this; + } + +} + diff --git a/src/Google/Protobuf/Enum.php b/src/Google/Protobuf/Enum.php new file mode 100644 index 00000000..243c40d2 --- /dev/null +++ b/src/Google/Protobuf/Enum.php @@ -0,0 +1,203 @@ +google.protobuf.Enum + */ +class Enum extends \Google\Protobuf\Internal\Message +{ + /** + * Enum type name. + * + * Generated from protobuf field string name = 1; + */ + private $name = ''; + /** + * Enum value definitions. + * + * Generated from protobuf field repeated .google.protobuf.EnumValue enumvalue = 2; + */ + private $enumvalue; + /** + * Protocol buffer options. + * + * Generated from protobuf field repeated .google.protobuf.Option options = 3; + */ + private $options; + /** + * The source context. + * + * Generated from protobuf field .google.protobuf.SourceContext source_context = 4; + */ + private $source_context = null; + /** + * The source syntax. + * + * Generated from protobuf field .google.protobuf.Syntax syntax = 5; + */ + private $syntax = 0; + + /** + * Constructor. + * + * @param array $data { + * Optional. Data for populating the Message object. + * + * @type string $name + * Enum type name. + * @type \Google\Protobuf\EnumValue[]|\Google\Protobuf\Internal\RepeatedField $enumvalue + * Enum value definitions. + * @type \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 string name = 1; + * @return string + */ + public function getName() + { + return $this->name; + } + + /** + * Enum type name. + * + * Generated from protobuf field string name = 1; + * @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 repeated .google.protobuf.EnumValue enumvalue = 2; + * @return \Google\Protobuf\Internal\RepeatedField + */ + public function getEnumvalue() + { + return $this->enumvalue; + } + + /** + * Enum value definitions. + * + * Generated from protobuf field repeated .google.protobuf.EnumValue enumvalue = 2; + * @param \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 repeated .google.protobuf.Option options = 3; + * @return \Google\Protobuf\Internal\RepeatedField + */ + public function getOptions() + { + return $this->options; + } + + /** + * Protocol buffer options. + * + * Generated from protobuf field repeated .google.protobuf.Option options = 3; + * @param \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 .google.protobuf.SourceContext source_context = 4; + * @return \Google\Protobuf\SourceContext + */ + public function getSourceContext() + { + return $this->source_context; + } + + /** + * The source context. + * + * Generated from protobuf field .google.protobuf.SourceContext source_context = 4; + * @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 .google.protobuf.Syntax syntax = 5; + * @return int + */ + public function getSyntax() + { + return $this->syntax; + } + + /** + * The source syntax. + * + * Generated from protobuf field .google.protobuf.Syntax syntax = 5; + * @param int $var + * @return $this + */ + public function setSyntax($var) + { + GPBUtil::checkEnum($var, \Google\Protobuf\Syntax::class); + $this->syntax = $var; + + return $this; + } + +} + diff --git a/src/Google/Protobuf/EnumDescriptor.php b/src/Google/Protobuf/EnumDescriptor.php new file mode 100644 index 00000000..a8b56c0d --- /dev/null +++ b/src/Google/Protobuf/EnumDescriptor.php @@ -0,0 +1,79 @@ +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(); + } +} diff --git a/src/Google/Protobuf/EnumValue.php b/src/Google/Protobuf/EnumValue.php new file mode 100644 index 00000000..1dc3c7a6 --- /dev/null +++ b/src/Google/Protobuf/EnumValue.php @@ -0,0 +1,135 @@ +google.protobuf.EnumValue + */ +class EnumValue extends \Google\Protobuf\Internal\Message +{ + /** + * Enum value name. + * + * Generated from protobuf field string name = 1; + */ + private $name = ''; + /** + * Enum value number. + * + * Generated from protobuf field int32 number = 2; + */ + private $number = 0; + /** + * Protocol buffer options. + * + * Generated from protobuf field repeated .google.protobuf.Option options = 3; + */ + 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 \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 string name = 1; + * @return string + */ + public function getName() + { + return $this->name; + } + + /** + * Enum value name. + * + * Generated from protobuf field string name = 1; + * @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 int32 number = 2; + * @return int + */ + public function getNumber() + { + return $this->number; + } + + /** + * Enum value number. + * + * Generated from protobuf field int32 number = 2; + * @param int $var + * @return $this + */ + public function setNumber($var) + { + GPBUtil::checkInt32($var); + $this->number = $var; + + return $this; + } + + /** + * Protocol buffer options. + * + * Generated from protobuf field repeated .google.protobuf.Option options = 3; + * @return \Google\Protobuf\Internal\RepeatedField + */ + public function getOptions() + { + return $this->options; + } + + /** + * Protocol buffer options. + * + * Generated from protobuf field repeated .google.protobuf.Option options = 3; + * @param \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; + } + +} + diff --git a/src/Google/Protobuf/EnumValueDescriptor.php b/src/Google/Protobuf/EnumValueDescriptor.php new file mode 100644 index 00000000..e76e1997 --- /dev/null +++ b/src/Google/Protobuf/EnumValueDescriptor.php @@ -0,0 +1,64 @@ +name = $name; + $this->number = $number; + } + + /** + * @return string + */ + public function getName() + { + return $this->name; + } + + /** + * @return int + */ + public function getNumber() + { + return $this->number; + } +} diff --git a/src/Google/Protobuf/Field.php b/src/Google/Protobuf/Field.php new file mode 100644 index 00000000..8da43e34 --- /dev/null +++ b/src/Google/Protobuf/Field.php @@ -0,0 +1,381 @@ +google.protobuf.Field + */ +class Field extends \Google\Protobuf\Internal\Message +{ + /** + * The field type. + * + * Generated from protobuf field .google.protobuf.Field.Kind kind = 1; + */ + private $kind = 0; + /** + * The field cardinality. + * + * Generated from protobuf field .google.protobuf.Field.Cardinality cardinality = 2; + */ + private $cardinality = 0; + /** + * The field number. + * + * Generated from protobuf field int32 number = 3; + */ + private $number = 0; + /** + * The field name. + * + * Generated from protobuf field string name = 4; + */ + private $name = ''; + /** + * The field type URL, without the scheme, for message or enumeration + * types. Example: `"type.googleapis.com/google.protobuf.Timestamp"`. + * + * Generated from protobuf field string type_url = 6; + */ + private $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 int32 oneof_index = 7; + */ + private $oneof_index = 0; + /** + * Whether to use alternative packed wire representation. + * + * Generated from protobuf field bool packed = 8; + */ + private $packed = false; + /** + * The protocol buffer options. + * + * Generated from protobuf field repeated .google.protobuf.Option options = 9; + */ + private $options; + /** + * The field JSON name. + * + * Generated from protobuf field string json_name = 10; + */ + private $json_name = ''; + /** + * The string value of the default value of this field. Proto2 syntax only. + * + * Generated from protobuf field string default_value = 11; + */ + private $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 \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 .google.protobuf.Field.Kind kind = 1; + * @return int + */ + public function getKind() + { + return $this->kind; + } + + /** + * The field type. + * + * Generated from protobuf field .google.protobuf.Field.Kind kind = 1; + * @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 .google.protobuf.Field.Cardinality cardinality = 2; + * @return int + */ + public function getCardinality() + { + return $this->cardinality; + } + + /** + * The field cardinality. + * + * Generated from protobuf field .google.protobuf.Field.Cardinality cardinality = 2; + * @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 int32 number = 3; + * @return int + */ + public function getNumber() + { + return $this->number; + } + + /** + * The field number. + * + * Generated from protobuf field int32 number = 3; + * @param int $var + * @return $this + */ + public function setNumber($var) + { + GPBUtil::checkInt32($var); + $this->number = $var; + + return $this; + } + + /** + * The field name. + * + * Generated from protobuf field string name = 4; + * @return string + */ + public function getName() + { + return $this->name; + } + + /** + * The field name. + * + * Generated from protobuf field string name = 4; + * @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 string type_url = 6; + * @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 string type_url = 6; + * @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 int32 oneof_index = 7; + * @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 int32 oneof_index = 7; + * @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 bool packed = 8; + * @return bool + */ + public function getPacked() + { + return $this->packed; + } + + /** + * Whether to use alternative packed wire representation. + * + * Generated from protobuf field bool packed = 8; + * @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 repeated .google.protobuf.Option options = 9; + * @return \Google\Protobuf\Internal\RepeatedField + */ + public function getOptions() + { + return $this->options; + } + + /** + * The protocol buffer options. + * + * Generated from protobuf field repeated .google.protobuf.Option options = 9; + * @param \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 string json_name = 10; + * @return string + */ + public function getJsonName() + { + return $this->json_name; + } + + /** + * The field JSON name. + * + * Generated from protobuf field string json_name = 10; + * @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 string default_value = 11; + * @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 string default_value = 11; + * @param string $var + * @return $this + */ + public function setDefaultValue($var) + { + GPBUtil::checkString($var, True); + $this->default_value = $var; + + return $this; + } + +} + diff --git a/src/Google/Protobuf/Field/Cardinality.php b/src/Google/Protobuf/Field/Cardinality.php new file mode 100644 index 00000000..479dc0bf --- /dev/null +++ b/src/Google/Protobuf/Field/Cardinality.php @@ -0,0 +1,70 @@ +google.protobuf.Field.Cardinality + */ +class Cardinality +{ + /** + * For fields with unknown cardinality. + * + * Generated from protobuf enum CARDINALITY_UNKNOWN = 0; + */ + const CARDINALITY_UNKNOWN = 0; + /** + * For optional fields. + * + * Generated from protobuf enum CARDINALITY_OPTIONAL = 1; + */ + const CARDINALITY_OPTIONAL = 1; + /** + * For required fields. Proto2 syntax only. + * + * Generated from protobuf enum CARDINALITY_REQUIRED = 2; + */ + const CARDINALITY_REQUIRED = 2; + /** + * For repeated fields. + * + * Generated from protobuf enum CARDINALITY_REPEATED = 3; + */ + 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); + diff --git a/src/Google/Protobuf/Field/Kind.php b/src/Google/Protobuf/Field/Kind.php new file mode 100644 index 00000000..f30bd2f5 --- /dev/null +++ b/src/Google/Protobuf/Field/Kind.php @@ -0,0 +1,175 @@ +google.protobuf.Field.Kind + */ +class Kind +{ + /** + * Field type unknown. + * + * Generated from protobuf enum TYPE_UNKNOWN = 0; + */ + const TYPE_UNKNOWN = 0; + /** + * Field type double. + * + * Generated from protobuf enum TYPE_DOUBLE = 1; + */ + const TYPE_DOUBLE = 1; + /** + * Field type float. + * + * Generated from protobuf enum TYPE_FLOAT = 2; + */ + const TYPE_FLOAT = 2; + /** + * Field type int64. + * + * Generated from protobuf enum TYPE_INT64 = 3; + */ + const TYPE_INT64 = 3; + /** + * Field type uint64. + * + * Generated from protobuf enum TYPE_UINT64 = 4; + */ + const TYPE_UINT64 = 4; + /** + * Field type int32. + * + * Generated from protobuf enum TYPE_INT32 = 5; + */ + const TYPE_INT32 = 5; + /** + * Field type fixed64. + * + * Generated from protobuf enum TYPE_FIXED64 = 6; + */ + const TYPE_FIXED64 = 6; + /** + * Field type fixed32. + * + * Generated from protobuf enum TYPE_FIXED32 = 7; + */ + const TYPE_FIXED32 = 7; + /** + * Field type bool. + * + * Generated from protobuf enum TYPE_BOOL = 8; + */ + const TYPE_BOOL = 8; + /** + * Field type string. + * + * Generated from protobuf enum TYPE_STRING = 9; + */ + const TYPE_STRING = 9; + /** + * Field type group. Proto2 syntax only, and deprecated. + * + * Generated from protobuf enum TYPE_GROUP = 10; + */ + const TYPE_GROUP = 10; + /** + * Field type message. + * + * Generated from protobuf enum TYPE_MESSAGE = 11; + */ + const TYPE_MESSAGE = 11; + /** + * Field type bytes. + * + * Generated from protobuf enum TYPE_BYTES = 12; + */ + const TYPE_BYTES = 12; + /** + * Field type uint32. + * + * Generated from protobuf enum TYPE_UINT32 = 13; + */ + const TYPE_UINT32 = 13; + /** + * Field type enum. + * + * Generated from protobuf enum TYPE_ENUM = 14; + */ + const TYPE_ENUM = 14; + /** + * Field type sfixed32. + * + * Generated from protobuf enum TYPE_SFIXED32 = 15; + */ + const TYPE_SFIXED32 = 15; + /** + * Field type sfixed64. + * + * Generated from protobuf enum TYPE_SFIXED64 = 16; + */ + const TYPE_SFIXED64 = 16; + /** + * Field type sint32. + * + * Generated from protobuf enum TYPE_SINT32 = 17; + */ + const TYPE_SINT32 = 17; + /** + * Field type sint64. + * + * Generated from protobuf enum TYPE_SINT64 = 18; + */ + 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); + diff --git a/src/Google/Protobuf/FieldDescriptor.php b/src/Google/Protobuf/FieldDescriptor.php new file mode 100644 index 00000000..ac9271f9 --- /dev/null +++ b/src/Google/Protobuf/FieldDescriptor.php @@ -0,0 +1,117 @@ +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 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(); + } +} diff --git a/src/Google/Protobuf/FieldMask.php b/src/Google/Protobuf/FieldMask.php new file mode 100644 index 00000000..8fb38cbf --- /dev/null +++ b/src/Google/Protobuf/FieldMask.php @@ -0,0 +1,223 @@ +google.protobuf.FieldMask + */ +class FieldMask extends \Google\Protobuf\Internal\Message +{ + /** + * The set of field mask paths. + * + * Generated from protobuf field repeated string paths = 1; + */ + private $paths; + + /** + * Constructor. + * + * @param array $data { + * Optional. Data for populating the Message object. + * + * @type 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 repeated string paths = 1; + * @return \Google\Protobuf\Internal\RepeatedField + */ + public function getPaths() + { + return $this->paths; + } + + /** + * The set of field mask paths. + * + * Generated from protobuf field repeated string paths = 1; + * @param 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; + } + +} + diff --git a/src/Google/Protobuf/Field_Cardinality.php b/src/Google/Protobuf/Field_Cardinality.php new file mode 100644 index 00000000..dff8f893 --- /dev/null +++ b/src/Google/Protobuf/Field_Cardinality.php @@ -0,0 +1,16 @@ +google.protobuf.FloatValue + */ +class FloatValue extends \Google\Protobuf\Internal\Message +{ + /** + * The float value. + * + * Generated from protobuf field float value = 1; + */ + private $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 float value = 1; + * @return float + */ + public function getValue() + { + return $this->value; + } + + /** + * The float value. + * + * Generated from protobuf field float value = 1; + * @param float $var + * @return $this + */ + public function setValue($var) + { + GPBUtil::checkFloat($var); + $this->value = $var; + + return $this; + } + +} + diff --git a/src/Google/Protobuf/GPBEmpty.php b/src/Google/Protobuf/GPBEmpty.php new file mode 100644 index 00000000..2de9c3bc --- /dev/null +++ b/src/Google/Protobuf/GPBEmpty.php @@ -0,0 +1,39 @@ +google.protobuf.Empty + */ +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); + } + +} + diff --git a/src/Google/Protobuf/Int32Value.php b/src/Google/Protobuf/Int32Value.php new file mode 100644 index 00000000..d7fd528d --- /dev/null +++ b/src/Google/Protobuf/Int32Value.php @@ -0,0 +1,68 @@ +google.protobuf.Int32Value + */ +class Int32Value extends \Google\Protobuf\Internal\Message +{ + /** + * The int32 value. + * + * Generated from protobuf field int32 value = 1; + */ + private $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 int32 value = 1; + * @return int + */ + public function getValue() + { + return $this->value; + } + + /** + * The int32 value. + * + * Generated from protobuf field int32 value = 1; + * @param int $var + * @return $this + */ + public function setValue($var) + { + GPBUtil::checkInt32($var); + $this->value = $var; + + return $this; + } + +} + diff --git a/src/Google/Protobuf/Int64Value.php b/src/Google/Protobuf/Int64Value.php new file mode 100644 index 00000000..ca663055 --- /dev/null +++ b/src/Google/Protobuf/Int64Value.php @@ -0,0 +1,68 @@ +google.protobuf.Int64Value + */ +class Int64Value extends \Google\Protobuf\Internal\Message +{ + /** + * The int64 value. + * + * Generated from protobuf field int64 value = 1; + */ + private $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 int64 value = 1; + * @return int|string + */ + public function getValue() + { + return $this->value; + } + + /** + * The int64 value. + * + * Generated from protobuf field int64 value = 1; + * @param int|string $var + * @return $this + */ + public function setValue($var) + { + GPBUtil::checkInt64($var); + $this->value = $var; + + return $this; + } + +} + diff --git a/src/Google/Protobuf/Internal/CodedInputStream.php b/src/Google/Protobuf/Internal/CodedInputStream.php new file mode 100644 index 00000000..2ed2dfde --- /dev/null +++ b/src/Google/Protobuf/Internal/CodedInputStream.php @@ -0,0 +1,382 @@ +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; + } +} diff --git a/src/Google/Protobuf/Internal/CodedOutputStream.php b/src/Google/Protobuf/Internal/CodedOutputStream.php new file mode 100644 index 00000000..f75e9c66 --- /dev/null +++ b/src/Google/Protobuf/Internal/CodedOutputStream.php @@ -0,0 +1,159 @@ +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; + } + +} diff --git a/src/Google/Protobuf/Internal/Descriptor.php b/src/Google/Protobuf/Internal/Descriptor.php new file mode 100644 index 00000000..21ac5de3 --- /dev/null +++ b/src/Google/Protobuf/Internal/Descriptor.php @@ -0,0 +1,222 @@ +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 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 = ""; + $fullname = ""; + GPBUtil::getFullClassName( + $proto, + $containing, + $file_proto, + $message_name_without_package, + $legacy_classname, + $classname, + $fullname); + $desc->setFullName($fullname); + $desc->setClass($classname); + $desc->setLegacyClass($legacy_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; + } +} diff --git a/src/Google/Protobuf/Internal/DescriptorPool.php b/src/Google/Protobuf/Internal/DescriptorPool.php new file mode 100644 index 00000000..f96b0fb7 --- /dev/null +++ b/src/Google/Protobuf/Internal/DescriptorPool.php @@ -0,0 +1,187 @@ +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; + 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(); + $subdesc = $this->getDescriptorByProtoName($proto); + if (is_null($subdesc)) { + trigger_error( + 'proto not added: ' . $proto + . " for " . $desc->getFullName(), E_ERROR); + } + $field->setMessageType($subdesc); + break; + case GPBType::ENUM: + $proto = $field->getEnumType(); + $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); + } +} diff --git a/src/Google/Protobuf/Internal/DescriptorProto.php b/src/Google/Protobuf/Internal/DescriptorProto.php new file mode 100644 index 00000000..7cc689d0 --- /dev/null +++ b/src/Google/Protobuf/Internal/DescriptorProto.php @@ -0,0 +1,386 @@ +google.protobuf.DescriptorProto + */ +class DescriptorProto extends \Google\Protobuf\Internal\Message +{ + /** + * Generated from protobuf field optional string name = 1; + */ + protected $name = ''; + private $has_name = false; + /** + * Generated from protobuf field repeated .google.protobuf.FieldDescriptorProto field = 2; + */ + private $field; + private $has_field = false; + /** + * Generated from protobuf field repeated .google.protobuf.FieldDescriptorProto extension = 6; + */ + private $extension; + private $has_extension = false; + /** + * Generated from protobuf field repeated .google.protobuf.DescriptorProto nested_type = 3; + */ + private $nested_type; + private $has_nested_type = false; + /** + * Generated from protobuf field repeated .google.protobuf.EnumDescriptorProto enum_type = 4; + */ + private $enum_type; + private $has_enum_type = false; + /** + * Generated from protobuf field repeated .google.protobuf.DescriptorProto.ExtensionRange extension_range = 5; + */ + private $extension_range; + private $has_extension_range = false; + /** + * Generated from protobuf field repeated .google.protobuf.OneofDescriptorProto oneof_decl = 8; + */ + private $oneof_decl; + private $has_oneof_decl = false; + /** + * Generated from protobuf field optional .google.protobuf.MessageOptions options = 7; + */ + protected $options = null; + private $has_options = false; + /** + * Generated from protobuf field repeated .google.protobuf.DescriptorProto.ReservedRange reserved_range = 9; + */ + private $reserved_range; + private $has_reserved_range = false; + /** + * 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 repeated string reserved_name = 10; + */ + private $reserved_name; + private $has_reserved_name = false; + + /** + * Constructor. + * + * @param array $data { + * Optional. Data for populating the Message object. + * + * @type string $name + * @type \Google\Protobuf\Internal\FieldDescriptorProto[]|\Google\Protobuf\Internal\RepeatedField $field + * @type \Google\Protobuf\Internal\FieldDescriptorProto[]|\Google\Protobuf\Internal\RepeatedField $extension + * @type \Google\Protobuf\Internal\DescriptorProto[]|\Google\Protobuf\Internal\RepeatedField $nested_type + * @type \Google\Protobuf\Internal\EnumDescriptorProto[]|\Google\Protobuf\Internal\RepeatedField $enum_type + * @type \Google\Protobuf\Internal\DescriptorProto\ExtensionRange[]|\Google\Protobuf\Internal\RepeatedField $extension_range + * @type \Google\Protobuf\Internal\OneofDescriptorProto[]|\Google\Protobuf\Internal\RepeatedField $oneof_decl + * @type \Google\Protobuf\Internal\MessageOptions $options + * @type \Google\Protobuf\Internal\DescriptorProto\ReservedRange[]|\Google\Protobuf\Internal\RepeatedField $reserved_range + * @type 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 optional string name = 1; + * @return string + */ + public function getName() + { + return $this->name; + } + + /** + * Generated from protobuf field optional string name = 1; + * @param string $var + * @return $this + */ + public function setName($var) + { + GPBUtil::checkString($var, True); + $this->name = $var; + $this->has_name = true; + + return $this; + } + + public function hasName() + { + return $this->has_name; + } + + /** + * Generated from protobuf field repeated .google.protobuf.FieldDescriptorProto field = 2; + * @return \Google\Protobuf\Internal\RepeatedField + */ + public function getField() + { + return $this->field; + } + + /** + * Generated from protobuf field repeated .google.protobuf.FieldDescriptorProto field = 2; + * @param \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; + $this->has_field = true; + + return $this; + } + + public function hasField() + { + return $this->has_field; + } + + /** + * Generated from protobuf field repeated .google.protobuf.FieldDescriptorProto extension = 6; + * @return \Google\Protobuf\Internal\RepeatedField + */ + public function getExtension() + { + return $this->extension; + } + + /** + * Generated from protobuf field repeated .google.protobuf.FieldDescriptorProto extension = 6; + * @param \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; + $this->has_extension = true; + + return $this; + } + + public function hasExtension() + { + return $this->has_extension; + } + + /** + * Generated from protobuf field repeated .google.protobuf.DescriptorProto nested_type = 3; + * @return \Google\Protobuf\Internal\RepeatedField + */ + public function getNestedType() + { + return $this->nested_type; + } + + /** + * Generated from protobuf field repeated .google.protobuf.DescriptorProto nested_type = 3; + * @param \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; + $this->has_nested_type = true; + + return $this; + } + + public function hasNestedType() + { + return $this->has_nested_type; + } + + /** + * Generated from protobuf field repeated .google.protobuf.EnumDescriptorProto enum_type = 4; + * @return \Google\Protobuf\Internal\RepeatedField + */ + public function getEnumType() + { + return $this->enum_type; + } + + /** + * Generated from protobuf field repeated .google.protobuf.EnumDescriptorProto enum_type = 4; + * @param \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; + $this->has_enum_type = true; + + return $this; + } + + public function hasEnumType() + { + return $this->has_enum_type; + } + + /** + * Generated from protobuf field repeated .google.protobuf.DescriptorProto.ExtensionRange extension_range = 5; + * @return \Google\Protobuf\Internal\RepeatedField + */ + public function getExtensionRange() + { + return $this->extension_range; + } + + /** + * Generated from protobuf field repeated .google.protobuf.DescriptorProto.ExtensionRange extension_range = 5; + * @param \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; + $this->has_extension_range = true; + + return $this; + } + + public function hasExtensionRange() + { + return $this->has_extension_range; + } + + /** + * Generated from protobuf field repeated .google.protobuf.OneofDescriptorProto oneof_decl = 8; + * @return \Google\Protobuf\Internal\RepeatedField + */ + public function getOneofDecl() + { + return $this->oneof_decl; + } + + /** + * Generated from protobuf field repeated .google.protobuf.OneofDescriptorProto oneof_decl = 8; + * @param \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; + $this->has_oneof_decl = true; + + return $this; + } + + public function hasOneofDecl() + { + return $this->has_oneof_decl; + } + + /** + * Generated from protobuf field optional .google.protobuf.MessageOptions options = 7; + * @return \Google\Protobuf\Internal\MessageOptions + */ + public function getOptions() + { + return $this->options; + } + + /** + * Generated from protobuf field optional .google.protobuf.MessageOptions options = 7; + * @param \Google\Protobuf\Internal\MessageOptions $var + * @return $this + */ + public function setOptions($var) + { + GPBUtil::checkMessage($var, \Google\Protobuf\Internal\MessageOptions::class); + $this->options = $var; + $this->has_options = true; + + return $this; + } + + public function hasOptions() + { + return $this->has_options; + } + + /** + * Generated from protobuf field repeated .google.protobuf.DescriptorProto.ReservedRange reserved_range = 9; + * @return \Google\Protobuf\Internal\RepeatedField + */ + public function getReservedRange() + { + return $this->reserved_range; + } + + /** + * Generated from protobuf field repeated .google.protobuf.DescriptorProto.ReservedRange reserved_range = 9; + * @param \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; + $this->has_reserved_range = true; + + return $this; + } + + public function hasReservedRange() + { + return $this->has_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 repeated string reserved_name = 10; + * @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 repeated string reserved_name = 10; + * @param 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; + $this->has_reserved_name = true; + + return $this; + } + + public function hasReservedName() + { + return $this->has_reserved_name; + } + +} + diff --git a/src/Google/Protobuf/Internal/DescriptorProto/ExtensionRange.php b/src/Google/Protobuf/Internal/DescriptorProto/ExtensionRange.php new file mode 100644 index 00000000..82b5695e --- /dev/null +++ b/src/Google/Protobuf/Internal/DescriptorProto/ExtensionRange.php @@ -0,0 +1,152 @@ +google.protobuf.DescriptorProto.ExtensionRange + */ +class ExtensionRange extends \Google\Protobuf\Internal\Message +{ + /** + * Inclusive. + * + * Generated from protobuf field optional int32 start = 1; + */ + protected $start = 0; + private $has_start = false; + /** + * Exclusive. + * + * Generated from protobuf field optional int32 end = 2; + */ + protected $end = 0; + private $has_end = false; + /** + * Generated from protobuf field optional .google.protobuf.ExtensionRangeOptions options = 3; + */ + protected $options = null; + private $has_options = false; + + /** + * 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 optional int32 start = 1; + * @return int + */ + public function getStart() + { + return $this->start; + } + + /** + * Inclusive. + * + * Generated from protobuf field optional int32 start = 1; + * @param int $var + * @return $this + */ + public function setStart($var) + { + GPBUtil::checkInt32($var); + $this->start = $var; + $this->has_start = true; + + return $this; + } + + public function hasStart() + { + return $this->has_start; + } + + /** + * Exclusive. + * + * Generated from protobuf field optional int32 end = 2; + * @return int + */ + public function getEnd() + { + return $this->end; + } + + /** + * Exclusive. + * + * Generated from protobuf field optional int32 end = 2; + * @param int $var + * @return $this + */ + public function setEnd($var) + { + GPBUtil::checkInt32($var); + $this->end = $var; + $this->has_end = true; + + return $this; + } + + public function hasEnd() + { + return $this->has_end; + } + + /** + * Generated from protobuf field optional .google.protobuf.ExtensionRangeOptions options = 3; + * @return \Google\Protobuf\Internal\ExtensionRangeOptions + */ + public function getOptions() + { + return $this->options; + } + + /** + * Generated from protobuf field optional .google.protobuf.ExtensionRangeOptions options = 3; + * @param \Google\Protobuf\Internal\ExtensionRangeOptions $var + * @return $this + */ + public function setOptions($var) + { + GPBUtil::checkMessage($var, \Google\Protobuf\Internal\ExtensionRangeOptions::class); + $this->options = $var; + $this->has_options = true; + + return $this; + } + + public function hasOptions() + { + return $this->has_options; + } + +} + +// Adding a class alias for backwards compatibility with the previous class name. +class_alias(ExtensionRange::class, \Google\Protobuf\Internal\DescriptorProto_ExtensionRange::class); + diff --git a/src/Google/Protobuf/Internal/DescriptorProto/ReservedRange.php b/src/Google/Protobuf/Internal/DescriptorProto/ReservedRange.php new file mode 100644 index 00000000..8022151a --- /dev/null +++ b/src/Google/Protobuf/Internal/DescriptorProto/ReservedRange.php @@ -0,0 +1,122 @@ +google.protobuf.DescriptorProto.ReservedRange + */ +class ReservedRange extends \Google\Protobuf\Internal\Message +{ + /** + * Inclusive. + * + * Generated from protobuf field optional int32 start = 1; + */ + protected $start = 0; + private $has_start = false; + /** + * Exclusive. + * + * Generated from protobuf field optional int32 end = 2; + */ + protected $end = 0; + private $has_end = false; + + /** + * 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 optional int32 start = 1; + * @return int + */ + public function getStart() + { + return $this->start; + } + + /** + * Inclusive. + * + * Generated from protobuf field optional int32 start = 1; + * @param int $var + * @return $this + */ + public function setStart($var) + { + GPBUtil::checkInt32($var); + $this->start = $var; + $this->has_start = true; + + return $this; + } + + public function hasStart() + { + return $this->has_start; + } + + /** + * Exclusive. + * + * Generated from protobuf field optional int32 end = 2; + * @return int + */ + public function getEnd() + { + return $this->end; + } + + /** + * Exclusive. + * + * Generated from protobuf field optional int32 end = 2; + * @param int $var + * @return $this + */ + public function setEnd($var) + { + GPBUtil::checkInt32($var); + $this->end = $var; + $this->has_end = true; + + return $this; + } + + public function hasEnd() + { + return $this->has_end; + } + +} + +// Adding a class alias for backwards compatibility with the previous class name. +class_alias(ReservedRange::class, \Google\Protobuf\Internal\DescriptorProto_ReservedRange::class); + diff --git a/src/Google/Protobuf/Internal/DescriptorProto_ExtensionRange.php b/src/Google/Protobuf/Internal/DescriptorProto_ExtensionRange.php new file mode 100644 index 00000000..c928fbe5 --- /dev/null +++ b/src/Google/Protobuf/Internal/DescriptorProto_ExtensionRange.php @@ -0,0 +1,16 @@ +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); + } +} diff --git a/src/Google/Protobuf/Internal/EnumDescriptor.php b/src/Google/Protobuf/Internal/EnumDescriptor.php new file mode 100644 index 00000000..7af4f840 --- /dev/null +++ b/src/Google/Protobuf/Internal/EnumDescriptor.php @@ -0,0 +1,115 @@ +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); + $desc->setFullName($fullname); + $desc->setClass($classname); + $desc->setLegacyClass($legacy_classname); + $values = $proto->getValue(); + foreach ($values as $value) { + $desc->addValue($value->getNumber(), $value); + } + + return $desc; + } +} diff --git a/src/Google/Protobuf/Internal/EnumDescriptorProto.php b/src/Google/Protobuf/Internal/EnumDescriptorProto.php new file mode 100644 index 00000000..f5c7fe14 --- /dev/null +++ b/src/Google/Protobuf/Internal/EnumDescriptorProto.php @@ -0,0 +1,231 @@ +google.protobuf.EnumDescriptorProto + */ +class EnumDescriptorProto extends \Google\Protobuf\Internal\Message +{ + /** + * Generated from protobuf field optional string name = 1; + */ + protected $name = ''; + private $has_name = false; + /** + * Generated from protobuf field repeated .google.protobuf.EnumValueDescriptorProto value = 2; + */ + private $value; + private $has_value = false; + /** + * Generated from protobuf field optional .google.protobuf.EnumOptions options = 3; + */ + protected $options = null; + private $has_options = false; + /** + * 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 repeated .google.protobuf.EnumDescriptorProto.EnumReservedRange reserved_range = 4; + */ + private $reserved_range; + private $has_reserved_range = false; + /** + * Reserved enum value names, which may not be reused. A given name may only + * be reserved once. + * + * Generated from protobuf field repeated string reserved_name = 5; + */ + private $reserved_name; + private $has_reserved_name = false; + + /** + * Constructor. + * + * @param array $data { + * Optional. Data for populating the Message object. + * + * @type string $name + * @type \Google\Protobuf\Internal\EnumValueDescriptorProto[]|\Google\Protobuf\Internal\RepeatedField $value + * @type \Google\Protobuf\Internal\EnumOptions $options + * @type \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 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 optional string name = 1; + * @return string + */ + public function getName() + { + return $this->name; + } + + /** + * Generated from protobuf field optional string name = 1; + * @param string $var + * @return $this + */ + public function setName($var) + { + GPBUtil::checkString($var, True); + $this->name = $var; + $this->has_name = true; + + return $this; + } + + public function hasName() + { + return $this->has_name; + } + + /** + * Generated from protobuf field repeated .google.protobuf.EnumValueDescriptorProto value = 2; + * @return \Google\Protobuf\Internal\RepeatedField + */ + public function getValue() + { + return $this->value; + } + + /** + * Generated from protobuf field repeated .google.protobuf.EnumValueDescriptorProto value = 2; + * @param \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; + $this->has_value = true; + + return $this; + } + + public function hasValue() + { + return $this->has_value; + } + + /** + * Generated from protobuf field optional .google.protobuf.EnumOptions options = 3; + * @return \Google\Protobuf\Internal\EnumOptions + */ + public function getOptions() + { + return $this->options; + } + + /** + * Generated from protobuf field optional .google.protobuf.EnumOptions options = 3; + * @param \Google\Protobuf\Internal\EnumOptions $var + * @return $this + */ + public function setOptions($var) + { + GPBUtil::checkMessage($var, \Google\Protobuf\Internal\EnumOptions::class); + $this->options = $var; + $this->has_options = true; + + return $this; + } + + public function hasOptions() + { + return $this->has_options; + } + + /** + * 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 repeated .google.protobuf.EnumDescriptorProto.EnumReservedRange reserved_range = 4; + * @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 repeated .google.protobuf.EnumDescriptorProto.EnumReservedRange reserved_range = 4; + * @param \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; + $this->has_reserved_range = true; + + return $this; + } + + public function hasReservedRange() + { + return $this->has_reserved_range; + } + + /** + * Reserved enum value names, which may not be reused. A given name may only + * be reserved once. + * + * Generated from protobuf field repeated string reserved_name = 5; + * @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 repeated string reserved_name = 5; + * @param 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; + $this->has_reserved_name = true; + + return $this; + } + + public function hasReservedName() + { + return $this->has_reserved_name; + } + +} + diff --git a/src/Google/Protobuf/Internal/EnumDescriptorProto/EnumReservedRange.php b/src/Google/Protobuf/Internal/EnumDescriptorProto/EnumReservedRange.php new file mode 100644 index 00000000..949dd891 --- /dev/null +++ b/src/Google/Protobuf/Internal/EnumDescriptorProto/EnumReservedRange.php @@ -0,0 +1,124 @@ +google.protobuf.EnumDescriptorProto.EnumReservedRange + */ +class EnumReservedRange extends \Google\Protobuf\Internal\Message +{ + /** + * Inclusive. + * + * Generated from protobuf field optional int32 start = 1; + */ + protected $start = 0; + private $has_start = false; + /** + * Inclusive. + * + * Generated from protobuf field optional int32 end = 2; + */ + protected $end = 0; + private $has_end = false; + + /** + * 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 optional int32 start = 1; + * @return int + */ + public function getStart() + { + return $this->start; + } + + /** + * Inclusive. + * + * Generated from protobuf field optional int32 start = 1; + * @param int $var + * @return $this + */ + public function setStart($var) + { + GPBUtil::checkInt32($var); + $this->start = $var; + $this->has_start = true; + + return $this; + } + + public function hasStart() + { + return $this->has_start; + } + + /** + * Inclusive. + * + * Generated from protobuf field optional int32 end = 2; + * @return int + */ + public function getEnd() + { + return $this->end; + } + + /** + * Inclusive. + * + * Generated from protobuf field optional int32 end = 2; + * @param int $var + * @return $this + */ + public function setEnd($var) + { + GPBUtil::checkInt32($var); + $this->end = $var; + $this->has_end = true; + + return $this; + } + + public function hasEnd() + { + return $this->has_end; + } + +} + +// Adding a class alias for backwards compatibility with the previous class name. +class_alias(EnumReservedRange::class, \Google\Protobuf\Internal\EnumDescriptorProto_EnumReservedRange::class); + diff --git a/src/Google/Protobuf/Internal/EnumDescriptorProto_EnumReservedRange.php b/src/Google/Protobuf/Internal/EnumDescriptorProto_EnumReservedRange.php new file mode 100644 index 00000000..b1b59ed9 --- /dev/null +++ b/src/Google/Protobuf/Internal/EnumDescriptorProto_EnumReservedRange.php @@ -0,0 +1,16 @@ +google.protobuf.EnumOptions + */ +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 optional bool allow_alias = 2; + */ + protected $allow_alias = false; + private $has_allow_alias = false; + /** + * 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 optional bool deprecated = 3 [default = false]; + */ + protected $deprecated = false; + private $has_deprecated = false; + /** + * The parser stores options it doesn't recognize here. See above. + * + * Generated from protobuf field repeated .google.protobuf.UninterpretedOption uninterpreted_option = 999; + */ + private $uninterpreted_option; + private $has_uninterpreted_option = false; + + /** + * 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 \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 optional bool allow_alias = 2; + * @return bool + */ + public function getAllowAlias() + { + return $this->allow_alias; + } + + /** + * Set this option to true to allow mapping different tag names to the same + * value. + * + * Generated from protobuf field optional bool allow_alias = 2; + * @param bool $var + * @return $this + */ + public function setAllowAlias($var) + { + GPBUtil::checkBool($var); + $this->allow_alias = $var; + $this->has_allow_alias = true; + + return $this; + } + + public function hasAllowAlias() + { + return $this->has_allow_alias; + } + + /** + * 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 optional bool deprecated = 3 [default = false]; + * @return bool + */ + public function getDeprecated() + { + return $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 optional bool deprecated = 3 [default = false]; + * @param bool $var + * @return $this + */ + public function setDeprecated($var) + { + GPBUtil::checkBool($var); + $this->deprecated = $var; + $this->has_deprecated = true; + + return $this; + } + + public function hasDeprecated() + { + return $this->has_deprecated; + } + + /** + * The parser stores options it doesn't recognize here. See above. + * + * Generated from protobuf field repeated .google.protobuf.UninterpretedOption uninterpreted_option = 999; + * @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 repeated .google.protobuf.UninterpretedOption uninterpreted_option = 999; + * @param \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; + $this->has_uninterpreted_option = true; + + return $this; + } + + public function hasUninterpretedOption() + { + return $this->has_uninterpreted_option; + } + +} + diff --git a/src/Google/Protobuf/Internal/EnumValueDescriptorProto.php b/src/Google/Protobuf/Internal/EnumValueDescriptorProto.php new file mode 100644 index 00000000..3dd95583 --- /dev/null +++ b/src/Google/Protobuf/Internal/EnumValueDescriptorProto.php @@ -0,0 +1,137 @@ +google.protobuf.EnumValueDescriptorProto + */ +class EnumValueDescriptorProto extends \Google\Protobuf\Internal\Message +{ + /** + * Generated from protobuf field optional string name = 1; + */ + protected $name = ''; + private $has_name = false; + /** + * Generated from protobuf field optional int32 number = 2; + */ + protected $number = 0; + private $has_number = false; + /** + * Generated from protobuf field optional .google.protobuf.EnumValueOptions options = 3; + */ + protected $options = null; + private $has_options = false; + + /** + * 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 optional string name = 1; + * @return string + */ + public function getName() + { + return $this->name; + } + + /** + * Generated from protobuf field optional string name = 1; + * @param string $var + * @return $this + */ + public function setName($var) + { + GPBUtil::checkString($var, True); + $this->name = $var; + $this->has_name = true; + + return $this; + } + + public function hasName() + { + return $this->has_name; + } + + /** + * Generated from protobuf field optional int32 number = 2; + * @return int + */ + public function getNumber() + { + return $this->number; + } + + /** + * Generated from protobuf field optional int32 number = 2; + * @param int $var + * @return $this + */ + public function setNumber($var) + { + GPBUtil::checkInt32($var); + $this->number = $var; + $this->has_number = true; + + return $this; + } + + public function hasNumber() + { + return $this->has_number; + } + + /** + * Generated from protobuf field optional .google.protobuf.EnumValueOptions options = 3; + * @return \Google\Protobuf\Internal\EnumValueOptions + */ + public function getOptions() + { + return $this->options; + } + + /** + * Generated from protobuf field optional .google.protobuf.EnumValueOptions options = 3; + * @param \Google\Protobuf\Internal\EnumValueOptions $var + * @return $this + */ + public function setOptions($var) + { + GPBUtil::checkMessage($var, \Google\Protobuf\Internal\EnumValueOptions::class); + $this->options = $var; + $this->has_options = true; + + return $this; + } + + public function hasOptions() + { + return $this->has_options; + } + +} + diff --git a/src/Google/Protobuf/Internal/EnumValueOptions.php b/src/Google/Protobuf/Internal/EnumValueOptions.php new file mode 100644 index 00000000..9f9fb3be --- /dev/null +++ b/src/Google/Protobuf/Internal/EnumValueOptions.php @@ -0,0 +1,127 @@ +google.protobuf.EnumValueOptions + */ +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 optional bool deprecated = 1 [default = false]; + */ + protected $deprecated = false; + private $has_deprecated = false; + /** + * The parser stores options it doesn't recognize here. See above. + * + * Generated from protobuf field repeated .google.protobuf.UninterpretedOption uninterpreted_option = 999; + */ + private $uninterpreted_option; + private $has_uninterpreted_option = false; + + /** + * 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 \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 optional bool deprecated = 1 [default = false]; + * @return bool + */ + public function getDeprecated() + { + return $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 optional bool deprecated = 1 [default = false]; + * @param bool $var + * @return $this + */ + public function setDeprecated($var) + { + GPBUtil::checkBool($var); + $this->deprecated = $var; + $this->has_deprecated = true; + + return $this; + } + + public function hasDeprecated() + { + return $this->has_deprecated; + } + + /** + * The parser stores options it doesn't recognize here. See above. + * + * Generated from protobuf field repeated .google.protobuf.UninterpretedOption uninterpreted_option = 999; + * @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 repeated .google.protobuf.UninterpretedOption uninterpreted_option = 999; + * @param \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; + $this->has_uninterpreted_option = true; + + return $this; + } + + public function hasUninterpretedOption() + { + return $this->has_uninterpreted_option; + } + +} + diff --git a/src/Google/Protobuf/Internal/ExtensionRangeOptions.php b/src/Google/Protobuf/Internal/ExtensionRangeOptions.php new file mode 100644 index 00000000..00fbebec --- /dev/null +++ b/src/Google/Protobuf/Internal/ExtensionRangeOptions.php @@ -0,0 +1,74 @@ +google.protobuf.ExtensionRangeOptions + */ +class ExtensionRangeOptions extends \Google\Protobuf\Internal\Message +{ + /** + * The parser stores options it doesn't recognize here. See above. + * + * Generated from protobuf field repeated .google.protobuf.UninterpretedOption uninterpreted_option = 999; + */ + private $uninterpreted_option; + private $has_uninterpreted_option = false; + + /** + * Constructor. + * + * @param array $data { + * Optional. Data for populating the Message object. + * + * @type \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 repeated .google.protobuf.UninterpretedOption uninterpreted_option = 999; + * @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 repeated .google.protobuf.UninterpretedOption uninterpreted_option = 999; + * @param \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; + $this->has_uninterpreted_option = true; + + return $this; + } + + public function hasUninterpretedOption() + { + return $this->has_uninterpreted_option; + } + +} + diff --git a/src/Google/Protobuf/Internal/FieldDescriptor.php b/src/Google/Protobuf/Internal/FieldDescriptor.php new file mode 100644 index 00000000..98b516fe --- /dev/null +++ b/src/Google/Protobuf/Internal/FieldDescriptor.php @@ -0,0 +1,284 @@ +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 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); + } + + 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; + $packed = false; + $options = $proto->getOptions(); + if ($options !== null) { + $packed = $options->getPacked(); + } + + $field = new FieldDescriptor(); + $field->setName($proto->getName()); + + $json_name = $proto->hasJsonName() ? $proto->getJsonName() : + lcfirst(implode('', array_map('ucwords', explode('_', $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); + + // 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); + } +} diff --git a/src/Google/Protobuf/Internal/FieldDescriptorProto.php b/src/Google/Protobuf/Internal/FieldDescriptorProto.php new file mode 100644 index 00000000..b231c9e1 --- /dev/null +++ b/src/Google/Protobuf/Internal/FieldDescriptorProto.php @@ -0,0 +1,473 @@ +google.protobuf.FieldDescriptorProto + */ +class FieldDescriptorProto extends \Google\Protobuf\Internal\Message +{ + /** + * Generated from protobuf field optional string name = 1; + */ + protected $name = ''; + private $has_name = false; + /** + * Generated from protobuf field optional int32 number = 3; + */ + protected $number = 0; + private $has_number = false; + /** + * Generated from protobuf field optional .google.protobuf.FieldDescriptorProto.Label label = 4; + */ + protected $label = 0; + private $has_label = false; + /** + * 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 optional .google.protobuf.FieldDescriptorProto.Type type = 5; + */ + protected $type = 0; + private $has_type = false; + /** + * 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 optional string type_name = 6; + */ + protected $type_name = ''; + private $has_type_name = false; + /** + * 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 optional string extendee = 2; + */ + protected $extendee = ''; + private $has_extendee = false; + /** + * 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. + * TODO(kenton): Base-64 encode? + * + * Generated from protobuf field optional string default_value = 7; + */ + protected $default_value = ''; + private $has_default_value = false; + /** + * 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 optional int32 oneof_index = 9; + */ + protected $oneof_index = 0; + private $has_oneof_index = false; + /** + * 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 optional string json_name = 10; + */ + protected $json_name = ''; + private $has_json_name = false; + /** + * Generated from protobuf field optional .google.protobuf.FieldOptions options = 8; + */ + protected $options = null; + private $has_options = false; + + /** + * 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. + * TODO(kenton): Base-64 encode? + * @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 + * } + */ + public function __construct($data = NULL) { + \GPBMetadata\Google\Protobuf\Internal\Descriptor::initOnce(); + parent::__construct($data); + } + + /** + * Generated from protobuf field optional string name = 1; + * @return string + */ + public function getName() + { + return $this->name; + } + + /** + * Generated from protobuf field optional string name = 1; + * @param string $var + * @return $this + */ + public function setName($var) + { + GPBUtil::checkString($var, True); + $this->name = $var; + $this->has_name = true; + + return $this; + } + + public function hasName() + { + return $this->has_name; + } + + /** + * Generated from protobuf field optional int32 number = 3; + * @return int + */ + public function getNumber() + { + return $this->number; + } + + /** + * Generated from protobuf field optional int32 number = 3; + * @param int $var + * @return $this + */ + public function setNumber($var) + { + GPBUtil::checkInt32($var); + $this->number = $var; + $this->has_number = true; + + return $this; + } + + public function hasNumber() + { + return $this->has_number; + } + + /** + * Generated from protobuf field optional .google.protobuf.FieldDescriptorProto.Label label = 4; + * @return int + */ + public function getLabel() + { + return $this->label; + } + + /** + * Generated from protobuf field optional .google.protobuf.FieldDescriptorProto.Label label = 4; + * @param int $var + * @return $this + */ + public function setLabel($var) + { + GPBUtil::checkEnum($var, \Google\Protobuf\Internal\FieldDescriptorProto_Label::class); + $this->label = $var; + $this->has_label = true; + + return $this; + } + + public function hasLabel() + { + return $this->has_label; + } + + /** + * 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 optional .google.protobuf.FieldDescriptorProto.Type type = 5; + * @return int + */ + public function getType() + { + return $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 optional .google.protobuf.FieldDescriptorProto.Type type = 5; + * @param int $var + * @return $this + */ + public function setType($var) + { + GPBUtil::checkEnum($var, \Google\Protobuf\Internal\FieldDescriptorProto_Type::class); + $this->type = $var; + $this->has_type = true; + + return $this; + } + + public function hasType() + { + return $this->has_type; + } + + /** + * 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 optional string type_name = 6; + * @return string + */ + public function getTypeName() + { + return $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 optional string type_name = 6; + * @param string $var + * @return $this + */ + public function setTypeName($var) + { + GPBUtil::checkString($var, True); + $this->type_name = $var; + $this->has_type_name = true; + + return $this; + } + + public function hasTypeName() + { + return $this->has_type_name; + } + + /** + * 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 optional string extendee = 2; + * @return string + */ + public function getExtendee() + { + return $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 optional string extendee = 2; + * @param string $var + * @return $this + */ + public function setExtendee($var) + { + GPBUtil::checkString($var, True); + $this->extendee = $var; + $this->has_extendee = true; + + return $this; + } + + public function hasExtendee() + { + return $this->has_extendee; + } + + /** + * 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. + * TODO(kenton): Base-64 encode? + * + * Generated from protobuf field optional string default_value = 7; + * @return string + */ + public function getDefaultValue() + { + return $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. + * TODO(kenton): Base-64 encode? + * + * Generated from protobuf field optional string default_value = 7; + * @param string $var + * @return $this + */ + public function setDefaultValue($var) + { + GPBUtil::checkString($var, True); + $this->default_value = $var; + $this->has_default_value = true; + + return $this; + } + + public function hasDefaultValue() + { + return $this->has_default_value; + } + + /** + * 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 optional int32 oneof_index = 9; + * @return int + */ + public function getOneofIndex() + { + return $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 optional int32 oneof_index = 9; + * @param int $var + * @return $this + */ + public function setOneofIndex($var) + { + GPBUtil::checkInt32($var); + $this->oneof_index = $var; + $this->has_oneof_index = true; + + return $this; + } + + public function hasOneofIndex() + { + return $this->has_oneof_index; + } + + /** + * 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 optional string json_name = 10; + * @return string + */ + public function getJsonName() + { + return $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 optional string json_name = 10; + * @param string $var + * @return $this + */ + public function setJsonName($var) + { + GPBUtil::checkString($var, True); + $this->json_name = $var; + $this->has_json_name = true; + + return $this; + } + + public function hasJsonName() + { + return $this->has_json_name; + } + + /** + * Generated from protobuf field optional .google.protobuf.FieldOptions options = 8; + * @return \Google\Protobuf\Internal\FieldOptions + */ + public function getOptions() + { + return $this->options; + } + + /** + * Generated from protobuf field optional .google.protobuf.FieldOptions options = 8; + * @param \Google\Protobuf\Internal\FieldOptions $var + * @return $this + */ + public function setOptions($var) + { + GPBUtil::checkMessage($var, \Google\Protobuf\Internal\FieldOptions::class); + $this->options = $var; + $this->has_options = true; + + return $this; + } + + public function hasOptions() + { + return $this->has_options; + } + +} + diff --git a/src/Google/Protobuf/Internal/FieldDescriptorProto/Label.php b/src/Google/Protobuf/Internal/FieldDescriptorProto/Label.php new file mode 100644 index 00000000..a54b228f --- /dev/null +++ b/src/Google/Protobuf/Internal/FieldDescriptorProto/Label.php @@ -0,0 +1,58 @@ +google.protobuf.FieldDescriptorProto.Label + */ +class Label +{ + /** + * 0 is reserved for errors + * + * Generated from protobuf enum LABEL_OPTIONAL = 1; + */ + const LABEL_OPTIONAL = 1; + /** + * Generated from protobuf enum LABEL_REQUIRED = 2; + */ + const LABEL_REQUIRED = 2; + /** + * Generated from protobuf enum LABEL_REPEATED = 3; + */ + 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); + diff --git a/src/Google/Protobuf/Internal/FieldDescriptorProto/Type.php b/src/Google/Protobuf/Internal/FieldDescriptorProto/Type.php new file mode 100644 index 00000000..6072e999 --- /dev/null +++ b/src/Google/Protobuf/Internal/FieldDescriptorProto/Type.php @@ -0,0 +1,153 @@ +google.protobuf.FieldDescriptorProto.Type + */ +class Type +{ + /** + * 0 is reserved for errors. + * Order is weird for historical reasons. + * + * Generated from protobuf enum TYPE_DOUBLE = 1; + */ + const TYPE_DOUBLE = 1; + /** + * Generated from protobuf enum TYPE_FLOAT = 2; + */ + const TYPE_FLOAT = 2; + /** + * Not ZigZag encoded. Negative numbers take 10 bytes. Use TYPE_SINT64 if + * negative values are likely. + * + * Generated from protobuf enum TYPE_INT64 = 3; + */ + const TYPE_INT64 = 3; + /** + * Generated from protobuf enum TYPE_UINT64 = 4; + */ + const TYPE_UINT64 = 4; + /** + * Not ZigZag encoded. Negative numbers take 10 bytes. Use TYPE_SINT32 if + * negative values are likely. + * + * Generated from protobuf enum TYPE_INT32 = 5; + */ + const TYPE_INT32 = 5; + /** + * Generated from protobuf enum TYPE_FIXED64 = 6; + */ + const TYPE_FIXED64 = 6; + /** + * Generated from protobuf enum TYPE_FIXED32 = 7; + */ + const TYPE_FIXED32 = 7; + /** + * Generated from protobuf enum TYPE_BOOL = 8; + */ + const TYPE_BOOL = 8; + /** + * Generated from protobuf enum TYPE_STRING = 9; + */ + 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 TYPE_GROUP = 10; + */ + const TYPE_GROUP = 10; + /** + * Length-delimited aggregate. + * + * Generated from protobuf enum TYPE_MESSAGE = 11; + */ + const TYPE_MESSAGE = 11; + /** + * New in version 2. + * + * Generated from protobuf enum TYPE_BYTES = 12; + */ + const TYPE_BYTES = 12; + /** + * Generated from protobuf enum TYPE_UINT32 = 13; + */ + const TYPE_UINT32 = 13; + /** + * Generated from protobuf enum TYPE_ENUM = 14; + */ + const TYPE_ENUM = 14; + /** + * Generated from protobuf enum TYPE_SFIXED32 = 15; + */ + const TYPE_SFIXED32 = 15; + /** + * Generated from protobuf enum TYPE_SFIXED64 = 16; + */ + const TYPE_SFIXED64 = 16; + /** + * Uses ZigZag encoding. + * + * Generated from protobuf enum TYPE_SINT32 = 17; + */ + const TYPE_SINT32 = 17; + /** + * Uses ZigZag encoding. + * + * Generated from protobuf enum TYPE_SINT64 = 18; + */ + 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); + diff --git a/src/Google/Protobuf/Internal/FieldDescriptorProto_Label.php b/src/Google/Protobuf/Internal/FieldDescriptorProto_Label.php new file mode 100644 index 00000000..218a846e --- /dev/null +++ b/src/Google/Protobuf/Internal/FieldDescriptorProto_Label.php @@ -0,0 +1,16 @@ +google.protobuf.FieldOptions + */ +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 optional .google.protobuf.FieldOptions.CType ctype = 1 [default = STRING]; + */ + protected $ctype = 0; + private $has_ctype = false; + /** + * 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 optional bool packed = 2; + */ + protected $packed = false; + private $has_packed = false; + /** + * 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 optional .google.protobuf.FieldOptions.JSType jstype = 6 [default = JS_NORMAL]; + */ + protected $jstype = 0; + private $has_jstype = false; + /** + * 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. + * + * Generated from protobuf field optional bool lazy = 5 [default = false]; + */ + protected $lazy = false; + private $has_lazy = false; + /** + * 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 optional bool deprecated = 3 [default = false]; + */ + protected $deprecated = false; + private $has_deprecated = false; + /** + * For Google-internal migration only. Do not use. + * + * Generated from protobuf field optional bool weak = 10 [default = false]; + */ + protected $weak = false; + private $has_weak = false; + /** + * The parser stores options it doesn't recognize here. See above. + * + * Generated from protobuf field repeated .google.protobuf.UninterpretedOption uninterpreted_option = 999; + */ + private $uninterpreted_option; + private $has_uninterpreted_option = false; + + /** + * 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. + * @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 \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 optional .google.protobuf.FieldOptions.CType ctype = 1 [default = STRING]; + * @return int + */ + public function getCtype() + { + return $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 optional .google.protobuf.FieldOptions.CType ctype = 1 [default = STRING]; + * @param int $var + * @return $this + */ + public function setCtype($var) + { + GPBUtil::checkEnum($var, \Google\Protobuf\Internal\FieldOptions_CType::class); + $this->ctype = $var; + $this->has_ctype = true; + + return $this; + } + + public function hasCtype() + { + return $this->has_ctype; + } + + /** + * 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 optional bool packed = 2; + * @return bool + */ + public function getPacked() + { + return $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 optional bool packed = 2; + * @param bool $var + * @return $this + */ + public function setPacked($var) + { + GPBUtil::checkBool($var); + $this->packed = $var; + $this->has_packed = true; + + return $this; + } + + public function hasPacked() + { + return $this->has_packed; + } + + /** + * 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 optional .google.protobuf.FieldOptions.JSType jstype = 6 [default = JS_NORMAL]; + * @return int + */ + public function getJstype() + { + return $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 optional .google.protobuf.FieldOptions.JSType jstype = 6 [default = JS_NORMAL]; + * @param int $var + * @return $this + */ + public function setJstype($var) + { + GPBUtil::checkEnum($var, \Google\Protobuf\Internal\FieldOptions_JSType::class); + $this->jstype = $var; + $this->has_jstype = true; + + return $this; + } + + public function hasJstype() + { + return $this->has_jstype; + } + + /** + * 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. + * + * Generated from protobuf field optional bool lazy = 5 [default = false]; + * @return bool + */ + public function getLazy() + { + return $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. + * + * Generated from protobuf field optional bool lazy = 5 [default = false]; + * @param bool $var + * @return $this + */ + public function setLazy($var) + { + GPBUtil::checkBool($var); + $this->lazy = $var; + $this->has_lazy = true; + + return $this; + } + + public function hasLazy() + { + return $this->has_lazy; + } + + /** + * 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 optional bool deprecated = 3 [default = false]; + * @return bool + */ + public function getDeprecated() + { + return $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 optional bool deprecated = 3 [default = false]; + * @param bool $var + * @return $this + */ + public function setDeprecated($var) + { + GPBUtil::checkBool($var); + $this->deprecated = $var; + $this->has_deprecated = true; + + return $this; + } + + public function hasDeprecated() + { + return $this->has_deprecated; + } + + /** + * For Google-internal migration only. Do not use. + * + * Generated from protobuf field optional bool weak = 10 [default = false]; + * @return bool + */ + public function getWeak() + { + return $this->weak; + } + + /** + * For Google-internal migration only. Do not use. + * + * Generated from protobuf field optional bool weak = 10 [default = false]; + * @param bool $var + * @return $this + */ + public function setWeak($var) + { + GPBUtil::checkBool($var); + $this->weak = $var; + $this->has_weak = true; + + return $this; + } + + public function hasWeak() + { + return $this->has_weak; + } + + /** + * The parser stores options it doesn't recognize here. See above. + * + * Generated from protobuf field repeated .google.protobuf.UninterpretedOption uninterpreted_option = 999; + * @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 repeated .google.protobuf.UninterpretedOption uninterpreted_option = 999; + * @param \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; + $this->has_uninterpreted_option = true; + + return $this; + } + + public function hasUninterpretedOption() + { + return $this->has_uninterpreted_option; + } + +} + diff --git a/src/Google/Protobuf/Internal/FieldOptions/CType.php b/src/Google/Protobuf/Internal/FieldOptions/CType.php new file mode 100644 index 00000000..ba9eb4ad --- /dev/null +++ b/src/Google/Protobuf/Internal/FieldOptions/CType.php @@ -0,0 +1,58 @@ +google.protobuf.FieldOptions.CType + */ +class CType +{ + /** + * Default mode. + * + * Generated from protobuf enum STRING = 0; + */ + const STRING = 0; + /** + * Generated from protobuf enum CORD = 1; + */ + const CORD = 1; + /** + * Generated from protobuf enum STRING_PIECE = 2; + */ + 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); + diff --git a/src/Google/Protobuf/Internal/FieldOptions/JSType.php b/src/Google/Protobuf/Internal/FieldOptions/JSType.php new file mode 100644 index 00000000..175a4330 --- /dev/null +++ b/src/Google/Protobuf/Internal/FieldOptions/JSType.php @@ -0,0 +1,62 @@ +google.protobuf.FieldOptions.JSType + */ +class JSType +{ + /** + * Use the default type. + * + * Generated from protobuf enum JS_NORMAL = 0; + */ + const JS_NORMAL = 0; + /** + * Use JavaScript strings. + * + * Generated from protobuf enum JS_STRING = 1; + */ + const JS_STRING = 1; + /** + * Use JavaScript numbers. + * + * Generated from protobuf enum JS_NUMBER = 2; + */ + 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); + diff --git a/src/Google/Protobuf/Internal/FieldOptions_CType.php b/src/Google/Protobuf/Internal/FieldOptions_CType.php new file mode 100644 index 00000000..4d18783e --- /dev/null +++ b/src/Google/Protobuf/Internal/FieldOptions_CType.php @@ -0,0 +1,16 @@ +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; + } +} diff --git a/src/Google/Protobuf/Internal/FileDescriptorProto.php b/src/Google/Protobuf/Internal/FileDescriptorProto.php new file mode 100644 index 00000000..c9e3648c --- /dev/null +++ b/src/Google/Protobuf/Internal/FileDescriptorProto.php @@ -0,0 +1,519 @@ +google.protobuf.FileDescriptorProto + */ +class FileDescriptorProto extends \Google\Protobuf\Internal\Message +{ + /** + * file name, relative to root of source tree + * + * Generated from protobuf field optional string name = 1; + */ + protected $name = ''; + private $has_name = false; + /** + * e.g. "foo", "foo.bar", etc. + * + * Generated from protobuf field optional string package = 2; + */ + protected $package = ''; + private $has_package = false; + /** + * Names of files imported by this file. + * + * Generated from protobuf field repeated string dependency = 3; + */ + private $dependency; + private $has_dependency = false; + /** + * Indexes of the public imported files in the dependency list above. + * + * Generated from protobuf field repeated int32 public_dependency = 10; + */ + private $public_dependency; + private $has_public_dependency = false; + /** + * Indexes of the weak imported files in the dependency list. + * For Google-internal migration only. Do not use. + * + * Generated from protobuf field repeated int32 weak_dependency = 11; + */ + private $weak_dependency; + private $has_weak_dependency = false; + /** + * All top-level definitions in this file. + * + * Generated from protobuf field repeated .google.protobuf.DescriptorProto message_type = 4; + */ + private $message_type; + private $has_message_type = false; + /** + * Generated from protobuf field repeated .google.protobuf.EnumDescriptorProto enum_type = 5; + */ + private $enum_type; + private $has_enum_type = false; + /** + * Generated from protobuf field repeated .google.protobuf.ServiceDescriptorProto service = 6; + */ + private $service; + private $has_service = false; + /** + * Generated from protobuf field repeated .google.protobuf.FieldDescriptorProto extension = 7; + */ + private $extension; + private $has_extension = false; + /** + * Generated from protobuf field optional .google.protobuf.FileOptions options = 8; + */ + protected $options = null; + private $has_options = false; + /** + * 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 optional .google.protobuf.SourceCodeInfo source_code_info = 9; + */ + protected $source_code_info = null; + private $has_source_code_info = false; + /** + * The syntax of the proto file. + * The supported values are "proto2" and "proto3". + * + * Generated from protobuf field optional string syntax = 12; + */ + protected $syntax = ''; + private $has_syntax = false; + + /** + * 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 string[]|\Google\Protobuf\Internal\RepeatedField $dependency + * Names of files imported by this file. + * @type int[]|\Google\Protobuf\Internal\RepeatedField $public_dependency + * Indexes of the public imported files in the dependency list above. + * @type 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 \Google\Protobuf\Internal\DescriptorProto[]|\Google\Protobuf\Internal\RepeatedField $message_type + * All top-level definitions in this file. + * @type \Google\Protobuf\Internal\EnumDescriptorProto[]|\Google\Protobuf\Internal\RepeatedField $enum_type + * @type \Google\Protobuf\Internal\ServiceDescriptorProto[]|\Google\Protobuf\Internal\RepeatedField $service + * @type \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" and "proto3". + * } + */ + 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 optional string name = 1; + * @return string + */ + public function getName() + { + return $this->name; + } + + /** + * file name, relative to root of source tree + * + * Generated from protobuf field optional string name = 1; + * @param string $var + * @return $this + */ + public function setName($var) + { + GPBUtil::checkString($var, True); + $this->name = $var; + $this->has_name = true; + + return $this; + } + + public function hasName() + { + return $this->has_name; + } + + /** + * e.g. "foo", "foo.bar", etc. + * + * Generated from protobuf field optional string package = 2; + * @return string + */ + public function getPackage() + { + return $this->package; + } + + /** + * e.g. "foo", "foo.bar", etc. + * + * Generated from protobuf field optional string package = 2; + * @param string $var + * @return $this + */ + public function setPackage($var) + { + GPBUtil::checkString($var, True); + $this->package = $var; + $this->has_package = true; + + return $this; + } + + public function hasPackage() + { + return $this->has_package; + } + + /** + * Names of files imported by this file. + * + * Generated from protobuf field repeated string dependency = 3; + * @return \Google\Protobuf\Internal\RepeatedField + */ + public function getDependency() + { + return $this->dependency; + } + + /** + * Names of files imported by this file. + * + * Generated from protobuf field repeated string dependency = 3; + * @param string[]|\Google\Protobuf\Internal\RepeatedField $var + * @return $this + */ + public function setDependency($var) + { + $arr = GPBUtil::checkRepeatedField($var, \Google\Protobuf\Internal\GPBType::STRING); + $this->dependency = $arr; + $this->has_dependency = true; + + return $this; + } + + public function hasDependency() + { + return $this->has_dependency; + } + + /** + * Indexes of the public imported files in the dependency list above. + * + * Generated from protobuf field repeated int32 public_dependency = 10; + * @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 repeated int32 public_dependency = 10; + * @param 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; + $this->has_public_dependency = true; + + return $this; + } + + public function hasPublicDependency() + { + return $this->has_public_dependency; + } + + /** + * Indexes of the weak imported files in the dependency list. + * For Google-internal migration only. Do not use. + * + * Generated from protobuf field repeated int32 weak_dependency = 11; + * @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 repeated int32 weak_dependency = 11; + * @param 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; + $this->has_weak_dependency = true; + + return $this; + } + + public function hasWeakDependency() + { + return $this->has_weak_dependency; + } + + /** + * All top-level definitions in this file. + * + * Generated from protobuf field repeated .google.protobuf.DescriptorProto message_type = 4; + * @return \Google\Protobuf\Internal\RepeatedField + */ + public function getMessageType() + { + return $this->message_type; + } + + /** + * All top-level definitions in this file. + * + * Generated from protobuf field repeated .google.protobuf.DescriptorProto message_type = 4; + * @param \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; + $this->has_message_type = true; + + return $this; + } + + public function hasMessageType() + { + return $this->has_message_type; + } + + /** + * Generated from protobuf field repeated .google.protobuf.EnumDescriptorProto enum_type = 5; + * @return \Google\Protobuf\Internal\RepeatedField + */ + public function getEnumType() + { + return $this->enum_type; + } + + /** + * Generated from protobuf field repeated .google.protobuf.EnumDescriptorProto enum_type = 5; + * @param \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; + $this->has_enum_type = true; + + return $this; + } + + public function hasEnumType() + { + return $this->has_enum_type; + } + + /** + * Generated from protobuf field repeated .google.protobuf.ServiceDescriptorProto service = 6; + * @return \Google\Protobuf\Internal\RepeatedField + */ + public function getService() + { + return $this->service; + } + + /** + * Generated from protobuf field repeated .google.protobuf.ServiceDescriptorProto service = 6; + * @param \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; + $this->has_service = true; + + return $this; + } + + public function hasService() + { + return $this->has_service; + } + + /** + * Generated from protobuf field repeated .google.protobuf.FieldDescriptorProto extension = 7; + * @return \Google\Protobuf\Internal\RepeatedField + */ + public function getExtension() + { + return $this->extension; + } + + /** + * Generated from protobuf field repeated .google.protobuf.FieldDescriptorProto extension = 7; + * @param \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; + $this->has_extension = true; + + return $this; + } + + public function hasExtension() + { + return $this->has_extension; + } + + /** + * Generated from protobuf field optional .google.protobuf.FileOptions options = 8; + * @return \Google\Protobuf\Internal\FileOptions + */ + public function getOptions() + { + return $this->options; + } + + /** + * Generated from protobuf field optional .google.protobuf.FileOptions options = 8; + * @param \Google\Protobuf\Internal\FileOptions $var + * @return $this + */ + public function setOptions($var) + { + GPBUtil::checkMessage($var, \Google\Protobuf\Internal\FileOptions::class); + $this->options = $var; + $this->has_options = true; + + return $this; + } + + public function hasOptions() + { + return $this->has_options; + } + + /** + * 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 optional .google.protobuf.SourceCodeInfo source_code_info = 9; + * @return \Google\Protobuf\Internal\SourceCodeInfo + */ + public function getSourceCodeInfo() + { + return $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 optional .google.protobuf.SourceCodeInfo source_code_info = 9; + * @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; + $this->has_source_code_info = true; + + return $this; + } + + public function hasSourceCodeInfo() + { + return $this->has_source_code_info; + } + + /** + * The syntax of the proto file. + * The supported values are "proto2" and "proto3". + * + * Generated from protobuf field optional string syntax = 12; + * @return string + */ + public function getSyntax() + { + return $this->syntax; + } + + /** + * The syntax of the proto file. + * The supported values are "proto2" and "proto3". + * + * Generated from protobuf field optional string syntax = 12; + * @param string $var + * @return $this + */ + public function setSyntax($var) + { + GPBUtil::checkString($var, True); + $this->syntax = $var; + $this->has_syntax = true; + + return $this; + } + + public function hasSyntax() + { + return $this->has_syntax; + } + +} + diff --git a/src/Google/Protobuf/Internal/FileDescriptorSet.php b/src/Google/Protobuf/Internal/FileDescriptorSet.php new file mode 100644 index 00000000..9907b17d --- /dev/null +++ b/src/Google/Protobuf/Internal/FileDescriptorSet.php @@ -0,0 +1,70 @@ +google.protobuf.FileDescriptorSet + */ +class FileDescriptorSet extends \Google\Protobuf\Internal\Message +{ + /** + * Generated from protobuf field repeated .google.protobuf.FileDescriptorProto file = 1; + */ + private $file; + private $has_file = false; + + /** + * Constructor. + * + * @param array $data { + * Optional. Data for populating the Message object. + * + * @type \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 repeated .google.protobuf.FileDescriptorProto file = 1; + * @return \Google\Protobuf\Internal\RepeatedField + */ + public function getFile() + { + return $this->file; + } + + /** + * Generated from protobuf field repeated .google.protobuf.FileDescriptorProto file = 1; + * @param \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; + $this->has_file = true; + + return $this; + } + + public function hasFile() + { + return $this->has_file; + } + +} + diff --git a/src/Google/Protobuf/Internal/FileOptions.php b/src/Google/Protobuf/Internal/FileOptions.php new file mode 100644 index 00000000..605d92bf --- /dev/null +++ b/src/Google/Protobuf/Internal/FileOptions.php @@ -0,0 +1,1046 @@ +google.protobuf.FileOptions + */ +class FileOptions extends \Google\Protobuf\Internal\Message +{ + /** + * Sets the Java package where classes generated from this .proto will be + * placed. By default, the proto package is used, but this is often + * inappropriate because proto packages do not normally start with backwards + * domain names. + * + * Generated from protobuf field optional string java_package = 1; + */ + protected $java_package = ''; + private $has_java_package = false; + /** + * If set, all the classes from the .proto file are wrapped in a single + * outer class with the given name. This applies to both Proto1 + * (equivalent to the old "--one_java_file" option) and Proto2 (where + * a .proto always translates to a single class, but you may want to + * explicitly choose the class name). + * + * Generated from protobuf field optional string java_outer_classname = 8; + */ + protected $java_outer_classname = ''; + private $has_java_outer_classname = false; + /** + * If set true, then the Java code generator will generate a separate .java + * file for each top-level message, enum, and service defined in the .proto + * file. Thus, these types will *not* be nested inside the outer class + * named by java_outer_classname. However, the outer class will still be + * generated to contain the file's getDescriptor() method as well as any + * top-level extensions defined in the file. + * + * Generated from protobuf field optional bool java_multiple_files = 10 [default = false]; + */ + protected $java_multiple_files = false; + private $has_java_multiple_files = false; + /** + * This option does nothing. + * + * Generated from protobuf field optional bool java_generate_equals_and_hash = 20 [deprecated = true]; + */ + protected $java_generate_equals_and_hash = false; + private $has_java_generate_equals_and_hash = false; + /** + * If set true, then the Java2 code generator will generate code that + * throws an exception whenever an attempt is made to assign a non-UTF-8 + * byte sequence to a string field. + * Message reflection will do the same. + * However, an extension field still accepts non-UTF-8 byte sequences. + * This option has no effect on when used with the lite runtime. + * + * Generated from protobuf field optional bool java_string_check_utf8 = 27 [default = false]; + */ + protected $java_string_check_utf8 = false; + private $has_java_string_check_utf8 = false; + /** + * Generated from protobuf field optional .google.protobuf.FileOptions.OptimizeMode optimize_for = 9 [default = SPEED]; + */ + protected $optimize_for = 0; + private $has_optimize_for = false; + /** + * Sets the Go package where structs generated from this .proto will be + * placed. If omitted, the Go package will be derived from the following: + * - The basename of the package import path, if provided. + * - Otherwise, the package statement in the .proto file, if present. + * - Otherwise, the basename of the .proto file, without extension. + * + * Generated from protobuf field optional string go_package = 11; + */ + protected $go_package = ''; + private $has_go_package = false; + /** + * Should generic services be generated in each language? "Generic" services + * are not specific to any particular RPC system. They are generated by the + * main code generators in each language (without additional plugins). + * Generic services were the only kind of service generation supported by + * early versions of google.protobuf. + * Generic services are now considered deprecated in favor of using plugins + * that generate code specific to your particular RPC system. Therefore, + * these default to false. Old code which depends on generic services should + * explicitly set them to true. + * + * Generated from protobuf field optional bool cc_generic_services = 16 [default = false]; + */ + protected $cc_generic_services = false; + private $has_cc_generic_services = false; + /** + * Generated from protobuf field optional bool java_generic_services = 17 [default = false]; + */ + protected $java_generic_services = false; + private $has_java_generic_services = false; + /** + * Generated from protobuf field optional bool py_generic_services = 18 [default = false]; + */ + protected $py_generic_services = false; + private $has_py_generic_services = false; + /** + * Generated from protobuf field optional bool php_generic_services = 42 [default = false]; + */ + protected $php_generic_services = false; + private $has_php_generic_services = false; + /** + * Is this file deprecated? + * Depending on the target platform, this can emit Deprecated annotations + * for everything in the file, or it will be completely ignored; in the very + * least, this is a formalization for deprecating files. + * + * Generated from protobuf field optional bool deprecated = 23 [default = false]; + */ + protected $deprecated = false; + private $has_deprecated = false; + /** + * Enables the use of arenas for the proto messages in this file. This applies + * only to generated classes for C++. + * + * Generated from protobuf field optional bool cc_enable_arenas = 31 [default = false]; + */ + protected $cc_enable_arenas = false; + private $has_cc_enable_arenas = false; + /** + * Sets the objective c class prefix which is prepended to all objective c + * generated classes from this .proto. There is no default. + * + * Generated from protobuf field optional string objc_class_prefix = 36; + */ + protected $objc_class_prefix = ''; + private $has_objc_class_prefix = false; + /** + * Namespace for generated classes; defaults to the package. + * + * Generated from protobuf field optional string csharp_namespace = 37; + */ + protected $csharp_namespace = ''; + private $has_csharp_namespace = false; + /** + * By default Swift generators will take the proto package and CamelCase it + * replacing '.' with underscore and use that to prefix the types/symbols + * defined. When this options is provided, they will use this value instead + * to prefix the types/symbols defined. + * + * Generated from protobuf field optional string swift_prefix = 39; + */ + protected $swift_prefix = ''; + private $has_swift_prefix = false; + /** + * Sets the php class prefix which is prepended to all php generated classes + * from this .proto. Default is empty. + * + * Generated from protobuf field optional string php_class_prefix = 40; + */ + protected $php_class_prefix = ''; + private $has_php_class_prefix = false; + /** + * Use this option to change the namespace of php generated classes. Default + * is empty. When this option is empty, the package name will be used for + * determining the namespace. + * + * Generated from protobuf field optional string php_namespace = 41; + */ + protected $php_namespace = ''; + private $has_php_namespace = false; + /** + * Use this option to change the namespace of php generated metadata classes. + * Default is empty. When this option is empty, the proto file name will be + * used for determining the namespace. + * + * Generated from protobuf field optional string php_metadata_namespace = 44; + */ + protected $php_metadata_namespace = ''; + private $has_php_metadata_namespace = false; + /** + * Use this option to change the package of ruby generated classes. Default + * is empty. When this option is not set, the package name will be used for + * determining the ruby package. + * + * Generated from protobuf field optional string ruby_package = 45; + */ + protected $ruby_package = ''; + private $has_ruby_package = false; + /** + * The parser stores options it doesn't recognize here. + * See the documentation for the "Options" section above. + * + * Generated from protobuf field repeated .google.protobuf.UninterpretedOption uninterpreted_option = 999; + */ + private $uninterpreted_option; + private $has_uninterpreted_option = false; + + /** + * Constructor. + * + * @param array $data { + * Optional. Data for populating the Message object. + * + * @type string $java_package + * Sets the Java package where classes generated from this .proto will be + * placed. By default, the proto package is used, but this is often + * inappropriate because proto packages do not normally start with backwards + * domain names. + * @type string $java_outer_classname + * If set, all the classes from the .proto file are wrapped in a single + * outer class with the given name. This applies to both Proto1 + * (equivalent to the old "--one_java_file" option) and Proto2 (where + * a .proto always translates to a single class, but you may want to + * explicitly choose the class name). + * @type bool $java_multiple_files + * If set true, then the Java code generator will generate a separate .java + * file for each top-level message, enum, and service defined in the .proto + * file. Thus, these types will *not* be nested inside the outer class + * named by java_outer_classname. However, the outer class will still be + * generated to contain the file's getDescriptor() method as well as any + * top-level extensions defined in the file. + * @type bool $java_generate_equals_and_hash + * This option does nothing. + * @type bool $java_string_check_utf8 + * If set true, then the Java2 code generator will generate code that + * throws an exception whenever an attempt is made to assign a non-UTF-8 + * byte sequence to a string field. + * Message reflection will do the same. + * However, an extension field still accepts non-UTF-8 byte sequences. + * This option has no effect on when used with the lite runtime. + * @type int $optimize_for + * @type string $go_package + * Sets the Go package where structs generated from this .proto will be + * placed. If omitted, the Go package will be derived from the following: + * - The basename of the package import path, if provided. + * - Otherwise, the package statement in the .proto file, if present. + * - Otherwise, the basename of the .proto file, without extension. + * @type bool $cc_generic_services + * Should generic services be generated in each language? "Generic" services + * are not specific to any particular RPC system. They are generated by the + * main code generators in each language (without additional plugins). + * Generic services were the only kind of service generation supported by + * early versions of google.protobuf. + * Generic services are now considered deprecated in favor of using plugins + * that generate code specific to your particular RPC system. Therefore, + * these default to false. Old code which depends on generic services should + * explicitly set them to true. + * @type bool $java_generic_services + * @type bool $py_generic_services + * @type bool $php_generic_services + * @type bool $deprecated + * Is this file deprecated? + * Depending on the target platform, this can emit Deprecated annotations + * for everything in the file, or it will be completely ignored; in the very + * least, this is a formalization for deprecating files. + * @type bool $cc_enable_arenas + * Enables the use of arenas for the proto messages in this file. This applies + * only to generated classes for C++. + * @type string $objc_class_prefix + * Sets the objective c class prefix which is prepended to all objective c + * generated classes from this .proto. There is no default. + * @type string $csharp_namespace + * Namespace for generated classes; defaults to the package. + * @type string $swift_prefix + * By default Swift generators will take the proto package and CamelCase it + * replacing '.' with underscore and use that to prefix the types/symbols + * defined. When this options is provided, they will use this value instead + * to prefix the types/symbols defined. + * @type string $php_class_prefix + * Sets the php class prefix which is prepended to all php generated classes + * from this .proto. Default is empty. + * @type string $php_namespace + * Use this option to change the namespace of php generated classes. Default + * is empty. When this option is empty, the package name will be used for + * determining the namespace. + * @type string $php_metadata_namespace + * Use this option to change the namespace of php generated metadata classes. + * Default is empty. When this option is empty, the proto file name will be + * used for determining the namespace. + * @type string $ruby_package + * Use this option to change the package of ruby generated classes. Default + * is empty. When this option is not set, the package name will be used for + * determining the ruby package. + * @type \Google\Protobuf\Internal\UninterpretedOption[]|\Google\Protobuf\Internal\RepeatedField $uninterpreted_option + * The parser stores options it doesn't recognize here. + * See the documentation for the "Options" section above. + * } + */ + public function __construct($data = NULL) { + \GPBMetadata\Google\Protobuf\Internal\Descriptor::initOnce(); + parent::__construct($data); + } + + /** + * Sets the Java package where classes generated from this .proto will be + * placed. By default, the proto package is used, but this is often + * inappropriate because proto packages do not normally start with backwards + * domain names. + * + * Generated from protobuf field optional string java_package = 1; + * @return string + */ + public function getJavaPackage() + { + return $this->java_package; + } + + /** + * Sets the Java package where classes generated from this .proto will be + * placed. By default, the proto package is used, but this is often + * inappropriate because proto packages do not normally start with backwards + * domain names. + * + * Generated from protobuf field optional string java_package = 1; + * @param string $var + * @return $this + */ + public function setJavaPackage($var) + { + GPBUtil::checkString($var, True); + $this->java_package = $var; + $this->has_java_package = true; + + return $this; + } + + public function hasJavaPackage() + { + return $this->has_java_package; + } + + /** + * If set, all the classes from the .proto file are wrapped in a single + * outer class with the given name. This applies to both Proto1 + * (equivalent to the old "--one_java_file" option) and Proto2 (where + * a .proto always translates to a single class, but you may want to + * explicitly choose the class name). + * + * Generated from protobuf field optional string java_outer_classname = 8; + * @return string + */ + public function getJavaOuterClassname() + { + return $this->java_outer_classname; + } + + /** + * If set, all the classes from the .proto file are wrapped in a single + * outer class with the given name. This applies to both Proto1 + * (equivalent to the old "--one_java_file" option) and Proto2 (where + * a .proto always translates to a single class, but you may want to + * explicitly choose the class name). + * + * Generated from protobuf field optional string java_outer_classname = 8; + * @param string $var + * @return $this + */ + public function setJavaOuterClassname($var) + { + GPBUtil::checkString($var, True); + $this->java_outer_classname = $var; + $this->has_java_outer_classname = true; + + return $this; + } + + public function hasJavaOuterClassname() + { + return $this->has_java_outer_classname; + } + + /** + * If set true, then the Java code generator will generate a separate .java + * file for each top-level message, enum, and service defined in the .proto + * file. Thus, these types will *not* be nested inside the outer class + * named by java_outer_classname. However, the outer class will still be + * generated to contain the file's getDescriptor() method as well as any + * top-level extensions defined in the file. + * + * Generated from protobuf field optional bool java_multiple_files = 10 [default = false]; + * @return bool + */ + public function getJavaMultipleFiles() + { + return $this->java_multiple_files; + } + + /** + * If set true, then the Java code generator will generate a separate .java + * file for each top-level message, enum, and service defined in the .proto + * file. Thus, these types will *not* be nested inside the outer class + * named by java_outer_classname. However, the outer class will still be + * generated to contain the file's getDescriptor() method as well as any + * top-level extensions defined in the file. + * + * Generated from protobuf field optional bool java_multiple_files = 10 [default = false]; + * @param bool $var + * @return $this + */ + public function setJavaMultipleFiles($var) + { + GPBUtil::checkBool($var); + $this->java_multiple_files = $var; + $this->has_java_multiple_files = true; + + return $this; + } + + public function hasJavaMultipleFiles() + { + return $this->has_java_multiple_files; + } + + /** + * This option does nothing. + * + * Generated from protobuf field optional bool java_generate_equals_and_hash = 20 [deprecated = true]; + * @return bool + */ + public function getJavaGenerateEqualsAndHash() + { + return $this->java_generate_equals_and_hash; + } + + /** + * This option does nothing. + * + * Generated from protobuf field optional bool java_generate_equals_and_hash = 20 [deprecated = true]; + * @param bool $var + * @return $this + */ + public function setJavaGenerateEqualsAndHash($var) + { + GPBUtil::checkBool($var); + $this->java_generate_equals_and_hash = $var; + $this->has_java_generate_equals_and_hash = true; + + return $this; + } + + public function hasJavaGenerateEqualsAndHash() + { + return $this->has_java_generate_equals_and_hash; + } + + /** + * If set true, then the Java2 code generator will generate code that + * throws an exception whenever an attempt is made to assign a non-UTF-8 + * byte sequence to a string field. + * Message reflection will do the same. + * However, an extension field still accepts non-UTF-8 byte sequences. + * This option has no effect on when used with the lite runtime. + * + * Generated from protobuf field optional bool java_string_check_utf8 = 27 [default = false]; + * @return bool + */ + public function getJavaStringCheckUtf8() + { + return $this->java_string_check_utf8; + } + + /** + * If set true, then the Java2 code generator will generate code that + * throws an exception whenever an attempt is made to assign a non-UTF-8 + * byte sequence to a string field. + * Message reflection will do the same. + * However, an extension field still accepts non-UTF-8 byte sequences. + * This option has no effect on when used with the lite runtime. + * + * Generated from protobuf field optional bool java_string_check_utf8 = 27 [default = false]; + * @param bool $var + * @return $this + */ + public function setJavaStringCheckUtf8($var) + { + GPBUtil::checkBool($var); + $this->java_string_check_utf8 = $var; + $this->has_java_string_check_utf8 = true; + + return $this; + } + + public function hasJavaStringCheckUtf8() + { + return $this->has_java_string_check_utf8; + } + + /** + * Generated from protobuf field optional .google.protobuf.FileOptions.OptimizeMode optimize_for = 9 [default = SPEED]; + * @return int + */ + public function getOptimizeFor() + { + return $this->optimize_for; + } + + /** + * Generated from protobuf field optional .google.protobuf.FileOptions.OptimizeMode optimize_for = 9 [default = SPEED]; + * @param int $var + * @return $this + */ + public function setOptimizeFor($var) + { + GPBUtil::checkEnum($var, \Google\Protobuf\Internal\FileOptions_OptimizeMode::class); + $this->optimize_for = $var; + $this->has_optimize_for = true; + + return $this; + } + + public function hasOptimizeFor() + { + return $this->has_optimize_for; + } + + /** + * Sets the Go package where structs generated from this .proto will be + * placed. If omitted, the Go package will be derived from the following: + * - The basename of the package import path, if provided. + * - Otherwise, the package statement in the .proto file, if present. + * - Otherwise, the basename of the .proto file, without extension. + * + * Generated from protobuf field optional string go_package = 11; + * @return string + */ + public function getGoPackage() + { + return $this->go_package; + } + + /** + * Sets the Go package where structs generated from this .proto will be + * placed. If omitted, the Go package will be derived from the following: + * - The basename of the package import path, if provided. + * - Otherwise, the package statement in the .proto file, if present. + * - Otherwise, the basename of the .proto file, without extension. + * + * Generated from protobuf field optional string go_package = 11; + * @param string $var + * @return $this + */ + public function setGoPackage($var) + { + GPBUtil::checkString($var, True); + $this->go_package = $var; + $this->has_go_package = true; + + return $this; + } + + public function hasGoPackage() + { + return $this->has_go_package; + } + + /** + * Should generic services be generated in each language? "Generic" services + * are not specific to any particular RPC system. They are generated by the + * main code generators in each language (without additional plugins). + * Generic services were the only kind of service generation supported by + * early versions of google.protobuf. + * Generic services are now considered deprecated in favor of using plugins + * that generate code specific to your particular RPC system. Therefore, + * these default to false. Old code which depends on generic services should + * explicitly set them to true. + * + * Generated from protobuf field optional bool cc_generic_services = 16 [default = false]; + * @return bool + */ + public function getCcGenericServices() + { + return $this->cc_generic_services; + } + + /** + * Should generic services be generated in each language? "Generic" services + * are not specific to any particular RPC system. They are generated by the + * main code generators in each language (without additional plugins). + * Generic services were the only kind of service generation supported by + * early versions of google.protobuf. + * Generic services are now considered deprecated in favor of using plugins + * that generate code specific to your particular RPC system. Therefore, + * these default to false. Old code which depends on generic services should + * explicitly set them to true. + * + * Generated from protobuf field optional bool cc_generic_services = 16 [default = false]; + * @param bool $var + * @return $this + */ + public function setCcGenericServices($var) + { + GPBUtil::checkBool($var); + $this->cc_generic_services = $var; + $this->has_cc_generic_services = true; + + return $this; + } + + public function hasCcGenericServices() + { + return $this->has_cc_generic_services; + } + + /** + * Generated from protobuf field optional bool java_generic_services = 17 [default = false]; + * @return bool + */ + public function getJavaGenericServices() + { + return $this->java_generic_services; + } + + /** + * Generated from protobuf field optional bool java_generic_services = 17 [default = false]; + * @param bool $var + * @return $this + */ + public function setJavaGenericServices($var) + { + GPBUtil::checkBool($var); + $this->java_generic_services = $var; + $this->has_java_generic_services = true; + + return $this; + } + + public function hasJavaGenericServices() + { + return $this->has_java_generic_services; + } + + /** + * Generated from protobuf field optional bool py_generic_services = 18 [default = false]; + * @return bool + */ + public function getPyGenericServices() + { + return $this->py_generic_services; + } + + /** + * Generated from protobuf field optional bool py_generic_services = 18 [default = false]; + * @param bool $var + * @return $this + */ + public function setPyGenericServices($var) + { + GPBUtil::checkBool($var); + $this->py_generic_services = $var; + $this->has_py_generic_services = true; + + return $this; + } + + public function hasPyGenericServices() + { + return $this->has_py_generic_services; + } + + /** + * Generated from protobuf field optional bool php_generic_services = 42 [default = false]; + * @return bool + */ + public function getPhpGenericServices() + { + return $this->php_generic_services; + } + + /** + * Generated from protobuf field optional bool php_generic_services = 42 [default = false]; + * @param bool $var + * @return $this + */ + public function setPhpGenericServices($var) + { + GPBUtil::checkBool($var); + $this->php_generic_services = $var; + $this->has_php_generic_services = true; + + return $this; + } + + public function hasPhpGenericServices() + { + return $this->has_php_generic_services; + } + + /** + * Is this file deprecated? + * Depending on the target platform, this can emit Deprecated annotations + * for everything in the file, or it will be completely ignored; in the very + * least, this is a formalization for deprecating files. + * + * Generated from protobuf field optional bool deprecated = 23 [default = false]; + * @return bool + */ + public function getDeprecated() + { + return $this->deprecated; + } + + /** + * Is this file deprecated? + * Depending on the target platform, this can emit Deprecated annotations + * for everything in the file, or it will be completely ignored; in the very + * least, this is a formalization for deprecating files. + * + * Generated from protobuf field optional bool deprecated = 23 [default = false]; + * @param bool $var + * @return $this + */ + public function setDeprecated($var) + { + GPBUtil::checkBool($var); + $this->deprecated = $var; + $this->has_deprecated = true; + + return $this; + } + + public function hasDeprecated() + { + return $this->has_deprecated; + } + + /** + * Enables the use of arenas for the proto messages in this file. This applies + * only to generated classes for C++. + * + * Generated from protobuf field optional bool cc_enable_arenas = 31 [default = false]; + * @return bool + */ + public function getCcEnableArenas() + { + return $this->cc_enable_arenas; + } + + /** + * Enables the use of arenas for the proto messages in this file. This applies + * only to generated classes for C++. + * + * Generated from protobuf field optional bool cc_enable_arenas = 31 [default = false]; + * @param bool $var + * @return $this + */ + public function setCcEnableArenas($var) + { + GPBUtil::checkBool($var); + $this->cc_enable_arenas = $var; + $this->has_cc_enable_arenas = true; + + return $this; + } + + public function hasCcEnableArenas() + { + return $this->has_cc_enable_arenas; + } + + /** + * Sets the objective c class prefix which is prepended to all objective c + * generated classes from this .proto. There is no default. + * + * Generated from protobuf field optional string objc_class_prefix = 36; + * @return string + */ + public function getObjcClassPrefix() + { + return $this->objc_class_prefix; + } + + /** + * Sets the objective c class prefix which is prepended to all objective c + * generated classes from this .proto. There is no default. + * + * Generated from protobuf field optional string objc_class_prefix = 36; + * @param string $var + * @return $this + */ + public function setObjcClassPrefix($var) + { + GPBUtil::checkString($var, True); + $this->objc_class_prefix = $var; + $this->has_objc_class_prefix = true; + + return $this; + } + + public function hasObjcClassPrefix() + { + return $this->has_objc_class_prefix; + } + + /** + * Namespace for generated classes; defaults to the package. + * + * Generated from protobuf field optional string csharp_namespace = 37; + * @return string + */ + public function getCsharpNamespace() + { + return $this->csharp_namespace; + } + + /** + * Namespace for generated classes; defaults to the package. + * + * Generated from protobuf field optional string csharp_namespace = 37; + * @param string $var + * @return $this + */ + public function setCsharpNamespace($var) + { + GPBUtil::checkString($var, True); + $this->csharp_namespace = $var; + $this->has_csharp_namespace = true; + + return $this; + } + + public function hasCsharpNamespace() + { + return $this->has_csharp_namespace; + } + + /** + * By default Swift generators will take the proto package and CamelCase it + * replacing '.' with underscore and use that to prefix the types/symbols + * defined. When this options is provided, they will use this value instead + * to prefix the types/symbols defined. + * + * Generated from protobuf field optional string swift_prefix = 39; + * @return string + */ + public function getSwiftPrefix() + { + return $this->swift_prefix; + } + + /** + * By default Swift generators will take the proto package and CamelCase it + * replacing '.' with underscore and use that to prefix the types/symbols + * defined. When this options is provided, they will use this value instead + * to prefix the types/symbols defined. + * + * Generated from protobuf field optional string swift_prefix = 39; + * @param string $var + * @return $this + */ + public function setSwiftPrefix($var) + { + GPBUtil::checkString($var, True); + $this->swift_prefix = $var; + $this->has_swift_prefix = true; + + return $this; + } + + public function hasSwiftPrefix() + { + return $this->has_swift_prefix; + } + + /** + * Sets the php class prefix which is prepended to all php generated classes + * from this .proto. Default is empty. + * + * Generated from protobuf field optional string php_class_prefix = 40; + * @return string + */ + public function getPhpClassPrefix() + { + return $this->php_class_prefix; + } + + /** + * Sets the php class prefix which is prepended to all php generated classes + * from this .proto. Default is empty. + * + * Generated from protobuf field optional string php_class_prefix = 40; + * @param string $var + * @return $this + */ + public function setPhpClassPrefix($var) + { + GPBUtil::checkString($var, True); + $this->php_class_prefix = $var; + $this->has_php_class_prefix = true; + + return $this; + } + + public function hasPhpClassPrefix() + { + return $this->has_php_class_prefix; + } + + /** + * Use this option to change the namespace of php generated classes. Default + * is empty. When this option is empty, the package name will be used for + * determining the namespace. + * + * Generated from protobuf field optional string php_namespace = 41; + * @return string + */ + public function getPhpNamespace() + { + return $this->php_namespace; + } + + /** + * Use this option to change the namespace of php generated classes. Default + * is empty. When this option is empty, the package name will be used for + * determining the namespace. + * + * Generated from protobuf field optional string php_namespace = 41; + * @param string $var + * @return $this + */ + public function setPhpNamespace($var) + { + GPBUtil::checkString($var, True); + $this->php_namespace = $var; + $this->has_php_namespace = true; + + return $this; + } + + public function hasPhpNamespace() + { + return $this->has_php_namespace; + } + + /** + * Use this option to change the namespace of php generated metadata classes. + * Default is empty. When this option is empty, the proto file name will be + * used for determining the namespace. + * + * Generated from protobuf field optional string php_metadata_namespace = 44; + * @return string + */ + public function getPhpMetadataNamespace() + { + return $this->php_metadata_namespace; + } + + /** + * Use this option to change the namespace of php generated metadata classes. + * Default is empty. When this option is empty, the proto file name will be + * used for determining the namespace. + * + * Generated from protobuf field optional string php_metadata_namespace = 44; + * @param string $var + * @return $this + */ + public function setPhpMetadataNamespace($var) + { + GPBUtil::checkString($var, True); + $this->php_metadata_namespace = $var; + $this->has_php_metadata_namespace = true; + + return $this; + } + + public function hasPhpMetadataNamespace() + { + return $this->has_php_metadata_namespace; + } + + /** + * Use this option to change the package of ruby generated classes. Default + * is empty. When this option is not set, the package name will be used for + * determining the ruby package. + * + * Generated from protobuf field optional string ruby_package = 45; + * @return string + */ + public function getRubyPackage() + { + return $this->ruby_package; + } + + /** + * Use this option to change the package of ruby generated classes. Default + * is empty. When this option is not set, the package name will be used for + * determining the ruby package. + * + * Generated from protobuf field optional string ruby_package = 45; + * @param string $var + * @return $this + */ + public function setRubyPackage($var) + { + GPBUtil::checkString($var, True); + $this->ruby_package = $var; + $this->has_ruby_package = true; + + return $this; + } + + public function hasRubyPackage() + { + return $this->has_ruby_package; + } + + /** + * The parser stores options it doesn't recognize here. + * See the documentation for the "Options" section above. + * + * Generated from protobuf field repeated .google.protobuf.UninterpretedOption uninterpreted_option = 999; + * @return \Google\Protobuf\Internal\RepeatedField + */ + public function getUninterpretedOption() + { + return $this->uninterpreted_option; + } + + /** + * The parser stores options it doesn't recognize here. + * See the documentation for the "Options" section above. + * + * Generated from protobuf field repeated .google.protobuf.UninterpretedOption uninterpreted_option = 999; + * @param \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; + $this->has_uninterpreted_option = true; + + return $this; + } + + public function hasUninterpretedOption() + { + return $this->has_uninterpreted_option; + } + +} + diff --git a/src/Google/Protobuf/Internal/FileOptions/OptimizeMode.php b/src/Google/Protobuf/Internal/FileOptions/OptimizeMode.php new file mode 100644 index 00000000..0df27b53 --- /dev/null +++ b/src/Google/Protobuf/Internal/FileOptions/OptimizeMode.php @@ -0,0 +1,64 @@ +google.protobuf.FileOptions.OptimizeMode + */ +class OptimizeMode +{ + /** + * Generate complete code for parsing, serialization, + * + * Generated from protobuf enum SPEED = 1; + */ + const SPEED = 1; + /** + * etc. + * + * Generated from protobuf enum CODE_SIZE = 2; + */ + const CODE_SIZE = 2; + /** + * Generate code using MessageLite and the lite runtime. + * + * Generated from protobuf enum LITE_RUNTIME = 3; + */ + 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); + diff --git a/src/Google/Protobuf/Internal/FileOptions_OptimizeMode.php b/src/Google/Protobuf/Internal/FileOptions_OptimizeMode.php new file mode 100644 index 00000000..8926e63b --- /dev/null +++ b/src/Google/Protobuf/Internal/FileOptions_OptimizeMode.php @@ -0,0 +1,16 @@ +writeRaw("\"", 1); + $field_name = GPBJsonWire::formatFieldName($field); + $output->writeRaw($field_name, strlen($field_name)); + $output->writeRaw("\":", 2); + } + return static::serializeFieldValueToStream( + $value, + $field, + $output, + !$has_field_name); + } + + public static function serializeFieldValueToStream( + $values, + $field, + &$output, + $is_well_known = false) + { + if ($field->isMap()) { + $output->writeRaw("{", 1); + $first = true; + $map_entry = $field->getMessageType(); + $key_field = $map_entry->getFieldByNumber(1); + $value_field = $map_entry->getFieldByNumber(2); + + switch ($key_field->getType()) { + case GPBType::STRING: + case GPBType::SFIXED64: + case GPBType::INT64: + case GPBType::SINT64: + case GPBType::FIXED64: + case GPBType::UINT64: + $additional_quote = false; + break; + default: + $additional_quote = true; + } + + foreach ($values as $key => $value) { + if ($first) { + $first = false; + } else { + $output->writeRaw(",", 1); + } + if ($additional_quote) { + $output->writeRaw("\"", 1); + } + if (!static::serializeSingularFieldValueToStream( + $key, + $key_field, + $output, + $is_well_known)) { + return false; + } + if ($additional_quote) { + $output->writeRaw("\"", 1); + } + $output->writeRaw(":", 1); + if (!static::serializeSingularFieldValueToStream( + $value, + $value_field, + $output, + $is_well_known)) { + return false; + } + } + $output->writeRaw("}", 1); + return true; + } elseif ($field->isRepeated()) { + $output->writeRaw("[", 1); + $first = true; + foreach ($values as $value) { + if ($first) { + $first = false; + } else { + $output->writeRaw(",", 1); + } + if (!static::serializeSingularFieldValueToStream( + $value, + $field, + $output, + $is_well_known)) { + return false; + } + } + $output->writeRaw("]", 1); + return true; + } else { + return static::serializeSingularFieldValueToStream( + $values, + $field, + $output, + $is_well_known); + } + } + + private static function serializeSingularFieldValueToStream( + $value, + $field, + &$output, $is_well_known = false) + { + switch ($field->getType()) { + case GPBType::SFIXED32: + case GPBType::SINT32: + case GPBType::INT32: + $str_value = strval($value); + $output->writeRaw($str_value, strlen($str_value)); + break; + case GPBType::FIXED32: + case GPBType::UINT32: + if ($value < 0) { + $value = bcadd($value, "4294967296"); + } + $str_value = strval($value); + $output->writeRaw($str_value, strlen($str_value)); + break; + case GPBType::FIXED64: + case GPBType::UINT64: + if ($value < 0) { + $value = bcadd($value, "18446744073709551616"); + } + // Intentional fall through. + case GPBType::SFIXED64: + case GPBType::INT64: + case GPBType::SINT64: + $output->writeRaw("\"", 1); + $str_value = strval($value); + $output->writeRaw($str_value, strlen($str_value)); + $output->writeRaw("\"", 1); + break; + case GPBType::FLOAT: + if (is_nan($value)) { + $str_value = "\"NaN\""; + } elseif ($value === INF) { + $str_value = "\"Infinity\""; + } elseif ($value === -INF) { + $str_value = "\"-Infinity\""; + } else { + $str_value = sprintf("%.8g", $value); + } + $output->writeRaw($str_value, strlen($str_value)); + break; + case GPBType::DOUBLE: + if (is_nan($value)) { + $str_value = "\"NaN\""; + } elseif ($value === INF) { + $str_value = "\"Infinity\""; + } elseif ($value === -INF) { + $str_value = "\"-Infinity\""; + } else { + $str_value = sprintf("%.17g", $value); + } + $output->writeRaw($str_value, strlen($str_value)); + break; + case GPBType::ENUM: + $enum_desc = $field->getEnumType(); + if ($enum_desc->getClass() === "Google\Protobuf\NullValue") { + $output->writeRaw("null", 4); + break; + } + $enum_value_desc = $enum_desc->getValueByNumber($value); + if (!is_null($enum_value_desc)) { + $str_value = $enum_value_desc->getName(); + $output->writeRaw("\"", 1); + $output->writeRaw($str_value, strlen($str_value)); + $output->writeRaw("\"", 1); + } else { + $str_value = strval($value); + $output->writeRaw($str_value, strlen($str_value)); + } + break; + case GPBType::BOOL: + if ($value) { + $output->writeRaw("true", 4); + } else { + $output->writeRaw("false", 5); + } + break; + case GPBType::BYTES: + $bytes_value = base64_encode($value); + $output->writeRaw("\"", 1); + $output->writeRaw($bytes_value, strlen($bytes_value)); + $output->writeRaw("\"", 1); + break; + case GPBType::STRING: + $value = json_encode($value, JSON_UNESCAPED_UNICODE); + $output->writeRaw($value, strlen($value)); + break; + // case GPBType::GROUP: + // echo "GROUP\xA"; + // trigger_error("Not implemented.", E_ERROR); + // break; + case GPBType::MESSAGE: + $value->serializeToJsonStream($output); + break; + default: + user_error("Unsupported type."); + return false; + } + return true; + } + + private static function formatFieldName($field) + { + return $field->getJsonName(); + } + + // Used for escaping control chars in strings. + private static $k_control_char_limit = 0x20; + + private static function jsonNiceEscape($c) + { + switch ($c) { + case '"': return "\\\""; + case '\\': return "\\\\"; + case '/': return "\\/"; + case '\b': return "\\b"; + case '\f': return "\\f"; + case '\n': return "\\n"; + case '\r': return "\\r"; + case '\t': return "\\t"; + default: return NULL; + } + } + + private static function isJsonEscaped($c) + { + // See RFC 4627. + return $c < chr($k_control_char_limit) || $c === "\"" || $c === "\\"; + } + + public static function escapedJson($value) + { + $escaped_value = ""; + $unescaped_run = ""; + for ($i = 0; $i < strlen($value); $i++) { + $c = $value[$i]; + // Handle escaping. + if (static::isJsonEscaped($c)) { + // Use a "nice" escape, like \n, if one exists for this + // character. + $escape = static::jsonNiceEscape($c); + if (is_null($escape)) { + $escape = "\\u00" . bin2hex($c); + } + if ($unescaped_run !== "") { + $escaped_value .= $unescaped_run; + $unescaped_run = ""; + } + $escaped_value .= $escape; + } else { + if ($unescaped_run === "") { + $unescaped_run .= $c; + } + } + } + $escaped_value .= $unescaped_run; + return $escaped_value; + } + +} diff --git a/src/Google/Protobuf/Internal/GPBLabel.php b/src/Google/Protobuf/Internal/GPBLabel.php new file mode 100644 index 00000000..0fb23841 --- /dev/null +++ b/src/Google/Protobuf/Internal/GPBLabel.php @@ -0,0 +1,40 @@ + 0) { + $high = (int) bcsub($high, 4294967296); + } else { + $high = (int) $high; + } + if (bccomp($low, 2147483647) > 0) { + $low = (int) bcsub($low, 4294967296); + } else { + $low = (int) $low; + } + + if ($isNeg) { + $high = ~$high; + $low = ~$low; + $low++; + if (!$low) { + $high = (int)($high + 1); + } + } + + if ($trim) { + $high = 0; + } + } + + public static function checkString(&$var, $check_utf8) + { + if (is_array($var) || is_object($var)) { + throw new \InvalidArgumentException("Expect string."); + } + if (!is_string($var)) { + $var = strval($var); + } + if ($check_utf8 && !preg_match('//u', $var)) { + throw new \Exception("Expect utf-8 encoding."); + } + } + + public static function checkEnum(&$var) + { + static::checkInt32($var); + } + + public static function checkInt32(&$var) + { + if (is_numeric($var)) { + $var = intval($var); + } else { + throw new \Exception("Expect integer."); + } + } + + public static function checkUint32(&$var) + { + if (is_numeric($var)) { + if (PHP_INT_SIZE === 8) { + $var = intval($var); + $var |= ((-(($var >> 31) & 0x1)) & ~0xFFFFFFFF); + } else { + if (bccomp($var, 0x7FFFFFFF) > 0) { + $var = bcsub($var, "4294967296"); + } + $var = (int) $var; + } + } else { + throw new \Exception("Expect integer."); + } + } + + public static function checkInt64(&$var) + { + if (is_numeric($var)) { + if (PHP_INT_SIZE == 8) { + $var = intval($var); + } else { + if (is_float($var) || + is_integer($var) || + (is_string($var) && + bccomp($var, "9223372036854774784") < 0)) { + $var = number_format($var, 0, ".", ""); + } + } + } else { + throw new \Exception("Expect integer."); + } + } + + public static function checkUint64(&$var) + { + if (is_numeric($var)) { + if (PHP_INT_SIZE == 8) { + $var = intval($var); + } else { + $var = number_format($var, 0, ".", ""); + } + } else { + throw new \Exception("Expect integer."); + } + } + + public static function checkFloat(&$var) + { + if (is_float($var) || is_numeric($var)) { + $var = floatval($var); + } else { + throw new \Exception("Expect float."); + } + } + + public static function checkDouble(&$var) + { + if (is_float($var) || is_numeric($var)) { + $var = floatval($var); + } else { + throw new \Exception("Expect float."); + } + } + + public static function checkBool(&$var) + { + if (is_array($var) || is_object($var)) { + throw new \Exception("Expect boolean."); + } + $var = boolval($var); + } + + public static function checkMessage(&$var, $klass, $newClass = null) + { + + if (!$var instanceof $klass && !is_null($var)) { + throw new \Exception("Expect $klass."); + } + } + + public static function checkRepeatedField(&$var, $type, $klass = null) + { + if (!$var instanceof RepeatedField && !is_array($var)) { + throw new \Exception("Expect array."); + } + if (is_array($var)) { + $tmp = new RepeatedField($type, $klass); + foreach ($var as $value) { + $tmp[] = $value; + } + return $tmp; + } else { + if ($var->getType() != $type) { + throw new \Exception( + "Expect repeated field of different type."); + } + if ($var->getType() === GPBType::MESSAGE && + $var->getClass() !== $klass && + $var->getLegacyClass() !== $klass) { + throw new \Exception( + "Expect repeated field of " . $klass . "."); + } + return $var; + } + } + + public static function checkMapField(&$var, $key_type, $value_type, $klass = null) + { + if (!$var instanceof MapField && !is_array($var)) { + throw new \Exception("Expect dict."); + } + if (is_array($var)) { + $tmp = new MapField($key_type, $value_type, $klass); + foreach ($var as $key => $value) { + $tmp[$key] = $value; + } + return $tmp; + } else { + if ($var->getKeyType() != $key_type) { + throw new \Exception("Expect map field of key type."); + } + if ($var->getValueType() != $value_type) { + throw new \Exception("Expect map field of value type."); + } + if ($var->getValueType() === GPBType::MESSAGE && + $var->getValueClass() !== $klass && + $var->getLegacyValueClass() !== $klass) { + throw new \Exception( + "Expect map field of " . $klass . "."); + } + return $var; + } + } + + public static function Int64($value) + { + return new Int64($value); + } + + public static function Uint64($value) + { + return new Uint64($value); + } + + public static function getClassNamePrefix( + $classname, + $file_proto) + { + $option = $file_proto->getOptions(); + $prefix = is_null($option) ? "" : $option->getPhpClassPrefix(); + if ($prefix !== "") { + return $prefix; + } + + $reserved_words = array( + "abstract"=>0, "and"=>0, "array"=>0, "as"=>0, "break"=>0, + "callable"=>0, "case"=>0, "catch"=>0, "class"=>0, "clone"=>0, + "const"=>0, "continue"=>0, "declare"=>0, "default"=>0, "die"=>0, + "do"=>0, "echo"=>0, "else"=>0, "elseif"=>0, "empty"=>0, + "enddeclare"=>0, "endfor"=>0, "endforeach"=>0, "endif"=>0, + "endswitch"=>0, "endwhile"=>0, "eval"=>0, "exit"=>0, "extends"=>0, + "final"=>0, "for"=>0, "foreach"=>0, "function"=>0, "global"=>0, + "goto"=>0, "if"=>0, "implements"=>0, "include"=>0, + "include_once"=>0, "instanceof"=>0, "insteadof"=>0, "interface"=>0, + "isset"=>0, "list"=>0, "namespace"=>0, "new"=>0, "or"=>0, + "print"=>0, "private"=>0, "protected"=>0, "public"=>0, "require"=>0, + "require_once"=>0, "return"=>0, "static"=>0, "switch"=>0, + "throw"=>0, "trait"=>0, "try"=>0, "unset"=>0, "use"=>0, "var"=>0, + "while"=>0, "xor"=>0, "int"=>0, "float"=>0, "bool"=>0, "string"=>0, + "true"=>0, "false"=>0, "null"=>0, "void"=>0, "iterable"=>0 + ); + + if (array_key_exists(strtolower($classname), $reserved_words)) { + if ($file_proto->getPackage() === "google.protobuf") { + return "GPB"; + } else { + return "PB"; + } + } + + return ""; + } + + public static function getLegacyClassNameWithoutPackage( + $name, + $file_proto) + { + $classname = implode('_', explode('.', $name)); + return static::getClassNamePrefix($classname, $file_proto) . $classname; + } + + public static function getClassNameWithoutPackage( + $name, + $file_proto) + { + $parts = explode('.', $name); + foreach ($parts as $i => $part) { + $parts[$i] = static::getClassNamePrefix($parts[$i], $file_proto) . $parts[$i]; + } + return implode('\\', $parts); + } + + public static function getFullClassName( + $proto, + $containing, + $file_proto, + &$message_name_without_package, + &$classname, + &$legacy_classname, + &$fullname) + { + // Full name needs to start with '.'. + $message_name_without_package = $proto->getName(); + if ($containing !== "") { + $message_name_without_package = + $containing . "." . $message_name_without_package; + } + + $package = $file_proto->getPackage(); + if ($package === "") { + $fullname = "." . $message_name_without_package; + } else { + $fullname = "." . $package . "." . $message_name_without_package; + } + + $class_name_without_package = + static::getClassNameWithoutPackage($message_name_without_package, $file_proto); + $legacy_class_name_without_package = + static::getLegacyClassNameWithoutPackage( + $message_name_without_package, $file_proto); + + $option = $file_proto->getOptions(); + if (!is_null($option) && $option->hasPhpNamespace()) { + $namespace = $option->getPhpNamespace(); + if ($namespace !== "") { + $classname = $namespace . "\\" . $class_name_without_package; + $legacy_classname = + $namespace . "\\" . $legacy_class_name_without_package; + return; + } else { + $classname = $class_name_without_package; + $legacy_classname = $legacy_class_name_without_package; + return; + } + } + + if ($package === "") { + $classname = $class_name_without_package; + $legacy_classname = $legacy_class_name_without_package; + } else { + $parts = array_map('ucwords', explode('.', $package)); + foreach ($parts as $i => $part) { + $parts[$i] = self::getClassNamePrefix($part, $file_proto).$part; + } + $classname = + implode('\\', $parts) . + "\\".self::getClassNamePrefix($class_name_without_package,$file_proto). + $class_name_without_package; + $legacy_classname = + implode('\\', array_map('ucwords', explode('.', $package))). + "\\".$legacy_class_name_without_package; + } + } + + public static function combineInt32ToInt64($high, $low) + { + $isNeg = $high < 0; + if ($isNeg) { + $high = ~$high; + $low = ~$low; + $low++; + if (!$low) { + $high = (int) ($high + 1); + } + } + $result = bcadd(bcmul($high, 4294967296), $low); + if ($low < 0) { + $result = bcadd($result, 4294967296); + } + if ($isNeg) { + $result = bcsub(0, $result); + } + return $result; + } + + public static function parseTimestamp($timestamp) + { + // prevent parsing timestamps containing with the non-existent year "0000" + // DateTime::createFromFormat parses without failing but as a nonsensical date + if (substr($timestamp, 0, 4) === "0000") { + throw new \Exception("Year cannot be zero."); + } + // prevent parsing timestamps ending with a lowercase z + if (substr($timestamp, -1, 1) === "z") { + throw new \Exception("Timezone cannot be a lowercase z."); + } + + $nanoseconds = 0; + $periodIndex = strpos($timestamp, "."); + if ($periodIndex !== false) { + $nanosecondsLength = 0; + // find the next non-numeric character in the timestamp to calculate + // the length of the nanoseconds text + for ($i = $periodIndex + 1, $length = strlen($timestamp); $i < $length; $i++) { + if (!is_numeric($timestamp[$i])) { + $nanosecondsLength = $i - ($periodIndex + 1); + break; + } + } + if ($nanosecondsLength % 3 !== 0) { + throw new \Exception("Nanoseconds must be disible by 3."); + } + if ($nanosecondsLength > 9) { + throw new \Exception("Nanoseconds must be in the range of 0 to 999,999,999 nanoseconds."); + } + if ($nanosecondsLength > 0) { + $nanoseconds = substr($timestamp, $periodIndex + 1, $nanosecondsLength); + $nanoseconds = intval($nanoseconds); + + // remove the nanoseconds and preceding period from the timestamp + $date = substr($timestamp, 0, $periodIndex); + $timezone = substr($timestamp, $periodIndex + $nanosecondsLength + 1); + $timestamp = $date.$timezone; + } + } + + $date = \DateTime::createFromFormat(\DateTime::RFC3339, $timestamp, new \DateTimeZone("UTC")); + if ($date === false) { + throw new \Exception("Invalid RFC 3339 timestamp."); + } + + $value = new \Google\Protobuf\Timestamp(); + $seconds = $date->format("U"); + $value->setSeconds($seconds); + $value->setNanos($nanoseconds); + return $value; + } + + public static function formatTimestamp($value) + { + if (bccomp($value->getSeconds(), "253402300800") != -1) { + throw new GPBDecodeException("Duration number too large."); + } + if (bccomp($value->getSeconds(), "-62135596801") != 1) { + throw new GPBDecodeException("Duration number too small."); + } + $nanoseconds = static::getNanosecondsForTimestamp($value->getNanos()); + if (!empty($nanoseconds)) { + $nanoseconds = ".".$nanoseconds; + } + $date = new \DateTime('@'.$value->getSeconds(), new \DateTimeZone("UTC")); + return $date->format("Y-m-d\TH:i:s".$nanoseconds."\Z"); + } + + public static function parseDuration($value) + { + if (strlen($value) < 2 || substr($value, -1) !== "s") { + throw new GPBDecodeException("Missing s after duration string"); + } + $number = substr($value, 0, -1); + if (bccomp($number, "315576000001") != -1) { + throw new GPBDecodeException("Duration number too large."); + } + if (bccomp($number, "-315576000001") != 1) { + throw new GPBDecodeException("Duration number too small."); + } + $pos = strrpos($number, "."); + if ($pos !== false) { + $seconds = substr($number, 0, $pos); + if (bccomp($seconds, 0) < 0) { + $nanos = bcmul("0" . substr($number, $pos), -1000000000); + } else { + $nanos = bcmul("0" . substr($number, $pos), 1000000000); + } + } else { + $seconds = $number; + $nanos = 0; + } + $duration = new Duration(); + $duration->setSeconds($seconds); + $duration->setNanos($nanos); + return $duration; + } + + public static function formatDuration($value) + { + if (bccomp($value->getSeconds(), '315576000001') != -1) { + throw new GPBDecodeException('Duration number too large.'); + } + if (bccomp($value->getSeconds(), '-315576000001') != 1) { + throw new GPBDecodeException('Duration number too small.'); + } + + $nanos = $value->getNanos(); + if ($nanos === 0) { + return (string) $value->getSeconds(); + } + + if ($nanos % 1000000 === 0) { + $digits = 3; + } elseif ($nanos % 1000 === 0) { + $digits = 6; + } else { + $digits = 9; + } + + $nanos = bcdiv($nanos, '1000000000', $digits); + return bcadd($value->getSeconds(), $nanos, $digits); + } + + public static function parseFieldMask($paths_string) + { + $field_mask = new FieldMask(); + if (strlen($paths_string) === 0) { + return $field_mask; + } + $path_strings = explode(",", $paths_string); + $paths = $field_mask->getPaths(); + foreach($path_strings as &$path_string) { + $field_strings = explode(".", $path_string); + foreach($field_strings as &$field_string) { + $field_string = camel2underscore($field_string); + } + $path_string = implode(".", $field_strings); + $paths[] = $path_string; + } + return $field_mask; + } + + public static function formatFieldMask($field_mask) + { + $converted_paths = []; + foreach($field_mask->getPaths() as $path) { + $fields = explode('.', $path); + $converted_path = []; + foreach ($fields as $field) { + $segments = explode('_', $field); + $start = true; + $converted_segments = ""; + foreach($segments as $segment) { + if (!$start) { + $converted = ucfirst($segment); + } else { + $converted = $segment; + $start = false; + } + $converted_segments .= $converted; + } + $converted_path []= $converted_segments; + } + $converted_path = implode(".", $converted_path); + $converted_paths []= $converted_path; + } + return implode(",", $converted_paths); + } + + public static function getNanosecondsForTimestamp($nanoseconds) + { + if ($nanoseconds == 0) { + return ''; + } + if ($nanoseconds % static::NANOS_PER_MILLISECOND == 0) { + return sprintf('%03d', $nanoseconds / static::NANOS_PER_MILLISECOND); + } + if ($nanoseconds % static::NANOS_PER_MICROSECOND == 0) { + return sprintf('%06d', $nanoseconds / static::NANOS_PER_MICROSECOND); + } + return sprintf('%09d', $nanoseconds); + } + + public static function hasSpecialJsonMapping($msg) + { + return is_a($msg, 'Google\Protobuf\Any') || + is_a($msg, "Google\Protobuf\ListValue") || + is_a($msg, "Google\Protobuf\Struct") || + is_a($msg, "Google\Protobuf\Value") || + is_a($msg, "Google\Protobuf\Duration") || + is_a($msg, "Google\Protobuf\Timestamp") || + is_a($msg, "Google\Protobuf\FieldMask") || + static::hasJsonValue($msg); + } + + public static function hasJsonValue($msg) + { + return is_a($msg, "Google\Protobuf\DoubleValue") || + is_a($msg, "Google\Protobuf\FloatValue") || + is_a($msg, "Google\Protobuf\Int64Value") || + is_a($msg, "Google\Protobuf\UInt64Value") || + is_a($msg, "Google\Protobuf\Int32Value") || + is_a($msg, "Google\Protobuf\UInt32Value") || + is_a($msg, "Google\Protobuf\BoolValue") || + is_a($msg, "Google\Protobuf\StringValue") || + is_a($msg, "Google\Protobuf\BytesValue"); + } +} diff --git a/src/Google/Protobuf/Internal/GPBWire.php b/src/Google/Protobuf/Internal/GPBWire.php new file mode 100644 index 00000000..7f1eab3c --- /dev/null +++ b/src/Google/Protobuf/Internal/GPBWire.php @@ -0,0 +1,622 @@ +> self::TAG_TYPE_BITS) & + (1 << ((PHP_INT_SIZE * 8) - self::TAG_TYPE_BITS)) - 1; + } + + public static function getTagWireType($tag) + { + return $tag & 0x7; + } + + public static function getWireType($type) + { + switch ($type) { + case GPBType::FLOAT: + case GPBType::FIXED32: + case GPBType::SFIXED32: + return self::WIRETYPE_FIXED32; + case GPBType::DOUBLE: + case GPBType::FIXED64: + case GPBType::SFIXED64: + return self::WIRETYPE_FIXED64; + case GPBType::UINT32: + case GPBType::UINT64: + case GPBType::INT32: + case GPBType::INT64: + case GPBType::SINT32: + case GPBType::SINT64: + case GPBType::ENUM: + case GPBType::BOOL: + return self::WIRETYPE_VARINT; + case GPBType::STRING: + case GPBType::BYTES: + case GPBType::MESSAGE: + return self::WIRETYPE_LENGTH_DELIMITED; + case GPBType::GROUP: + user_error("Unsupported type."); + return 0; + default: + user_error("Unsupported type."); + return 0; + } + } + + // ZigZag Transform: Encodes signed integers so that they can be effectively + // used with varint encoding. + // + // varint operates on unsigned integers, encoding smaller numbers into fewer + // bytes. If you try to use it on a signed integer, it will treat this + // number as a very large unsigned integer, which means that even small + // signed numbers like -1 will take the maximum number of bytes (10) to + // encode. zigZagEncode() maps signed integers to unsigned in such a way + // that those with a small absolute value will have smaller encoded values, + // making them appropriate for encoding using varint. + // + // int32 -> uint32 + // ------------------------- + // 0 -> 0 + // -1 -> 1 + // 1 -> 2 + // -2 -> 3 + // ... -> ... + // 2147483647 -> 4294967294 + // -2147483648 -> 4294967295 + // + // >> encode >> + // << decode << + public static function zigZagEncode32($int32) + { + if (PHP_INT_SIZE == 8) { + $trim_int32 = $int32 & 0xFFFFFFFF; + return (($trim_int32 << 1) ^ ($int32 << 32 >> 63)) & 0xFFFFFFFF; + } else { + return ($int32 << 1) ^ ($int32 >> 31); + } + } + + public static function zigZagDecode32($uint32) + { + // Fill high 32 bits. + if (PHP_INT_SIZE === 8) { + $uint32 |= ($uint32 & 0xFFFFFFFF); + } + + $int32 = (($uint32 >> 1) & 0x7FFFFFFF) ^ (-($uint32 & 1)); + + return $int32; + } + + public static function zigZagEncode64($int64) + { + if (PHP_INT_SIZE == 4) { + if (bccomp($int64, 0) >= 0) { + return bcmul($int64, 2); + } else { + return bcsub(bcmul(bcsub(0, $int64), 2), 1); + } + } else { + return ($int64 << 1) ^ ($int64 >> 63); + } + } + + public static function zigZagDecode64($uint64) + { + if (PHP_INT_SIZE == 4) { + if (bcmod($uint64, 2) == 0) { + return bcdiv($uint64, 2, 0); + } else { + return bcsub(0, bcdiv(bcadd($uint64, 1), 2, 0)); + } + } else { + return (($uint64 >> 1) & 0x7FFFFFFFFFFFFFFF) ^ (-($uint64 & 1)); + } + } + + public static function readInt32(&$input, &$value) + { + return $input->readVarint32($value); + } + + public static function readInt64(&$input, &$value) + { + $success = $input->readVarint64($value); + if (PHP_INT_SIZE == 4 && bccomp($value, "9223372036854775807") > 0) { + $value = bcsub($value, "18446744073709551616"); + } + return $success; + } + + public static function readUint32(&$input, &$value) + { + return self::readInt32($input, $value); + } + + public static function readUint64(&$input, &$value) + { + return self::readInt64($input, $value); + } + + public static function readSint32(&$input, &$value) + { + if (!$input->readVarint32($value)) { + return false; + } + $value = GPBWire::zigZagDecode32($value); + return true; + } + + public static function readSint64(&$input, &$value) + { + if (!$input->readVarint64($value)) { + return false; + } + $value = GPBWire::zigZagDecode64($value); + return true; + } + + public static function readFixed32(&$input, &$value) + { + return $input->readLittleEndian32($value); + } + + public static function readFixed64(&$input, &$value) + { + return $input->readLittleEndian64($value); + } + + public static function readSfixed32(&$input, &$value) + { + if (!self::readFixed32($input, $value)) { + return false; + } + if (PHP_INT_SIZE === 8) { + $value |= (-($value >> 31) << 32); + } + return true; + } + + public static function readSfixed64(&$input, &$value) + { + $success = $input->readLittleEndian64($value); + if (PHP_INT_SIZE == 4 && bccomp($value, "9223372036854775807") > 0) { + $value = bcsub($value, "18446744073709551616"); + } + return $success; + } + + public static function readFloat(&$input, &$value) + { + $data = null; + if (!$input->readRaw(4, $data)) { + return false; + } + $value = unpack('f', $data)[1]; + return true; + } + + public static function readDouble(&$input, &$value) + { + $data = null; + if (!$input->readRaw(8, $data)) { + return false; + } + $value = unpack('d', $data)[1]; + return true; + } + + public static function readBool(&$input, &$value) + { + if (!$input->readVarint64($value)) { + return false; + } + if ($value == 0) { + $value = false; + } else { + $value = true; + } + return true; + } + + public static function readString(&$input, &$value) + { + $length = 0; + return $input->readVarintSizeAsInt($length) && $input->readRaw($length, $value); + } + + public static function readMessage(&$input, &$message) + { + $length = 0; + if (!$input->readVarintSizeAsInt($length)) { + return false; + } + $old_limit = 0; + $recursion_limit = 0; + $input->incrementRecursionDepthAndPushLimit( + $length, + $old_limit, + $recursion_limit); + if ($recursion_limit < 0 || !$message->parseFromStream($input)) { + return false; + } + return $input->decrementRecursionDepthAndPopLimit($old_limit); + } + + public static function writeTag(&$output, $tag) + { + return $output->writeTag($tag); + } + + public static function writeInt32(&$output, $value) + { + return $output->writeVarint32($value, false); + } + + public static function writeInt64(&$output, $value) + { + return $output->writeVarint64($value); + } + + public static function writeUint32(&$output, $value) + { + return $output->writeVarint32($value, true); + } + + public static function writeUint64(&$output, $value) + { + return $output->writeVarint64($value); + } + + public static function writeSint32(&$output, $value) + { + $value = GPBWire::zigZagEncode32($value); + return $output->writeVarint32($value, true); + } + + public static function writeSint64(&$output, $value) + { + $value = GPBWire::zigZagEncode64($value); + return $output->writeVarint64($value); + } + + public static function writeFixed32(&$output, $value) + { + return $output->writeLittleEndian32($value); + } + + public static function writeFixed64(&$output, $value) + { + return $output->writeLittleEndian64($value); + } + + public static function writeSfixed32(&$output, $value) + { + return $output->writeLittleEndian32($value); + } + + public static function writeSfixed64(&$output, $value) + { + return $output->writeLittleEndian64($value); + } + + public static function writeBool(&$output, $value) + { + if ($value) { + return $output->writeVarint32(1, true); + } else { + return $output->writeVarint32(0, true); + } + } + + public static function writeFloat(&$output, $value) + { + $data = pack("f", $value); + return $output->writeRaw($data, 4); + } + + public static function writeDouble(&$output, $value) + { + $data = pack("d", $value); + return $output->writeRaw($data, 8); + } + + public static function writeString(&$output, $value) + { + return self::writeBytes($output, $value); + } + + public static function writeBytes(&$output, $value) + { + $size = strlen($value); + if (!$output->writeVarint32($size, true)) { + return false; + } + return $output->writeRaw($value, $size); + } + + public static function writeMessage(&$output, $value) + { + $size = $value->byteSize(); + if (!$output->writeVarint32($size, true)) { + return false; + } + return $value->serializeToStream($output); + } + + public static function makeTag($number, $type) + { + return ($number << 3) | self::getWireType($type); + } + + public static function tagSize($field) + { + $tag = self::makeTag($field->getNumber(), $field->getType()); + return self::varint32Size($tag); + } + + public static function varint32Size($value, $sign_extended = false) + { + if ($value < 0) { + if ($sign_extended) { + return 10; + } else { + return 5; + } + } + if ($value < (1 << 7)) { + return 1; + } + if ($value < (1 << 14)) { + return 2; + } + if ($value < (1 << 21)) { + return 3; + } + if ($value < (1 << 28)) { + return 4; + } + return 5; + } + + public static function sint32Size($value) + { + $value = self::zigZagEncode32($value); + return self::varint32Size($value); + } + + public static function sint64Size($value) + { + $value = self::zigZagEncode64($value); + return self::varint64Size($value); + } + + public static function varint64Size($value) + { + if (PHP_INT_SIZE == 4) { + if (bccomp($value, 0) < 0 || + bccomp($value, "9223372036854775807") > 0) { + return 10; + } + if (bccomp($value, 1 << 7) < 0) { + return 1; + } + if (bccomp($value, 1 << 14) < 0) { + return 2; + } + if (bccomp($value, 1 << 21) < 0) { + return 3; + } + if (bccomp($value, 1 << 28) < 0) { + return 4; + } + if (bccomp($value, '34359738368') < 0) { + return 5; + } + if (bccomp($value, '4398046511104') < 0) { + return 6; + } + if (bccomp($value, '562949953421312') < 0) { + return 7; + } + if (bccomp($value, '72057594037927936') < 0) { + return 8; + } + return 9; + } else { + if ($value < 0) { + return 10; + } + if ($value < (1 << 7)) { + return 1; + } + if ($value < (1 << 14)) { + return 2; + } + if ($value < (1 << 21)) { + return 3; + } + if ($value < (1 << 28)) { + return 4; + } + if ($value < (1 << 35)) { + return 5; + } + if ($value < (1 << 42)) { + return 6; + } + if ($value < (1 << 49)) { + return 7; + } + if ($value < (1 << 56)) { + return 8; + } + return 9; + } + } + + public static function serializeFieldToStream( + $value, + $field, + $need_tag, + &$output) + { + if ($need_tag) { + if (!GPBWire::writeTag( + $output, + self::makeTag( + $field->getNumber(), + $field->getType()))) { + return false; + } + } + switch ($field->getType()) { + case GPBType::DOUBLE: + if (!GPBWire::writeDouble($output, $value)) { + return false; + } + break; + case GPBType::FLOAT: + if (!GPBWire::writeFloat($output, $value)) { + return false; + } + break; + case GPBType::INT64: + if (!GPBWire::writeInt64($output, $value)) { + return false; + } + break; + case GPBType::UINT64: + if (!GPBWire::writeUint64($output, $value)) { + return false; + } + break; + case GPBType::INT32: + if (!GPBWire::writeInt32($output, $value)) { + return false; + } + break; + case GPBType::FIXED32: + if (!GPBWire::writeFixed32($output, $value)) { + return false; + } + break; + case GPBType::FIXED64: + if (!GPBWire::writeFixed64($output, $value)) { + return false; + } + break; + case GPBType::BOOL: + if (!GPBWire::writeBool($output, $value)) { + return false; + } + break; + case GPBType::STRING: + if (!GPBWire::writeString($output, $value)) { + return false; + } + break; + // case GPBType::GROUP: + // echo "GROUP\xA"; + // trigger_error("Not implemented.", E_ERROR); + // break; + case GPBType::MESSAGE: + if (!GPBWire::writeMessage($output, $value)) { + return false; + } + break; + case GPBType::BYTES: + if (!GPBWire::writeBytes($output, $value)) { + return false; + } + break; + case GPBType::UINT32: + if (PHP_INT_SIZE === 8 && $value < 0) { + $value += 4294967296; + } + if (!GPBWire::writeUint32($output, $value)) { + return false; + } + break; + case GPBType::ENUM: + if (!GPBWire::writeInt32($output, $value)) { + return false; + } + break; + case GPBType::SFIXED32: + if (!GPBWire::writeSfixed32($output, $value)) { + return false; + } + break; + case GPBType::SFIXED64: + if (!GPBWire::writeSfixed64($output, $value)) { + return false; + } + break; + case GPBType::SINT32: + if (!GPBWire::writeSint32($output, $value)) { + return false; + } + break; + case GPBType::SINT64: + if (!GPBWire::writeSint64($output, $value)) { + return false; + } + break; + default: + user_error("Unsupported type."); + return false; + } + + return true; + } +} diff --git a/src/Google/Protobuf/Internal/GPBWireType.php b/src/Google/Protobuf/Internal/GPBWireType.php new file mode 100644 index 00000000..c1ad370e --- /dev/null +++ b/src/Google/Protobuf/Internal/GPBWireType.php @@ -0,0 +1,43 @@ +google.protobuf.GeneratedCodeInfo + */ +class GeneratedCodeInfo extends \Google\Protobuf\Internal\Message +{ + /** + * An Annotation connects some span of text in generated code to an element + * of its generating .proto file. + * + * Generated from protobuf field repeated .google.protobuf.GeneratedCodeInfo.Annotation annotation = 1; + */ + private $annotation; + private $has_annotation = false; + + /** + * Constructor. + * + * @param array $data { + * Optional. Data for populating the Message object. + * + * @type \Google\Protobuf\Internal\GeneratedCodeInfo\Annotation[]|\Google\Protobuf\Internal\RepeatedField $annotation + * An Annotation connects some span of text in generated code to an element + * of its generating .proto file. + * } + */ + public function __construct($data = NULL) { + \GPBMetadata\Google\Protobuf\Internal\Descriptor::initOnce(); + parent::__construct($data); + } + + /** + * An Annotation connects some span of text in generated code to an element + * of its generating .proto file. + * + * Generated from protobuf field repeated .google.protobuf.GeneratedCodeInfo.Annotation annotation = 1; + * @return \Google\Protobuf\Internal\RepeatedField + */ + public function getAnnotation() + { + return $this->annotation; + } + + /** + * An Annotation connects some span of text in generated code to an element + * of its generating .proto file. + * + * Generated from protobuf field repeated .google.protobuf.GeneratedCodeInfo.Annotation annotation = 1; + * @param \Google\Protobuf\Internal\GeneratedCodeInfo\Annotation[]|\Google\Protobuf\Internal\RepeatedField $var + * @return $this + */ + public function setAnnotation($var) + { + $arr = GPBUtil::checkRepeatedField($var, \Google\Protobuf\Internal\GPBType::MESSAGE, \Google\Protobuf\Internal\GeneratedCodeInfo\Annotation::class); + $this->annotation = $arr; + $this->has_annotation = true; + + return $this; + } + + public function hasAnnotation() + { + return $this->has_annotation; + } + +} + diff --git a/src/Google/Protobuf/Internal/GeneratedCodeInfo/Annotation.php b/src/Google/Protobuf/Internal/GeneratedCodeInfo/Annotation.php new file mode 100644 index 00000000..369fea48 --- /dev/null +++ b/src/Google/Protobuf/Internal/GeneratedCodeInfo/Annotation.php @@ -0,0 +1,216 @@ +google.protobuf.GeneratedCodeInfo.Annotation + */ +class Annotation extends \Google\Protobuf\Internal\Message +{ + /** + * Identifies the element in the original source .proto file. This field + * is formatted the same as SourceCodeInfo.Location.path. + * + * Generated from protobuf field repeated int32 path = 1 [packed = true]; + */ + private $path; + private $has_path = false; + /** + * Identifies the filesystem path to the original source .proto. + * + * Generated from protobuf field optional string source_file = 2; + */ + protected $source_file = ''; + private $has_source_file = false; + /** + * Identifies the starting offset in bytes in the generated code + * that relates to the identified object. + * + * Generated from protobuf field optional int32 begin = 3; + */ + protected $begin = 0; + private $has_begin = false; + /** + * Identifies the ending offset in bytes in the generated code that + * relates to the identified offset. The end offset should be one past + * the last relevant byte (so the length of the text = end - begin). + * + * Generated from protobuf field optional int32 end = 4; + */ + protected $end = 0; + private $has_end = false; + + /** + * Constructor. + * + * @param array $data { + * Optional. Data for populating the Message object. + * + * @type int[]|\Google\Protobuf\Internal\RepeatedField $path + * Identifies the element in the original source .proto file. This field + * is formatted the same as SourceCodeInfo.Location.path. + * @type string $source_file + * Identifies the filesystem path to the original source .proto. + * @type int $begin + * Identifies the starting offset in bytes in the generated code + * that relates to the identified object. + * @type int $end + * Identifies the ending offset in bytes in the generated code that + * relates to the identified offset. The end offset should be one past + * the last relevant byte (so the length of the text = end - begin). + * } + */ + public function __construct($data = NULL) { + \GPBMetadata\Google\Protobuf\Internal\Descriptor::initOnce(); + parent::__construct($data); + } + + /** + * Identifies the element in the original source .proto file. This field + * is formatted the same as SourceCodeInfo.Location.path. + * + * Generated from protobuf field repeated int32 path = 1 [packed = true]; + * @return \Google\Protobuf\Internal\RepeatedField + */ + public function getPath() + { + return $this->path; + } + + /** + * Identifies the element in the original source .proto file. This field + * is formatted the same as SourceCodeInfo.Location.path. + * + * Generated from protobuf field repeated int32 path = 1 [packed = true]; + * @param int[]|\Google\Protobuf\Internal\RepeatedField $var + * @return $this + */ + public function setPath($var) + { + $arr = GPBUtil::checkRepeatedField($var, \Google\Protobuf\Internal\GPBType::INT32); + $this->path = $arr; + $this->has_path = true; + + return $this; + } + + public function hasPath() + { + return $this->has_path; + } + + /** + * Identifies the filesystem path to the original source .proto. + * + * Generated from protobuf field optional string source_file = 2; + * @return string + */ + public function getSourceFile() + { + return $this->source_file; + } + + /** + * Identifies the filesystem path to the original source .proto. + * + * Generated from protobuf field optional string source_file = 2; + * @param string $var + * @return $this + */ + public function setSourceFile($var) + { + GPBUtil::checkString($var, True); + $this->source_file = $var; + $this->has_source_file = true; + + return $this; + } + + public function hasSourceFile() + { + return $this->has_source_file; + } + + /** + * Identifies the starting offset in bytes in the generated code + * that relates to the identified object. + * + * Generated from protobuf field optional int32 begin = 3; + * @return int + */ + public function getBegin() + { + return $this->begin; + } + + /** + * Identifies the starting offset in bytes in the generated code + * that relates to the identified object. + * + * Generated from protobuf field optional int32 begin = 3; + * @param int $var + * @return $this + */ + public function setBegin($var) + { + GPBUtil::checkInt32($var); + $this->begin = $var; + $this->has_begin = true; + + return $this; + } + + public function hasBegin() + { + return $this->has_begin; + } + + /** + * Identifies the ending offset in bytes in the generated code that + * relates to the identified offset. The end offset should be one past + * the last relevant byte (so the length of the text = end - begin). + * + * Generated from protobuf field optional int32 end = 4; + * @return int + */ + public function getEnd() + { + return $this->end; + } + + /** + * Identifies the ending offset in bytes in the generated code that + * relates to the identified offset. The end offset should be one past + * the last relevant byte (so the length of the text = end - begin). + * + * Generated from protobuf field optional int32 end = 4; + * @param int $var + * @return $this + */ + public function setEnd($var) + { + GPBUtil::checkInt32($var); + $this->end = $var; + $this->has_end = true; + + return $this; + } + + public function hasEnd() + { + return $this->has_end; + } + +} + +// Adding a class alias for backwards compatibility with the previous class name. +class_alias(Annotation::class, \Google\Protobuf\Internal\GeneratedCodeInfo_Annotation::class); + diff --git a/src/Google/Protobuf/Internal/GeneratedCodeInfo_Annotation.php b/src/Google/Protobuf/Internal/GeneratedCodeInfo_Annotation.php new file mode 100644 index 00000000..e36f1e57 --- /dev/null +++ b/src/Google/Protobuf/Internal/GeneratedCodeInfo_Annotation.php @@ -0,0 +1,16 @@ +getPublicDescriptor(); + } +} diff --git a/src/Google/Protobuf/Internal/HasPublicDescriptorTrait.php b/src/Google/Protobuf/Internal/HasPublicDescriptorTrait.php new file mode 100644 index 00000000..ed5d1660 --- /dev/null +++ b/src/Google/Protobuf/Internal/HasPublicDescriptorTrait.php @@ -0,0 +1,43 @@ +public_desc; + } +} diff --git a/src/Google/Protobuf/Internal/MapEntry.php b/src/Google/Protobuf/Internal/MapEntry.php new file mode 100644 index 00000000..e89481f0 --- /dev/null +++ b/src/Google/Protobuf/Internal/MapEntry.php @@ -0,0 +1,71 @@ +getFieldByNumber(2); + if ($value_field->getType() == GPBType::MESSAGE) { + $klass = $value_field->getMessageType()->getClass(); + $value = new $klass; + $this->setValue($value); + } + } + + public function setKey($key) { + $this->key = $key; + } + + public function getKey() { + return $this->key; + } + + public function setValue($value) { + $this->value = $value; + } + + public function getValue() { + return $this->value; + } +} diff --git a/src/Google/Protobuf/Internal/MapField.php b/src/Google/Protobuf/Internal/MapField.php new file mode 100644 index 00000000..2c66aa0c --- /dev/null +++ b/src/Google/Protobuf/Internal/MapField.php @@ -0,0 +1,290 @@ +container = []; + $this->key_type = $key_type; + $this->value_type = $value_type; + $this->klass = $klass; + + if ($this->value_type == GPBType::MESSAGE) { + $pool = DescriptorPool::getGeneratedPool(); + $desc = $pool->getDescriptorByClassName($klass); + if ($desc == NULL) { + new $klass; // No msg class instance has been created before. + $desc = $pool->getDescriptorByClassName($klass); + } + $this->klass = $desc->getClass(); + $this->legacy_klass = $desc->getLegacyClass(); + } + } + + /** + * @ignore + */ + public function getKeyType() + { + return $this->key_type; + } + + /** + * @ignore + */ + public function getValueType() + { + return $this->value_type; + } + + /** + * @ignore + */ + public function getValueClass() + { + return $this->klass; + } + + /** + * @ignore + */ + public function getLegacyValueClass() + { + return $this->legacy_klass; + } + + /** + * Return the element at the given key. + * + * This will also be called for: $ele = $arr[$key] + * + * @param object $key The key of the element to be fetched. + * @return object The stored element at given key. + * @throws \ErrorException Invalid type for index. + * @throws \ErrorException Non-existing index. + */ + public function offsetGet($key) + { + return $this->container[$key]; + } + + /** + * Assign the element at the given key. + * + * This will also be called for: $arr[$key] = $value + * + * @param object $key The key of the element to be fetched. + * @param object $value The element to be assigned. + * @return void + * @throws \ErrorException Invalid type for key. + * @throws \ErrorException Invalid type for value. + * @throws \ErrorException Non-existing key. + */ + public function offsetSet($key, $value) + { + $this->checkKey($this->key_type, $key); + + switch ($this->value_type) { + case GPBType::SFIXED32: + case GPBType::SINT32: + case GPBType::INT32: + case GPBType::ENUM: + GPBUtil::checkInt32($value); + break; + case GPBType::FIXED32: + case GPBType::UINT32: + GPBUtil::checkUint32($value); + break; + case GPBType::SFIXED64: + case GPBType::SINT64: + case GPBType::INT64: + GPBUtil::checkInt64($value); + break; + case GPBType::FIXED64: + case GPBType::UINT64: + GPBUtil::checkUint64($value); + break; + case GPBType::FLOAT: + GPBUtil::checkFloat($value); + break; + case GPBType::DOUBLE: + GPBUtil::checkDouble($value); + break; + case GPBType::BOOL: + GPBUtil::checkBool($value); + break; + case GPBType::STRING: + GPBUtil::checkString($value, true); + break; + case GPBType::MESSAGE: + if (is_null($value)) { + trigger_error("Map element cannot be null.", E_USER_ERROR); + } + GPBUtil::checkMessage($value, $this->klass); + break; + default: + break; + } + + $this->container[$key] = $value; + } + + /** + * Remove the element at the given key. + * + * This will also be called for: unset($arr) + * + * @param object $key The key of the element to be removed. + * @return void + * @throws \ErrorException Invalid type for key. + */ + public function offsetUnset($key) + { + $this->checkKey($this->key_type, $key); + unset($this->container[$key]); + } + + /** + * Check the existence of the element at the given key. + * + * This will also be called for: isset($arr) + * + * @param object $key The key of the element to be removed. + * @return bool True if the element at the given key exists. + * @throws \ErrorException Invalid type for key. + */ + public function offsetExists($key) + { + $this->checkKey($this->key_type, $key); + return isset($this->container[$key]); + } + + /** + * @ignore + */ + public function getIterator() + { + return new MapFieldIter($this->container, $this->key_type); + } + + /** + * Return the number of stored elements. + * + * This will also be called for: count($arr) + * + * @return integer The number of stored elements. + */ + public function count() + { + return count($this->container); + } + + /** + * @ignore + */ + private function checkKey($key_type, &$key) + { + switch ($key_type) { + case GPBType::SFIXED32: + case GPBType::SINT32: + case GPBType::INT32: + GPBUtil::checkInt32($key); + break; + case GPBType::FIXED32: + case GPBType::UINT32: + GPBUtil::checkUint32($key); + break; + case GPBType::SFIXED64: + case GPBType::SINT64: + case GPBType::INT64: + GPBUtil::checkInt64($key); + break; + case GPBType::FIXED64: + case GPBType::UINT64: + GPBUtil::checkUint64($key); + break; + case GPBType::BOOL: + GPBUtil::checkBool($key); + break; + case GPBType::STRING: + GPBUtil::checkString($key, true); + break; + default: + trigger_error( + "Given type cannot be map key.", + E_USER_ERROR); + break; + } + } +} diff --git a/src/Google/Protobuf/Internal/MapFieldIter.php b/src/Google/Protobuf/Internal/MapFieldIter.php new file mode 100644 index 00000000..4e18005e --- /dev/null +++ b/src/Google/Protobuf/Internal/MapFieldIter.php @@ -0,0 +1,134 @@ +container = $container; + $this->key_type = $key_type; + } + + /** + * Reset the status of the iterator + * + * @return void + */ + public function rewind() + { + return reset($this->container); + } + + /** + * Return the element at the current position. + * + * @return object The element at the current position. + */ + public function current() + { + return current($this->container); + } + + /** + * Return the current key. + * + * @return object The current key. + */ + public function key() + { + $key = key($this->container); + switch ($this->key_type) { + case GPBType::INT64: + case GPBType::UINT64: + case GPBType::FIXED64: + case GPBType::SFIXED64: + case GPBType::SINT64: + if (PHP_INT_SIZE === 8) { + return $key; + } + // Intentionally fall through + case GPBType::STRING: + // PHP associative array stores int string as int for key. + return strval($key); + case GPBType::BOOL: + // PHP associative array stores bool as integer for key. + return boolval($key); + default: + return $key; + } + } + + /** + * Move to the next position. + * + * @return void + */ + public function next() + { + return next($this->container); + } + + /** + * Check whether there are more elements to iterate. + * + * @return bool True if there are more elements to iterate. + */ + public function valid() + { + return key($this->container) !== null; + } +} diff --git a/src/Google/Protobuf/Internal/Message.php b/src/Google/Protobuf/Internal/Message.php new file mode 100644 index 00000000..e292026f --- /dev/null +++ b/src/Google/Protobuf/Internal/Message.php @@ -0,0 +1,2000 @@ +initWithDescriptor($data); + } else { + $this->initWithGeneratedPool(); + if (is_array($data)) { + $this->mergeFromArray($data); + } else if (!empty($data)) { + throw new \InvalidArgumentException( + 'Message constructor must be an array or null.' + ); + } + } + } + + /** + * @ignore + */ + private function initWithGeneratedPool() + { + $pool = DescriptorPool::getGeneratedPool(); + $this->desc = $pool->getDescriptorByClassName(get_class($this)); + if (is_null($this->desc)) { + user_error(get_class($this) . " is not found in descriptor pool."); + return; + } + foreach ($this->desc->getField() as $field) { + $setter = $field->getSetter(); + if ($field->isMap()) { + $message_type = $field->getMessageType(); + $key_field = $message_type->getFieldByNumber(1); + $value_field = $message_type->getFieldByNumber(2); + switch ($value_field->getType()) { + case GPBType::MESSAGE: + case GPBType::GROUP: + $map_field = new MapField( + $key_field->getType(), + $value_field->getType(), + $value_field->getMessageType()->getClass()); + $this->$setter($map_field); + break; + case GPBType::ENUM: + $map_field = new MapField( + $key_field->getType(), + $value_field->getType(), + $value_field->getEnumType()->getClass()); + $this->$setter($map_field); + break; + default: + $map_field = new MapField( + $key_field->getType(), + $value_field->getType()); + $this->$setter($map_field); + break; + } + } else if ($field->getLabel() === GPBLabel::REPEATED) { + switch ($field->getType()) { + case GPBType::MESSAGE: + case GPBType::GROUP: + $repeated_field = new RepeatedField( + $field->getType(), + $field->getMessageType()->getClass()); + $this->$setter($repeated_field); + break; + case GPBType::ENUM: + $repeated_field = new RepeatedField( + $field->getType(), + $field->getEnumType()->getClass()); + $this->$setter($repeated_field); + break; + default: + $repeated_field = new RepeatedField($field->getType()); + $this->$setter($repeated_field); + break; + } + } else if ($field->getOneofIndex() !== -1) { + $oneof = $this->desc->getOneofDecl()[$field->getOneofIndex()]; + $oneof_name = $oneof->getName(); + $this->$oneof_name = new OneofField($oneof); + } else if ($field->getLabel() === GPBLabel::OPTIONAL && + PHP_INT_SIZE == 4) { + switch ($field->getType()) { + case GPBType::INT64: + case GPBType::UINT64: + case GPBType::FIXED64: + case GPBType::SFIXED64: + case GPBType::SINT64: + $this->$setter("0"); + } + } + } + } + + /** + * @ignore + */ + private function initWithDescriptor(Descriptor $desc) + { + $this->desc = $desc; + foreach ($desc->getField() as $field) { + $setter = $field->getSetter(); + $defaultValue = $this->defaultValue($field); + $this->$setter($defaultValue); + } + } + + protected function readWrapperValue($member) + { + $field = $this->desc->getFieldByName($member); + $oneof_index = $field->getOneofIndex(); + if ($oneof_index === -1) { + $wrapper = $this->$member; + } else { + $wrapper = $this->readOneof($field->getNumber()); + } + + if (is_null($wrapper)) { + return NULL; + } else { + return $wrapper->getValue(); + } + } + + protected function writeWrapperValue($member, $value) + { + $field = $this->desc->getFieldByName($member); + $wrapped_value = $value; + if (!is_null($value)) { + $desc = $field->getMessageType(); + $klass = $desc->getClass(); + $wrapped_value = new $klass; + $wrapped_value->setValue($value); + } + + $oneof_index = $field->getOneofIndex(); + if ($oneof_index === -1) { + $this->$member = $wrapped_value; + } else { + $this->writeOneof($field->getNumber(), $wrapped_value); + } + } + + protected function readOneof($number) + { + $field = $this->desc->getFieldByNumber($number); + $oneof = $this->desc->getOneofDecl()[$field->getOneofIndex()]; + $oneof_name = $oneof->getName(); + $oneof_field = $this->$oneof_name; + if ($number === $oneof_field->getNumber()) { + return $oneof_field->getValue(); + } else { + return $this->defaultValue($field); + } + } + + protected function writeOneof($number, $value) + { + $field = $this->desc->getFieldByNumber($number); + $oneof = $this->desc->getOneofDecl()[$field->getOneofIndex()]; + $oneof_name = $oneof->getName(); + $oneof_field = $this->$oneof_name; + $oneof_field->setValue($value); + $oneof_field->setFieldName($field->getName()); + $oneof_field->setNumber($number); + } + + protected function whichOneof($oneof_name) + { + $oneof_field = $this->$oneof_name; + $number = $oneof_field->getNumber(); + if ($number == 0) { + return ""; + } + $field = $this->desc->getFieldByNumber($number); + return $field->getName(); + } + + /** + * @ignore + */ + private function defaultValue($field) + { + $value = null; + + switch ($field->getType()) { + case GPBType::DOUBLE: + case GPBType::FLOAT: + return 0.0; + case GPBType::UINT32: + case GPBType::INT32: + case GPBType::FIXED32: + case GPBType::SFIXED32: + case GPBType::SINT32: + case GPBType::ENUM: + return 0; + case GPBType::INT64: + case GPBType::UINT64: + case GPBType::FIXED64: + case GPBType::SFIXED64: + case GPBType::SINT64: + if (PHP_INT_SIZE === 4) { + return '0'; + } else { + return 0; + } + case GPBType::BOOL: + return false; + case GPBType::STRING: + case GPBType::BYTES: + return ""; + case GPBType::GROUP: + case GPBType::MESSAGE: + return null; + default: + user_error("Unsupported type."); + return false; + } + } + + /** + * @ignore + */ + private function skipField($input, $tag) + { + $number = GPBWire::getTagFieldNumber($tag); + if ($number === 0) { + throw new GPBDecodeException("Illegal field number zero."); + } + + $start = $input->current(); + switch (GPBWire::getTagWireType($tag)) { + case GPBWireType::VARINT: + $uint64 = 0; + if (!$input->readVarint64($uint64)) { + throw new GPBDecodeException( + "Unexpected EOF inside varint."); + } + break; + case GPBWireType::FIXED64: + $uint64 = 0; + if (!$input->readLittleEndian64($uint64)) { + throw new GPBDecodeException( + "Unexpected EOF inside fixed64."); + } + break; + case GPBWireType::FIXED32: + $uint32 = 0; + if (!$input->readLittleEndian32($uint32)) { + throw new GPBDecodeException( + "Unexpected EOF inside fixed32."); + } + break; + case GPBWireType::LENGTH_DELIMITED: + $length = 0; + if (!$input->readVarint32($length)) { + throw new GPBDecodeException( + "Unexpected EOF inside length."); + } + $data = NULL; + if (!$input->readRaw($length, $data)) { + throw new GPBDecodeException( + "Unexpected EOF inside length delimited data."); + } + break; + case GPBWireType::START_GROUP: + case GPBWireType::END_GROUP: + throw new GPBDecodeException("Unexpected wire type."); + default: + throw new GPBDecodeException("Unexpected wire type."); + } + $end = $input->current(); + + $bytes = str_repeat(chr(0), CodedOutputStream::MAX_VARINT64_BYTES); + $size = CodedOutputStream::writeVarintToArray($tag, $bytes, true); + $this->unknown .= substr($bytes, 0, $size) . $input->substr($start, $end); + } + + /** + * @ignore + */ + private static function parseFieldFromStreamNoTag($input, $field, &$value) + { + switch ($field->getType()) { + case GPBType::DOUBLE: + if (!GPBWire::readDouble($input, $value)) { + throw new GPBDecodeException( + "Unexpected EOF inside double field."); + } + break; + case GPBType::FLOAT: + if (!GPBWire::readFloat($input, $value)) { + throw new GPBDecodeException( + "Unexpected EOF inside float field."); + } + break; + case GPBType::INT64: + if (!GPBWire::readInt64($input, $value)) { + throw new GPBDecodeException( + "Unexpected EOF inside int64 field."); + } + break; + case GPBType::UINT64: + if (!GPBWire::readUint64($input, $value)) { + throw new GPBDecodeException( + "Unexpected EOF inside uint64 field."); + } + break; + case GPBType::INT32: + if (!GPBWire::readInt32($input, $value)) { + throw new GPBDecodeException( + "Unexpected EOF inside int32 field."); + } + break; + case GPBType::FIXED64: + if (!GPBWire::readFixed64($input, $value)) { + throw new GPBDecodeException( + "Unexpected EOF inside fixed64 field."); + } + break; + case GPBType::FIXED32: + if (!GPBWire::readFixed32($input, $value)) { + throw new GPBDecodeException( + "Unexpected EOF inside fixed32 field."); + } + break; + case GPBType::BOOL: + if (!GPBWire::readBool($input, $value)) { + throw new GPBDecodeException( + "Unexpected EOF inside bool field."); + } + break; + case GPBType::STRING: + // TODO(teboring): Add utf-8 check. + if (!GPBWire::readString($input, $value)) { + throw new GPBDecodeException( + "Unexpected EOF inside string field."); + } + break; + case GPBType::GROUP: + trigger_error("Not implemented.", E_ERROR); + break; + case GPBType::MESSAGE: + if ($field->isMap()) { + $value = new MapEntry($field->getMessageType()); + } else { + $klass = $field->getMessageType()->getClass(); + $value = new $klass; + } + if (!GPBWire::readMessage($input, $value)) { + throw new GPBDecodeException( + "Unexpected EOF inside message."); + } + break; + case GPBType::BYTES: + if (!GPBWire::readString($input, $value)) { + throw new GPBDecodeException( + "Unexpected EOF inside bytes field."); + } + break; + case GPBType::UINT32: + if (!GPBWire::readUint32($input, $value)) { + throw new GPBDecodeException( + "Unexpected EOF inside uint32 field."); + } + break; + case GPBType::ENUM: + // TODO(teboring): Check unknown enum value. + if (!GPBWire::readInt32($input, $value)) { + throw new GPBDecodeException( + "Unexpected EOF inside enum field."); + } + break; + case GPBType::SFIXED32: + if (!GPBWire::readSfixed32($input, $value)) { + throw new GPBDecodeException( + "Unexpected EOF inside sfixed32 field."); + } + break; + case GPBType::SFIXED64: + if (!GPBWire::readSfixed64($input, $value)) { + throw new GPBDecodeException( + "Unexpected EOF inside sfixed64 field."); + } + break; + case GPBType::SINT32: + if (!GPBWire::readSint32($input, $value)) { + throw new GPBDecodeException( + "Unexpected EOF inside sint32 field."); + } + break; + case GPBType::SINT64: + if (!GPBWire::readSint64($input, $value)) { + throw new GPBDecodeException( + "Unexpected EOF inside sint64 field."); + } + break; + default: + user_error("Unsupported type."); + return false; + } + return true; + } + + /** + * @ignore + */ + private function parseFieldFromStream($tag, $input, $field) + { + $value = null; + + if (is_null($field)) { + $value_format = GPBWire::UNKNOWN; + } elseif (GPBWire::getTagWireType($tag) === + GPBWire::getWireType($field->getType())) { + $value_format = GPBWire::NORMAL_FORMAT; + } elseif ($field->isPackable() && + GPBWire::getTagWireType($tag) === + GPBWire::WIRETYPE_LENGTH_DELIMITED) { + $value_format = GPBWire::PACKED_FORMAT; + } else { + // the wire type doesn't match. Put it in our unknown field set. + $value_format = GPBWire::UNKNOWN; + } + + if ($value_format === GPBWire::UNKNOWN) { + $this->skipField($input, $tag); + return; + } elseif ($value_format === GPBWire::NORMAL_FORMAT) { + self::parseFieldFromStreamNoTag($input, $field, $value); + } elseif ($value_format === GPBWire::PACKED_FORMAT) { + $length = 0; + if (!GPBWire::readInt32($input, $length)) { + throw new GPBDecodeException( + "Unexpected EOF inside packed length."); + } + $limit = $input->pushLimit($length); + $getter = $field->getGetter(); + while ($input->bytesUntilLimit() > 0) { + self::parseFieldFromStreamNoTag($input, $field, $value); + $this->appendHelper($field, $value); + } + $input->popLimit($limit); + return; + } else { + return; + } + + if ($field->isMap()) { + $this->kvUpdateHelper($field, $value->getKey(), $value->getValue()); + } else if ($field->isRepeated()) { + $this->appendHelper($field, $value); + } else { + $setter = $field->getSetter(); + $this->$setter($value); + } + } + + /** + * Clear all containing fields. + * @return null. + */ + public function clear() + { + $this->unknown = ""; + foreach ($this->desc->getField() as $field) { + $setter = $field->getSetter(); + if ($field->isMap()) { + $message_type = $field->getMessageType(); + $key_field = $message_type->getFieldByNumber(1); + $value_field = $message_type->getFieldByNumber(2); + switch ($value_field->getType()) { + case GPBType::MESSAGE: + case GPBType::GROUP: + $map_field = new MapField( + $key_field->getType(), + $value_field->getType(), + $value_field->getMessageType()->getClass()); + $this->$setter($map_field); + break; + case GPBType::ENUM: + $map_field = new MapField( + $key_field->getType(), + $value_field->getType(), + $value_field->getEnumType()->getClass()); + $this->$setter($map_field); + break; + default: + $map_field = new MapField( + $key_field->getType(), + $value_field->getType()); + $this->$setter($map_field); + break; + } + } else if ($field->getLabel() === GPBLabel::REPEATED) { + switch ($field->getType()) { + case GPBType::MESSAGE: + case GPBType::GROUP: + $repeated_field = new RepeatedField( + $field->getType(), + $field->getMessageType()->getClass()); + $this->$setter($repeated_field); + break; + case GPBType::ENUM: + $repeated_field = new RepeatedField( + $field->getType(), + $field->getEnumType()->getClass()); + $this->$setter($repeated_field); + break; + default: + $repeated_field = new RepeatedField($field->getType()); + $this->$setter($repeated_field); + break; + } + } else if ($field->getOneofIndex() !== -1) { + $oneof = $this->desc->getOneofDecl()[$field->getOneofIndex()]; + $oneof_name = $oneof->getName(); + $this->$oneof_name = new OneofField($oneof); + } else if ($field->getLabel() === GPBLabel::OPTIONAL) { + switch ($field->getType()) { + case GPBType::DOUBLE : + case GPBType::FLOAT : + $this->$setter(0.0); + break; + case GPBType::INT32 : + case GPBType::FIXED32 : + case GPBType::UINT32 : + case GPBType::SFIXED32 : + case GPBType::SINT32 : + case GPBType::ENUM : + $this->$setter(0); + break; + case GPBType::BOOL : + $this->$setter(false); + break; + case GPBType::STRING : + case GPBType::BYTES : + $this->$setter(""); + break; + case GPBType::GROUP : + case GPBType::MESSAGE : + $null = null; + $this->$setter($null); + break; + } + if (PHP_INT_SIZE == 4) { + switch ($field->getType()) { + case GPBType::INT64: + case GPBType::UINT64: + case GPBType::FIXED64: + case GPBType::SFIXED64: + case GPBType::SINT64: + $this->$setter("0"); + } + } else { + switch ($field->getType()) { + case GPBType::INT64: + case GPBType::UINT64: + case GPBType::FIXED64: + case GPBType::SFIXED64: + case GPBType::SINT64: + $this->$setter(0); + } + } + } + } + } + + /** + * Clear all unknown fields previously parsed. + * @return null. + */ + public function discardUnknownFields() + { + $this->unknown = ""; + foreach ($this->desc->getField() as $field) { + if ($field->getType() != GPBType::MESSAGE) { + continue; + } + if ($field->isMap()) { + $value_field = $field->getMessageType()->getFieldByNumber(2); + if ($value_field->getType() != GPBType::MESSAGE) { + continue; + } + $getter = $field->getGetter(); + $map = $this->$getter(); + foreach ($map as $key => $value) { + $value->discardUnknownFields(); + } + } else if ($field->getLabel() === GPBLabel::REPEATED) { + $getter = $field->getGetter(); + $arr = $this->$getter(); + foreach ($arr as $sub) { + $sub->discardUnknownFields(); + } + } else if ($field->getLabel() === GPBLabel::OPTIONAL) { + $getter = $field->getGetter(); + $sub = $this->$getter(); + if (!is_null($sub)) { + $sub->discardUnknownFields(); + } + } + } + } + + /** + * Merges the contents of the specified message into current message. + * + * This method merges the contents of the specified message into the + * current message. Singular fields that are set in the specified message + * overwrite the corresponding fields in the current message. Repeated + * fields are appended. Map fields key-value pairs are overwritten. + * Singular/Oneof sub-messages are recursively merged. All overwritten + * sub-messages are deep-copied. + * + * @param object $msg Protobuf message to be merged from. + * @return null. + */ + public function mergeFrom($msg) + { + if (get_class($this) !== get_class($msg)) { + user_error("Cannot merge messages with different class."); + return; + } + + foreach ($this->desc->getField() as $field) { + $setter = $field->getSetter(); + $getter = $field->getGetter(); + if ($field->isMap()) { + if (count($msg->$getter()) != 0) { + $value_field = $field->getMessageType()->getFieldByNumber(2); + foreach ($msg->$getter() as $key => $value) { + if ($value_field->getType() == GPBType::MESSAGE) { + $klass = $value_field->getMessageType()->getClass(); + $copy = new $klass; + $copy->mergeFrom($value); + + $this->kvUpdateHelper($field, $key, $copy); + } else { + $this->kvUpdateHelper($field, $key, $value); + } + } + } + } else if ($field->getLabel() === GPBLabel::REPEATED) { + if (count($msg->$getter()) != 0) { + foreach ($msg->$getter() as $tmp) { + if ($field->getType() == GPBType::MESSAGE) { + $klass = $field->getMessageType()->getClass(); + $copy = new $klass; + $copy->mergeFrom($tmp); + $this->appendHelper($field, $copy); + } else { + $this->appendHelper($field, $tmp); + } + } + } + } else if ($field->getLabel() === GPBLabel::OPTIONAL) { + if($msg->$getter() !== $this->defaultValue($field)) { + $tmp = $msg->$getter(); + if ($field->getType() == GPBType::MESSAGE) { + if (is_null($this->$getter())) { + $klass = $field->getMessageType()->getClass(); + $new_msg = new $klass; + $this->$setter($new_msg); + } + $this->$getter()->mergeFrom($tmp); + } else { + $this->$setter($tmp); + } + } + } + } + } + + /** + * Parses a protocol buffer contained in a string. + * + * This function takes a string in the (non-human-readable) binary wire + * format, matching the encoding output by serializeToString(). + * See mergeFrom() for merging behavior, if the field is already set in the + * specified message. + * + * @param string $data Binary protobuf data. + * @return null. + * @throws \Exception Invalid data. + */ + public function mergeFromString($data) + { + $input = new CodedInputStream($data); + $this->parseFromStream($input); + } + + /** + * Parses a json string to protobuf message. + * + * This function takes a string in the json wire format, matching the + * encoding output by serializeToJsonString(). + * See mergeFrom() for merging behavior, if the field is already set in the + * specified message. + * + * @param string $data Json protobuf data. + * @return null. + * @throws \Exception Invalid data. + */ + public function mergeFromJsonString($data) + { + $input = new RawInputStream($data); + $this->parseFromJsonStream($input); + } + + /** + * @ignore + */ + public function parseFromStream($input) + { + while (true) { + $tag = $input->readTag(); + // End of input. This is a valid place to end, so return true. + if ($tag === 0) { + return true; + } + + $number = GPBWire::getTagFieldNumber($tag); + $field = $this->desc->getFieldByNumber($number); + + $this->parseFieldFromStream($tag, $input, $field); + } + } + + private function convertJsonValueToProtoValue( + $value, + $field, + $is_map_key = false) + { + switch ($field->getType()) { + case GPBType::MESSAGE: + $klass = $field->getMessageType()->getClass(); + $submsg = new $klass; + + if (is_a($submsg, "Google\Protobuf\Duration")) { + if (is_null($value)) { + return $this->defaultValue($field); + } else if (!is_string($value)) { + throw new GPBDecodeException("Expect string."); + } + return GPBUtil::parseDuration($value); + } else if ($field->isTimestamp()) { + if (is_null($value)) { + return $this->defaultValue($field); + } else if (!is_string($value)) { + throw new GPBDecodeException("Expect string."); + } + try { + $timestamp = GPBUtil::parseTimestamp($value); + } catch (\Exception $e) { + throw new GPBDecodeException( + "Invalid RFC 3339 timestamp: ".$e->getMessage()); + } + + $submsg->setSeconds($timestamp->getSeconds()); + $submsg->setNanos($timestamp->getNanos()); + } else if (is_a($submsg, "Google\Protobuf\FieldMask")) { + if (is_null($value)) { + return $this->defaultValue($field); + } + try { + return GPBUtil::parseFieldMask($value); + } catch (\Exception $e) { + throw new GPBDecodeException( + "Invalid FieldMask: ".$e->getMessage()); + } + } else { + if (is_null($value) && + !is_a($submsg, "Google\Protobuf\Value")) { + return $this->defaultValue($field); + } + if (GPBUtil::hasSpecialJsonMapping($submsg)) { + } elseif (!is_object($value) && !is_array($value)) { + throw new GPBDecodeException("Expect message."); + } + $submsg->mergeFromJsonArray($value); + } + return $submsg; + case GPBType::ENUM: + if (is_null($value)) { + return $this->defaultValue($field); + } + if (is_integer($value)) { + return $value; + } + $enum_value = $field->getEnumType()->getValueByName($value); + if (!is_null($enum_value)) { + return $enum_value->getNumber(); + } + throw new GPBDecodeException( + "Enum field only accepts integer or enum value name"); + case GPBType::STRING: + if (is_null($value)) { + return $this->defaultValue($field); + } + if (is_numeric($value)) { + return strval($value); + } + if (!is_string($value)) { + throw new GPBDecodeException( + "String field only accepts string value"); + } + return $value; + case GPBType::BYTES: + if (is_null($value)) { + return $this->defaultValue($field); + } + if (!is_string($value)) { + throw new GPBDecodeException( + "Byte field only accepts string value"); + } + $proto_value = base64_decode($value, true); + if ($proto_value === false) { + throw new GPBDecodeException("Invalid base64 characters"); + } + return $proto_value; + case GPBType::BOOL: + if (is_null($value)) { + return $this->defaultValue($field); + } + if ($is_map_key) { + if ($value === "true") { + return true; + } + if ($value === "false") { + return false; + } + throw new GPBDecodeException( + "Bool field only accepts bool value"); + } + if (!is_bool($value)) { + throw new GPBDecodeException( + "Bool field only accepts bool value"); + } + return $value; + case GPBType::FLOAT: + case GPBType::DOUBLE: + if (is_null($value)) { + return $this->defaultValue($field); + } + if ($value === "Infinity") { + return INF; + } + if ($value === "-Infinity") { + return -INF; + } + if ($value === "NaN") { + return NAN; + } + return $value; + case GPBType::INT32: + case GPBType::SINT32: + case GPBType::SFIXED32: + if (is_null($value)) { + return $this->defaultValue($field); + } + if (!is_numeric($value)) { + throw new GPBDecodeException( + "Invalid data type for int32 field"); + } + if (is_string($value) && trim($value) !== $value) { + throw new GPBDecodeException( + "Invalid data type for int32 field"); + } + if (bccomp($value, "2147483647") > 0) { + throw new GPBDecodeException( + "Int32 too large"); + } + if (bccomp($value, "-2147483648") < 0) { + throw new GPBDecodeException( + "Int32 too small"); + } + return $value; + case GPBType::UINT32: + case GPBType::FIXED32: + if (is_null($value)) { + return $this->defaultValue($field); + } + if (!is_numeric($value)) { + throw new GPBDecodeException( + "Invalid data type for uint32 field"); + } + if (is_string($value) && trim($value) !== $value) { + throw new GPBDecodeException( + "Invalid data type for int32 field"); + } + if (bccomp($value, 4294967295) > 0) { + throw new GPBDecodeException( + "Uint32 too large"); + } + return $value; + case GPBType::INT64: + case GPBType::SINT64: + case GPBType::SFIXED64: + if (is_null($value)) { + return $this->defaultValue($field); + } + if (!is_numeric($value)) { + throw new GPBDecodeException( + "Invalid data type for int64 field"); + } + if (is_string($value) && trim($value) !== $value) { + throw new GPBDecodeException( + "Invalid data type for int64 field"); + } + if (bccomp($value, "9223372036854775807") > 0) { + throw new GPBDecodeException( + "Int64 too large"); + } + if (bccomp($value, "-9223372036854775808") < 0) { + throw new GPBDecodeException( + "Int64 too small"); + } + return $value; + case GPBType::UINT64: + case GPBType::FIXED64: + if (is_null($value)) { + return $this->defaultValue($field); + } + if (!is_numeric($value)) { + throw new GPBDecodeException( + "Invalid data type for int64 field"); + } + if (is_string($value) && trim($value) !== $value) { + throw new GPBDecodeException( + "Invalid data type for int64 field"); + } + if (bccomp($value, "18446744073709551615") > 0) { + throw new GPBDecodeException( + "Uint64 too large"); + } + if (bccomp($value, "9223372036854775807") > 0) { + $value = bcsub($value, "18446744073709551616"); + } + return $value; + default: + return $value; + } + } + + /** + * Populates the message from a user-supplied PHP array. Array keys + * correspond to Message properties and nested message properties. + * + * Example: + * ``` + * $message->mergeFromArray([ + * 'name' => 'This is a message name', + * 'interval' => [ + * 'startTime' => time() - 60, + * 'endTime' => time(), + * ] + * ]); + * ``` + * + * This method will trigger an error if it is passed data that cannot + * be converted to the correct type. For example, a StringValue field + * must receive data that is either a string or a StringValue object. + * + * @param array $array An array containing message properties and values. + * @return null. + */ + protected function mergeFromArray(array $array) + { + // Just call the setters for the field names + foreach ($array as $key => $value) { + $field = $this->desc->getFieldByName($key); + if (is_null($field)) { + throw new \UnexpectedValueException( + 'Invalid message property: ' . $key); + } + $setter = $field->getSetter(); + if ($field->isMap()) { + $valueField = $field->getMessageType()->getFieldByName('value'); + if (!is_null($valueField) && $valueField->isWrapperType()) { + self::normalizeArrayElementsToMessageType($value, $valueField->getMessageType()->getClass()); + } + } elseif ($field->isWrapperType()) { + $class = $field->getMessageType()->getClass(); + if ($field->isRepeated()) { + self::normalizeArrayElementsToMessageType($value, $class); + } else { + self::normalizeToMessageType($value, $class); + } + } + $this->$setter($value); + } + } + + /** + * Tries to normalize the elements in $value into a provided protobuf + * wrapper type $class. If $value is any type other than array, we do + * not do any conversion, and instead rely on the existing protobuf + * type checking. If $value is an array, we process each element and + * try to convert it to an instance of $class. + * + * @param mixed $value The array of values to normalize. + * @param string $class The expected wrapper class name + */ + private static function normalizeArrayElementsToMessageType(&$value, $class) + { + if (!is_array($value)) { + // In the case that $value is not an array, we do not want to + // attempt any conversion. Note that this includes the cases + // when $value is a RepeatedField of MapField. In those cases, + // we do not need to convert the elements, as they should + // already be the correct types. + return; + } else { + // Normalize each element in the array. + foreach ($value as $key => &$elementValue) { + self::normalizeToMessageType($elementValue, $class); + } + } + } + + /** + * Tries to normalize $value into a provided protobuf wrapper type $class. + * If $value is any type other than an object, we attempt to construct an + * instance of $class and assign $value to it using the setValue method + * shared by all wrapper types. + * + * This method will raise an error if it receives a type that cannot be + * assigned to the wrapper type via setValue. + * + * @param mixed $value The value to normalize. + * @param string $class The expected wrapper class name + */ + private static function normalizeToMessageType(&$value, $class) + { + if (is_null($value) || is_object($value)) { + // This handles the case that $value is an instance of $class. We + // choose not to do any more strict checking here, relying on the + // existing type checking done by GPBUtil. + return; + } else { + // Try to instantiate $class and set the value + try { + $msg = new $class; + $msg->setValue($value); + $value = $msg; + return; + } catch (\Exception $exception) { + trigger_error( + "Error normalizing value to type '$class': " . $exception->getMessage(), + E_USER_ERROR + ); + } + } + } + + protected function mergeFromJsonArray($array) + { + if (is_a($this, "Google\Protobuf\Any")) { + $this->clear(); + $this->setTypeUrl($array["@type"]); + $msg = $this->unpack(); + if (GPBUtil::hasSpecialJsonMapping($msg)) { + $msg->mergeFromJsonArray($array["value"]); + } else { + unset($array["@type"]); + $msg->mergeFromJsonArray($array); + } + $this->setValue($msg->serializeToString()); + return; + } + if (is_a($this, "Google\Protobuf\DoubleValue") || + is_a($this, "Google\Protobuf\FloatValue") || + is_a($this, "Google\Protobuf\Int64Value") || + is_a($this, "Google\Protobuf\UInt64Value") || + is_a($this, "Google\Protobuf\Int32Value") || + is_a($this, "Google\Protobuf\UInt32Value") || + is_a($this, "Google\Protobuf\BoolValue") || + is_a($this, "Google\Protobuf\StringValue")) { + $this->setValue($array); + return; + } + if (is_a($this, "Google\Protobuf\BytesValue")) { + $this->setValue(base64_decode($array)); + return; + } + if (is_a($this, "Google\Protobuf\Duration")) { + $this->mergeFrom(GPBUtil::parseDuration($array)); + return; + } + if (is_a($this, "Google\Protobuf\FieldMask")) { + $this->mergeFrom(GPBUtil::parseFieldMask($array)); + return; + } + if (is_a($this, "Google\Protobuf\Timestamp")) { + $this->mergeFrom(GPBUtil::parseTimestamp($array)); + return; + } + if (is_a($this, "Google\Protobuf\Struct")) { + $fields = $this->getFields(); + foreach($array as $key => $value) { + $v = new Value(); + $v->mergeFromJsonArray($value); + $fields[$key] = $v; + } + } + if (is_a($this, "Google\Protobuf\Value")) { + if (is_bool($array)) { + $this->setBoolValue($array); + } elseif (is_string($array)) { + $this->setStringValue($array); + } elseif (is_null($array)) { + $this->setNullValue(0); + } elseif (is_double($array) || is_integer($array)) { + $this->setNumberValue($array); + } elseif (is_array($array)) { + if (array_values($array) !== $array) { + // Associative array + $struct_value = $this->getStructValue(); + if (is_null($struct_value)) { + $struct_value = new Struct(); + $this->setStructValue($struct_value); + } + foreach ($array as $key => $v) { + $value = new Value(); + $value->mergeFromJsonArray($v); + $values = $struct_value->getFields(); + $values[$key]= $value; + } + } else { + // Array + $list_value = $this->getListValue(); + if (is_null($list_value)) { + $list_value = new ListValue(); + $this->setListValue($list_value); + } + foreach ($array as $v) { + $value = new Value(); + $value->mergeFromJsonArray($v); + $values = $list_value->getValues(); + $values[]= $value; + } + } + } else { + throw new GPBDecodeException("Invalid type for Value."); + } + return; + } + $this->mergeFromArrayJsonImpl($array); + } + + private function mergeFromArrayJsonImpl($array) + { + foreach ($array as $key => $value) { + $field = $this->desc->getFieldByJsonName($key); + if (is_null($field)) { + $field = $this->desc->getFieldByName($key); + if (is_null($field)) { + continue; + } + } + if ($field->isMap()) { + if (is_null($value)) { + continue; + } + $key_field = $field->getMessageType()->getFieldByNumber(1); + $value_field = $field->getMessageType()->getFieldByNumber(2); + foreach ($value as $tmp_key => $tmp_value) { + if (is_null($tmp_value)) { + throw new \Exception( + "Map value field element cannot be null."); + } + $proto_key = $this->convertJsonValueToProtoValue( + $tmp_key, + $key_field, + true); + $proto_value = $this->convertJsonValueToProtoValue( + $tmp_value, + $value_field); + self::kvUpdateHelper($field, $proto_key, $proto_value); + } + } else if ($field->isRepeated()) { + if (is_null($value)) { + continue; + } + foreach ($value as $tmp) { + if (is_null($tmp)) { + throw new \Exception( + "Repeated field elements cannot be null."); + } + $proto_value = $this->convertJsonValueToProtoValue( + $tmp, + $field); + self::appendHelper($field, $proto_value); + } + } else { + $setter = $field->getSetter(); + $proto_value = $this->convertJsonValueToProtoValue( + $value, + $field); + if ($field->getType() === GPBType::MESSAGE) { + if (is_null($proto_value)) { + continue; + } + $getter = $field->getGetter(); + $submsg = $this->$getter(); + if (!is_null($submsg)) { + $submsg->mergeFrom($proto_value); + continue; + } + } + $this->$setter($proto_value); + } + } + } + + /** + * @ignore + */ + public function parseFromJsonStream($input) + { + $array = json_decode($input->getData(), true, 512, JSON_BIGINT_AS_STRING); + if ($this instanceof \Google\Protobuf\ListValue) { + $array = ["values"=>$array]; + } + if (is_null($array)) { + if ($this instanceof \Google\Protobuf\Value) { + $this->setNullValue(\Google\Protobuf\NullValue::NULL_VALUE); + return; + } else { + throw new GPBDecodeException( + "Cannot decode json string: " . $input->getData()); + } + } + try { + $this->mergeFromJsonArray($array); + } catch (\Exception $e) { + throw new GPBDecodeException($e->getMessage()); + } + } + + /** + * @ignore + */ + private function serializeSingularFieldToStream($field, &$output) + { + if (!$this->existField($field)) { + return true; + } + $getter = $field->getGetter(); + $value = $this->$getter(); + if (!GPBWire::serializeFieldToStream($value, $field, true, $output)) { + return false; + } + return true; + } + + /** + * @ignore + */ + private function serializeRepeatedFieldToStream($field, &$output) + { + $getter = $field->getGetter(); + $values = $this->$getter(); + $count = count($values); + if ($count === 0) { + return true; + } + + $packed = $field->getPacked(); + if ($packed) { + if (!GPBWire::writeTag( + $output, + GPBWire::makeTag($field->getNumber(), GPBType::STRING))) { + return false; + } + $size = 0; + foreach ($values as $value) { + $size += $this->fieldDataOnlyByteSize($field, $value); + } + if (!$output->writeVarint32($size, true)) { + return false; + } + } + + foreach ($values as $value) { + if (!GPBWire::serializeFieldToStream( + $value, + $field, + !$packed, + $output)) { + return false; + } + } + return true; + } + + /** + * @ignore + */ + private function serializeMapFieldToStream($field, $output) + { + $getter = $field->getGetter(); + $values = $this->$getter(); + $count = count($values); + if ($count === 0) { + return true; + } + + foreach ($values as $key => $value) { + $map_entry = new MapEntry($field->getMessageType()); + $map_entry->setKey($key); + $map_entry->setValue($value); + if (!GPBWire::serializeFieldToStream( + $map_entry, + $field, + true, + $output)) { + return false; + } + } + return true; + } + + /** + * @ignore + */ + private function serializeFieldToStream(&$output, $field) + { + if ($field->isMap()) { + return $this->serializeMapFieldToStream($field, $output); + } elseif ($field->isRepeated()) { + return $this->serializeRepeatedFieldToStream($field, $output); + } else { + return $this->serializeSingularFieldToStream($field, $output); + } + } + + /** + * @ignore + */ + private function serializeFieldToJsonStream(&$output, $field) + { + $getter = $field->getGetter(); + $values = $this->$getter(); + return GPBJsonWire::serializeFieldToStream( + $values, $field, $output, !GPBUtil::hasSpecialJsonMapping($this)); + } + + /** + * @ignore + */ + public function serializeToStream(&$output) + { + $fields = $this->desc->getField(); + foreach ($fields as $field) { + if (!$this->serializeFieldToStream($output, $field)) { + return false; + } + } + $output->writeRaw($this->unknown, strlen($this->unknown)); + return true; + } + + /** + * @ignore + */ + public function serializeToJsonStream(&$output) + { + if (is_a($this, 'Google\Protobuf\Any')) { + $output->writeRaw("{", 1); + $type_field = $this->desc->getFieldByNumber(1); + $value_msg = $this->unpack(); + + // Serialize type url. + $output->writeRaw("\"@type\":", 8); + $output->writeRaw("\"", 1); + $output->writeRaw($this->getTypeUrl(), strlen($this->getTypeUrl())); + $output->writeRaw("\"", 1); + + // Serialize value + if (GPBUtil::hasSpecialJsonMapping($value_msg)) { + $output->writeRaw(",\"value\":", 9); + $value_msg->serializeToJsonStream($output); + } else { + $value_fields = $value_msg->desc->getField(); + foreach ($value_fields as $field) { + if ($value_msg->existField($field)) { + $output->writeRaw(",", 1); + if (!$value_msg->serializeFieldToJsonStream($output, $field)) { + return false; + } + } + } + } + + $output->writeRaw("}", 1); + } elseif (is_a($this, 'Google\Protobuf\FieldMask')) { + $field_mask = GPBUtil::formatFieldMask($this); + $output->writeRaw("\"", 1); + $output->writeRaw($field_mask, strlen($field_mask)); + $output->writeRaw("\"", 1); + } elseif (is_a($this, 'Google\Protobuf\Duration')) { + $duration = GPBUtil::formatDuration($this) . "s"; + $output->writeRaw("\"", 1); + $output->writeRaw($duration, strlen($duration)); + $output->writeRaw("\"", 1); + } elseif (get_class($this) === 'Google\Protobuf\Timestamp') { + $timestamp = GPBUtil::formatTimestamp($this); + $timestamp = json_encode($timestamp); + $output->writeRaw($timestamp, strlen($timestamp)); + } elseif (get_class($this) === 'Google\Protobuf\ListValue') { + $field = $this->desc->getField()[1]; + if (!$this->existField($field)) { + $output->writeRaw("[]", 2); + } else { + if (!$this->serializeFieldToJsonStream($output, $field)) { + return false; + } + } + } elseif (get_class($this) === 'Google\Protobuf\Struct') { + $field = $this->desc->getField()[1]; + if (!$this->existField($field)) { + $output->writeRaw("{}", 2); + } else { + if (!$this->serializeFieldToJsonStream($output, $field)) { + return false; + } + } + } else { + if (!GPBUtil::hasSpecialJsonMapping($this)) { + $output->writeRaw("{", 1); + } + $fields = $this->desc->getField(); + $first = true; + foreach ($fields as $field) { + if ($this->existField($field) || + GPBUtil::hasJsonValue($this)) { + if ($first) { + $first = false; + } else { + $output->writeRaw(",", 1); + } + if (!$this->serializeFieldToJsonStream($output, $field)) { + return false; + } + } + } + if (!GPBUtil::hasSpecialJsonMapping($this)) { + $output->writeRaw("}", 1); + } + } + return true; + } + + /** + * Serialize the message to string. + * @return string Serialized binary protobuf data. + */ + public function serializeToString() + { + $output = new CodedOutputStream($this->byteSize()); + $this->serializeToStream($output); + return $output->getData(); + } + + /** + * Serialize the message to json string. + * @return string Serialized json protobuf data. + */ + public function serializeToJsonString() + { + $output = new CodedOutputStream($this->jsonByteSize()); + $this->serializeToJsonStream($output); + return $output->getData(); + } + + /** + * @ignore + */ + private function existField($field) + { + $oneof_index = $field->getOneofIndex(); + if ($oneof_index !== -1) { + $oneof = $this->desc->getOneofDecl()[$oneof_index]; + $oneof_name = $oneof->getName(); + return $this->$oneof_name->getNumber() === $field->getNumber(); + } + + $getter = $field->getGetter(); + $values = $this->$getter(); + if ($field->isMap()) { + return count($values) !== 0; + } elseif ($field->isRepeated()) { + return count($values) !== 0; + } else { + return $values !== $this->defaultValue($field); + } + } + + /** + * @ignore + */ + private function repeatedFieldDataOnlyByteSize($field) + { + $size = 0; + + $getter = $field->getGetter(); + $values = $this->$getter(); + $count = count($values); + if ($count !== 0) { + $size += $count * GPBWire::tagSize($field); + foreach ($values as $value) { + $size += $this->singularFieldDataOnlyByteSize($field); + } + } + } + + /** + * @ignore + */ + private function fieldDataOnlyByteSize($field, $value) + { + $size = 0; + + switch ($field->getType()) { + case GPBType::BOOL: + $size += 1; + break; + case GPBType::FLOAT: + case GPBType::FIXED32: + case GPBType::SFIXED32: + $size += 4; + break; + case GPBType::DOUBLE: + case GPBType::FIXED64: + case GPBType::SFIXED64: + $size += 8; + break; + case GPBType::INT32: + case GPBType::ENUM: + $size += GPBWire::varint32Size($value, true); + break; + case GPBType::UINT32: + $size += GPBWire::varint32Size($value); + break; + case GPBType::UINT64: + case GPBType::INT64: + $size += GPBWire::varint64Size($value); + break; + case GPBType::SINT32: + $size += GPBWire::sint32Size($value); + break; + case GPBType::SINT64: + $size += GPBWire::sint64Size($value); + break; + case GPBType::STRING: + case GPBType::BYTES: + $size += strlen($value); + $size += GPBWire::varint32Size($size); + break; + case GPBType::MESSAGE: + $size += $value->byteSize(); + $size += GPBWire::varint32Size($size); + break; + case GPBType::GROUP: + // TODO(teboring): Add support. + user_error("Unsupported type."); + break; + default: + user_error("Unsupported type."); + return 0; + } + + return $size; + } + + /** + * @ignore + */ + private function fieldDataOnlyJsonByteSize($field, $value) + { + $size = 0; + + switch ($field->getType()) { + case GPBType::SFIXED32: + case GPBType::SINT32: + case GPBType::INT32: + $size += strlen(strval($value)); + break; + case GPBType::FIXED32: + case GPBType::UINT32: + if ($value < 0) { + $value = bcadd($value, "4294967296"); + } + $size += strlen(strval($value)); + break; + case GPBType::FIXED64: + case GPBType::UINT64: + if ($value < 0) { + $value = bcadd($value, "18446744073709551616"); + } + // Intentional fall through. + case GPBType::SFIXED64: + case GPBType::INT64: + case GPBType::SINT64: + $size += 2; // size for "" + $size += strlen(strval($value)); + break; + case GPBType::FLOAT: + if (is_nan($value)) { + $size += strlen("NaN") + 2; + } elseif ($value === INF) { + $size += strlen("Infinity") + 2; + } elseif ($value === -INF) { + $size += strlen("-Infinity") + 2; + } else { + $size += strlen(sprintf("%.8g", $value)); + } + break; + case GPBType::DOUBLE: + if (is_nan($value)) { + $size += strlen("NaN") + 2; + } elseif ($value === INF) { + $size += strlen("Infinity") + 2; + } elseif ($value === -INF) { + $size += strlen("-Infinity") + 2; + } else { + $size += strlen(sprintf("%.17g", $value)); + } + break; + case GPBType::ENUM: + $enum_desc = $field->getEnumType(); + if ($enum_desc->getClass() === "Google\Protobuf\NullValue") { + $size += 4; + break; + } + $enum_value_desc = $enum_desc->getValueByNumber($value); + if (!is_null($enum_value_desc)) { + $size += 2; // size for "" + $size += strlen($enum_value_desc->getName()); + } else { + $str_value = strval($value); + $size += strlen($str_value); + } + break; + case GPBType::BOOL: + if ($value) { + $size += 4; + } else { + $size += 5; + } + break; + case GPBType::STRING: + $value = json_encode($value, JSON_UNESCAPED_UNICODE); + $size += strlen($value); + break; + case GPBType::BYTES: + # if (is_a($this, "Google\Protobuf\BytesValue")) { + # $size += strlen(json_encode($value)); + # } else { + # $size += strlen(base64_encode($value)); + # $size += 2; // size for \"\" + # } + $size += strlen(base64_encode($value)); + $size += 2; // size for \"\" + break; + case GPBType::MESSAGE: + $size += $value->jsonByteSize(); + break; +# case GPBType::GROUP: +# // TODO(teboring): Add support. +# user_error("Unsupported type."); +# break; + default: + user_error("Unsupported type " . $field->getType()); + return 0; + } + + return $size; + } + + /** + * @ignore + */ + private function fieldByteSize($field) + { + $size = 0; + if ($field->isMap()) { + $getter = $field->getGetter(); + $values = $this->$getter(); + $count = count($values); + if ($count !== 0) { + $size += $count * GPBWire::tagSize($field); + $message_type = $field->getMessageType(); + $key_field = $message_type->getFieldByNumber(1); + $value_field = $message_type->getFieldByNumber(2); + foreach ($values as $key => $value) { + $data_size = 0; + if ($key != $this->defaultValue($key_field)) { + $data_size += $this->fieldDataOnlyByteSize( + $key_field, + $key); + $data_size += GPBWire::tagSize($key_field); + } + if ($value != $this->defaultValue($value_field)) { + $data_size += $this->fieldDataOnlyByteSize( + $value_field, + $value); + $data_size += GPBWire::tagSize($value_field); + } + $size += GPBWire::varint32Size($data_size) + $data_size; + } + } + } elseif ($field->isRepeated()) { + $getter = $field->getGetter(); + $values = $this->$getter(); + $count = count($values); + if ($count !== 0) { + if ($field->getPacked()) { + $data_size = 0; + foreach ($values as $value) { + $data_size += $this->fieldDataOnlyByteSize($field, $value); + } + $size += GPBWire::tagSize($field); + $size += GPBWire::varint32Size($data_size); + $size += $data_size; + } else { + $size += $count * GPBWire::tagSize($field); + foreach ($values as $value) { + $size += $this->fieldDataOnlyByteSize($field, $value); + } + } + } + } elseif ($this->existField($field)) { + $size += GPBWire::tagSize($field); + $getter = $field->getGetter(); + $value = $this->$getter(); + $size += $this->fieldDataOnlyByteSize($field, $value); + } + return $size; + } + + /** + * @ignore + */ + private function fieldJsonByteSize($field) + { + $size = 0; + + if ($field->isMap()) { + $getter = $field->getGetter(); + $values = $this->$getter(); + $count = count($values); + if ($count !== 0) { + if (!GPBUtil::hasSpecialJsonMapping($this)) { + $size += 3; // size for "\"\":". + $size += strlen($field->getJsonName()); // size for field name + } + $size += 2; // size for "{}". + $size += $count - 1; // size for commas + $getter = $field->getGetter(); + $map_entry = $field->getMessageType(); + $key_field = $map_entry->getFieldByNumber(1); + $value_field = $map_entry->getFieldByNumber(2); + switch ($key_field->getType()) { + case GPBType::STRING: + case GPBType::SFIXED64: + case GPBType::INT64: + case GPBType::SINT64: + case GPBType::FIXED64: + case GPBType::UINT64: + $additional_quote = false; + break; + default: + $additional_quote = true; + } + foreach ($values as $key => $value) { + if ($additional_quote) { + $size += 2; // size for "" + } + $size += $this->fieldDataOnlyJsonByteSize($key_field, $key); + $size += $this->fieldDataOnlyJsonByteSize($value_field, $value); + $size += 1; // size for : + } + } + } elseif ($field->isRepeated()) { + $getter = $field->getGetter(); + $values = $this->$getter(); + $count = count($values); + if ($count !== 0) { + if (!GPBUtil::hasSpecialJsonMapping($this)) { + $size += 3; // size for "\"\":". + $size += strlen($field->getJsonName()); // size for field name + } + $size += 2; // size for "[]". + $size += $count - 1; // size for commas + $getter = $field->getGetter(); + foreach ($values as $value) { + $size += $this->fieldDataOnlyJsonByteSize($field, $value); + } + } + } elseif ($this->existField($field) || GPBUtil::hasJsonValue($this)) { + if (!GPBUtil::hasSpecialJsonMapping($this)) { + $size += 3; // size for "\"\":". + $size += strlen($field->getJsonName()); // size for field name + } + $getter = $field->getGetter(); + $value = $this->$getter(); + $size += $this->fieldDataOnlyJsonByteSize($field, $value); + } + return $size; + } + + /** + * @ignore + */ + public function byteSize() + { + $size = 0; + + $fields = $this->desc->getField(); + foreach ($fields as $field) { + $size += $this->fieldByteSize($field); + } + $size += strlen($this->unknown); + return $size; + } + + private function appendHelper($field, $append_value) + { + $getter = $field->getGetter(); + $setter = $field->getSetter(); + + $field_arr_value = $this->$getter(); + $field_arr_value[] = $append_value; + + if (!is_object($field_arr_value)) { + $this->$setter($field_arr_value); + } + } + + private function kvUpdateHelper($field, $update_key, $update_value) + { + $getter = $field->getGetter(); + $setter = $field->getSetter(); + + $field_arr_value = $this->$getter(); + $field_arr_value[$update_key] = $update_value; + + if (!is_object($field_arr_value)) { + $this->$setter($field_arr_value); + } + } + + /** + * @ignore + */ + public function jsonByteSize() + { + $size = 0; + if (is_a($this, 'Google\Protobuf\Any')) { + // Size for "{}". + $size += 2; + + // Size for "\"@type\":". + $size += 8; + + // Size for url. +2 for "" /. + $size += strlen($this->getTypeUrl()) + 2; + + $value_msg = $this->unpack(); + if (GPBUtil::hasSpecialJsonMapping($value_msg)) { + // Size for "\",value\":". + $size += 9; + $size += $value_msg->jsonByteSize(); + } else { + // Size for value. +1 for comma, -2 for "{}". + $size += $value_msg->jsonByteSize() -1; + } + } elseif (get_class($this) === 'Google\Protobuf\FieldMask') { + $field_mask = GPBUtil::formatFieldMask($this); + $size += strlen($field_mask) + 2; // 2 for "" + } elseif (get_class($this) === 'Google\Protobuf\Duration') { + $duration = GPBUtil::formatDuration($this) . "s"; + $size += strlen($duration) + 2; // 2 for "" + } elseif (get_class($this) === 'Google\Protobuf\Timestamp') { + $timestamp = GPBUtil::formatTimestamp($this); + $timestamp = json_encode($timestamp); + $size += strlen($timestamp); + } elseif (get_class($this) === 'Google\Protobuf\ListValue') { + $field = $this->desc->getField()[1]; + if ($this->existField($field)) { + $field_size = $this->fieldJsonByteSize($field); + $size += $field_size; + } else { + // Size for "[]". + $size += 2; + } + } elseif (get_class($this) === 'Google\Protobuf\Struct') { + $field = $this->desc->getField()[1]; + if ($this->existField($field)) { + $field_size = $this->fieldJsonByteSize($field); + $size += $field_size; + } else { + // Size for "{}". + $size += 2; + } + } else { + if (!GPBUtil::hasSpecialJsonMapping($this)) { + // Size for "{}". + $size += 2; + } + + $fields = $this->desc->getField(); + $count = 0; + foreach ($fields as $field) { + $field_size = $this->fieldJsonByteSize($field); + $size += $field_size; + if ($field_size != 0) { + $count++; + } + } + // size for comma + $size += $count > 0 ? ($count - 1) : 0; + } + return $size; + } +} diff --git a/src/Google/Protobuf/Internal/MessageBuilderContext.php b/src/Google/Protobuf/Internal/MessageBuilderContext.php new file mode 100644 index 00000000..2724d267 --- /dev/null +++ b/src/Google/Protobuf/Internal/MessageBuilderContext.php @@ -0,0 +1,120 @@ +descriptor = new Descriptor(); + $this->descriptor->setFullName($full_name); + $this->descriptor->setClass($klass); + $this->pool = $pool; + } + + private function getFieldDescriptor($name, $label, $type, + $number, $type_name = null) + { + $field = new FieldDescriptor(); + $field->setName($name); + $camel_name = implode('', array_map('ucwords', explode('_', $name))); + $field->setGetter('get' . $camel_name); + $field->setSetter('set' . $camel_name); + $field->setType($type); + $field->setNumber($number); + $field->setLabel($label); + + // 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 function optional($name, $type, $number, $type_name = null) + { + $this->descriptor->addField($this->getFieldDescriptor( + $name, + GPBLabel::OPTIONAL, + $type, + $number, + $type_name)); + return $this; + } + + public function repeated($name, $type, $number, $type_name = null) + { + $this->descriptor->addField($this->getFieldDescriptor( + $name, + GPBLabel::REPEATED, + $type, + $number, + $type_name)); + return $this; + } + + public function required($name, $type, $number, $type_name = null) + { + $this->descriptor->addField($this->getFieldDescriptor( + $name, + GPBLabel::REQUIRED, + $type, + $number, + $type_name)); + return $this; + } + + public function finalizeToPool() + { + $this->pool->addDescriptor($this->descriptor); + } +} diff --git a/src/Google/Protobuf/Internal/MessageOptions.php b/src/Google/Protobuf/Internal/MessageOptions.php new file mode 100644 index 00000000..95bb706a --- /dev/null +++ b/src/Google/Protobuf/Internal/MessageOptions.php @@ -0,0 +1,382 @@ +google.protobuf.MessageOptions + */ +class MessageOptions extends \Google\Protobuf\Internal\Message +{ + /** + * Set true to use the old proto1 MessageSet wire format for extensions. + * This is provided for backwards-compatibility with the MessageSet wire + * format. You should not use this for any other reason: It's less + * efficient, has fewer features, and is more complicated. + * The message must be defined exactly as follows: + * message Foo { + * option message_set_wire_format = true; + * extensions 4 to max; + * } + * Note that the message cannot have any defined fields; MessageSets only + * have extensions. + * All extensions of your type must be singular messages; e.g. they cannot + * be int32s, enums, or repeated messages. + * Because this is an option, the above two restrictions are not enforced by + * the protocol compiler. + * + * Generated from protobuf field optional bool message_set_wire_format = 1 [default = false]; + */ + protected $message_set_wire_format = false; + private $has_message_set_wire_format = false; + /** + * Disables the generation of the standard "descriptor()" accessor, which can + * conflict with a field of the same name. This is meant to make migration + * from proto1 easier; new code should avoid fields named "descriptor". + * + * Generated from protobuf field optional bool no_standard_descriptor_accessor = 2 [default = false]; + */ + protected $no_standard_descriptor_accessor = false; + private $has_no_standard_descriptor_accessor = false; + /** + * Is this message deprecated? + * Depending on the target platform, this can emit Deprecated annotations + * for the message, or it will be completely ignored; in the very least, + * this is a formalization for deprecating messages. + * + * Generated from protobuf field optional bool deprecated = 3 [default = false]; + */ + protected $deprecated = false; + private $has_deprecated = false; + /** + * Whether the message is an automatically generated map entry type for the + * maps field. + * For maps fields: + * map map_field = 1; + * The parsed descriptor looks like: + * message MapFieldEntry { + * option map_entry = true; + * optional KeyType key = 1; + * optional ValueType value = 2; + * } + * repeated MapFieldEntry map_field = 1; + * Implementations may choose not to generate the map_entry=true message, but + * use a native map in the target language to hold the keys and values. + * The reflection APIs in such implementations still need to work as + * if the field is a repeated message field. + * NOTE: Do not set the option in .proto files. Always use the maps syntax + * instead. The option should only be implicitly set by the proto compiler + * parser. + * + * Generated from protobuf field optional bool map_entry = 7; + */ + protected $map_entry = false; + private $has_map_entry = false; + /** + * The parser stores options it doesn't recognize here. See above. + * + * Generated from protobuf field repeated .google.protobuf.UninterpretedOption uninterpreted_option = 999; + */ + private $uninterpreted_option; + private $has_uninterpreted_option = false; + + /** + * Constructor. + * + * @param array $data { + * Optional. Data for populating the Message object. + * + * @type bool $message_set_wire_format + * Set true to use the old proto1 MessageSet wire format for extensions. + * This is provided for backwards-compatibility with the MessageSet wire + * format. You should not use this for any other reason: It's less + * efficient, has fewer features, and is more complicated. + * The message must be defined exactly as follows: + * message Foo { + * option message_set_wire_format = true; + * extensions 4 to max; + * } + * Note that the message cannot have any defined fields; MessageSets only + * have extensions. + * All extensions of your type must be singular messages; e.g. they cannot + * be int32s, enums, or repeated messages. + * Because this is an option, the above two restrictions are not enforced by + * the protocol compiler. + * @type bool $no_standard_descriptor_accessor + * Disables the generation of the standard "descriptor()" accessor, which can + * conflict with a field of the same name. This is meant to make migration + * from proto1 easier; new code should avoid fields named "descriptor". + * @type bool $deprecated + * Is this message deprecated? + * Depending on the target platform, this can emit Deprecated annotations + * for the message, or it will be completely ignored; in the very least, + * this is a formalization for deprecating messages. + * @type bool $map_entry + * Whether the message is an automatically generated map entry type for the + * maps field. + * For maps fields: + * map map_field = 1; + * The parsed descriptor looks like: + * message MapFieldEntry { + * option map_entry = true; + * optional KeyType key = 1; + * optional ValueType value = 2; + * } + * repeated MapFieldEntry map_field = 1; + * Implementations may choose not to generate the map_entry=true message, but + * use a native map in the target language to hold the keys and values. + * The reflection APIs in such implementations still need to work as + * if the field is a repeated message field. + * NOTE: Do not set the option in .proto files. Always use the maps syntax + * instead. The option should only be implicitly set by the proto compiler + * parser. + * @type \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 true to use the old proto1 MessageSet wire format for extensions. + * This is provided for backwards-compatibility with the MessageSet wire + * format. You should not use this for any other reason: It's less + * efficient, has fewer features, and is more complicated. + * The message must be defined exactly as follows: + * message Foo { + * option message_set_wire_format = true; + * extensions 4 to max; + * } + * Note that the message cannot have any defined fields; MessageSets only + * have extensions. + * All extensions of your type must be singular messages; e.g. they cannot + * be int32s, enums, or repeated messages. + * Because this is an option, the above two restrictions are not enforced by + * the protocol compiler. + * + * Generated from protobuf field optional bool message_set_wire_format = 1 [default = false]; + * @return bool + */ + public function getMessageSetWireFormat() + { + return $this->message_set_wire_format; + } + + /** + * Set true to use the old proto1 MessageSet wire format for extensions. + * This is provided for backwards-compatibility with the MessageSet wire + * format. You should not use this for any other reason: It's less + * efficient, has fewer features, and is more complicated. + * The message must be defined exactly as follows: + * message Foo { + * option message_set_wire_format = true; + * extensions 4 to max; + * } + * Note that the message cannot have any defined fields; MessageSets only + * have extensions. + * All extensions of your type must be singular messages; e.g. they cannot + * be int32s, enums, or repeated messages. + * Because this is an option, the above two restrictions are not enforced by + * the protocol compiler. + * + * Generated from protobuf field optional bool message_set_wire_format = 1 [default = false]; + * @param bool $var + * @return $this + */ + public function setMessageSetWireFormat($var) + { + GPBUtil::checkBool($var); + $this->message_set_wire_format = $var; + $this->has_message_set_wire_format = true; + + return $this; + } + + public function hasMessageSetWireFormat() + { + return $this->has_message_set_wire_format; + } + + /** + * Disables the generation of the standard "descriptor()" accessor, which can + * conflict with a field of the same name. This is meant to make migration + * from proto1 easier; new code should avoid fields named "descriptor". + * + * Generated from protobuf field optional bool no_standard_descriptor_accessor = 2 [default = false]; + * @return bool + */ + public function getNoStandardDescriptorAccessor() + { + return $this->no_standard_descriptor_accessor; + } + + /** + * Disables the generation of the standard "descriptor()" accessor, which can + * conflict with a field of the same name. This is meant to make migration + * from proto1 easier; new code should avoid fields named "descriptor". + * + * Generated from protobuf field optional bool no_standard_descriptor_accessor = 2 [default = false]; + * @param bool $var + * @return $this + */ + public function setNoStandardDescriptorAccessor($var) + { + GPBUtil::checkBool($var); + $this->no_standard_descriptor_accessor = $var; + $this->has_no_standard_descriptor_accessor = true; + + return $this; + } + + public function hasNoStandardDescriptorAccessor() + { + return $this->has_no_standard_descriptor_accessor; + } + + /** + * Is this message deprecated? + * Depending on the target platform, this can emit Deprecated annotations + * for the message, or it will be completely ignored; in the very least, + * this is a formalization for deprecating messages. + * + * Generated from protobuf field optional bool deprecated = 3 [default = false]; + * @return bool + */ + public function getDeprecated() + { + return $this->deprecated; + } + + /** + * Is this message deprecated? + * Depending on the target platform, this can emit Deprecated annotations + * for the message, or it will be completely ignored; in the very least, + * this is a formalization for deprecating messages. + * + * Generated from protobuf field optional bool deprecated = 3 [default = false]; + * @param bool $var + * @return $this + */ + public function setDeprecated($var) + { + GPBUtil::checkBool($var); + $this->deprecated = $var; + $this->has_deprecated = true; + + return $this; + } + + public function hasDeprecated() + { + return $this->has_deprecated; + } + + /** + * Whether the message is an automatically generated map entry type for the + * maps field. + * For maps fields: + * map map_field = 1; + * The parsed descriptor looks like: + * message MapFieldEntry { + * option map_entry = true; + * optional KeyType key = 1; + * optional ValueType value = 2; + * } + * repeated MapFieldEntry map_field = 1; + * Implementations may choose not to generate the map_entry=true message, but + * use a native map in the target language to hold the keys and values. + * The reflection APIs in such implementations still need to work as + * if the field is a repeated message field. + * NOTE: Do not set the option in .proto files. Always use the maps syntax + * instead. The option should only be implicitly set by the proto compiler + * parser. + * + * Generated from protobuf field optional bool map_entry = 7; + * @return bool + */ + public function getMapEntry() + { + return $this->map_entry; + } + + /** + * Whether the message is an automatically generated map entry type for the + * maps field. + * For maps fields: + * map map_field = 1; + * The parsed descriptor looks like: + * message MapFieldEntry { + * option map_entry = true; + * optional KeyType key = 1; + * optional ValueType value = 2; + * } + * repeated MapFieldEntry map_field = 1; + * Implementations may choose not to generate the map_entry=true message, but + * use a native map in the target language to hold the keys and values. + * The reflection APIs in such implementations still need to work as + * if the field is a repeated message field. + * NOTE: Do not set the option in .proto files. Always use the maps syntax + * instead. The option should only be implicitly set by the proto compiler + * parser. + * + * Generated from protobuf field optional bool map_entry = 7; + * @param bool $var + * @return $this + */ + public function setMapEntry($var) + { + GPBUtil::checkBool($var); + $this->map_entry = $var; + $this->has_map_entry = true; + + return $this; + } + + public function hasMapEntry() + { + return $this->has_map_entry; + } + + /** + * The parser stores options it doesn't recognize here. See above. + * + * Generated from protobuf field repeated .google.protobuf.UninterpretedOption uninterpreted_option = 999; + * @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 repeated .google.protobuf.UninterpretedOption uninterpreted_option = 999; + * @param \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; + $this->has_uninterpreted_option = true; + + return $this; + } + + public function hasUninterpretedOption() + { + return $this->has_uninterpreted_option; + } + +} + diff --git a/src/Google/Protobuf/Internal/MethodDescriptorProto.php b/src/Google/Protobuf/Internal/MethodDescriptorProto.php new file mode 100644 index 00000000..f40f20f0 --- /dev/null +++ b/src/Google/Protobuf/Internal/MethodDescriptorProto.php @@ -0,0 +1,264 @@ +google.protobuf.MethodDescriptorProto + */ +class MethodDescriptorProto extends \Google\Protobuf\Internal\Message +{ + /** + * Generated from protobuf field optional string name = 1; + */ + protected $name = ''; + private $has_name = false; + /** + * Input and output type names. These are resolved in the same way as + * FieldDescriptorProto.type_name, but must refer to a message type. + * + * Generated from protobuf field optional string input_type = 2; + */ + protected $input_type = ''; + private $has_input_type = false; + /** + * Generated from protobuf field optional string output_type = 3; + */ + protected $output_type = ''; + private $has_output_type = false; + /** + * Generated from protobuf field optional .google.protobuf.MethodOptions options = 4; + */ + protected $options = null; + private $has_options = false; + /** + * Identifies if client streams multiple client messages + * + * Generated from protobuf field optional bool client_streaming = 5 [default = false]; + */ + protected $client_streaming = false; + private $has_client_streaming = false; + /** + * Identifies if server streams multiple server messages + * + * Generated from protobuf field optional bool server_streaming = 6 [default = false]; + */ + protected $server_streaming = false; + private $has_server_streaming = false; + + /** + * Constructor. + * + * @param array $data { + * Optional. Data for populating the Message object. + * + * @type string $name + * @type string $input_type + * Input and output type names. These are resolved in the same way as + * FieldDescriptorProto.type_name, but must refer to a message type. + * @type string $output_type + * @type \Google\Protobuf\Internal\MethodOptions $options + * @type bool $client_streaming + * Identifies if client streams multiple client messages + * @type bool $server_streaming + * Identifies if server streams multiple server messages + * } + */ + public function __construct($data = NULL) { + \GPBMetadata\Google\Protobuf\Internal\Descriptor::initOnce(); + parent::__construct($data); + } + + /** + * Generated from protobuf field optional string name = 1; + * @return string + */ + public function getName() + { + return $this->name; + } + + /** + * Generated from protobuf field optional string name = 1; + * @param string $var + * @return $this + */ + public function setName($var) + { + GPBUtil::checkString($var, True); + $this->name = $var; + $this->has_name = true; + + return $this; + } + + public function hasName() + { + return $this->has_name; + } + + /** + * Input and output type names. These are resolved in the same way as + * FieldDescriptorProto.type_name, but must refer to a message type. + * + * Generated from protobuf field optional string input_type = 2; + * @return string + */ + public function getInputType() + { + return $this->input_type; + } + + /** + * Input and output type names. These are resolved in the same way as + * FieldDescriptorProto.type_name, but must refer to a message type. + * + * Generated from protobuf field optional string input_type = 2; + * @param string $var + * @return $this + */ + public function setInputType($var) + { + GPBUtil::checkString($var, True); + $this->input_type = $var; + $this->has_input_type = true; + + return $this; + } + + public function hasInputType() + { + return $this->has_input_type; + } + + /** + * Generated from protobuf field optional string output_type = 3; + * @return string + */ + public function getOutputType() + { + return $this->output_type; + } + + /** + * Generated from protobuf field optional string output_type = 3; + * @param string $var + * @return $this + */ + public function setOutputType($var) + { + GPBUtil::checkString($var, True); + $this->output_type = $var; + $this->has_output_type = true; + + return $this; + } + + public function hasOutputType() + { + return $this->has_output_type; + } + + /** + * Generated from protobuf field optional .google.protobuf.MethodOptions options = 4; + * @return \Google\Protobuf\Internal\MethodOptions + */ + public function getOptions() + { + return $this->options; + } + + /** + * Generated from protobuf field optional .google.protobuf.MethodOptions options = 4; + * @param \Google\Protobuf\Internal\MethodOptions $var + * @return $this + */ + public function setOptions($var) + { + GPBUtil::checkMessage($var, \Google\Protobuf\Internal\MethodOptions::class); + $this->options = $var; + $this->has_options = true; + + return $this; + } + + public function hasOptions() + { + return $this->has_options; + } + + /** + * Identifies if client streams multiple client messages + * + * Generated from protobuf field optional bool client_streaming = 5 [default = false]; + * @return bool + */ + public function getClientStreaming() + { + return $this->client_streaming; + } + + /** + * Identifies if client streams multiple client messages + * + * Generated from protobuf field optional bool client_streaming = 5 [default = false]; + * @param bool $var + * @return $this + */ + public function setClientStreaming($var) + { + GPBUtil::checkBool($var); + $this->client_streaming = $var; + $this->has_client_streaming = true; + + return $this; + } + + public function hasClientStreaming() + { + return $this->has_client_streaming; + } + + /** + * Identifies if server streams multiple server messages + * + * Generated from protobuf field optional bool server_streaming = 6 [default = false]; + * @return bool + */ + public function getServerStreaming() + { + return $this->server_streaming; + } + + /** + * Identifies if server streams multiple server messages + * + * Generated from protobuf field optional bool server_streaming = 6 [default = false]; + * @param bool $var + * @return $this + */ + public function setServerStreaming($var) + { + GPBUtil::checkBool($var); + $this->server_streaming = $var; + $this->has_server_streaming = true; + + return $this; + } + + public function hasServerStreaming() + { + return $this->has_server_streaming; + } + +} + diff --git a/src/Google/Protobuf/Internal/MethodOptions.php b/src/Google/Protobuf/Internal/MethodOptions.php new file mode 100644 index 00000000..6a4c92de --- /dev/null +++ b/src/Google/Protobuf/Internal/MethodOptions.php @@ -0,0 +1,161 @@ +google.protobuf.MethodOptions + */ +class MethodOptions extends \Google\Protobuf\Internal\Message +{ + /** + * Is this method deprecated? + * Depending on the target platform, this can emit Deprecated annotations + * for the method, or it will be completely ignored; in the very least, + * this is a formalization for deprecating methods. + * + * Generated from protobuf field optional bool deprecated = 33 [default = false]; + */ + protected $deprecated = false; + private $has_deprecated = false; + /** + * Generated from protobuf field optional .google.protobuf.MethodOptions.IdempotencyLevel idempotency_level = 34 [default = IDEMPOTENCY_UNKNOWN]; + */ + protected $idempotency_level = 0; + private $has_idempotency_level = false; + /** + * The parser stores options it doesn't recognize here. See above. + * + * Generated from protobuf field repeated .google.protobuf.UninterpretedOption uninterpreted_option = 999; + */ + private $uninterpreted_option; + private $has_uninterpreted_option = false; + + /** + * Constructor. + * + * @param array $data { + * Optional. Data for populating the Message object. + * + * @type bool $deprecated + * Is this method deprecated? + * Depending on the target platform, this can emit Deprecated annotations + * for the method, or it will be completely ignored; in the very least, + * this is a formalization for deprecating methods. + * @type int $idempotency_level + * @type \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 method deprecated? + * Depending on the target platform, this can emit Deprecated annotations + * for the method, or it will be completely ignored; in the very least, + * this is a formalization for deprecating methods. + * + * Generated from protobuf field optional bool deprecated = 33 [default = false]; + * @return bool + */ + public function getDeprecated() + { + return $this->deprecated; + } + + /** + * Is this method deprecated? + * Depending on the target platform, this can emit Deprecated annotations + * for the method, or it will be completely ignored; in the very least, + * this is a formalization for deprecating methods. + * + * Generated from protobuf field optional bool deprecated = 33 [default = false]; + * @param bool $var + * @return $this + */ + public function setDeprecated($var) + { + GPBUtil::checkBool($var); + $this->deprecated = $var; + $this->has_deprecated = true; + + return $this; + } + + public function hasDeprecated() + { + return $this->has_deprecated; + } + + /** + * Generated from protobuf field optional .google.protobuf.MethodOptions.IdempotencyLevel idempotency_level = 34 [default = IDEMPOTENCY_UNKNOWN]; + * @return int + */ + public function getIdempotencyLevel() + { + return $this->idempotency_level; + } + + /** + * Generated from protobuf field optional .google.protobuf.MethodOptions.IdempotencyLevel idempotency_level = 34 [default = IDEMPOTENCY_UNKNOWN]; + * @param int $var + * @return $this + */ + public function setIdempotencyLevel($var) + { + GPBUtil::checkEnum($var, \Google\Protobuf\Internal\MethodOptions_IdempotencyLevel::class); + $this->idempotency_level = $var; + $this->has_idempotency_level = true; + + return $this; + } + + public function hasIdempotencyLevel() + { + return $this->has_idempotency_level; + } + + /** + * The parser stores options it doesn't recognize here. See above. + * + * Generated from protobuf field repeated .google.protobuf.UninterpretedOption uninterpreted_option = 999; + * @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 repeated .google.protobuf.UninterpretedOption uninterpreted_option = 999; + * @param \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; + $this->has_uninterpreted_option = true; + + return $this; + } + + public function hasUninterpretedOption() + { + return $this->has_uninterpreted_option; + } + +} + diff --git a/src/Google/Protobuf/Internal/MethodOptions/IdempotencyLevel.php b/src/Google/Protobuf/Internal/MethodOptions/IdempotencyLevel.php new file mode 100644 index 00000000..ce3c062c --- /dev/null +++ b/src/Google/Protobuf/Internal/MethodOptions/IdempotencyLevel.php @@ -0,0 +1,64 @@ +google.protobuf.MethodOptions.IdempotencyLevel + */ +class IdempotencyLevel +{ + /** + * Generated from protobuf enum IDEMPOTENCY_UNKNOWN = 0; + */ + const IDEMPOTENCY_UNKNOWN = 0; + /** + * implies idempotent + * + * Generated from protobuf enum NO_SIDE_EFFECTS = 1; + */ + const NO_SIDE_EFFECTS = 1; + /** + * idempotent, but may have side effects + * + * Generated from protobuf enum IDEMPOTENT = 2; + */ + const IDEMPOTENT = 2; + + private static $valueToName = [ + self::IDEMPOTENCY_UNKNOWN => 'IDEMPOTENCY_UNKNOWN', + self::NO_SIDE_EFFECTS => 'NO_SIDE_EFFECTS', + self::IDEMPOTENT => 'IDEMPOTENT', + ]; + + 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(IdempotencyLevel::class, \Google\Protobuf\Internal\MethodOptions_IdempotencyLevel::class); + diff --git a/src/Google/Protobuf/Internal/MethodOptions_IdempotencyLevel.php b/src/Google/Protobuf/Internal/MethodOptions_IdempotencyLevel.php new file mode 100644 index 00000000..a2913114 --- /dev/null +++ b/src/Google/Protobuf/Internal/MethodOptions_IdempotencyLevel.php @@ -0,0 +1,16 @@ +public_desc = new \Google\Protobuf\OneofDescriptor($this); + } + + public function setName($name) + { + $this->name = $name; + } + + public function getName() + { + return $this->name; + } + + public function addField(FieldDescriptor $field) + { + $this->fields[] = $field; + } + + public function getFields() + { + return $this->fields; + } + + public static function buildFromProto($oneof_proto, $desc, $index) + { + $oneof = new OneofDescriptor(); + $oneof->setName($oneof_proto->getName()); + foreach ($desc->getField() as $field) { + if ($field->getOneofIndex() == $index) { + $oneof->addField($field); + } + } + return $oneof; + } +} diff --git a/src/Google/Protobuf/Internal/OneofDescriptorProto.php b/src/Google/Protobuf/Internal/OneofDescriptorProto.php new file mode 100644 index 00000000..413b8e55 --- /dev/null +++ b/src/Google/Protobuf/Internal/OneofDescriptorProto.php @@ -0,0 +1,103 @@ +google.protobuf.OneofDescriptorProto + */ +class OneofDescriptorProto extends \Google\Protobuf\Internal\Message +{ + /** + * Generated from protobuf field optional string name = 1; + */ + protected $name = ''; + private $has_name = false; + /** + * Generated from protobuf field optional .google.protobuf.OneofOptions options = 2; + */ + protected $options = null; + private $has_options = false; + + /** + * Constructor. + * + * @param array $data { + * Optional. Data for populating the Message object. + * + * @type string $name + * @type \Google\Protobuf\Internal\OneofOptions $options + * } + */ + public function __construct($data = NULL) { + \GPBMetadata\Google\Protobuf\Internal\Descriptor::initOnce(); + parent::__construct($data); + } + + /** + * Generated from protobuf field optional string name = 1; + * @return string + */ + public function getName() + { + return $this->name; + } + + /** + * Generated from protobuf field optional string name = 1; + * @param string $var + * @return $this + */ + public function setName($var) + { + GPBUtil::checkString($var, True); + $this->name = $var; + $this->has_name = true; + + return $this; + } + + public function hasName() + { + return $this->has_name; + } + + /** + * Generated from protobuf field optional .google.protobuf.OneofOptions options = 2; + * @return \Google\Protobuf\Internal\OneofOptions + */ + public function getOptions() + { + return $this->options; + } + + /** + * Generated from protobuf field optional .google.protobuf.OneofOptions options = 2; + * @param \Google\Protobuf\Internal\OneofOptions $var + * @return $this + */ + public function setOptions($var) + { + GPBUtil::checkMessage($var, \Google\Protobuf\Internal\OneofOptions::class); + $this->options = $var; + $this->has_options = true; + + return $this; + } + + public function hasOptions() + { + return $this->has_options; + } + +} + diff --git a/src/Google/Protobuf/Internal/OneofField.php b/src/Google/Protobuf/Internal/OneofField.php new file mode 100644 index 00000000..2c689e83 --- /dev/null +++ b/src/Google/Protobuf/Internal/OneofField.php @@ -0,0 +1,77 @@ +desc = $desc; + } + + public function setValue($value) + { + $this->value = $value; + } + + public function getValue() + { + return $this->value; + } + + public function setFieldName($field_name) + { + $this->field_name = $field_name; + } + + public function getFieldName() + { + return $this->field_name; + } + + public function setNumber($number) + { + $this->number = $number; + } + + public function getNumber() + { + return $this->number; + } +} diff --git a/src/Google/Protobuf/Internal/OneofOptions.php b/src/Google/Protobuf/Internal/OneofOptions.php new file mode 100644 index 00000000..46b516f3 --- /dev/null +++ b/src/Google/Protobuf/Internal/OneofOptions.php @@ -0,0 +1,74 @@ +google.protobuf.OneofOptions + */ +class OneofOptions extends \Google\Protobuf\Internal\Message +{ + /** + * The parser stores options it doesn't recognize here. See above. + * + * Generated from protobuf field repeated .google.protobuf.UninterpretedOption uninterpreted_option = 999; + */ + private $uninterpreted_option; + private $has_uninterpreted_option = false; + + /** + * Constructor. + * + * @param array $data { + * Optional. Data for populating the Message object. + * + * @type \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 repeated .google.protobuf.UninterpretedOption uninterpreted_option = 999; + * @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 repeated .google.protobuf.UninterpretedOption uninterpreted_option = 999; + * @param \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; + $this->has_uninterpreted_option = true; + + return $this; + } + + public function hasUninterpretedOption() + { + return $this->has_uninterpreted_option; + } + +} + diff --git a/src/Google/Protobuf/Internal/RawInputStream.php b/src/Google/Protobuf/Internal/RawInputStream.php new file mode 100644 index 00000000..4e7ed5cb --- /dev/null +++ b/src/Google/Protobuf/Internal/RawInputStream.php @@ -0,0 +1,50 @@ +buffer = $buffer; + } + + public function getData() + { + return $this->buffer; + } + +} diff --git a/src/Google/Protobuf/Internal/RepeatedField.php b/src/Google/Protobuf/Internal/RepeatedField.php new file mode 100644 index 00000000..ec7a3a6d --- /dev/null +++ b/src/Google/Protobuf/Internal/RepeatedField.php @@ -0,0 +1,258 @@ +container = []; + $this->type = $type; + if ($this->type == GPBType::MESSAGE) { + $pool = DescriptorPool::getGeneratedPool(); + $desc = $pool->getDescriptorByClassName($klass); + if ($desc == NULL) { + new $klass; // No msg class instance has been created before. + $desc = $pool->getDescriptorByClassName($klass); + } + $this->klass = $desc->getClass(); + $this->legacy_klass = $desc->getLegacyClass(); + } + } + + /** + * @ignore + */ + public function getType() + { + return $this->type; + } + + /** + * @ignore + */ + public function getClass() + { + return $this->klass; + } + + /** + * @ignore + */ + public function getLegacyClass() + { + return $this->legacy_klass; + } + + /** + * Return the element at the given index. + * + * This will also be called for: $ele = $arr[0] + * + * @param long $offset The index of the element to be fetched. + * @return object The stored element at given index. + * @throws \ErrorException Invalid type for index. + * @throws \ErrorException Non-existing index. + */ + public function offsetGet($offset) + { + return $this->container[$offset]; + } + + /** + * Assign the element at the given index. + * + * This will also be called for: $arr []= $ele and $arr[0] = ele + * + * @param long $offset The index of the element to be assigned. + * @param object $value The element to be assigned. + * @return void + * @throws \ErrorException Invalid type for index. + * @throws \ErrorException Non-existing index. + * @throws \ErrorException Incorrect type of the element. + */ + public function offsetSet($offset, $value) + { + switch ($this->type) { + case GPBType::SFIXED32: + case GPBType::SINT32: + case GPBType::INT32: + case GPBType::ENUM: + GPBUtil::checkInt32($value); + break; + case GPBType::FIXED32: + case GPBType::UINT32: + GPBUtil::checkUint32($value); + break; + case GPBType::SFIXED64: + case GPBType::SINT64: + case GPBType::INT64: + GPBUtil::checkInt64($value); + break; + case GPBType::FIXED64: + case GPBType::UINT64: + GPBUtil::checkUint64($value); + break; + case GPBType::FLOAT: + GPBUtil::checkFloat($value); + break; + case GPBType::DOUBLE: + GPBUtil::checkDouble($value); + break; + case GPBType::BOOL: + GPBUtil::checkBool($value); + break; + case GPBType::BYTES: + GPBUtil::checkString($value, false); + break; + case GPBType::STRING: + GPBUtil::checkString($value, true); + break; + case GPBType::MESSAGE: + if (is_null($value)) { + trigger_error("RepeatedField element cannot be null.", + E_USER_ERROR); + } + GPBUtil::checkMessage($value, $this->klass); + break; + default: + break; + } + if (is_null($offset)) { + $this->container[] = $value; + } else { + $count = count($this->container); + if (!is_numeric($offset) || $offset < 0 || $offset >= $count) { + trigger_error( + "Cannot modify element at the given index", + E_USER_ERROR); + return; + } + $this->container[$offset] = $value; + } + } + + /** + * Remove the element at the given index. + * + * This will also be called for: unset($arr) + * + * @param long $offset The index of the element to be removed. + * @return void + * @throws \ErrorException Invalid type for index. + * @throws \ErrorException The element to be removed is not at the end of the + * RepeatedField. + */ + public function offsetUnset($offset) + { + $count = count($this->container); + if (!is_numeric($offset) || $count === 0 || $offset !== $count - 1) { + trigger_error( + "Cannot remove element at the given index", + E_USER_ERROR); + return; + } + array_pop($this->container); + } + + /** + * Check the existence of the element at the given index. + * + * This will also be called for: isset($arr) + * + * @param long $offset The index of the element to be removed. + * @return bool True if the element at the given offset exists. + * @throws \ErrorException Invalid type for index. + */ + public function offsetExists($offset) + { + return isset($this->container[$offset]); + } + + /** + * @ignore + */ + public function getIterator() + { + return new RepeatedFieldIter($this->container); + } + + /** + * Return the number of stored elements. + * + * This will also be called for: count($arr) + * + * @return integer The number of stored elements. + */ + public function count() + { + return count($this->container); + } +} diff --git a/src/Google/Protobuf/Internal/RepeatedFieldIter.php b/src/Google/Protobuf/Internal/RepeatedFieldIter.php new file mode 100644 index 00000000..2b6f8230 --- /dev/null +++ b/src/Google/Protobuf/Internal/RepeatedFieldIter.php @@ -0,0 +1,118 @@ +position = 0; + $this->container = $container; + } + + /** + * Reset the status of the iterator + * + * @return void + */ + public function rewind() + { + $this->position = 0; + } + + /** + * Return the element at the current position. + * + * @return object The element at the current position. + */ + public function current() + { + return $this->container[$this->position]; + } + + /** + * Return the current position. + * + * @return integer The current position. + */ + public function key() + { + return $this->position; + } + + /** + * Move to the next position. + * + * @return void + */ + public function next() + { + ++$this->position; + } + + /** + * Check whether there are more elements to iterate. + * + * @return bool True if there are more elements to iterate. + */ + public function valid() + { + return isset($this->container[$this->position]); + } +} diff --git a/src/Google/Protobuf/Internal/ServiceDescriptorProto.php b/src/Google/Protobuf/Internal/ServiceDescriptorProto.php new file mode 100644 index 00000000..aaeefbc9 --- /dev/null +++ b/src/Google/Protobuf/Internal/ServiceDescriptorProto.php @@ -0,0 +1,137 @@ +google.protobuf.ServiceDescriptorProto + */ +class ServiceDescriptorProto extends \Google\Protobuf\Internal\Message +{ + /** + * Generated from protobuf field optional string name = 1; + */ + protected $name = ''; + private $has_name = false; + /** + * Generated from protobuf field repeated .google.protobuf.MethodDescriptorProto method = 2; + */ + private $method; + private $has_method = false; + /** + * Generated from protobuf field optional .google.protobuf.ServiceOptions options = 3; + */ + protected $options = null; + private $has_options = false; + + /** + * Constructor. + * + * @param array $data { + * Optional. Data for populating the Message object. + * + * @type string $name + * @type \Google\Protobuf\Internal\MethodDescriptorProto[]|\Google\Protobuf\Internal\RepeatedField $method + * @type \Google\Protobuf\Internal\ServiceOptions $options + * } + */ + public function __construct($data = NULL) { + \GPBMetadata\Google\Protobuf\Internal\Descriptor::initOnce(); + parent::__construct($data); + } + + /** + * Generated from protobuf field optional string name = 1; + * @return string + */ + public function getName() + { + return $this->name; + } + + /** + * Generated from protobuf field optional string name = 1; + * @param string $var + * @return $this + */ + public function setName($var) + { + GPBUtil::checkString($var, True); + $this->name = $var; + $this->has_name = true; + + return $this; + } + + public function hasName() + { + return $this->has_name; + } + + /** + * Generated from protobuf field repeated .google.protobuf.MethodDescriptorProto method = 2; + * @return \Google\Protobuf\Internal\RepeatedField + */ + public function getMethod() + { + return $this->method; + } + + /** + * Generated from protobuf field repeated .google.protobuf.MethodDescriptorProto method = 2; + * @param \Google\Protobuf\Internal\MethodDescriptorProto[]|\Google\Protobuf\Internal\RepeatedField $var + * @return $this + */ + public function setMethod($var) + { + $arr = GPBUtil::checkRepeatedField($var, \Google\Protobuf\Internal\GPBType::MESSAGE, \Google\Protobuf\Internal\MethodDescriptorProto::class); + $this->method = $arr; + $this->has_method = true; + + return $this; + } + + public function hasMethod() + { + return $this->has_method; + } + + /** + * Generated from protobuf field optional .google.protobuf.ServiceOptions options = 3; + * @return \Google\Protobuf\Internal\ServiceOptions + */ + public function getOptions() + { + return $this->options; + } + + /** + * Generated from protobuf field optional .google.protobuf.ServiceOptions options = 3; + * @param \Google\Protobuf\Internal\ServiceOptions $var + * @return $this + */ + public function setOptions($var) + { + GPBUtil::checkMessage($var, \Google\Protobuf\Internal\ServiceOptions::class); + $this->options = $var; + $this->has_options = true; + + return $this; + } + + public function hasOptions() + { + return $this->has_options; + } + +} + diff --git a/src/Google/Protobuf/Internal/ServiceOptions.php b/src/Google/Protobuf/Internal/ServiceOptions.php new file mode 100644 index 00000000..0581efba --- /dev/null +++ b/src/Google/Protobuf/Internal/ServiceOptions.php @@ -0,0 +1,127 @@ +google.protobuf.ServiceOptions + */ +class ServiceOptions extends \Google\Protobuf\Internal\Message +{ + /** + * Is this service deprecated? + * Depending on the target platform, this can emit Deprecated annotations + * for the service, or it will be completely ignored; in the very least, + * this is a formalization for deprecating services. + * + * Generated from protobuf field optional bool deprecated = 33 [default = false]; + */ + protected $deprecated = false; + private $has_deprecated = false; + /** + * The parser stores options it doesn't recognize here. See above. + * + * Generated from protobuf field repeated .google.protobuf.UninterpretedOption uninterpreted_option = 999; + */ + private $uninterpreted_option; + private $has_uninterpreted_option = false; + + /** + * Constructor. + * + * @param array $data { + * Optional. Data for populating the Message object. + * + * @type bool $deprecated + * Is this service deprecated? + * Depending on the target platform, this can emit Deprecated annotations + * for the service, or it will be completely ignored; in the very least, + * this is a formalization for deprecating services. + * @type \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 service deprecated? + * Depending on the target platform, this can emit Deprecated annotations + * for the service, or it will be completely ignored; in the very least, + * this is a formalization for deprecating services. + * + * Generated from protobuf field optional bool deprecated = 33 [default = false]; + * @return bool + */ + public function getDeprecated() + { + return $this->deprecated; + } + + /** + * Is this service deprecated? + * Depending on the target platform, this can emit Deprecated annotations + * for the service, or it will be completely ignored; in the very least, + * this is a formalization for deprecating services. + * + * Generated from protobuf field optional bool deprecated = 33 [default = false]; + * @param bool $var + * @return $this + */ + public function setDeprecated($var) + { + GPBUtil::checkBool($var); + $this->deprecated = $var; + $this->has_deprecated = true; + + return $this; + } + + public function hasDeprecated() + { + return $this->has_deprecated; + } + + /** + * The parser stores options it doesn't recognize here. See above. + * + * Generated from protobuf field repeated .google.protobuf.UninterpretedOption uninterpreted_option = 999; + * @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 repeated .google.protobuf.UninterpretedOption uninterpreted_option = 999; + * @param \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; + $this->has_uninterpreted_option = true; + + return $this; + } + + public function hasUninterpretedOption() + { + return $this->has_uninterpreted_option; + } + +} + diff --git a/src/Google/Protobuf/Internal/SourceCodeInfo.php b/src/Google/Protobuf/Internal/SourceCodeInfo.php new file mode 100644 index 00000000..dfeb69ff --- /dev/null +++ b/src/Google/Protobuf/Internal/SourceCodeInfo.php @@ -0,0 +1,237 @@ +google.protobuf.SourceCodeInfo + */ +class SourceCodeInfo extends \Google\Protobuf\Internal\Message +{ + /** + * A Location identifies a piece of source code in a .proto file which + * corresponds to a particular definition. This information is intended + * to be useful to IDEs, code indexers, documentation generators, and similar + * tools. + * For example, say we have a file like: + * message Foo { + * optional string foo = 1; + * } + * Let's look at just the field definition: + * optional string foo = 1; + * ^ ^^ ^^ ^ ^^^ + * a bc de f ghi + * We have the following locations: + * span path represents + * [a,i) [ 4, 0, 2, 0 ] The whole field definition. + * [a,b) [ 4, 0, 2, 0, 4 ] The label (optional). + * [c,d) [ 4, 0, 2, 0, 5 ] The type (string). + * [e,f) [ 4, 0, 2, 0, 1 ] The name (foo). + * [g,h) [ 4, 0, 2, 0, 3 ] The number (1). + * Notes: + * - A location may refer to a repeated field itself (i.e. not to any + * particular index within it). This is used whenever a set of elements are + * logically enclosed in a single code segment. For example, an entire + * extend block (possibly containing multiple extension definitions) will + * have an outer location whose path refers to the "extensions" repeated + * field without an index. + * - Multiple locations may have the same path. This happens when a single + * logical declaration is spread out across multiple places. The most + * obvious example is the "extend" block again -- there may be multiple + * extend blocks in the same scope, each of which will have the same path. + * - A location's span is not always a subset of its parent's span. For + * example, the "extendee" of an extension declaration appears at the + * beginning of the "extend" block and is shared by all extensions within + * the block. + * - Just because a location's span is a subset of some other location's span + * does not mean that it is a descendant. For example, a "group" defines + * both a type and a field in a single declaration. Thus, the locations + * corresponding to the type and field and their components will overlap. + * - Code which tries to interpret locations should probably be designed to + * ignore those that it doesn't understand, as more types of locations could + * be recorded in the future. + * + * Generated from protobuf field repeated .google.protobuf.SourceCodeInfo.Location location = 1; + */ + private $location; + private $has_location = false; + + /** + * Constructor. + * + * @param array $data { + * Optional. Data for populating the Message object. + * + * @type \Google\Protobuf\Internal\SourceCodeInfo\Location[]|\Google\Protobuf\Internal\RepeatedField $location + * A Location identifies a piece of source code in a .proto file which + * corresponds to a particular definition. This information is intended + * to be useful to IDEs, code indexers, documentation generators, and similar + * tools. + * For example, say we have a file like: + * message Foo { + * optional string foo = 1; + * } + * Let's look at just the field definition: + * optional string foo = 1; + * ^ ^^ ^^ ^ ^^^ + * a bc de f ghi + * We have the following locations: + * span path represents + * [a,i) [ 4, 0, 2, 0 ] The whole field definition. + * [a,b) [ 4, 0, 2, 0, 4 ] The label (optional). + * [c,d) [ 4, 0, 2, 0, 5 ] The type (string). + * [e,f) [ 4, 0, 2, 0, 1 ] The name (foo). + * [g,h) [ 4, 0, 2, 0, 3 ] The number (1). + * Notes: + * - A location may refer to a repeated field itself (i.e. not to any + * particular index within it). This is used whenever a set of elements are + * logically enclosed in a single code segment. For example, an entire + * extend block (possibly containing multiple extension definitions) will + * have an outer location whose path refers to the "extensions" repeated + * field without an index. + * - Multiple locations may have the same path. This happens when a single + * logical declaration is spread out across multiple places. The most + * obvious example is the "extend" block again -- there may be multiple + * extend blocks in the same scope, each of which will have the same path. + * - A location's span is not always a subset of its parent's span. For + * example, the "extendee" of an extension declaration appears at the + * beginning of the "extend" block and is shared by all extensions within + * the block. + * - Just because a location's span is a subset of some other location's span + * does not mean that it is a descendant. For example, a "group" defines + * both a type and a field in a single declaration. Thus, the locations + * corresponding to the type and field and their components will overlap. + * - Code which tries to interpret locations should probably be designed to + * ignore those that it doesn't understand, as more types of locations could + * be recorded in the future. + * } + */ + public function __construct($data = NULL) { + \GPBMetadata\Google\Protobuf\Internal\Descriptor::initOnce(); + parent::__construct($data); + } + + /** + * A Location identifies a piece of source code in a .proto file which + * corresponds to a particular definition. This information is intended + * to be useful to IDEs, code indexers, documentation generators, and similar + * tools. + * For example, say we have a file like: + * message Foo { + * optional string foo = 1; + * } + * Let's look at just the field definition: + * optional string foo = 1; + * ^ ^^ ^^ ^ ^^^ + * a bc de f ghi + * We have the following locations: + * span path represents + * [a,i) [ 4, 0, 2, 0 ] The whole field definition. + * [a,b) [ 4, 0, 2, 0, 4 ] The label (optional). + * [c,d) [ 4, 0, 2, 0, 5 ] The type (string). + * [e,f) [ 4, 0, 2, 0, 1 ] The name (foo). + * [g,h) [ 4, 0, 2, 0, 3 ] The number (1). + * Notes: + * - A location may refer to a repeated field itself (i.e. not to any + * particular index within it). This is used whenever a set of elements are + * logically enclosed in a single code segment. For example, an entire + * extend block (possibly containing multiple extension definitions) will + * have an outer location whose path refers to the "extensions" repeated + * field without an index. + * - Multiple locations may have the same path. This happens when a single + * logical declaration is spread out across multiple places. The most + * obvious example is the "extend" block again -- there may be multiple + * extend blocks in the same scope, each of which will have the same path. + * - A location's span is not always a subset of its parent's span. For + * example, the "extendee" of an extension declaration appears at the + * beginning of the "extend" block and is shared by all extensions within + * the block. + * - Just because a location's span is a subset of some other location's span + * does not mean that it is a descendant. For example, a "group" defines + * both a type and a field in a single declaration. Thus, the locations + * corresponding to the type and field and their components will overlap. + * - Code which tries to interpret locations should probably be designed to + * ignore those that it doesn't understand, as more types of locations could + * be recorded in the future. + * + * Generated from protobuf field repeated .google.protobuf.SourceCodeInfo.Location location = 1; + * @return \Google\Protobuf\Internal\RepeatedField + */ + public function getLocation() + { + return $this->location; + } + + /** + * A Location identifies a piece of source code in a .proto file which + * corresponds to a particular definition. This information is intended + * to be useful to IDEs, code indexers, documentation generators, and similar + * tools. + * For example, say we have a file like: + * message Foo { + * optional string foo = 1; + * } + * Let's look at just the field definition: + * optional string foo = 1; + * ^ ^^ ^^ ^ ^^^ + * a bc de f ghi + * We have the following locations: + * span path represents + * [a,i) [ 4, 0, 2, 0 ] The whole field definition. + * [a,b) [ 4, 0, 2, 0, 4 ] The label (optional). + * [c,d) [ 4, 0, 2, 0, 5 ] The type (string). + * [e,f) [ 4, 0, 2, 0, 1 ] The name (foo). + * [g,h) [ 4, 0, 2, 0, 3 ] The number (1). + * Notes: + * - A location may refer to a repeated field itself (i.e. not to any + * particular index within it). This is used whenever a set of elements are + * logically enclosed in a single code segment. For example, an entire + * extend block (possibly containing multiple extension definitions) will + * have an outer location whose path refers to the "extensions" repeated + * field without an index. + * - Multiple locations may have the same path. This happens when a single + * logical declaration is spread out across multiple places. The most + * obvious example is the "extend" block again -- there may be multiple + * extend blocks in the same scope, each of which will have the same path. + * - A location's span is not always a subset of its parent's span. For + * example, the "extendee" of an extension declaration appears at the + * beginning of the "extend" block and is shared by all extensions within + * the block. + * - Just because a location's span is a subset of some other location's span + * does not mean that it is a descendant. For example, a "group" defines + * both a type and a field in a single declaration. Thus, the locations + * corresponding to the type and field and their components will overlap. + * - Code which tries to interpret locations should probably be designed to + * ignore those that it doesn't understand, as more types of locations could + * be recorded in the future. + * + * Generated from protobuf field repeated .google.protobuf.SourceCodeInfo.Location location = 1; + * @param \Google\Protobuf\Internal\SourceCodeInfo\Location[]|\Google\Protobuf\Internal\RepeatedField $var + * @return $this + */ + public function setLocation($var) + { + $arr = GPBUtil::checkRepeatedField($var, \Google\Protobuf\Internal\GPBType::MESSAGE, \Google\Protobuf\Internal\SourceCodeInfo\Location::class); + $this->location = $arr; + $this->has_location = true; + + return $this; + } + + public function hasLocation() + { + return $this->has_location; + } + +} + diff --git a/src/Google/Protobuf/Internal/SourceCodeInfo/Location.php b/src/Google/Protobuf/Internal/SourceCodeInfo/Location.php new file mode 100644 index 00000000..0aeea61c --- /dev/null +++ b/src/Google/Protobuf/Internal/SourceCodeInfo/Location.php @@ -0,0 +1,463 @@ +google.protobuf.SourceCodeInfo.Location + */ +class Location extends \Google\Protobuf\Internal\Message +{ + /** + * Identifies which part of the FileDescriptorProto was defined at this + * location. + * Each element is a field number or an index. They form a path from + * the root FileDescriptorProto to the place where the definition. For + * example, this path: + * [ 4, 3, 2, 7, 1 ] + * refers to: + * file.message_type(3) // 4, 3 + * .field(7) // 2, 7 + * .name() // 1 + * This is because FileDescriptorProto.message_type has field number 4: + * repeated DescriptorProto message_type = 4; + * and DescriptorProto.field has field number 2: + * repeated FieldDescriptorProto field = 2; + * and FieldDescriptorProto.name has field number 1: + * optional string name = 1; + * Thus, the above path gives the location of a field name. If we removed + * the last element: + * [ 4, 3, 2, 7 ] + * this path refers to the whole field declaration (from the beginning + * of the label to the terminating semicolon). + * + * Generated from protobuf field repeated int32 path = 1 [packed = true]; + */ + private $path; + private $has_path = false; + /** + * Always has exactly three or four elements: start line, start column, + * end line (optional, otherwise assumed same as start line), end column. + * These are packed into a single field for efficiency. Note that line + * and column numbers are zero-based -- typically you will want to add + * 1 to each before displaying to a user. + * + * Generated from protobuf field repeated int32 span = 2 [packed = true]; + */ + private $span; + private $has_span = false; + /** + * If this SourceCodeInfo represents a complete declaration, these are any + * comments appearing before and after the declaration which appear to be + * attached to the declaration. + * A series of line comments appearing on consecutive lines, with no other + * tokens appearing on those lines, will be treated as a single comment. + * leading_detached_comments will keep paragraphs of comments that appear + * before (but not connected to) the current element. Each paragraph, + * separated by empty lines, will be one comment element in the repeated + * field. + * Only the comment content is provided; comment markers (e.g. //) are + * stripped out. For block comments, leading whitespace and an asterisk + * will be stripped from the beginning of each line other than the first. + * Newlines are included in the output. + * Examples: + * optional int32 foo = 1; // Comment attached to foo. + * // Comment attached to bar. + * optional int32 bar = 2; + * optional string baz = 3; + * // Comment attached to baz. + * // Another line attached to baz. + * // Comment attached to qux. + * // + * // Another line attached to qux. + * optional double qux = 4; + * // Detached comment for corge. This is not leading or trailing comments + * // to qux or corge because there are blank lines separating it from + * // both. + * // Detached comment for corge paragraph 2. + * optional string corge = 5; + * /* Block comment attached + * * to corge. Leading asterisks + * * will be removed. */ + * /* Block comment attached to + * * grault. */ + * optional int32 grault = 6; + * // ignored detached comments. + * + * Generated from protobuf field optional string leading_comments = 3; + */ + protected $leading_comments = ''; + private $has_leading_comments = false; + /** + * Generated from protobuf field optional string trailing_comments = 4; + */ + protected $trailing_comments = ''; + private $has_trailing_comments = false; + /** + * Generated from protobuf field repeated string leading_detached_comments = 6; + */ + private $leading_detached_comments; + private $has_leading_detached_comments = false; + + /** + * Constructor. + * + * @param array $data { + * Optional. Data for populating the Message object. + * + * @type int[]|\Google\Protobuf\Internal\RepeatedField $path + * Identifies which part of the FileDescriptorProto was defined at this + * location. + * Each element is a field number or an index. They form a path from + * the root FileDescriptorProto to the place where the definition. For + * example, this path: + * [ 4, 3, 2, 7, 1 ] + * refers to: + * file.message_type(3) // 4, 3 + * .field(7) // 2, 7 + * .name() // 1 + * This is because FileDescriptorProto.message_type has field number 4: + * repeated DescriptorProto message_type = 4; + * and DescriptorProto.field has field number 2: + * repeated FieldDescriptorProto field = 2; + * and FieldDescriptorProto.name has field number 1: + * optional string name = 1; + * Thus, the above path gives the location of a field name. If we removed + * the last element: + * [ 4, 3, 2, 7 ] + * this path refers to the whole field declaration (from the beginning + * of the label to the terminating semicolon). + * @type int[]|\Google\Protobuf\Internal\RepeatedField $span + * Always has exactly three or four elements: start line, start column, + * end line (optional, otherwise assumed same as start line), end column. + * These are packed into a single field for efficiency. Note that line + * and column numbers are zero-based -- typically you will want to add + * 1 to each before displaying to a user. + * @type string $leading_comments + * If this SourceCodeInfo represents a complete declaration, these are any + * comments appearing before and after the declaration which appear to be + * attached to the declaration. + * A series of line comments appearing on consecutive lines, with no other + * tokens appearing on those lines, will be treated as a single comment. + * leading_detached_comments will keep paragraphs of comments that appear + * before (but not connected to) the current element. Each paragraph, + * separated by empty lines, will be one comment element in the repeated + * field. + * Only the comment content is provided; comment markers (e.g. //) are + * stripped out. For block comments, leading whitespace and an asterisk + * will be stripped from the beginning of each line other than the first. + * Newlines are included in the output. + * Examples: + * optional int32 foo = 1; // Comment attached to foo. + * // Comment attached to bar. + * optional int32 bar = 2; + * optional string baz = 3; + * // Comment attached to baz. + * // Another line attached to baz. + * // Comment attached to qux. + * // + * // Another line attached to qux. + * optional double qux = 4; + * // Detached comment for corge. This is not leading or trailing comments + * // to qux or corge because there are blank lines separating it from + * // both. + * // Detached comment for corge paragraph 2. + * optional string corge = 5; + * /* Block comment attached + * * to corge. Leading asterisks + * * will be removed. */ + * /* Block comment attached to + * * grault. */ + * optional int32 grault = 6; + * // ignored detached comments. + * @type string $trailing_comments + * @type string[]|\Google\Protobuf\Internal\RepeatedField $leading_detached_comments + * } + */ + public function __construct($data = NULL) { + \GPBMetadata\Google\Protobuf\Internal\Descriptor::initOnce(); + parent::__construct($data); + } + + /** + * Identifies which part of the FileDescriptorProto was defined at this + * location. + * Each element is a field number or an index. They form a path from + * the root FileDescriptorProto to the place where the definition. For + * example, this path: + * [ 4, 3, 2, 7, 1 ] + * refers to: + * file.message_type(3) // 4, 3 + * .field(7) // 2, 7 + * .name() // 1 + * This is because FileDescriptorProto.message_type has field number 4: + * repeated DescriptorProto message_type = 4; + * and DescriptorProto.field has field number 2: + * repeated FieldDescriptorProto field = 2; + * and FieldDescriptorProto.name has field number 1: + * optional string name = 1; + * Thus, the above path gives the location of a field name. If we removed + * the last element: + * [ 4, 3, 2, 7 ] + * this path refers to the whole field declaration (from the beginning + * of the label to the terminating semicolon). + * + * Generated from protobuf field repeated int32 path = 1 [packed = true]; + * @return \Google\Protobuf\Internal\RepeatedField + */ + public function getPath() + { + return $this->path; + } + + /** + * Identifies which part of the FileDescriptorProto was defined at this + * location. + * Each element is a field number or an index. They form a path from + * the root FileDescriptorProto to the place where the definition. For + * example, this path: + * [ 4, 3, 2, 7, 1 ] + * refers to: + * file.message_type(3) // 4, 3 + * .field(7) // 2, 7 + * .name() // 1 + * This is because FileDescriptorProto.message_type has field number 4: + * repeated DescriptorProto message_type = 4; + * and DescriptorProto.field has field number 2: + * repeated FieldDescriptorProto field = 2; + * and FieldDescriptorProto.name has field number 1: + * optional string name = 1; + * Thus, the above path gives the location of a field name. If we removed + * the last element: + * [ 4, 3, 2, 7 ] + * this path refers to the whole field declaration (from the beginning + * of the label to the terminating semicolon). + * + * Generated from protobuf field repeated int32 path = 1 [packed = true]; + * @param int[]|\Google\Protobuf\Internal\RepeatedField $var + * @return $this + */ + public function setPath($var) + { + $arr = GPBUtil::checkRepeatedField($var, \Google\Protobuf\Internal\GPBType::INT32); + $this->path = $arr; + $this->has_path = true; + + return $this; + } + + public function hasPath() + { + return $this->has_path; + } + + /** + * Always has exactly three or four elements: start line, start column, + * end line (optional, otherwise assumed same as start line), end column. + * These are packed into a single field for efficiency. Note that line + * and column numbers are zero-based -- typically you will want to add + * 1 to each before displaying to a user. + * + * Generated from protobuf field repeated int32 span = 2 [packed = true]; + * @return \Google\Protobuf\Internal\RepeatedField + */ + public function getSpan() + { + return $this->span; + } + + /** + * Always has exactly three or four elements: start line, start column, + * end line (optional, otherwise assumed same as start line), end column. + * These are packed into a single field for efficiency. Note that line + * and column numbers are zero-based -- typically you will want to add + * 1 to each before displaying to a user. + * + * Generated from protobuf field repeated int32 span = 2 [packed = true]; + * @param int[]|\Google\Protobuf\Internal\RepeatedField $var + * @return $this + */ + public function setSpan($var) + { + $arr = GPBUtil::checkRepeatedField($var, \Google\Protobuf\Internal\GPBType::INT32); + $this->span = $arr; + $this->has_span = true; + + return $this; + } + + public function hasSpan() + { + return $this->has_span; + } + + /** + * If this SourceCodeInfo represents a complete declaration, these are any + * comments appearing before and after the declaration which appear to be + * attached to the declaration. + * A series of line comments appearing on consecutive lines, with no other + * tokens appearing on those lines, will be treated as a single comment. + * leading_detached_comments will keep paragraphs of comments that appear + * before (but not connected to) the current element. Each paragraph, + * separated by empty lines, will be one comment element in the repeated + * field. + * Only the comment content is provided; comment markers (e.g. //) are + * stripped out. For block comments, leading whitespace and an asterisk + * will be stripped from the beginning of each line other than the first. + * Newlines are included in the output. + * Examples: + * optional int32 foo = 1; // Comment attached to foo. + * // Comment attached to bar. + * optional int32 bar = 2; + * optional string baz = 3; + * // Comment attached to baz. + * // Another line attached to baz. + * // Comment attached to qux. + * // + * // Another line attached to qux. + * optional double qux = 4; + * // Detached comment for corge. This is not leading or trailing comments + * // to qux or corge because there are blank lines separating it from + * // both. + * // Detached comment for corge paragraph 2. + * optional string corge = 5; + * /* Block comment attached + * * to corge. Leading asterisks + * * will be removed. */ + * /* Block comment attached to + * * grault. */ + * optional int32 grault = 6; + * // ignored detached comments. + * + * Generated from protobuf field optional string leading_comments = 3; + * @return string + */ + public function getLeadingComments() + { + return $this->leading_comments; + } + + /** + * If this SourceCodeInfo represents a complete declaration, these are any + * comments appearing before and after the declaration which appear to be + * attached to the declaration. + * A series of line comments appearing on consecutive lines, with no other + * tokens appearing on those lines, will be treated as a single comment. + * leading_detached_comments will keep paragraphs of comments that appear + * before (but not connected to) the current element. Each paragraph, + * separated by empty lines, will be one comment element in the repeated + * field. + * Only the comment content is provided; comment markers (e.g. //) are + * stripped out. For block comments, leading whitespace and an asterisk + * will be stripped from the beginning of each line other than the first. + * Newlines are included in the output. + * Examples: + * optional int32 foo = 1; // Comment attached to foo. + * // Comment attached to bar. + * optional int32 bar = 2; + * optional string baz = 3; + * // Comment attached to baz. + * // Another line attached to baz. + * // Comment attached to qux. + * // + * // Another line attached to qux. + * optional double qux = 4; + * // Detached comment for corge. This is not leading or trailing comments + * // to qux or corge because there are blank lines separating it from + * // both. + * // Detached comment for corge paragraph 2. + * optional string corge = 5; + * /* Block comment attached + * * to corge. Leading asterisks + * * will be removed. */ + * /* Block comment attached to + * * grault. */ + * optional int32 grault = 6; + * // ignored detached comments. + * + * Generated from protobuf field optional string leading_comments = 3; + * @param string $var + * @return $this + */ + public function setLeadingComments($var) + { + GPBUtil::checkString($var, True); + $this->leading_comments = $var; + $this->has_leading_comments = true; + + return $this; + } + + public function hasLeadingComments() + { + return $this->has_leading_comments; + } + + /** + * Generated from protobuf field optional string trailing_comments = 4; + * @return string + */ + public function getTrailingComments() + { + return $this->trailing_comments; + } + + /** + * Generated from protobuf field optional string trailing_comments = 4; + * @param string $var + * @return $this + */ + public function setTrailingComments($var) + { + GPBUtil::checkString($var, True); + $this->trailing_comments = $var; + $this->has_trailing_comments = true; + + return $this; + } + + public function hasTrailingComments() + { + return $this->has_trailing_comments; + } + + /** + * Generated from protobuf field repeated string leading_detached_comments = 6; + * @return \Google\Protobuf\Internal\RepeatedField + */ + public function getLeadingDetachedComments() + { + return $this->leading_detached_comments; + } + + /** + * Generated from protobuf field repeated string leading_detached_comments = 6; + * @param string[]|\Google\Protobuf\Internal\RepeatedField $var + * @return $this + */ + public function setLeadingDetachedComments($var) + { + $arr = GPBUtil::checkRepeatedField($var, \Google\Protobuf\Internal\GPBType::STRING); + $this->leading_detached_comments = $arr; + $this->has_leading_detached_comments = true; + + return $this; + } + + public function hasLeadingDetachedComments() + { + return $this->has_leading_detached_comments; + } + +} + +// Adding a class alias for backwards compatibility with the previous class name. +class_alias(Location::class, \Google\Protobuf\Internal\SourceCodeInfo_Location::class); + diff --git a/src/Google/Protobuf/Internal/SourceCodeInfo_Location.php b/src/Google/Protobuf/Internal/SourceCodeInfo_Location.php new file mode 100644 index 00000000..1346492d --- /dev/null +++ b/src/Google/Protobuf/Internal/SourceCodeInfo_Location.php @@ -0,0 +1,16 @@ +google.protobuf.UninterpretedOption + */ +class UninterpretedOption extends \Google\Protobuf\Internal\Message +{ + /** + * Generated from protobuf field repeated .google.protobuf.UninterpretedOption.NamePart name = 2; + */ + private $name; + private $has_name = false; + /** + * The value of the uninterpreted option, in whatever type the tokenizer + * identified it as during parsing. Exactly one of these should be set. + * + * Generated from protobuf field optional string identifier_value = 3; + */ + protected $identifier_value = ''; + private $has_identifier_value = false; + /** + * Generated from protobuf field optional uint64 positive_int_value = 4; + */ + protected $positive_int_value = 0; + private $has_positive_int_value = false; + /** + * Generated from protobuf field optional int64 negative_int_value = 5; + */ + protected $negative_int_value = 0; + private $has_negative_int_value = false; + /** + * Generated from protobuf field optional double double_value = 6; + */ + protected $double_value = 0.0; + private $has_double_value = false; + /** + * Generated from protobuf field optional bytes string_value = 7; + */ + protected $string_value = ''; + private $has_string_value = false; + /** + * Generated from protobuf field optional string aggregate_value = 8; + */ + protected $aggregate_value = ''; + private $has_aggregate_value = false; + + /** + * Constructor. + * + * @param array $data { + * Optional. Data for populating the Message object. + * + * @type \Google\Protobuf\Internal\UninterpretedOption\NamePart[]|\Google\Protobuf\Internal\RepeatedField $name + * @type string $identifier_value + * The value of the uninterpreted option, in whatever type the tokenizer + * identified it as during parsing. Exactly one of these should be set. + * @type int|string $positive_int_value + * @type int|string $negative_int_value + * @type float $double_value + * @type string $string_value + * @type string $aggregate_value + * } + */ + public function __construct($data = NULL) { + \GPBMetadata\Google\Protobuf\Internal\Descriptor::initOnce(); + parent::__construct($data); + } + + /** + * Generated from protobuf field repeated .google.protobuf.UninterpretedOption.NamePart name = 2; + * @return \Google\Protobuf\Internal\RepeatedField + */ + public function getName() + { + return $this->name; + } + + /** + * Generated from protobuf field repeated .google.protobuf.UninterpretedOption.NamePart name = 2; + * @param \Google\Protobuf\Internal\UninterpretedOption\NamePart[]|\Google\Protobuf\Internal\RepeatedField $var + * @return $this + */ + public function setName($var) + { + $arr = GPBUtil::checkRepeatedField($var, \Google\Protobuf\Internal\GPBType::MESSAGE, \Google\Protobuf\Internal\UninterpretedOption\NamePart::class); + $this->name = $arr; + $this->has_name = true; + + return $this; + } + + public function hasName() + { + return $this->has_name; + } + + /** + * The value of the uninterpreted option, in whatever type the tokenizer + * identified it as during parsing. Exactly one of these should be set. + * + * Generated from protobuf field optional string identifier_value = 3; + * @return string + */ + public function getIdentifierValue() + { + return $this->identifier_value; + } + + /** + * The value of the uninterpreted option, in whatever type the tokenizer + * identified it as during parsing. Exactly one of these should be set. + * + * Generated from protobuf field optional string identifier_value = 3; + * @param string $var + * @return $this + */ + public function setIdentifierValue($var) + { + GPBUtil::checkString($var, True); + $this->identifier_value = $var; + $this->has_identifier_value = true; + + return $this; + } + + public function hasIdentifierValue() + { + return $this->has_identifier_value; + } + + /** + * Generated from protobuf field optional uint64 positive_int_value = 4; + * @return int|string + */ + public function getPositiveIntValue() + { + return $this->positive_int_value; + } + + /** + * Generated from protobuf field optional uint64 positive_int_value = 4; + * @param int|string $var + * @return $this + */ + public function setPositiveIntValue($var) + { + GPBUtil::checkUint64($var); + $this->positive_int_value = $var; + $this->has_positive_int_value = true; + + return $this; + } + + public function hasPositiveIntValue() + { + return $this->has_positive_int_value; + } + + /** + * Generated from protobuf field optional int64 negative_int_value = 5; + * @return int|string + */ + public function getNegativeIntValue() + { + return $this->negative_int_value; + } + + /** + * Generated from protobuf field optional int64 negative_int_value = 5; + * @param int|string $var + * @return $this + */ + public function setNegativeIntValue($var) + { + GPBUtil::checkInt64($var); + $this->negative_int_value = $var; + $this->has_negative_int_value = true; + + return $this; + } + + public function hasNegativeIntValue() + { + return $this->has_negative_int_value; + } + + /** + * Generated from protobuf field optional double double_value = 6; + * @return float + */ + public function getDoubleValue() + { + return $this->double_value; + } + + /** + * Generated from protobuf field optional double double_value = 6; + * @param float $var + * @return $this + */ + public function setDoubleValue($var) + { + GPBUtil::checkDouble($var); + $this->double_value = $var; + $this->has_double_value = true; + + return $this; + } + + public function hasDoubleValue() + { + return $this->has_double_value; + } + + /** + * Generated from protobuf field optional bytes string_value = 7; + * @return string + */ + public function getStringValue() + { + return $this->string_value; + } + + /** + * Generated from protobuf field optional bytes string_value = 7; + * @param string $var + * @return $this + */ + public function setStringValue($var) + { + GPBUtil::checkString($var, False); + $this->string_value = $var; + $this->has_string_value = true; + + return $this; + } + + public function hasStringValue() + { + return $this->has_string_value; + } + + /** + * Generated from protobuf field optional string aggregate_value = 8; + * @return string + */ + public function getAggregateValue() + { + return $this->aggregate_value; + } + + /** + * Generated from protobuf field optional string aggregate_value = 8; + * @param string $var + * @return $this + */ + public function setAggregateValue($var) + { + GPBUtil::checkString($var, True); + $this->aggregate_value = $var; + $this->has_aggregate_value = true; + + return $this; + } + + public function hasAggregateValue() + { + return $this->has_aggregate_value; + } + +} + diff --git a/src/Google/Protobuf/Internal/UninterpretedOption/NamePart.php b/src/Google/Protobuf/Internal/UninterpretedOption/NamePart.php new file mode 100644 index 00000000..1956ba7f --- /dev/null +++ b/src/Google/Protobuf/Internal/UninterpretedOption/NamePart.php @@ -0,0 +1,110 @@ +google.protobuf.UninterpretedOption.NamePart + */ +class NamePart extends \Google\Protobuf\Internal\Message +{ + /** + * Generated from protobuf field required string name_part = 1; + */ + protected $name_part = ''; + private $has_name_part = false; + /** + * Generated from protobuf field required bool is_extension = 2; + */ + protected $is_extension = false; + private $has_is_extension = false; + + /** + * Constructor. + * + * @param array $data { + * Optional. Data for populating the Message object. + * + * @type string $name_part + * @type bool $is_extension + * } + */ + public function __construct($data = NULL) { + \GPBMetadata\Google\Protobuf\Internal\Descriptor::initOnce(); + parent::__construct($data); + } + + /** + * Generated from protobuf field required string name_part = 1; + * @return string + */ + public function getNamePart() + { + return $this->name_part; + } + + /** + * Generated from protobuf field required string name_part = 1; + * @param string $var + * @return $this + */ + public function setNamePart($var) + { + GPBUtil::checkString($var, True); + $this->name_part = $var; + $this->has_name_part = true; + + return $this; + } + + public function hasNamePart() + { + return $this->has_name_part; + } + + /** + * Generated from protobuf field required bool is_extension = 2; + * @return bool + */ + public function getIsExtension() + { + return $this->is_extension; + } + + /** + * Generated from protobuf field required bool is_extension = 2; + * @param bool $var + * @return $this + */ + public function setIsExtension($var) + { + GPBUtil::checkBool($var); + $this->is_extension = $var; + $this->has_is_extension = true; + + return $this; + } + + public function hasIsExtension() + { + return $this->has_is_extension; + } + +} + +// Adding a class alias for backwards compatibility with the previous class name. +class_alias(NamePart::class, \Google\Protobuf\Internal\UninterpretedOption_NamePart::class); + diff --git a/src/Google/Protobuf/Internal/UninterpretedOption_NamePart.php b/src/Google/Protobuf/Internal/UninterpretedOption_NamePart.php new file mode 100644 index 00000000..9750eb01 --- /dev/null +++ b/src/Google/Protobuf/Internal/UninterpretedOption_NamePart.php @@ -0,0 +1,16 @@ +google.protobuf.ListValue + */ +class ListValue extends \Google\Protobuf\Internal\Message +{ + /** + * Repeated field of dynamically typed values. + * + * Generated from protobuf field repeated .google.protobuf.Value values = 1; + */ + private $values; + + /** + * Constructor. + * + * @param array $data { + * Optional. Data for populating the Message object. + * + * @type \Google\Protobuf\Value[]|\Google\Protobuf\Internal\RepeatedField $values + * Repeated field of dynamically typed values. + * } + */ + public function __construct($data = NULL) { + \GPBMetadata\Google\Protobuf\Struct::initOnce(); + parent::__construct($data); + } + + /** + * Repeated field of dynamically typed values. + * + * Generated from protobuf field repeated .google.protobuf.Value values = 1; + * @return \Google\Protobuf\Internal\RepeatedField + */ + public function getValues() + { + return $this->values; + } + + /** + * Repeated field of dynamically typed values. + * + * Generated from protobuf field repeated .google.protobuf.Value values = 1; + * @param \Google\Protobuf\Value[]|\Google\Protobuf\Internal\RepeatedField $var + * @return $this + */ + public function setValues($var) + { + $arr = GPBUtil::checkRepeatedField($var, \Google\Protobuf\Internal\GPBType::MESSAGE, \Google\Protobuf\Value::class); + $this->values = $arr; + + return $this; + } + +} + diff --git a/src/Google/Protobuf/Method.php b/src/Google/Protobuf/Method.php new file mode 100644 index 00000000..8e803506 --- /dev/null +++ b/src/Google/Protobuf/Method.php @@ -0,0 +1,271 @@ +google.protobuf.Method + */ +class Method extends \Google\Protobuf\Internal\Message +{ + /** + * The simple name of this method. + * + * Generated from protobuf field string name = 1; + */ + private $name = ''; + /** + * A URL of the input message type. + * + * Generated from protobuf field string request_type_url = 2; + */ + private $request_type_url = ''; + /** + * If true, the request is streamed. + * + * Generated from protobuf field bool request_streaming = 3; + */ + private $request_streaming = false; + /** + * The URL of the output message type. + * + * Generated from protobuf field string response_type_url = 4; + */ + private $response_type_url = ''; + /** + * If true, the response is streamed. + * + * Generated from protobuf field bool response_streaming = 5; + */ + private $response_streaming = false; + /** + * Any metadata attached to the method. + * + * Generated from protobuf field repeated .google.protobuf.Option options = 6; + */ + private $options; + /** + * The source syntax of this method. + * + * Generated from protobuf field .google.protobuf.Syntax syntax = 7; + */ + private $syntax = 0; + + /** + * Constructor. + * + * @param array $data { + * Optional. Data for populating the Message object. + * + * @type string $name + * The simple name of this method. + * @type string $request_type_url + * A URL of the input message type. + * @type bool $request_streaming + * If true, the request is streamed. + * @type string $response_type_url + * The URL of the output message type. + * @type bool $response_streaming + * If true, the response is streamed. + * @type \Google\Protobuf\Option[]|\Google\Protobuf\Internal\RepeatedField $options + * Any metadata attached to the method. + * @type int $syntax + * The source syntax of this method. + * } + */ + public function __construct($data = NULL) { + \GPBMetadata\Google\Protobuf\Api::initOnce(); + parent::__construct($data); + } + + /** + * The simple name of this method. + * + * Generated from protobuf field string name = 1; + * @return string + */ + public function getName() + { + return $this->name; + } + + /** + * The simple name of this method. + * + * Generated from protobuf field string name = 1; + * @param string $var + * @return $this + */ + public function setName($var) + { + GPBUtil::checkString($var, True); + $this->name = $var; + + return $this; + } + + /** + * A URL of the input message type. + * + * Generated from protobuf field string request_type_url = 2; + * @return string + */ + public function getRequestTypeUrl() + { + return $this->request_type_url; + } + + /** + * A URL of the input message type. + * + * Generated from protobuf field string request_type_url = 2; + * @param string $var + * @return $this + */ + public function setRequestTypeUrl($var) + { + GPBUtil::checkString($var, True); + $this->request_type_url = $var; + + return $this; + } + + /** + * If true, the request is streamed. + * + * Generated from protobuf field bool request_streaming = 3; + * @return bool + */ + public function getRequestStreaming() + { + return $this->request_streaming; + } + + /** + * If true, the request is streamed. + * + * Generated from protobuf field bool request_streaming = 3; + * @param bool $var + * @return $this + */ + public function setRequestStreaming($var) + { + GPBUtil::checkBool($var); + $this->request_streaming = $var; + + return $this; + } + + /** + * The URL of the output message type. + * + * Generated from protobuf field string response_type_url = 4; + * @return string + */ + public function getResponseTypeUrl() + { + return $this->response_type_url; + } + + /** + * The URL of the output message type. + * + * Generated from protobuf field string response_type_url = 4; + * @param string $var + * @return $this + */ + public function setResponseTypeUrl($var) + { + GPBUtil::checkString($var, True); + $this->response_type_url = $var; + + return $this; + } + + /** + * If true, the response is streamed. + * + * Generated from protobuf field bool response_streaming = 5; + * @return bool + */ + public function getResponseStreaming() + { + return $this->response_streaming; + } + + /** + * If true, the response is streamed. + * + * Generated from protobuf field bool response_streaming = 5; + * @param bool $var + * @return $this + */ + public function setResponseStreaming($var) + { + GPBUtil::checkBool($var); + $this->response_streaming = $var; + + return $this; + } + + /** + * Any metadata attached to the method. + * + * Generated from protobuf field repeated .google.protobuf.Option options = 6; + * @return \Google\Protobuf\Internal\RepeatedField + */ + public function getOptions() + { + return $this->options; + } + + /** + * Any metadata attached to the method. + * + * Generated from protobuf field repeated .google.protobuf.Option options = 6; + * @param \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 syntax of this method. + * + * Generated from protobuf field .google.protobuf.Syntax syntax = 7; + * @return int + */ + public function getSyntax() + { + return $this->syntax; + } + + /** + * The source syntax of this method. + * + * Generated from protobuf field .google.protobuf.Syntax syntax = 7; + * @param int $var + * @return $this + */ + public function setSyntax($var) + { + GPBUtil::checkEnum($var, \Google\Protobuf\Syntax::class); + $this->syntax = $var; + + return $this; + } + +} + diff --git a/src/Google/Protobuf/Mixin.php b/src/Google/Protobuf/Mixin.php new file mode 100644 index 00000000..a2ea59c7 --- /dev/null +++ b/src/Google/Protobuf/Mixin.php @@ -0,0 +1,166 @@ +google.protobuf.Mixin + */ +class Mixin extends \Google\Protobuf\Internal\Message +{ + /** + * The fully qualified name of the interface which is included. + * + * Generated from protobuf field string name = 1; + */ + private $name = ''; + /** + * If non-empty specifies a path under which inherited HTTP paths + * are rooted. + * + * Generated from protobuf field string root = 2; + */ + private $root = ''; + + /** + * Constructor. + * + * @param array $data { + * Optional. Data for populating the Message object. + * + * @type string $name + * The fully qualified name of the interface which is included. + * @type string $root + * If non-empty specifies a path under which inherited HTTP paths + * are rooted. + * } + */ + public function __construct($data = NULL) { + \GPBMetadata\Google\Protobuf\Api::initOnce(); + parent::__construct($data); + } + + /** + * The fully qualified name of the interface which is included. + * + * Generated from protobuf field string name = 1; + * @return string + */ + public function getName() + { + return $this->name; + } + + /** + * The fully qualified name of the interface which is included. + * + * Generated from protobuf field string name = 1; + * @param string $var + * @return $this + */ + public function setName($var) + { + GPBUtil::checkString($var, True); + $this->name = $var; + + return $this; + } + + /** + * If non-empty specifies a path under which inherited HTTP paths + * are rooted. + * + * Generated from protobuf field string root = 2; + * @return string + */ + public function getRoot() + { + return $this->root; + } + + /** + * If non-empty specifies a path under which inherited HTTP paths + * are rooted. + * + * Generated from protobuf field string root = 2; + * @param string $var + * @return $this + */ + public function setRoot($var) + { + GPBUtil::checkString($var, True); + $this->root = $var; + + return $this; + } + +} + diff --git a/src/Google/Protobuf/NullValue.php b/src/Google/Protobuf/NullValue.php new file mode 100644 index 00000000..a72cbb2e --- /dev/null +++ b/src/Google/Protobuf/NullValue.php @@ -0,0 +1,48 @@ +google.protobuf.NullValue + */ +class NullValue +{ + /** + * Null value. + * + * Generated from protobuf enum NULL_VALUE = 0; + */ + const NULL_VALUE = 0; + + private static $valueToName = [ + self::NULL_VALUE => 'NULL_VALUE', + ]; + + 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); + } +} + diff --git a/src/Google/Protobuf/OneofDescriptor.php b/src/Google/Protobuf/OneofDescriptor.php new file mode 100644 index 00000000..d9736634 --- /dev/null +++ b/src/Google/Protobuf/OneofDescriptor.php @@ -0,0 +1,75 @@ +internal_desc = $internal_desc; + } + + /** + * @return string The name of the oneof + */ + public function getName() + { + return $this->internal_desc->getName(); + } + + /** + * @param int $index Must be >= 0 and < getFieldCount() + * @return FieldDescriptor + */ + public function getField($index) + { + return $this->getPublicDescriptor($this->internal_desc->getFields()[$index]); + } + + /** + * @return int Number of fields in the oneof + */ + public function getFieldCount() + { + return count($this->internal_desc->getFields()); + } +} diff --git a/src/Google/Protobuf/Option.php b/src/Google/Protobuf/Option.php new file mode 100644 index 00000000..22ecfc5f --- /dev/null +++ b/src/Google/Protobuf/Option.php @@ -0,0 +1,126 @@ +google.protobuf.Option + */ +class Option extends \Google\Protobuf\Internal\Message +{ + /** + * The option's name. For protobuf built-in options (options defined in + * descriptor.proto), this is the short name. For example, `"map_entry"`. + * For custom options, it should be the fully-qualified name. For example, + * `"google.api.http"`. + * + * Generated from protobuf field string name = 1; + */ + private $name = ''; + /** + * The option's value packed in an Any message. If the value is a primitive, + * the corresponding wrapper type defined in google/protobuf/wrappers.proto + * should be used. If the value is an enum, it should be stored as an int32 + * value using the google.protobuf.Int32Value type. + * + * Generated from protobuf field .google.protobuf.Any value = 2; + */ + private $value = null; + + /** + * Constructor. + * + * @param array $data { + * Optional. Data for populating the Message object. + * + * @type string $name + * The option's name. For protobuf built-in options (options defined in + * descriptor.proto), this is the short name. For example, `"map_entry"`. + * For custom options, it should be the fully-qualified name. For example, + * `"google.api.http"`. + * @type \Google\Protobuf\Any $value + * The option's value packed in an Any message. If the value is a primitive, + * the corresponding wrapper type defined in google/protobuf/wrappers.proto + * should be used. If the value is an enum, it should be stored as an int32 + * value using the google.protobuf.Int32Value type. + * } + */ + public function __construct($data = NULL) { + \GPBMetadata\Google\Protobuf\Type::initOnce(); + parent::__construct($data); + } + + /** + * The option's name. For protobuf built-in options (options defined in + * descriptor.proto), this is the short name. For example, `"map_entry"`. + * For custom options, it should be the fully-qualified name. For example, + * `"google.api.http"`. + * + * Generated from protobuf field string name = 1; + * @return string + */ + public function getName() + { + return $this->name; + } + + /** + * The option's name. For protobuf built-in options (options defined in + * descriptor.proto), this is the short name. For example, `"map_entry"`. + * For custom options, it should be the fully-qualified name. For example, + * `"google.api.http"`. + * + * Generated from protobuf field string name = 1; + * @param string $var + * @return $this + */ + public function setName($var) + { + GPBUtil::checkString($var, True); + $this->name = $var; + + return $this; + } + + /** + * The option's value packed in an Any message. If the value is a primitive, + * the corresponding wrapper type defined in google/protobuf/wrappers.proto + * should be used. If the value is an enum, it should be stored as an int32 + * value using the google.protobuf.Int32Value type. + * + * Generated from protobuf field .google.protobuf.Any value = 2; + * @return \Google\Protobuf\Any + */ + public function getValue() + { + return $this->value; + } + + /** + * The option's value packed in an Any message. If the value is a primitive, + * the corresponding wrapper type defined in google/protobuf/wrappers.proto + * should be used. If the value is an enum, it should be stored as an int32 + * value using the google.protobuf.Int32Value type. + * + * Generated from protobuf field .google.protobuf.Any value = 2; + * @param \Google\Protobuf\Any $var + * @return $this + */ + public function setValue($var) + { + GPBUtil::checkMessage($var, \Google\Protobuf\Any::class); + $this->value = $var; + + return $this; + } + +} + diff --git a/src/Google/Protobuf/SourceContext.php b/src/Google/Protobuf/SourceContext.php new file mode 100644 index 00000000..cbc50c68 --- /dev/null +++ b/src/Google/Protobuf/SourceContext.php @@ -0,0 +1,72 @@ +google.protobuf.SourceContext + */ +class SourceContext extends \Google\Protobuf\Internal\Message +{ + /** + * The path-qualified name of the .proto file that contained the associated + * protobuf element. For example: `"google/protobuf/source_context.proto"`. + * + * Generated from protobuf field string file_name = 1; + */ + private $file_name = ''; + + /** + * Constructor. + * + * @param array $data { + * Optional. Data for populating the Message object. + * + * @type string $file_name + * The path-qualified name of the .proto file that contained the associated + * protobuf element. For example: `"google/protobuf/source_context.proto"`. + * } + */ + public function __construct($data = NULL) { + \GPBMetadata\Google\Protobuf\SourceContext::initOnce(); + parent::__construct($data); + } + + /** + * The path-qualified name of the .proto file that contained the associated + * protobuf element. For example: `"google/protobuf/source_context.proto"`. + * + * Generated from protobuf field string file_name = 1; + * @return string + */ + public function getFileName() + { + return $this->file_name; + } + + /** + * The path-qualified name of the .proto file that contained the associated + * protobuf element. For example: `"google/protobuf/source_context.proto"`. + * + * Generated from protobuf field string file_name = 1; + * @param string $var + * @return $this + */ + public function setFileName($var) + { + GPBUtil::checkString($var, True); + $this->file_name = $var; + + return $this; + } + +} + diff --git a/src/Google/Protobuf/StringValue.php b/src/Google/Protobuf/StringValue.php new file mode 100644 index 00000000..8fb354f3 --- /dev/null +++ b/src/Google/Protobuf/StringValue.php @@ -0,0 +1,68 @@ +google.protobuf.StringValue + */ +class StringValue extends \Google\Protobuf\Internal\Message +{ + /** + * The string value. + * + * Generated from protobuf field string value = 1; + */ + private $value = ''; + + /** + * Constructor. + * + * @param array $data { + * Optional. Data for populating the Message object. + * + * @type string $value + * The string value. + * } + */ + public function __construct($data = NULL) { + \GPBMetadata\Google\Protobuf\Wrappers::initOnce(); + parent::__construct($data); + } + + /** + * The string value. + * + * Generated from protobuf field string value = 1; + * @return string + */ + public function getValue() + { + return $this->value; + } + + /** + * The string value. + * + * Generated from protobuf field string value = 1; + * @param string $var + * @return $this + */ + public function setValue($var) + { + GPBUtil::checkString($var, True); + $this->value = $var; + + return $this; + } + +} + diff --git a/src/Google/Protobuf/Struct.php b/src/Google/Protobuf/Struct.php new file mode 100644 index 00000000..0456541c --- /dev/null +++ b/src/Google/Protobuf/Struct.php @@ -0,0 +1,73 @@ +google.protobuf.Struct + */ +class Struct extends \Google\Protobuf\Internal\Message +{ + /** + * Unordered map of dynamically typed values. + * + * Generated from protobuf field map fields = 1; + */ + private $fields; + + /** + * Constructor. + * + * @param array $data { + * Optional. Data for populating the Message object. + * + * @type array|\Google\Protobuf\Internal\MapField $fields + * Unordered map of dynamically typed values. + * } + */ + public function __construct($data = NULL) { + \GPBMetadata\Google\Protobuf\Struct::initOnce(); + parent::__construct($data); + } + + /** + * Unordered map of dynamically typed values. + * + * Generated from protobuf field map fields = 1; + * @return \Google\Protobuf\Internal\MapField + */ + public function getFields() + { + return $this->fields; + } + + /** + * Unordered map of dynamically typed values. + * + * Generated from protobuf field map fields = 1; + * @param array|\Google\Protobuf\Internal\MapField $var + * @return $this + */ + public function setFields($var) + { + $arr = GPBUtil::checkMapField($var, \Google\Protobuf\Internal\GPBType::STRING, \Google\Protobuf\Internal\GPBType::MESSAGE, \Google\Protobuf\Value::class); + $this->fields = $arr; + + return $this; + } + +} + diff --git a/src/Google/Protobuf/Syntax.php b/src/Google/Protobuf/Syntax.php new file mode 100644 index 00000000..9812669d --- /dev/null +++ b/src/Google/Protobuf/Syntax.php @@ -0,0 +1,53 @@ +google.protobuf.Syntax + */ +class Syntax +{ + /** + * Syntax `proto2`. + * + * Generated from protobuf enum SYNTAX_PROTO2 = 0; + */ + const SYNTAX_PROTO2 = 0; + /** + * Syntax `proto3`. + * + * Generated from protobuf enum SYNTAX_PROTO3 = 1; + */ + const SYNTAX_PROTO3 = 1; + + private static $valueToName = [ + self::SYNTAX_PROTO2 => 'SYNTAX_PROTO2', + self::SYNTAX_PROTO3 => 'SYNTAX_PROTO3', + ]; + + 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); + } +} + diff --git a/src/Google/Protobuf/Timestamp.php b/src/Google/Protobuf/Timestamp.php new file mode 100644 index 00000000..6d26f6c5 --- /dev/null +++ b/src/Google/Protobuf/Timestamp.php @@ -0,0 +1,200 @@ +google.protobuf.Timestamp + */ +class Timestamp extends \Google\Protobuf\Internal\Message +{ + /** + * Represents seconds of UTC time since Unix epoch + * 1970-01-01T00:00:00Z. Must be from 0001-01-01T00:00:00Z to + * 9999-12-31T23:59:59Z inclusive. + * + * Generated from protobuf field int64 seconds = 1; + */ + private $seconds = 0; + /** + * Non-negative fractions of a second at nanosecond resolution. Negative + * second values with fractions must still have non-negative nanos values + * that count forward in time. Must be from 0 to 999,999,999 + * inclusive. + * + * Generated from protobuf field int32 nanos = 2; + */ + private $nanos = 0; + + /** + * Constructor. + * + * @param array $data { + * Optional. Data for populating the Message object. + * + * @type int|string $seconds + * Represents seconds of UTC time since Unix epoch + * 1970-01-01T00:00:00Z. Must be from 0001-01-01T00:00:00Z to + * 9999-12-31T23:59:59Z inclusive. + * @type int $nanos + * Non-negative fractions of a second at nanosecond resolution. Negative + * second values with fractions must still have non-negative nanos values + * that count forward in time. Must be from 0 to 999,999,999 + * inclusive. + * } + */ + public function __construct($data = NULL) { + \GPBMetadata\Google\Protobuf\Timestamp::initOnce(); + parent::__construct($data); + } + + /** + * Represents seconds of UTC time since Unix epoch + * 1970-01-01T00:00:00Z. Must be from 0001-01-01T00:00:00Z to + * 9999-12-31T23:59:59Z inclusive. + * + * Generated from protobuf field int64 seconds = 1; + * @return int|string + */ + public function getSeconds() + { + return $this->seconds; + } + + /** + * Represents seconds of UTC time since Unix epoch + * 1970-01-01T00:00:00Z. Must be from 0001-01-01T00:00:00Z to + * 9999-12-31T23:59:59Z inclusive. + * + * Generated from protobuf field int64 seconds = 1; + * @param int|string $var + * @return $this + */ + public function setSeconds($var) + { + GPBUtil::checkInt64($var); + $this->seconds = $var; + + return $this; + } + + /** + * Non-negative fractions of a second at nanosecond resolution. Negative + * second values with fractions must still have non-negative nanos values + * that count forward in time. Must be from 0 to 999,999,999 + * inclusive. + * + * Generated from protobuf field int32 nanos = 2; + * @return int + */ + public function getNanos() + { + return $this->nanos; + } + + /** + * Non-negative fractions of a second at nanosecond resolution. Negative + * second values with fractions must still have non-negative nanos values + * that count forward in time. Must be from 0 to 999,999,999 + * inclusive. + * + * Generated from protobuf field int32 nanos = 2; + * @param int $var + * @return $this + */ + public function setNanos($var) + { + GPBUtil::checkInt32($var); + $this->nanos = $var; + + return $this; + } + + /* + * Converts PHP DateTime to Timestamp. + * + * @param \DateTime $datetime + */ + public function fromDateTime(\DateTime $datetime) + { + $this->seconds = $datetime->getTimestamp(); + $this->nanos = 1000 * $datetime->format('u'); + } + + /** + * Converts Timestamp to PHP DateTime. + * + * @return \DateTime $datetime + */ + public function toDateTime() + { + $time = sprintf('%s.%06d', $this->seconds, $this->nanos / 1000); + return \DateTime::createFromFormat('U.u', $time); + } +} + diff --git a/src/Google/Protobuf/Type.php b/src/Google/Protobuf/Type.php new file mode 100644 index 00000000..1b478110 --- /dev/null +++ b/src/Google/Protobuf/Type.php @@ -0,0 +1,237 @@ +google.protobuf.Type + */ +class Type extends \Google\Protobuf\Internal\Message +{ + /** + * The fully qualified message name. + * + * Generated from protobuf field string name = 1; + */ + private $name = ''; + /** + * The list of fields. + * + * Generated from protobuf field repeated .google.protobuf.Field fields = 2; + */ + private $fields; + /** + * The list of types appearing in `oneof` definitions in this type. + * + * Generated from protobuf field repeated string oneofs = 3; + */ + private $oneofs; + /** + * The protocol buffer options. + * + * Generated from protobuf field repeated .google.protobuf.Option options = 4; + */ + private $options; + /** + * The source context. + * + * Generated from protobuf field .google.protobuf.SourceContext source_context = 5; + */ + private $source_context = null; + /** + * The source syntax. + * + * Generated from protobuf field .google.protobuf.Syntax syntax = 6; + */ + private $syntax = 0; + + /** + * Constructor. + * + * @param array $data { + * Optional. Data for populating the Message object. + * + * @type string $name + * The fully qualified message name. + * @type \Google\Protobuf\Field[]|\Google\Protobuf\Internal\RepeatedField $fields + * The list of fields. + * @type string[]|\Google\Protobuf\Internal\RepeatedField $oneofs + * The list of types appearing in `oneof` definitions in this type. + * @type \Google\Protobuf\Option[]|\Google\Protobuf\Internal\RepeatedField $options + * The 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); + } + + /** + * The fully qualified message name. + * + * Generated from protobuf field string name = 1; + * @return string + */ + public function getName() + { + return $this->name; + } + + /** + * The fully qualified message name. + * + * Generated from protobuf field string name = 1; + * @param string $var + * @return $this + */ + public function setName($var) + { + GPBUtil::checkString($var, True); + $this->name = $var; + + return $this; + } + + /** + * The list of fields. + * + * Generated from protobuf field repeated .google.protobuf.Field fields = 2; + * @return \Google\Protobuf\Internal\RepeatedField + */ + public function getFields() + { + return $this->fields; + } + + /** + * The list of fields. + * + * Generated from protobuf field repeated .google.protobuf.Field fields = 2; + * @param \Google\Protobuf\Field[]|\Google\Protobuf\Internal\RepeatedField $var + * @return $this + */ + public function setFields($var) + { + $arr = GPBUtil::checkRepeatedField($var, \Google\Protobuf\Internal\GPBType::MESSAGE, \Google\Protobuf\Field::class); + $this->fields = $arr; + + return $this; + } + + /** + * The list of types appearing in `oneof` definitions in this type. + * + * Generated from protobuf field repeated string oneofs = 3; + * @return \Google\Protobuf\Internal\RepeatedField + */ + public function getOneofs() + { + return $this->oneofs; + } + + /** + * The list of types appearing in `oneof` definitions in this type. + * + * Generated from protobuf field repeated string oneofs = 3; + * @param string[]|\Google\Protobuf\Internal\RepeatedField $var + * @return $this + */ + public function setOneofs($var) + { + $arr = GPBUtil::checkRepeatedField($var, \Google\Protobuf\Internal\GPBType::STRING); + $this->oneofs = $arr; + + return $this; + } + + /** + * The protocol buffer options. + * + * Generated from protobuf field repeated .google.protobuf.Option options = 4; + * @return \Google\Protobuf\Internal\RepeatedField + */ + public function getOptions() + { + return $this->options; + } + + /** + * The protocol buffer options. + * + * Generated from protobuf field repeated .google.protobuf.Option options = 4; + * @param \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 .google.protobuf.SourceContext source_context = 5; + * @return \Google\Protobuf\SourceContext + */ + public function getSourceContext() + { + return $this->source_context; + } + + /** + * The source context. + * + * Generated from protobuf field .google.protobuf.SourceContext source_context = 5; + * @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 .google.protobuf.Syntax syntax = 6; + * @return int + */ + public function getSyntax() + { + return $this->syntax; + } + + /** + * The source syntax. + * + * Generated from protobuf field .google.protobuf.Syntax syntax = 6; + * @param int $var + * @return $this + */ + public function setSyntax($var) + { + GPBUtil::checkEnum($var, \Google\Protobuf\Syntax::class); + $this->syntax = $var; + + return $this; + } + +} + diff --git a/src/Google/Protobuf/UInt32Value.php b/src/Google/Protobuf/UInt32Value.php new file mode 100644 index 00000000..f5a522d2 --- /dev/null +++ b/src/Google/Protobuf/UInt32Value.php @@ -0,0 +1,68 @@ +google.protobuf.UInt32Value + */ +class UInt32Value extends \Google\Protobuf\Internal\Message +{ + /** + * The uint32 value. + * + * Generated from protobuf field uint32 value = 1; + */ + private $value = 0; + + /** + * Constructor. + * + * @param array $data { + * Optional. Data for populating the Message object. + * + * @type int $value + * The uint32 value. + * } + */ + public function __construct($data = NULL) { + \GPBMetadata\Google\Protobuf\Wrappers::initOnce(); + parent::__construct($data); + } + + /** + * The uint32 value. + * + * Generated from protobuf field uint32 value = 1; + * @return int + */ + public function getValue() + { + return $this->value; + } + + /** + * The uint32 value. + * + * Generated from protobuf field uint32 value = 1; + * @param int $var + * @return $this + */ + public function setValue($var) + { + GPBUtil::checkUint32($var); + $this->value = $var; + + return $this; + } + +} + diff --git a/src/Google/Protobuf/UInt64Value.php b/src/Google/Protobuf/UInt64Value.php new file mode 100644 index 00000000..89e69cd8 --- /dev/null +++ b/src/Google/Protobuf/UInt64Value.php @@ -0,0 +1,68 @@ +google.protobuf.UInt64Value + */ +class UInt64Value extends \Google\Protobuf\Internal\Message +{ + /** + * The uint64 value. + * + * Generated from protobuf field uint64 value = 1; + */ + private $value = 0; + + /** + * Constructor. + * + * @param array $data { + * Optional. Data for populating the Message object. + * + * @type int|string $value + * The uint64 value. + * } + */ + public function __construct($data = NULL) { + \GPBMetadata\Google\Protobuf\Wrappers::initOnce(); + parent::__construct($data); + } + + /** + * The uint64 value. + * + * Generated from protobuf field uint64 value = 1; + * @return int|string + */ + public function getValue() + { + return $this->value; + } + + /** + * The uint64 value. + * + * Generated from protobuf field uint64 value = 1; + * @param int|string $var + * @return $this + */ + public function setValue($var) + { + GPBUtil::checkUint64($var); + $this->value = $var; + + return $this; + } + +} + diff --git a/src/Google/Protobuf/Value.php b/src/Google/Protobuf/Value.php new file mode 100644 index 00000000..5c1e864c --- /dev/null +++ b/src/Google/Protobuf/Value.php @@ -0,0 +1,214 @@ +google.protobuf.Value + */ +class Value extends \Google\Protobuf\Internal\Message +{ + protected $kind; + + /** + * Constructor. + * + * @param array $data { + * Optional. Data for populating the Message object. + * + * @type int $null_value + * Represents a null value. + * @type float $number_value + * Represents a double value. + * @type string $string_value + * Represents a string value. + * @type bool $bool_value + * Represents a boolean value. + * @type \Google\Protobuf\Struct $struct_value + * Represents a structured value. + * @type \Google\Protobuf\ListValue $list_value + * Represents a repeated `Value`. + * } + */ + public function __construct($data = NULL) { + \GPBMetadata\Google\Protobuf\Struct::initOnce(); + parent::__construct($data); + } + + /** + * Represents a null value. + * + * Generated from protobuf field .google.protobuf.NullValue null_value = 1; + * @return int + */ + public function getNullValue() + { + return $this->readOneof(1); + } + + /** + * Represents a null value. + * + * Generated from protobuf field .google.protobuf.NullValue null_value = 1; + * @param int $var + * @return $this + */ + public function setNullValue($var) + { + GPBUtil::checkEnum($var, \Google\Protobuf\NullValue::class); + $this->writeOneof(1, $var); + + return $this; + } + + /** + * Represents a double value. + * + * Generated from protobuf field double number_value = 2; + * @return float + */ + public function getNumberValue() + { + return $this->readOneof(2); + } + + /** + * Represents a double value. + * + * Generated from protobuf field double number_value = 2; + * @param float $var + * @return $this + */ + public function setNumberValue($var) + { + GPBUtil::checkDouble($var); + $this->writeOneof(2, $var); + + return $this; + } + + /** + * Represents a string value. + * + * Generated from protobuf field string string_value = 3; + * @return string + */ + public function getStringValue() + { + return $this->readOneof(3); + } + + /** + * Represents a string value. + * + * Generated from protobuf field string string_value = 3; + * @param string $var + * @return $this + */ + public function setStringValue($var) + { + GPBUtil::checkString($var, True); + $this->writeOneof(3, $var); + + return $this; + } + + /** + * Represents a boolean value. + * + * Generated from protobuf field bool bool_value = 4; + * @return bool + */ + public function getBoolValue() + { + return $this->readOneof(4); + } + + /** + * Represents a boolean value. + * + * Generated from protobuf field bool bool_value = 4; + * @param bool $var + * @return $this + */ + public function setBoolValue($var) + { + GPBUtil::checkBool($var); + $this->writeOneof(4, $var); + + return $this; + } + + /** + * Represents a structured value. + * + * Generated from protobuf field .google.protobuf.Struct struct_value = 5; + * @return \Google\Protobuf\Struct + */ + public function getStructValue() + { + return $this->readOneof(5); + } + + /** + * Represents a structured value. + * + * Generated from protobuf field .google.protobuf.Struct struct_value = 5; + * @param \Google\Protobuf\Struct $var + * @return $this + */ + public function setStructValue($var) + { + GPBUtil::checkMessage($var, \Google\Protobuf\Struct::class); + $this->writeOneof(5, $var); + + return $this; + } + + /** + * Represents a repeated `Value`. + * + * Generated from protobuf field .google.protobuf.ListValue list_value = 6; + * @return \Google\Protobuf\ListValue + */ + public function getListValue() + { + return $this->readOneof(6); + } + + /** + * Represents a repeated `Value`. + * + * Generated from protobuf field .google.protobuf.ListValue list_value = 6; + * @param \Google\Protobuf\ListValue $var + * @return $this + */ + public function setListValue($var) + { + GPBUtil::checkMessage($var, \Google\Protobuf\ListValue::class); + $this->writeOneof(6, $var); + + return $this; + } + + /** + * @return string + */ + public function getKind() + { + return $this->whichOneof("kind"); + } + +} + diff --git a/src/autoload.php b/src/autoload.php new file mode 100644 index 00000000..e44068b8 --- /dev/null +++ b/src/autoload.php @@ -0,0 +1,9 @@ + \ No newline at end of file diff --git a/src/helper/BCMathService.php b/src/helper/BCMathService.php new file mode 100644 index 00000000..329e1ceb --- /dev/null +++ b/src/helper/BCMathService.php @@ -0,0 +1,165 @@ +alphabet = $alphabet; + $this->base = strlen($alphabet); + } + /** + * Encode a string into base58. + * + * @param string $string The string you wish to encode. + * @since Release v1.1.0 + * @return string The Base58 encoded string. + */ + public function encode($string) + { + // Type validation + if (is_string($string) === false) { + throw new InvalidArgumentException('Argument $string must be a string.'); + } + + // If the string is empty, then the encoded string is obviously empty + if (strlen($string) === 0) { + return ''; + } + + // Strings in PHP are essentially 8-bit byte arrays + // so lets convert the string into a PHP array + $bytes = array_values(unpack('C*', $string)); + + // Now we need to convert the byte array into an arbitrary-precision decimal + // We basically do this by performing a base256 to base10 conversion + $decimal = $bytes[0]; + + for ($i = 1, $l = count($bytes); $i < $l; $i++) { + $decimal = bcmul($decimal, 256); + $decimal = bcadd($decimal, $bytes[$i]); + } + + // This loop now performs base 10 to base 58 conversion + // The remainder or modulo on each loop becomes a base 58 character + $output = ''; + while ($decimal >= $this->base) { + $div = bcdiv($decimal, $this->base, 0); + $mod = (int) bcmod($decimal, $this->base); + $output .= $this->alphabet[$mod]; + $decimal = $div; + } + + // If there's still a remainder, append it + if ($decimal > 0) { + $output .= $this->alphabet[$decimal]; + } + + // Now we need to reverse the encoded data + $output = strrev($output); + + // Now we need to add leading zeros + foreach ($bytes as $byte) { + if ($byte === 0) { + $output = $this->alphabet[0] . $output; + continue; + } + break; + } + + return (string) $output; + } + + /** + * Decode base58 into a PHP string. + * + * @param string $base58 The base58 encoded string. + * @since Release v1.1.0 + * @return string Returns the decoded string. + */ + public function decode($base58) + { + // Type Validation + if (is_string($base58) === false) { + throw new InvalidArgumentException('Argument $base58 must be a string.'); + } + + // If the string is empty, then the decoded string is obviously empty + if (strlen($base58) === 0) { + return ''; + } + + $indexes = array_flip(str_split($this->alphabet)); + $chars = str_split($base58); + + // Check for invalid characters in the supplied base58 string + foreach ($chars as $char) { + if (isset($indexes[$char]) === false) { + throw new InvalidArgumentException('Argument $base58 contains invalid characters. ($char: "'.$char.'" | $base58: "'.$base58.'") '); + } + } + + // Convert from base58 to base10 + $decimal = $indexes[$chars[0]]; + + for ($i = 1, $l = count($chars); $i < $l; $i++) { + $decimal = bcmul($decimal, $this->base); + $decimal = bcadd($decimal, $indexes[$chars[$i]]); + } + + // Convert from base10 to base256 (8-bit byte array) + $output = ''; + while ($decimal > 0) { + $byte = (int) bcmod($decimal, 256); + $output = pack('C', $byte) . $output; + $decimal = bcdiv($decimal, 256, 0); + } + + // Now we need to add leading zeros + foreach ($chars as $char) { + if ($indexes[$char] === 0) { + $output = "\x00" . $output; + continue; + } + break; + } + + return $output; + } +} diff --git a/src/helper/Base58.php b/src/helper/Base58.php new file mode 100644 index 00000000..7b9d2819 --- /dev/null +++ b/src/helper/Base58.php @@ -0,0 +1,126 @@ + + * @copyright 2014 Stephen Hill + * @license http://www.opensource.org/licenses/MIT The MIT License + * @link https://github.com/stephen-hill/base58php + * @since Release v1.0.0 + */ +class Base58 +{ + /** + * @var StephenHill\ServiceInterface; + * @since v1.1.0 + */ + protected $service; + + /** + * Constructor + * + * @param string $alphabet optional + * @param ServiceInterface $service optional + * @since v1.0.0 + * @since v1.1.0 Added the optional $service argument. + */ + public function __construct( + $alphabet = null, + ServiceInterface $service = null + ) { + // Handle null alphabet + if (is_null($alphabet) === true) { + $alphabet = '123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz'; + } + + // Type validation + if (is_string($alphabet) === false) { + throw new InvalidArgumentException('Argument $alphabet must be a string.'); + } + + // The alphabet must contain 58 characters + if (strlen($alphabet) !== 58) { + throw new InvalidArgumentException('Argument $alphabet must contain 58 characters.'); + } + + // Provide a default service if one isn't injected + if ($service === null) { + // Check for GMP support first + if (function_exists('\gmp_init') === true) { + $service = new GMPService($alphabet); + } + else if (function_exists('\bcmul') === true) { + $service = new BCMathService($alphabet); + } + else { + throw new \Exception('Please install the BC Math or GMP extension.'); + } + } + + $this->service = $service; + } + + /** + * Encode a string into base58. + * + * @param string $string The string you wish to encode. + * @since v1.0.0 + * @return string The Base58 encoded string. + */ + public function encode($string) + { + return $this->service->encode($string); + } + + /** + * Decode base58 into a PHP string. + * + * @param string $base58 The base58 encoded string. + * @since v1.0.0 + * @return string Returns the decoded string. + */ + public function decode($base58) + { + return $this->service->decode($base58); + } + + public function decodeChecked($address) + { + + $address = $this->decode($address); + + if(strlen($address) < 4) + return false; + $checksum = substr($address, strlen($address)-4, 4); + $rawAddress = substr($address, 0, strlen($address)-4); + + if(substr(hex2bin($this->hash256($rawAddress)), 0, 4) === $checksum) + return $rawAddress; + else + return false; + } + + + public function encodeChecked($address){ + $checksum =hex2bin($this->hash256($address)); + $address = $address.substr($checksum, 0, 4); + + $address = $this->encode($address); + + return $address; + } + /*** + * Bitcoin standard 256 bit hash function : double sha256 + * + * @param string $data + * @return string (hexa) + */ + public function hash256($data) + { + return hash('sha256', hex2bin(hash('sha256', $data))); + } +} diff --git a/src/helper/BitcoinECDSA.php b/src/helper/BitcoinECDSA.php new file mode 100644 index 00000000..2f795862 --- /dev/null +++ b/src/helper/BitcoinECDSA.php @@ -0,0 +1,1327 @@ +a = gmp_init('0', 10); + $this->b = gmp_init('7', 10); + $this->p = gmp_init('FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFEFFFFFC2F', 16); + $this->n = gmp_init('FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFEBAAEDCE6AF48A03BBFD25E8CD0364141', 16); + + $this->G = [ + 'x' => gmp_init('55066263022277343669578718895168534326250603453777594175500187360389116729240'), + 'y' => gmp_init('32670510020758816978083085130507043184471273380659243275938904335757337482424') + ]; + + $this->networkPrefix = '00'; + } + + /*** + * Convert a number to a compact Int + * taken from https://github.com/scintill/php-bitcoin-signature-routines/blob/master/verifymessage.php + * + * @param int $i + * @return string (bin) + * @throws \Exception + */ + public function numToVarIntString($i) { + if ($i < 0xfd) { + return chr($i); + } else if ($i <= 0xffff) { + return pack('Cv', 0xfd, $i); + } else if ($i <= 0xffffffff) { + return pack('CV', 0xfe, $i); + } else { + throw new \Exception('int too large'); + } + } + + /*** + * Set the network prefix, '00' = main network, '6f' = test network. + * + * @param string $prefix (hexa) + */ + public function setNetworkPrefix($prefix) + { + $this->networkPrefix = $prefix; + } + + /** + * Returns the current network prefix, '00' = main network, '6f' = test network. + * + * @return string (hexa) + */ + public function getNetworkPrefix() + { + return $this->networkPrefix; + } + + /** + * Returns the current network prefix for WIF, '80' = main network, 'ef' = test network. + * + * @return string (hexa) + */ + public function getPrivatePrefix(){ + if($this->networkPrefix =='6f') + return 'ef'; + else + return '80'; + } + + /*** + * Permutation table used for Base58 encoding and decoding. + * + * @param string $char + * @param bool $reverse + * @return string|null + */ + public function base58_permutation($char, $reverse = false) + { + $table = [ + '1','2','3','4','5','6','7','8','9','A','B','C','D', + 'E','F','G','H','J','K','L','M','N','P','Q','R','S','T','U','V','W', + 'X','Y','Z','a','b','c','d','e','f','g','h','i','j','k','m','n','o', + 'p','q','r','s','t','u','v','w','x','y','z' + ]; + + if($reverse) + { + $reversedTable = []; + foreach($table as $key => $element) + { + $reversedTable[$element] = $key; + } + + if(isset($reversedTable[$char])) + return $reversedTable[$char]; + else + return null; + } + + if(isset($table[$char])) + return $table[$char]; + else + return null; + } + + /*** + * Bitcoin standard 256 bit hash function : double sha256 + * + * @param string $data + * @return string (hexa) + */ + public function hash256($data) + { + return hash('sha256', hex2bin(hash('sha256', $data))); + } + + /** + * @param string $data + * @return string (hexa) + */ + public function hash160($data) + { + return hash('ripemd160', hex2bin(hash('sha256', $data))); + } + + /** + * Generates a random 256 bytes hexadecimal encoded string that is smaller than n + * + * @param string $extra + * @return string (hexa) + * @throws \Exception + */ + public function generateRandom256BitsHexaString($extra = 'FkejkzqesrfeifH3ioio9hb55sdssdsdfOO:ss') + { + do + { + $bytes = openssl_random_pseudo_bytes(256, $cStrong); + $hex = bin2hex($bytes); + $random = $hex . microtime(true) . $extra; + + if ($cStrong === false) { + throw new \Exception('Your system is not able to generate strong enough random numbers'); + } + $res = $this->hash256($random); + + } while(gmp_cmp(gmp_init($res, 16), gmp_sub($this->n, gmp_init(1, 10))) === 1); // make sure the generate string is smaller than n + + return $res; + } + + /*** + * encode a hexadecimal string in Base58. + * + * @param string $data (hexa) + * @param bool $littleEndian + * @return string (base58) + * @throws \Exception + */ + public function base58_encode($data, $littleEndian = true) + { + $res = ''; + $dataIntVal = gmp_init($data, 16); + while(gmp_cmp($dataIntVal, gmp_init(0, 10)) > 0) + { + $qr = gmp_div_qr($dataIntVal, gmp_init(58, 10)); + $dataIntVal = $qr[0]; + $reminder = gmp_strval($qr[1]); + if(!$this->base58_permutation($reminder)) + { + throw new \Exception('Something went wrong during base58 encoding'); + } + $res .= $this->base58_permutation($reminder); + } + + //get number of leading zeros + $leading = ''; + $i = 0; + while(substr($data, $i, 1) === '0') + { + if($i!== 0 && $i%2) + { + $leading .= '1'; + } + $i++; + } + + if($littleEndian) + return strrev($res . $leading); + else + return $res.$leading; + } + + /*** + * Decode a Base58 encoded string and returns it's value as a hexadecimal string + * + * @param string $encodedData (base58) + * @param bool $littleEndian + * @return string (hexa) + */ + public function base58_decode($encodedData, $littleEndian = true) + { + $res = gmp_init(0, 10); + $length = strlen($encodedData); + if($littleEndian) + { + $encodedData = strrev($encodedData); + } + + for($i = $length - 1; $i >= 0; $i--) + { + $res = gmp_add( + gmp_mul( + $res, + gmp_init(58, 10) + ), + $this->base58_permutation(substr($encodedData, $i, 1), true) + ); + } + + $res = gmp_strval($res, 16); + $i = $length - 1; + while(substr($encodedData, $i, 1) === '1') + { + $res = '00' . $res; + $i--; + } + + if(strlen($res)%2 !== 0) + { + $res = '0' . $res; + } + + return $res; + } + + /*** + * Computes the result of a point addition and returns the resulting point as an Array. + * + * @param Array $pt + * @return Array Point + * @throws \Exception + */ + public function doublePoint(Array $pt) + { + $a = $this->a; + $p = $this->p; + + $gcd = gmp_strval(gmp_gcd(gmp_mod(gmp_mul(gmp_init(2, 10), $pt['y']), $p),$p)); + if($gcd !== '1') + { + throw new \Exception('This library doesn\'t yet supports point at infinity. See https://github.com/BitcoinPHP/BitcoinECDSA.php/issues/9'); + } + + // SLOPE = (3 * ptX^2 + a )/( 2*ptY ) + // Equals (3 * ptX^2 + a ) * ( 2*ptY )^-1 + $slope = gmp_mod( + gmp_mul( + gmp_invert( + gmp_mod( + gmp_mul( + gmp_init(2, 10), + $pt['y'] + ), + $p + ), + $p + ), + gmp_add( + gmp_mul( + gmp_init(3, 10), + gmp_pow($pt['x'], 2) + ), + $a + ) + ), + $p + ); + + // nPtX = slope^2 - 2 * ptX + // Equals slope^2 - ptX - ptX + $nPt = []; + $nPt['x'] = gmp_mod( + gmp_sub( + gmp_sub( + gmp_pow($slope, 2), + $pt['x'] + ), + $pt['x'] + ), + $p + ); + + // nPtY = slope * (ptX - nPtx) - ptY + $nPt['y'] = gmp_mod( + gmp_sub( + gmp_mul( + $slope, + gmp_sub( + $pt['x'], + $nPt['x'] + ) + ), + $pt['y'] + ), + $p + ); + + return $nPt; + } + + /*** + * Computes the result of a point addition and returns the resulting point as an Array. + * + * @param Array $pt1 + * @param Array $pt2 + * @return Array Point + * @throws \Exception + */ + public function addPoints(Array $pt1, Array $pt2) + { + $p = $this->p; + if(gmp_cmp($pt1['x'], $pt2['x']) === 0 && gmp_cmp($pt1['y'], $pt2['y']) === 0) //if identical + { + return $this->doublePoint($pt1); + } + + $gcd = gmp_strval(gmp_gcd(gmp_sub($pt1['x'], $pt2['x']), $p)); + if($gcd !== '1') + { + throw new \Exception('This library doesn\'t yet supports point at infinity. See https://github.com/BitcoinPHP/BitcoinECDSA.php/issues/9'); + } + + // SLOPE = (pt1Y - pt2Y)/( pt1X - pt2X ) + // Equals (pt1Y - pt2Y) * ( pt1X - pt2X )^-1 + $slope = gmp_mod( + gmp_mul( + gmp_sub( + $pt1['y'], + $pt2['y'] + ), + gmp_invert( + gmp_sub( + $pt1['x'], + $pt2['x'] + ), + $p + ) + ), + $p + ); + + // nPtX = slope^2 - ptX1 - ptX2 + $nPt = []; + $nPt['x'] = gmp_mod( + gmp_sub( + gmp_sub( + gmp_pow($slope, 2), + $pt1['x'] + ), + $pt2['x'] + ), + $p + ); + + // nPtX = slope * (ptX1 - nPtX) - ptY1 + $nPt['y'] = gmp_mod( + gmp_sub( + gmp_mul( + $slope, + gmp_sub( + $pt1['x'], + $nPt['x'] + ) + ), + $pt1['y'] + ), + $p + ); + + return $nPt; + } + + /*** + * Computes the result of a point multiplication and returns the resulting point as an Array. + * + * @param string|resource $k (hexa|GMP|Other bases definded in base) + * @param Array $pG + * @param $base + * @throws \Exception + * @return Array Point + */ + public function mulPoint($k, Array $pG, $base = null) + { + //in order to calculate k*G + if($base === 16 || $base === null || is_resource($base)) + $k = gmp_init($k, 16); + if($base === 10) + $k = gmp_init($k, 10); + $kBin = gmp_strval($k, 2); + + $lastPoint = $pG; + for($i = 1; $i < strlen($kBin); $i++) + { + if(substr($kBin, $i, 1) === '1') + { + $dPt = $this->doublePoint($lastPoint); + $lastPoint = $this->addPoints($dPt, $pG); + } + else + { + $lastPoint = $this->doublePoint($lastPoint); + } + } + if(!$this->validatePoint(gmp_strval($lastPoint['x'], 16), gmp_strval($lastPoint['y'], 16))) + throw new \Exception('The resulting point is not on the curve.'); + return $lastPoint; + } + + /*** + * Calculates the square root of $a mod p and returns the 2 solutions as an array. + * + * @param resource $a (GMP) + * @return array|null + * @throws \Exception + */ + public function sqrt($a) + { + $p = $this->p; + + if(gmp_legendre($a, $p) !== 1) + { + //no result + return null; + } + + if(gmp_strval(gmp_mod($p, gmp_init(4, 10)), 10) === '3') + { + $sqrt1 = gmp_powm( + $a, + gmp_div_q( + gmp_add($p, gmp_init(1, 10)), + gmp_init(4, 10) + ), + $p + ); + // there are always 2 results for a square root + // In an infinite number field you have -2^2 = 2^2 = 4 + // In a finite number field you have a^2 = (p-a)^2 + $sqrt2 = gmp_mod(gmp_sub($p, $sqrt1), $p); + return [$sqrt1, $sqrt2]; + } + else + { + throw new \Exception('P % 4 != 3 , this isn\'t supported yet.'); + } + } + + /*** + * Calculate the Y coordinates for a given X coordinate. + * + * @param string $x (hexa) + * @param null $derEvenOrOddCode + * @return array|null|String + */ + public function calculateYWithX($x, $derEvenOrOddCode = null) + { + $a = $this->a; + $b = $this->b; + $p = $this->p; + + $x = gmp_init($x, 16); + $y2 = gmp_mod( + gmp_add( + gmp_add( + gmp_powm($x, gmp_init(3, 10), $p), + gmp_mul($a, $x) + ), + $b + ), + $p + ); + + $y = $this->sqrt($y2); + + if($y === null) //if there is no result + { + return null; + } + + if($derEvenOrOddCode === null) + { + return $y; + } + + else if($derEvenOrOddCode === '02') // even + { + $resY = null; + if(gmp_strval(gmp_mod($y[0], gmp_init(2, 10)), 10) === '0') + $resY = gmp_strval($y[0], 16); + if(gmp_strval(gmp_mod($y[1], gmp_init(2, 10)), 10) === '0') + $resY = gmp_strval($y[1], 16); + if($resY !== null) + { + while(strlen($resY) < 64) + { + $resY = '0' . $resY; + } + } + return $resY; + } + else if($derEvenOrOddCode === '03') // odd + { + $resY = null; + if(gmp_strval(gmp_mod($y[0], gmp_init(2, 10)), 10) === '1') + $resY = gmp_strval($y[0], 16); + if(gmp_strval(gmp_mod($y[1], gmp_init(2, 10)), 10) === '1') + $resY = gmp_strval($y[1], 16); + if($resY !== null) + { + while(strlen($resY) < 64) + { + $resY = '0' . $resY; + } + } + return $resY; + } + + return null; + } + + /*** + * returns the public key coordinates as an array. + * + * @param string $derPubKey (hexa) + * @return array + * @throws \Exception + */ + public function getPubKeyPointsWithDerPubKey($derPubKey) + { + if(substr($derPubKey, 0, 2) === '04' && strlen($derPubKey) === 130) + { + //uncompressed der encoded public key + $x = substr($derPubKey, 2, 64); + $y = substr($derPubKey, 66, 64); + return ['x' => $x, 'y' => $y]; + } + else if((substr($derPubKey, 0, 2) === '02' || substr($derPubKey, 0, 2) === '03') && strlen($derPubKey) === 66) + { + //compressed der encoded public key + $x = substr($derPubKey, 2, 64); + $y = $this->calculateYWithX($x, substr($derPubKey, 0, 2)); + return ['x' => $x, 'y' => $y]; + } + else + { + throw new \Exception('Invalid derPubKey format : ' . $derPubKey); + } + } + + + /** + * @param array $pubKey (array ) + * @param bool $compressed + * @return string + */ + public function getDerPubKeyWithPubKeyPoints($pubKey, $compressed = true) + { + if($compressed === false) + { + return '04' . $pubKey['x'] . $pubKey['y']; + } + else + { + if(gmp_strval(gmp_mod(gmp_init($pubKey['y'], 16), gmp_init(2, 10))) === '0') + $pubKey = '02' . $pubKey['x']; //if $pubKey['y'] is even + else + $pubKey = '03' . $pubKey['x']; //if $pubKey['y'] is odd + + return $pubKey; + } + } + + /*** + * Returns true if the point is on the curve and false if it isn't. + * + * @param string $x (hexa) + * @param string $y (hexa) + * @return bool + */ + public function validatePoint($x, $y) + { + $a = $this->a; + $b = $this->b; + $p = $this->p; + + $x = gmp_init($x, 16); + $y2 = gmp_mod( + gmp_add( + gmp_add( + gmp_powm($x, gmp_init(3, 10), $p), + gmp_mul($a, $x) + ), + $b + ), + $p + ); + $y = gmp_mod(gmp_pow(gmp_init($y, 16), 2), $p); + + if(gmp_cmp($y2, $y) === 0) + return true; + else + return false; + } + + /*** + * returns the X and Y point coordinates of the public key. + * + * @return Array Point + * @throws \Exception + */ + public function getPubKeyPoints() + { + $G = $this->G; + $k = $this->k; + + if(!isset($this->k)) + { + throw new \Exception('No Private Key was defined'); + } + + $pubKey = $this->mulPoint( + $k, + ['x' => $G['x'], 'y' => $G['y']] + ); + + $pubKey['x'] = gmp_strval($pubKey['x'], 16); + $pubKey['y'] = gmp_strval($pubKey['y'], 16); + + while(strlen($pubKey['x']) < 64) + { + $pubKey['x'] = '0' . $pubKey['x']; + } + + while(strlen($pubKey['y']) < 64) + { + $pubKey['y'] = '0' . $pubKey['y']; + } + + return $pubKey; + } + public function decodeChecked($address) + { + + $address = hex2bin($this->base58_decode($address)); + + if(strlen($address) < 4) + return false; + $checksum = substr($address, strlen($address)-4, 4); + + $rawAddress = substr($address, 0, strlen($address)-4); + if(substr(hex2bin($this->hash256($rawAddress)), 0, 4) === $checksum) + return $rawAddress; + else + return false; + } + /*** + * returns the uncompressed DER encoded public key. + * + * @param array $pubKeyPts (array ) + * @return string (hexa) + * @throws \Exception + */ + public function getUncompressedPubKey(array $pubKeyPts = []) + { + if(empty($pubKeyPts)) + $pubKeyPts = $this->getPubKeyPoints(); + $uncompressedPubKey = '04' . $pubKeyPts['x'] . $pubKeyPts['y']; + + return $uncompressedPubKey; + } + + /*** + * returns the compressed DER encoded public key. + * + * @param array $pubKeyPts (array ) + * @return array|string + * @throws \Exception + */ + public function getPubKey(array $pubKeyPts = []) + { + if(empty($pubKeyPts)) + $pubKeyPts = $this->getPubKeyPoints(); + + if(gmp_strval(gmp_mod(gmp_init($pubKeyPts['y'], 16), gmp_init(2, 10))) === '0') + $compressedPubKey = '02' . $pubKeyPts['x']; //if $pubKey['y'] is even + else + $compressedPubKey = '03' . $pubKeyPts['x']; //if $pubKey['y'] is odd + + return $compressedPubKey; + } + + /*** + * returns the uncompressed Bitcoin address generated from the private key if $compressed is false and + * the compressed if $compressed is true. + * + * @param bool $compressed + * @param string $derPubKey (hexa) + * @throws \Exception + * @return String Base58 + */ + public function getUncompressedAddress($compressed = false, $derPubKey = null) + { + if($derPubKey !== null) + { + if($compressed === true) { + $address = $this->getPubKey($this->getPubKeyPointsWithDerPubKey($derPubKey)); + } + else { + $address = $this->getUncompressedPubKey($this->getPubKeyPointsWithDerPubKey($derPubKey)); + } + } + else + { + if($compressed === true) { + $address = $this->getPubKey(); + } + else { + $address = $this->getUncompressedPubKey(); + } + } + + $address = $this->hash256(hex2bin($address)); + //checksum + $address = $address.substr($this->hash256(hex2bin($address)), 0, 8); + $address = $this->base58_encode($address); + return $address; + /* if($this->validateAddress($address)) + return $address; + else + throw new \Exception('the generated address seems not to be valid.');*/ + } + + /*** + * returns the compressed Bitcoin address generated from the private key. + * + * @param string $derPubKey (hexa) + * @return String (base58) + */ + public function getAddress($derPubKey = null) + { + return $this->getUncompressedAddress(true, $derPubKey); + } + + /*** + * set a private key. + * + * @param string $k (hexa) + * @throws \Exception + */ + public function setPrivateKey($k) + { + //private key has to be passed as an hexadecimal number + if(gmp_cmp(gmp_init($k, 16), gmp_sub($this->n, gmp_init(1, 10))) === 1) + { + throw new \Exception('Private Key is not in the 1,n-1 range'); + } + $this->k = $k; + } + + /*** + * return the private key. + * + * @return string (hexa) + */ + public function getPrivateKey() + { + return $this->k; + } + + + /*** + * Generate a new random private key. + * The extra parameter can be some random data typed down by the user or mouse movements to add randomness. + * + * @param string $extra + * @throws \Exception + */ + public function generateRandomPrivateKey($extra = 'FSQF5356dsdsqdfEFEQ3fq4q6dq4s5d') + { + $this->k = $this->generateRandom256BitsHexaString($extra); + } + + /*** + * Tests if the address is valid or not. + * + * @param string $address (base58) + * @return bool + */ + public function validateAddress($address) + { + $address = hex2bin($this->base58_decode($address)); + if(strlen($address) !== 25) + return false; + $checksum = substr($address, 21, 4); + $rawAddress = substr($address, 0, 21); + + if(substr(hex2bin($this->hash256($rawAddress)), 0, 4) === $checksum) + return true; + else + return false; + } + + /*** + * returns the private key under the Wallet Import Format + * + * @return string (base58) + * @throws \Exception + */ + public function getWif($compressed = true) + { + if(!isset($this->k)) + { + throw new \Exception('No Private Key was defined'); + } + + $k = $this->k; + + while(strlen($k) < 64) + $k = '0' . $k; + + $secretKey = $this->getPrivatePrefix() . $k; + + if($compressed) { + $secretKey .= '01'; + } + + $secretKey .= substr($this->hash256(hex2bin($secretKey)), 0, 8); + + return $this->base58_encode($secretKey); + } + + /*** + * returns the private key under the Wallet Import Format for an uncompressed address + * + * @return string (base58) + * @throws \Exception + */ + public function getUncompressedWif() + { + return getWif(false); + } + + /*** + * Tests if the Wif key (Wallet Import Format) is valid or not. + * + * @param string $wif (base58) + * @return bool + */ + public function validateWifKey($wif) + { + $key = $this->base58_decode($wif, true); + $length = strlen($key); + $checksum = $this->hash256(hex2bin(substr($key, 0, $length - 8))); + if(substr($checksum, 0, 8) === substr($key, $length - 8, 8)) + return true; + else + return false; + } + + /** + * @param string $wif (base58) + * @return bool + */ + public function setPrivateKeyWithWif($wif) + { + if(!$this->validateWifKey($wif)) { + throw new \Exception('Invalid WIF'); + } + + $key = $this->base58_decode($wif, true); + + $this->setPrivateKey(substr($key, 2, 64)); + } + + /*** + * Sign a hash with the private key that was set and returns signatures as an array (R,S) + * + * @param string $hash (hexa) + * @param null $nonce + * @throws \Exception + * @return Array + */ + public function getSignatureHashPoints($hash, $nonce = null) + { + $n = $this->n; + $k = $this->k; + + if(empty($k)) + { + throw new \Exception('No Private Key was defined'); + } + + if($nonce === null) + { + $nonce = gmp_strval( + gmp_mod( + gmp_init($this->generateRandom256BitsHexaString(), 16), + $n), + 16 + ); + } + + //first part of the signature (R). + + $rPt = $this->mulPoint($nonce, $this->G); + $R = gmp_strval($rPt ['x'], 16); + + while(strlen($R) < 64) + { + $R = '0' . $R; + } + + //second part of the signature (S). + //S = nonce^-1 (hash + privKey * R) mod p + + + $S = gmp_mod( + gmp_mul( + gmp_invert( + gmp_init($nonce, 16), + $n + ), + gmp_add( + gmp_init($hash, 16), + gmp_mul( + gmp_init($k, 16), + gmp_init($R, 16) + ) + ) + ), + $n + ); + + //BIP 62, make sure we use the low-s value + if(gmp_cmp($S, gmp_div($n, 2)) === 1) + { + $S = gmp_sub($n, $S); + } + + $S = gmp_strval($S, 16); + + if(strlen($S)%2) + { + $S = '0' . $S; + } + + if(strlen($R)%2) + { + $R = '0' . $R; + } + + return ['R' => $R, 'S' => $S]; + } + + /*** + * Sign a hash with the private key that was set and returns a DER encoded signature + * + * @param string $hash (hexa) + * @param null $nonce + * @return string + */ + public function signHash($hash, $nonce = null) + { + $points = $this->getSignatureHashPoints($hash, $nonce); + + $signature = '02' . dechex(strlen(hex2bin($points['R']))) . $points['R'] . '02' . dechex(strlen(hex2bin($points['S']))) . $points['S']; + $signature = '30' . dechex(strlen(hex2bin($signature))) . $signature; + + return $signature; + } + + /*** + * Satoshi client's standard message signature implementation. + * + * @param string $message + * @param bool $onlySignature + * @param bool $compressed + * @param null $nonce + * @return string + * @throws \Exception + */ + public function signMessage($message, $onlySignature = false ,$compressed = true, $nonce = null) + { + + $hash = $this->hash256("\x18Bitcoin Signed Message:\n" . $this->numToVarIntString(strlen($message)). $message); + $points = $this->getSignatureHashPoints( + $hash, + $nonce + ); + + $R = $points['R']; + $S = $points['S']; + + while(strlen($R) < 64) + $R = '0' . $R; + + while(strlen($S) < 64) + $S = '0' . $S; + + $res = "\n-----BEGIN BITCOIN SIGNED MESSAGE-----\n"; + $res .= $message; + $res .= "\n-----BEGIN SIGNATURE-----\n"; + if($compressed === true) + $res .= $this->getAddress() . "\n"; + else + $res .= $this->getUncompressedAddress() . "\n"; + + $finalFlag = 0; + for($i = 0; $i < 4; $i++) + { + $flag = 27; + if($compressed === true) + $flag += 4; + $flag += $i; + + $pubKeyPts = $this->getPubKeyPoints(); + + $recoveredPubKey = $this->getPubKeyWithRS($flag, $R, $S, $hash); + + if($this->getDerPubKeyWithPubKeyPoints($pubKeyPts, $compressed) === $recoveredPubKey) + { + $finalFlag = $flag; + } + } + + //echo "Final flag : " . dechex($finalFlag) . "\n"; + if($finalFlag === 0) + { + throw new \Exception('Unable to get a valid signature flag.'); + } + + $signature = base64_encode(hex2bin(dechex($finalFlag) . $R . $S)); + + if($onlySignature) { + return $signature; + } + + $res .= $signature; + $res .= "\n-----END BITCOIN SIGNED MESSAGE-----"; + + return $res; + } + + /*** + * extract the public key from the signature and using the recovery flag. + * see http://crypto.stackexchange.com/a/18106/10927 + * based on https://github.com/brainwallet/brainwallet.github.io/blob/master/js/bitcoinsig.js + * possible public keys are r−1(sR−zG) and r−1(sR′−zG) + * Recovery flag rules are : + * binary number between 28 and 35 inclusive + * if the flag is > 30 then the address is compressed. + * + * @param int $flag + * @param string $R (hexa) + * @param string $S (hexa) + * @param string $hash (hexa) + * @return array + */ + public function getPubKeyWithRS($flag, $R, $S, $hash) + { + + $isCompressed = false; + + if ($flag < 27 || $flag >= 35) + return null; + + if($flag >= 31) //if address is compressed + { + $isCompressed = true; + $flag -= 4; + } + + $recid = $flag - 27; + + //step 1.1 + $x = gmp_add( + gmp_init($R, 16), + gmp_mul( + $this->n, + gmp_div_q( //check if j is equal to 0 or to 1. + gmp_init($recid, 10), + gmp_init(2, 10) + ) + ) + ); + + //step 1.3 + $y = null; + if($flag % 2 === 1) //check if y is even. + { + $gmpY = $this->calculateYWithX(gmp_strval($x, 16), '02'); + if($gmpY !== null) + $y = gmp_init($gmpY, 16); + } + else + { + $gmpY = $this->calculateYWithX(gmp_strval($x, 16), '03'); + if($gmpY !== null) + $y = gmp_init($gmpY, 16); + } + + if($y === null) + return null; + + $Rpt = ['x' => $x, 'y' => $y]; + + //step 1.6.1 + //calculate r^-1 (S*Rpt - eG) + + $eG = $this->mulPoint($hash, $this->G); + + $eG['y'] = gmp_mod(gmp_neg($eG['y']), $this->p); + + $SR = $this->mulPoint($S, $Rpt); + + $pubKey = $this->mulPoint( + gmp_strval(gmp_invert(gmp_init($R, 16), $this->n), 16), + $this->addPoints( + $SR, + $eG + ) + ); + + $pubKey['x'] = gmp_strval($pubKey['x'], 16); + $pubKey['y'] = gmp_strval($pubKey['y'], 16); + + while(strlen($pubKey['x']) < 64) + $pubKey['x'] = '0' . $pubKey['x']; + + while(strlen($pubKey['y']) < 64) + $pubKey['y'] = '0' . $pubKey['y']; + + $derPubKey = $this->getDerPubKeyWithPubKeyPoints($pubKey, $isCompressed); + + + if($this->checkSignaturePoints($derPubKey, $R, $S, $hash)) + return $derPubKey; + else + return null; + + } + + /*** + * Check signature with public key R & S values of the signature and the message hash. + * + * @param string $pubKey (hexa) + * @param string $R (hexa) + * @param string $S (hexa) + * @param string $hash (hexa) + * @return bool + */ + public function checkSignaturePoints($pubKey, $R, $S, $hash) + { + $G = $this->G; + + $pubKeyPts = $this->getPubKeyPointsWithDerPubKey($pubKey); + + // S^-1* hash * G + S^-1 * R * Qa + + // S^-1* hash + $exp1 = gmp_strval( + gmp_mul( + gmp_invert( + gmp_init($S, 16), + $this->n + ), + gmp_init($hash, 16) + ), + 16 + ); + + // S^-1* hash * G + $exp1Pt = $this->mulPoint($exp1, $G); + + + // S^-1 * R + $exp2 = gmp_strval( + gmp_mul( + gmp_invert( + gmp_init($S, 16), + $this->n + ), + gmp_init($R, 16) + ), + 16 + ); + // S^-1 * R * Qa + + $pubKeyPts['x'] = gmp_init($pubKeyPts['x'], 16); + $pubKeyPts['y'] = gmp_init($pubKeyPts['y'], 16); + + $exp2Pt = $this->mulPoint($exp2,$pubKeyPts); + + $resultingPt = $this->addPoints($exp1Pt, $exp2Pt); + + $xRes = gmp_strval($resultingPt['x'], 16); + + while(strlen($xRes) < 64) + $xRes = '0' . $xRes; + + if(strtoupper($xRes) === strtoupper($R)) + return true; + else + return false; + } + + /*** + * checkSignaturePoints wrapper for DER signatures + * + * @param string $pubKey (hexa) + * @param string $signature (hexa) + * @param string $hash (hexa) + * @return bool + */ + public function checkDerSignature($pubKey, $signature, $hash) + { + $signature = hex2bin($signature); + if(bin2hex(substr($signature, 0, 1)) !== '30') + return false; + + $RLength = hexdec(bin2hex(substr($signature, 3, 1))); + $R = bin2hex(substr($signature, 4, $RLength)); + + $SLength = hexdec(bin2hex(substr($signature, $RLength + 5, 1))); + $S = bin2hex(substr($signature, $RLength + 6, $SLength)); + + //echo "\n\nsignature:\n"; + //print_r(bin2hex($signature)); + + //echo "\n\nR:\n"; + //print_r($R); + //echo "\n\nS:\n"; + //print_r($S); + + return $this->checkSignaturePoints($pubKey, $R, $S, $hash); + } + + /*** + * checks the signature of a bitcoin signed message. + * + * @param string $rawMessage + * @return bool + */ + public function checkSignatureForRawMessage($rawMessage) + { + //recover message. + preg_match_all("#-----BEGIN BITCOIN SIGNED MESSAGE-----\n(.{0,})\n-----BEGIN SIGNATURE-----\n#USi", $rawMessage, $out); + $message = $out[1][0]; + + preg_match_all("#\n-----BEGIN SIGNATURE-----\n(.{0,})\n(.{0,})\n-----END BITCOIN SIGNED MESSAGE-----#USi", $rawMessage, $out); + $address = $out[1][0]; + $signature = $out[2][0]; + + return $this->checkSignatureForMessage($address, $signature, $message); + } + + /*** + * checks the signature of a bitcoin signed message. + * + * @param string $address (base58) + * @param string $encodedSignature (base64) + * @param string $message + * @return bool + */ + public function checkSignatureForMessage($address, $encodedSignature, $message) + { + $hash = $this->hash256("\x18Bitcoin Signed Message:\n" . $this->numToVarIntString(strlen($message)) . $message); + + //recover flag + $signature = base64_decode($encodedSignature); + + $flag = hexdec(bin2hex(substr($signature, 0, 1))); + + $isCompressed = false; + if($flag >= 31 & $flag < 35) //if address is compressed + { + $isCompressed = true; + } + + $R = bin2hex(substr($signature, 1, 32)); + $S = bin2hex(substr($signature, 33, 32)); + + $derPubKey = $this->getPubKeyWithRS($flag, $R, $S, $hash); + + if($isCompressed === true) + $recoveredAddress = $this->getAddress($derPubKey); + else + $recoveredAddress = $this->getUncompressedAddress(false, $derPubKey); + + if($address === $recoveredAddress) + return true; + else + return false; + } +} diff --git a/src/helper/Bytes.php b/src/helper/Bytes.php new file mode 100644 index 00000000..f2a66bd8 --- /dev/null +++ b/src/helper/Bytes.php @@ -0,0 +1,137 @@ +> 8 & 0xff); + $byt[2] = ($val >> 16 & 0xff); + $byt[3] = ($val >> 24 & 0xff); + return $byt; + } + + /** + * reads an Integer from the specified position in the byte array + * @param $bytes array + * @param $position the starting position specified + * @return an Integer type of data + */ + public static function bytesToInteger($bytes, $position) { + $val = 0; + $val = $bytes[$position + 3] & 0xff; + $val <<= 8; + $val |= $bytes[$position + 2] & 0xff; + $val <<= 8; + $val |= $bytes[$position + 1] & 0xff; + $val <<= 8; + $val |= $bytes[$position] & 0xff; + return $val; + } + + /** + * converts a shor string to a byte array + * @param $byt target byte array + * @param $val string to be converted + * + */ + public static function shortToBytes($val) { + $byt = array(); + $byt[0] = ($val & 0xff); + $byt[1] = ($val >> 8 & 0xff); + return $byt; + } + + + /** + * reads data of type Short from the specified location in the byte array. + * @param $bytes array + * @param $position the starting position specified + * @return a Short type of data + */ + public static function bytesToShort($bytes, $position) { + $val = 0; + $val = $bytes[$position + 1] & 0xFF; + $val = $val << 8; + $val |= $bytes[$position] & 0xFF; + return $val; + } + +} +?> \ No newline at end of file diff --git a/src/helper/Curl.php b/src/helper/Curl.php new file mode 100644 index 00000000..7e33917e --- /dev/null +++ b/src/helper/Curl.php @@ -0,0 +1,194 @@ + true, + CURLOPT_SSL_VERIFYPEER => false, + CURLOPT_FOLLOWLOCATION => true, + CURLOPT_RETURNTRANSFER => true, + CURLOPT_SSL_VERIFYHOST => false, + CURLOPT_SSLVERSION => 3, + CURLOPT_IPRESOLVE => CURL_IPRESOLVE_V4, + //int + CURLOPT_MAXREDIRS => 3, + CURLOPT_TIMEOUT => 6, + CURLOPT_CONNECTTIMEOUT => 3, + //string + CURLOPT_USERAGENT => 'Multi-cURL client v1.5.0', + ]; + + public function __construct($id = null, array $options = []) + { + $this->id = $id; + $this->options = $options + self::$defaultOptions; + $this->meetPhp55 = version_compare(PHP_VERSION, '5.5.0', '>='); + } + + protected function init() + { + if ($this->meetPhp55) { + if ($this->handle === null) { + $this->handle = curl_init(); + } else { + curl_reset($this->handle); //Reuse cUrl handle: since 5.5.0 + } + } else { + if ($this->handle !== null) { + curl_close($this->handle); + } + $this->handle = curl_init(); + } + curl_setopt_array($this->handle, $this->options); + } + + public function getId() + { + return $this->id; + } + + public function makeGet($url, $params = null, array $headers = []) + { + $this->init(); + + if (is_string($params) || is_array($params)) { + is_array($params) AND $params = http_build_query($params); + $url = rtrim($url, '?'); + if (strpos($url, '?') !== false) { + $url .= '&' . $params; + } else { + $url .= '?' . $params; + } + } + + curl_setopt_array($this->handle, [CURLOPT_URL => $url, CURLOPT_HTTPGET => true]); + + if (!empty($headers)) { + curl_setopt($this->handle, CURLOPT_HTTPHEADER, $headers); + } + } + + public function makeDelete($url,$params =null ,array $headers = []){ + $this->init(); + + curl_setopt_array($this->handle, [CURLOPT_URL => $url]); + curl_setopt($this->handle, CURLOPT_CUSTOMREQUEST, "DELETE"); + //CURLFile support + if (is_array($params)) { + $hasUploadFile = false; + if ($this->meetPhp55) {//CURLFile: since 5.5.0 + foreach ($params as $k => $v) { + if ($v instanceof \CURLFile) { + $hasUploadFile = true; + break; + } + } + } + $hasUploadFile OR $params = http_build_query($params); + } + + //$params: array => multipart/form-data, string => application/x-www-form-urlencoded + if (!empty($params)) { + curl_setopt($this->handle, CURLOPT_POSTFIELDS, $params); + } + + if (!empty($headers)) { + curl_setopt($this->handle, CURLOPT_HTTPHEADER, $headers); + } + } + + public function makePost($url, $params = null, array $headers = []) + { + $this->init(); + + curl_setopt_array($this->handle, [CURLOPT_URL => $url, CURLOPT_POST => true]); + + //CURLFile support + if (is_array($params)) { + $hasUploadFile = false; + if ($this->meetPhp55) {//CURLFile: since 5.5.0 + foreach ($params as $k => $v) { + if ($v instanceof \CURLFile) { + $hasUploadFile = true; + break; + } + } + } + $hasUploadFile OR $params = http_build_query($params); + } + + //$params: array => multipart/form-data, string => application/x-www-form-urlencoded + if (!empty($params)) { + curl_setopt($this->handle, CURLOPT_POSTFIELDS, $params); + } + + if (!empty($headers)) { + curl_setopt($this->handle, CURLOPT_HTTPHEADER, $headers); + } + + } + + public function exec() + { + if ($this->multi) { + $responseStr = curl_multi_getcontent($this->handle); + } else { + $responseStr = curl_exec($this->handle); + } + $errno = curl_errno($this->handle); + $errstr = curl_error($this->handle);//Fix: curl_errno() always return 0 when fail + $url = curl_getinfo($this->handle, CURLINFO_EFFECTIVE_URL); + $code = curl_getinfo($this->handle, CURLINFO_HTTP_CODE); + $headerSize = curl_getinfo($this->handle, CURLINFO_HEADER_SIZE); + $this->response = Response::make($url, $code, $responseStr, $headerSize, [$errno, $errstr]); + return $this->response; + } + + public function setMulti($isMulti) + { + $this->multi = (bool)$isMulti; + } + + public function responseToFile($filename) + { + $folder = dirname($filename); + if (!file_exists($folder)) { + mkdir($folder, 0777, true); + } + return file_put_contents($filename, $this->getResponse()->getBody()); + } + + public function getResponse() + { + return $this->response; + } + + public function getHandle() + { + return $this->handle; + } + + public function __destruct() + { + if ($this->handle !== null) { + curl_close($this->handle); + } + } +} \ No newline at end of file diff --git a/src/helper/GMPService.php b/src/helper/GMPService.php new file mode 100644 index 00000000..0dde3059 --- /dev/null +++ b/src/helper/GMPService.php @@ -0,0 +1,156 @@ +alphabet = $alphabet; + $this->base = strlen($alphabet); + } + /** + * Encode a string into base58. + * + * @param string $string The string you wish to encode. + * @since Release v1.1.0 + * @return string The Base58 encoded string. + */ + public function encode($string) + { + // Type validation + if (is_string($string) === false) { + throw new InvalidArgumentException('Argument $string must be a string.'); + } + + // If the string is empty, then the encoded string is obviously empty + if (strlen($string) === 0) { + return ''; + } + + // Now we need to convert the byte array into an arbitrary-precision decimal + // We basically do this by performing a base256 to base10 conversion + $hex = unpack('H*', $string); + $hex = reset($hex); + $decimal = gmp_init($hex, 16); + + // This loop now performs base 10 to base 58 conversion + // The remainder or modulo on each loop becomes a base 58 character + $output = ''; + while (gmp_cmp($decimal, $this->base) >= 0) { + list($decimal, $mod) = gmp_div_qr($decimal, $this->base); + $output .= $this->alphabet[gmp_intval($mod)]; + } + + // If there's still a remainder, append it + if (gmp_cmp($decimal, 0) > 0) { + $output .= $this->alphabet[gmp_intval($decimal)]; + } + + // Now we need to reverse the encoded data + $output = strrev($output); + + // Now we need to add leading zeros + $bytes = str_split($string); + foreach ($bytes as $byte) { + if ($byte === "\x00") { + $output = $this->alphabet[0] . $output; + continue; + } + break; + } + + return (string) $output; + } + + /** + * Decode base58 into a PHP string. + * + * @param string $base58 The base58 encoded string. + * @since Release v1.1.0 + * @return string Returns the decoded string. + */ + public function decode($base58) + { + // Type Validation + if (is_string($base58) === false) { + throw new InvalidArgumentException('Argument $base58 must be a string.'); + } + + // If the string is empty, then the decoded string is obviously empty + if (strlen($base58) === 0) { + return ''; + } + + $indexes = array_flip(str_split($this->alphabet)); + $chars = str_split($base58); + + // Check for invalid characters in the supplied base58 string + foreach ($chars as $char) { + if (isset($indexes[$char]) === false) { + throw new InvalidArgumentException('Argument $base58 contains invalid characters.'); + } + } + + // Convert from base58 to base10 + $decimal = gmp_init($indexes[$chars[0]], 10); + + for ($i = 1, $l = count($chars); $i < $l; $i++) { + $decimal = gmp_mul($decimal, $this->base); + $decimal = gmp_add($decimal, $indexes[$chars[$i]]); + } + + // Convert from base10 to base256 (8-bit byte array) + $output = ''; + while (gmp_cmp($decimal, 0) > 0) { + list($decimal, $byte) = gmp_div_qr($decimal, 256); + $output = pack('C', gmp_intval($byte)) . $output; + } + + // Now we need to add leading zeros + foreach ($chars as $char) { + if ($indexes[$char] === 0) { + $output = "\x00" . $output; + continue; + } + break; + } + + return $output; + } +} diff --git a/src/helper/MultiCurl.php b/src/helper/MultiCurl.php new file mode 100644 index 00000000..6036da5b --- /dev/null +++ b/src/helper/MultiCurl.php @@ -0,0 +1,97 @@ +handle = curl_multi_init(); + + if (version_compare(PHP_VERSION, '5.5.0', '>=')) { + foreach ($options as $option => $value) { + curl_multi_setopt($this->handle, $option, $value); + } + } + } + + public function addCurl(Curl $curl) + { + $code = curl_multi_add_handle($this->handle, $curl->getHandle()); + if ($code !== CURLM_OK) { + return false; + } + $curl->setMulti(true); + $this->curls[] = $curl; + return true; + } + + public function addCurls(array $curls) + { + foreach ($curls as $curl) { + if (!$this->addCurl($curl)) { + return false; + } + } + return true; + } + + public function exec(array $options = []) + { + if (count($this->curls) == 0) { + return false; + } + + //Default select timeout + $selectTimeout = isset($options['selectTimeout']) ? $options['selectTimeout'] : 1.0; + + //The first curl_multi_select often times out no matter what, but is usually required for fast transfers + $timeout = 0.001; + $active = false; + do { + while (($mrc = curl_multi_exec($this->handle, $active)) === CURLM_CALL_MULTI_PERFORM) { + ; + } + if ($active && curl_multi_select($this->handle, $timeout) === -1) { + // Perform a usleep if a select returns -1: https://bugs.php.net/bug.php?id=61141 + usleep(150); + } + $timeout = $selectTimeout; + } while ($active); + + + //Clean to re-exec && check success + $success = true; + foreach ($this->curls as $curl) { + $curl->exec(); + if ($curl->getResponse()->hasError()) { + $success = false; + } + curl_multi_remove_handle($this->handle, $curl->getHandle()); + } + + return $success; + } + + public function reset() + { + $this->curls = []; + } + + public function getCurls() + { + return $this->curls; + } + + public function __destruct() + { + curl_multi_close($this->handle); + } +} \ No newline at end of file diff --git a/src/helper/Response.php b/src/helper/Response.php new file mode 100644 index 00000000..a2e4555c --- /dev/null +++ b/src/helper/Response.php @@ -0,0 +1,102 @@ +url = $url; + $this->httpCode = $httpCode; + $this->headers = array_change_key_case($headers, CASE_LOWER); + $this->body = $body; + $this->error = $error; + } + + public function getUrl() + { + return $this->url; + } + + public function getHttpCode() + { + return $this->httpCode; + } + + public function getHeader($key) + { + $key = strtolower($key); + return isset($this->headers[$key]) ? $this->headers[$key] : null; + } + + public function getHeaders() + { + return $this->headers; + } + + public function getBody() + { + return $this->body; + } + + public function hasError() + { + return !empty($this->error[0]) || !empty($this->error[1]); + } + + public function getError() + { + return $this->error; + } + + public function __toString() + { + return $this->body; + } + + public static function parse($responseStr, $headerSize) + { + $header = substr($responseStr, 0, $headerSize); + $body = substr($responseStr, $headerSize); + $lines = explode("\n", $header); + array_shift($lines);//Remove status + + $headers = []; + foreach ($lines as $part) { + $middle = explode(':', $part); + $key = trim($middle[0]); + if ($key === '') { + continue; + } + if (isset($headers[$key])) { + $headers[$key] = (array)$headers[$key]; + $headers[$key][] = isset($middle[1]) ? trim($middle[1]) : ''; + } else { + $headers[$key] = isset($middle[1]) ? trim($middle[1]) : ''; + } + } + return [$headers, $body]; + } + + public static function make($url, $code, $responseStr, $headerSize, array $error) + { + if (!empty($error[0]) || !empty($error[1])) { + $headers = []; + $body = ''; + } else { + list($headers, $body) = static::parse($responseStr, $headerSize); + } + return new static($url, $code, $body, $headers, $error); + } +} \ No newline at end of file diff --git a/src/helper/ServiceInterface.php b/src/helper/ServiceInterface.php new file mode 100644 index 00000000..0fe37452 --- /dev/null +++ b/src/helper/ServiceInterface.php @@ -0,0 +1,24 @@ + \ No newline at end of file diff --git a/src/openssl.cnf b/src/openssl.cnf new file mode 100644 index 00000000..4acca4b0 --- /dev/null +++ b/src/openssl.cnf @@ -0,0 +1,350 @@ +# +# OpenSSL example configuration file. +# This is mostly being used for generation of certificate requests. +# + +# Note that you can include other files from the main configuration +# file using the .include directive. +#.include filename + +# This definition stops the following lines choking if HOME isn't +# defined. +HOME = . + +# Extra OBJECT IDENTIFIER info: +#oid_file = $ENV::HOME/.oid +oid_section = new_oids + +# To use this configuration file with the "-extfile" option of the +# "openssl x509" utility, name here the section containing the +# X.509v3 extensions to use: +# extensions = +# (Alternatively, use a configuration file that has only +# X.509v3 extensions in its main [= default] section.) + +[ new_oids ] + +# We can add new OIDs in here for use by 'ca', 'req' and 'ts'. +# Add a simple OID like this: +# testoid1=1.2.3.4 +# Or use config file substitution like this: +# testoid2=${testoid1}.5.6 + +# Policies used by the TSA examples. +tsa_policy1 = 1.2.3.4.1 +tsa_policy2 = 1.2.3.4.5.6 +tsa_policy3 = 1.2.3.4.5.7 + +#################################################################### +[ ca ] +default_ca = CA_default # The default ca section + +#################################################################### +[ CA_default ] + +dir = ./demoCA # Where everything is kept +certs = $dir/certs # Where the issued certs are kept +crl_dir = $dir/crl # Where the issued crl are kept +database = $dir/index.txt # database index file. +#unique_subject = no # Set to 'no' to allow creation of + # several certs with same subject. +new_certs_dir = $dir/newcerts # default place for new certs. + +certificate = $dir/cacert.pem # The CA certificate +serial = $dir/serial # The current serial number +crlnumber = $dir/crlnumber # the current crl number + # must be commented out to leave a V1 CRL +crl = $dir/crl.pem # The current CRL +private_key = $dir/private/cakey.pem# The private key + +x509_extensions = usr_cert # The extensions to add to the cert + +# Comment out the following two lines for the "traditional" +# (and highly broken) format. +name_opt = ca_default # Subject Name options +cert_opt = ca_default # Certificate field options + +# Extension copying option: use with caution. +# copy_extensions = copy + +# Extensions to add to a CRL. Note: Netscape communicator chokes on V2 CRLs +# so this is commented out by default to leave a V1 CRL. +# crlnumber must also be commented out to leave a V1 CRL. +# crl_extensions = crl_ext + +default_days = 365 # how long to certify for +default_crl_days= 30 # how long before next CRL +default_md = default # use public key default MD +preserve = no # keep passed DN ordering + +# A few difference way of specifying how similar the request should look +# For type CA, the listed attributes must be the same, and the optional +# and supplied fields are just that :-) +policy = policy_match + +# For the CA policy +[ policy_match ] +countryName = match +stateOrProvinceName = match +organizationName = match +organizationalUnitName = optional +commonName = supplied +emailAddress = optional + +# For the 'anything' policy +# At this point in time, you must list all acceptable 'object' +# types. +[ policy_anything ] +countryName = optional +stateOrProvinceName = optional +localityName = optional +organizationName = optional +organizationalUnitName = optional +commonName = supplied +emailAddress = optional + +#################################################################### +[ req ] +default_bits = 2048 +default_keyfile = privkey.pem +distinguished_name = req_distinguished_name +attributes = req_attributes +x509_extensions = v3_ca # The extensions to add to the self signed cert + +# Passwords for private keys if not present they will be prompted for +# input_password = secret +# output_password = secret + +# This sets a mask for permitted string types. There are several options. +# default: PrintableString, T61String, BMPString. +# pkix : PrintableString, BMPString (PKIX recommendation before 2004) +# utf8only: only UTF8Strings (PKIX recommendation after 2004). +# nombstr : PrintableString, T61String (no BMPStrings or UTF8Strings). +# MASK:XXXX a literal mask value. +# WARNING: ancient versions of Netscape crash on BMPStrings or UTF8Strings. +string_mask = utf8only + +# req_extensions = v3_req # The extensions to add to a certificate request + +[ req_distinguished_name ] +countryName = Country Name (2 letter code) +countryName_default = AU +countryName_min = 2 +countryName_max = 2 + +stateOrProvinceName = State or Province Name (full name) +stateOrProvinceName_default = Some-State + +localityName = Locality Name (eg, city) + +0.organizationName = Organization Name (eg, company) +0.organizationName_default = Internet Widgits Pty Ltd + +# we can do this but it is not needed normally :-) +#1.organizationName = Second Organization Name (eg, company) +#1.organizationName_default = World Wide Web Pty Ltd + +organizationalUnitName = Organizational Unit Name (eg, section) +#organizationalUnitName_default = + +commonName = Common Name (e.g. server FQDN or YOUR name) +commonName_max = 64 + +emailAddress = Email Address +emailAddress_max = 64 + +# SET-ex3 = SET extension number 3 + +[ req_attributes ] +challengePassword = A challenge password +challengePassword_min = 4 +challengePassword_max = 20 + +unstructuredName = An optional company name + +[ usr_cert ] + +# These extensions are added when 'ca' signs a request. + +# This goes against PKIX guidelines but some CAs do it and some software +# requires this to avoid interpreting an end user certificate as a CA. + +basicConstraints=CA:FALSE + +# Here are some examples of the usage of nsCertType. If it is omitted +# the certificate can be used for anything *except* object signing. + +# This is OK for an SSL server. +# nsCertType = server + +# For an object signing certificate this would be used. +# nsCertType = objsign + +# For normal client use this is typical +# nsCertType = client, email + +# and for everything including object signing: +# nsCertType = client, email, objsign + +# This is typical in keyUsage for a client certificate. +# keyUsage = nonRepudiation, digitalSignature, keyEncipherment + +# This will be displayed in Netscape's comment listbox. +nsComment = "OpenSSL Generated Certificate" + +# PKIX recommendations harmless if included in all certificates. +subjectKeyIdentifier=hash +authorityKeyIdentifier=keyid,issuer + +# This stuff is for subjectAltName and issuerAltname. +# Import the email address. +# subjectAltName=email:copy +# An alternative to produce certificates that aren't +# deprecated according to PKIX. +# subjectAltName=email:move + +# Copy subject details +# issuerAltName=issuer:copy + +#nsCaRevocationUrl = http://www.domain.dom/ca-crl.pem +#nsBaseUrl +#nsRevocationUrl +#nsRenewalUrl +#nsCaPolicyUrl +#nsSslServerName + +# This is required for TSA certificates. +# extendedKeyUsage = critical,timeStamping + +[ v3_req ] + +# Extensions to add to a certificate request + +basicConstraints = CA:FALSE +keyUsage = nonRepudiation, digitalSignature, keyEncipherment + +[ v3_ca ] + + +# Extensions for a typical CA + + +# PKIX recommendation. + +subjectKeyIdentifier=hash + +authorityKeyIdentifier=keyid:always,issuer + +basicConstraints = critical,CA:true + +# Key usage: this is typical for a CA certificate. However since it will +# prevent it being used as an test self-signed certificate it is best +# left out by default. +# keyUsage = cRLSign, keyCertSign + +# Some might want this also +# nsCertType = sslCA, emailCA + +# Include email address in subject alt name: another PKIX recommendation +# subjectAltName=email:copy +# Copy issuer details +# issuerAltName=issuer:copy + +# DER hex encoding of an extension: beware experts only! +# obj=DER:02:03 +# Where 'obj' is a standard or added object +# You can even override a supported extension: +# basicConstraints= critical, DER:30:03:01:01:FF + +[ crl_ext ] + +# CRL extensions. +# Only issuerAltName and authorityKeyIdentifier make any sense in a CRL. + +# issuerAltName=issuer:copy +authorityKeyIdentifier=keyid:always + +[ proxy_cert_ext ] +# These extensions should be added when creating a proxy certificate + +# This goes against PKIX guidelines but some CAs do it and some software +# requires this to avoid interpreting an end user certificate as a CA. + +basicConstraints=CA:FALSE + +# Here are some examples of the usage of nsCertType. If it is omitted +# the certificate can be used for anything *except* object signing. + +# This is OK for an SSL server. +# nsCertType = server + +# For an object signing certificate this would be used. +# nsCertType = objsign + +# For normal client use this is typical +# nsCertType = client, email + +# and for everything including object signing: +# nsCertType = client, email, objsign + +# This is typical in keyUsage for a client certificate. +# keyUsage = nonRepudiation, digitalSignature, keyEncipherment + +# This will be displayed in Netscape's comment listbox. +nsComment = "OpenSSL Generated Certificate" + +# PKIX recommendations harmless if included in all certificates. +subjectKeyIdentifier=hash +authorityKeyIdentifier=keyid,issuer + +# This stuff is for subjectAltName and issuerAltname. +# Import the email address. +# subjectAltName=email:copy +# An alternative to produce certificates that aren't +# deprecated according to PKIX. +# subjectAltName=email:move + +# Copy subject details +# issuerAltName=issuer:copy + +#nsCaRevocationUrl = http://www.domain.dom/ca-crl.pem +#nsBaseUrl +#nsRevocationUrl +#nsRenewalUrl +#nsCaPolicyUrl +#nsSslServerName + +# This really needs to be in place for it to be a proxy certificate. +proxyCertInfo=critical,language:id-ppl-anyLanguage,pathlen:3,policy:foo + +#################################################################### +[ tsa ] + +default_tsa = tsa_config1 # the default TSA section + +[ tsa_config1 ] + +# These are used by the TSA reply generation only. +dir = ./demoCA # TSA root directory +serial = $dir/tsaserial # The current serial number (mandatory) +crypto_device = builtin # OpenSSL engine to use for signing +signer_cert = $dir/tsacert.pem # The TSA signing certificate + # (optional) +certs = $dir/cacert.pem # Certificate chain to include in reply + # (optional) +signer_key = $dir/private/tsakey.pem # The TSA private key (optional) +signer_digest = sha256 # Signing digest to use. (Optional) +default_policy = tsa_policy1 # Policy if request did not specify it + # (optional) +other_policies = tsa_policy2, tsa_policy3 # acceptable policies (optional) +digests = sha1, sha256, sha384, sha512 # Acceptable message digests (mandatory) +accuracy = secs:1, millisecs:500, microsecs:100 # (optional) +clock_precision_digits = 0 # number of digits after dot. (optional) +ordering = yes # Is ordering defined for timestamps? + # (optional, default: no) +tsa_name = yes # Must the TSA name be included in the reply? + # (optional, default: no) +ess_cert_id_chain = no # Must the ESS cert id chain be included? + # (optional, default: no) +ess_cert_id_alg = sha1 # algorithm to compute certificate + # identifier (optional, default: sha1) diff --git a/src/phpdoc.dist.xml b/src/phpdoc.dist.xml new file mode 100644 index 00000000..dd313025 --- /dev/null +++ b/src/phpdoc.dist.xml @@ -0,0 +1,15 @@ + + + + + doc + + + doc + + + Google/Protobuf/Internal/MapField.php + Google/Protobuf/Internal/Message.php + Google/Protobuf/Internal/RepeatedField.php + + diff --git a/src/pro/Aelf/Protobuf/Generated/Address.php b/src/pro/Aelf/Protobuf/Generated/Address.php new file mode 100644 index 00000000..9c31f1d7 --- /dev/null +++ b/src/pro/Aelf/Protobuf/Generated/Address.php @@ -0,0 +1,59 @@ +aelf.protobuf.generated.Address + */ +class Address extends \Google\Protobuf\Internal\Message +{ + /** + * Generated from protobuf field bytes value = 1; + */ + private $value = ''; + + /** + * Constructor. + * + * @param array $data { + * Optional. Data for populating the Message object. + * + * @type string $value + * } + */ + public function __construct($data = NULL) { + \GPBMetadata\Types::initOnce(); + parent::__construct($data); + } + + /** + * Generated from protobuf field bytes value = 1; + * @return string + */ + public function getValue() + { + return $this->value; + } + + /** + * Generated from protobuf field bytes value = 1; + * @param string $var + * @return $this + */ + public function setValue($var) + { + GPBUtil::checkString($var, False); + $this->value = $var; + + return $this; + } + +} + diff --git a/src/pro/Aelf/Protobuf/Generated/CandidateVote.php b/src/pro/Aelf/Protobuf/Generated/CandidateVote.php new file mode 100644 index 00000000..cf2298a3 --- /dev/null +++ b/src/pro/Aelf/Protobuf/Generated/CandidateVote.php @@ -0,0 +1,221 @@ +aelf.protobuf.generated.CandidateVote + */ +class CandidateVote extends \Google\Protobuf\Internal\Message +{ + /** + * Generated from protobuf field repeated .aelf.protobuf.generated.Hash obtained_active_voting_record_ids = 1; + */ + private $obtained_active_voting_record_ids; + /** + * Generated from protobuf field repeated .aelf.protobuf.generated.Hash obtained_withdrawn_voting_record_ids = 2; + */ + private $obtained_withdrawn_voting_record_ids; + /** + * Generated from protobuf field sint64 obtained_active_voted_votes_amount = 3; + */ + private $obtained_active_voted_votes_amount = 0; + /** + * Generated from protobuf field sint64 all_obtained_voted_votes_amount = 4; + */ + private $all_obtained_voted_votes_amount = 0; + /** + * Generated from protobuf field repeated .aelf.protobuf.generated.ElectionVotingRecord obtained_active_voting_records = 5; + */ + private $obtained_active_voting_records; + /** + * Generated from protobuf field repeated .aelf.protobuf.generated.ElectionVotingRecord obtained_withdrawn_votes_records = 6; + */ + private $obtained_withdrawn_votes_records; + /** + * Generated from protobuf field bytes public_key = 7; + */ + private $public_key = ''; + + /** + * Constructor. + * + * @param array $data { + * Optional. Data for populating the Message object. + * + * @type \Aelf\Protobuf\Generated\Hash[]|\Google\Protobuf\Internal\RepeatedField $obtained_active_voting_record_ids + * @type \Aelf\Protobuf\Generated\Hash[]|\Google\Protobuf\Internal\RepeatedField $obtained_withdrawn_voting_record_ids + * @type int|string $obtained_active_voted_votes_amount + * @type int|string $all_obtained_voted_votes_amount + * @type \Aelf\Protobuf\Generated\ElectionVotingRecord[]|\Google\Protobuf\Internal\RepeatedField $obtained_active_voting_records + * @type \Aelf\Protobuf\Generated\ElectionVotingRecord[]|\Google\Protobuf\Internal\RepeatedField $obtained_withdrawn_votes_records + * @type string $public_key + * } + */ + public function __construct($data = NULL) { + \GPBMetadata\Types::initOnce(); + parent::__construct($data); + } + + /** + * Generated from protobuf field repeated .aelf.protobuf.generated.Hash obtained_active_voting_record_ids = 1; + * @return \Google\Protobuf\Internal\RepeatedField + */ + public function getObtainedActiveVotingRecordIds() + { + return $this->obtained_active_voting_record_ids; + } + + /** + * Generated from protobuf field repeated .aelf.protobuf.generated.Hash obtained_active_voting_record_ids = 1; + * @param \Aelf\Protobuf\Generated\Hash[]|\Google\Protobuf\Internal\RepeatedField $var + * @return $this + */ + public function setObtainedActiveVotingRecordIds($var) + { + $arr = GPBUtil::checkRepeatedField($var, \Google\Protobuf\Internal\GPBType::MESSAGE, \Aelf\Protobuf\Generated\Hash::class); + $this->obtained_active_voting_record_ids = $arr; + + return $this; + } + + /** + * Generated from protobuf field repeated .aelf.protobuf.generated.Hash obtained_withdrawn_voting_record_ids = 2; + * @return \Google\Protobuf\Internal\RepeatedField + */ + public function getObtainedWithdrawnVotingRecordIds() + { + return $this->obtained_withdrawn_voting_record_ids; + } + + /** + * Generated from protobuf field repeated .aelf.protobuf.generated.Hash obtained_withdrawn_voting_record_ids = 2; + * @param \Aelf\Protobuf\Generated\Hash[]|\Google\Protobuf\Internal\RepeatedField $var + * @return $this + */ + public function setObtainedWithdrawnVotingRecordIds($var) + { + $arr = GPBUtil::checkRepeatedField($var, \Google\Protobuf\Internal\GPBType::MESSAGE, \Aelf\Protobuf\Generated\Hash::class); + $this->obtained_withdrawn_voting_record_ids = $arr; + + return $this; + } + + /** + * Generated from protobuf field sint64 obtained_active_voted_votes_amount = 3; + * @return int|string + */ + public function getObtainedActiveVotedVotesAmount() + { + return $this->obtained_active_voted_votes_amount; + } + + /** + * Generated from protobuf field sint64 obtained_active_voted_votes_amount = 3; + * @param int|string $var + * @return $this + */ + public function setObtainedActiveVotedVotesAmount($var) + { + GPBUtil::checkInt64($var); + $this->obtained_active_voted_votes_amount = $var; + + return $this; + } + + /** + * Generated from protobuf field sint64 all_obtained_voted_votes_amount = 4; + * @return int|string + */ + public function getAllObtainedVotedVotesAmount() + { + return $this->all_obtained_voted_votes_amount; + } + + /** + * Generated from protobuf field sint64 all_obtained_voted_votes_amount = 4; + * @param int|string $var + * @return $this + */ + public function setAllObtainedVotedVotesAmount($var) + { + GPBUtil::checkInt64($var); + $this->all_obtained_voted_votes_amount = $var; + + return $this; + } + + /** + * Generated from protobuf field repeated .aelf.protobuf.generated.ElectionVotingRecord obtained_active_voting_records = 5; + * @return \Google\Protobuf\Internal\RepeatedField + */ + public function getObtainedActiveVotingRecords() + { + return $this->obtained_active_voting_records; + } + + /** + * Generated from protobuf field repeated .aelf.protobuf.generated.ElectionVotingRecord obtained_active_voting_records = 5; + * @param \Aelf\Protobuf\Generated\ElectionVotingRecord[]|\Google\Protobuf\Internal\RepeatedField $var + * @return $this + */ + public function setObtainedActiveVotingRecords($var) + { + $arr = GPBUtil::checkRepeatedField($var, \Google\Protobuf\Internal\GPBType::MESSAGE, \Aelf\Protobuf\Generated\ElectionVotingRecord::class); + $this->obtained_active_voting_records = $arr; + + return $this; + } + + /** + * Generated from protobuf field repeated .aelf.protobuf.generated.ElectionVotingRecord obtained_withdrawn_votes_records = 6; + * @return \Google\Protobuf\Internal\RepeatedField + */ + public function getObtainedWithdrawnVotesRecords() + { + return $this->obtained_withdrawn_votes_records; + } + + /** + * Generated from protobuf field repeated .aelf.protobuf.generated.ElectionVotingRecord obtained_withdrawn_votes_records = 6; + * @param \Aelf\Protobuf\Generated\ElectionVotingRecord[]|\Google\Protobuf\Internal\RepeatedField $var + * @return $this + */ + public function setObtainedWithdrawnVotesRecords($var) + { + $arr = GPBUtil::checkRepeatedField($var, \Google\Protobuf\Internal\GPBType::MESSAGE, \Aelf\Protobuf\Generated\ElectionVotingRecord::class); + $this->obtained_withdrawn_votes_records = $arr; + + return $this; + } + + /** + * Generated from protobuf field bytes public_key = 7; + * @return string + */ + public function getPublicKey() + { + return $this->public_key; + } + + /** + * Generated from protobuf field bytes public_key = 7; + * @param string $var + * @return $this + */ + public function setPublicKey($var) + { + GPBUtil::checkString($var, False); + $this->public_key = $var; + + return $this; + } + +} + diff --git a/src/pro/Aelf/Protobuf/Generated/ContractDeploymentInput.php b/src/pro/Aelf/Protobuf/Generated/ContractDeploymentInput.php new file mode 100644 index 00000000..65abd44a --- /dev/null +++ b/src/pro/Aelf/Protobuf/Generated/ContractDeploymentInput.php @@ -0,0 +1,86 @@ +aelf.protobuf.generated.ContractDeploymentInput + */ +class ContractDeploymentInput extends \Google\Protobuf\Internal\Message +{ + /** + * Generated from protobuf field sint32 category = 1; + */ + private $category = 0; + /** + * Generated from protobuf field bytes code = 2; + */ + private $code = ''; + + /** + * Constructor. + * + * @param array $data { + * Optional. Data for populating the Message object. + * + * @type int $category + * @type string $code + * } + */ + public function __construct($data = NULL) { + \GPBMetadata\Types::initOnce(); + parent::__construct($data); + } + + /** + * Generated from protobuf field sint32 category = 1; + * @return int + */ + public function getCategory() + { + return $this->category; + } + + /** + * Generated from protobuf field sint32 category = 1; + * @param int $var + * @return $this + */ + public function setCategory($var) + { + GPBUtil::checkInt32($var); + $this->category = $var; + + return $this; + } + + /** + * Generated from protobuf field bytes code = 2; + * @return string + */ + public function getCode() + { + return $this->code; + } + + /** + * Generated from protobuf field bytes code = 2; + * @param string $var + * @return $this + */ + public function setCode($var) + { + GPBUtil::checkString($var, False); + $this->code = $var; + + return $this; + } + +} + diff --git a/src/pro/Aelf/Protobuf/Generated/ContractUpdateInput.php b/src/pro/Aelf/Protobuf/Generated/ContractUpdateInput.php new file mode 100644 index 00000000..de761ee2 --- /dev/null +++ b/src/pro/Aelf/Protobuf/Generated/ContractUpdateInput.php @@ -0,0 +1,86 @@ +aelf.protobuf.generated.ContractUpdateInput + */ +class ContractUpdateInput extends \Google\Protobuf\Internal\Message +{ + /** + * Generated from protobuf field .aelf.protobuf.generated.Address address = 1; + */ + private $address = null; + /** + * Generated from protobuf field bytes code = 2; + */ + private $code = ''; + + /** + * Constructor. + * + * @param array $data { + * Optional. Data for populating the Message object. + * + * @type \Aelf\Protobuf\Generated\Address $address + * @type string $code + * } + */ + public function __construct($data = NULL) { + \GPBMetadata\Types::initOnce(); + parent::__construct($data); + } + + /** + * Generated from protobuf field .aelf.protobuf.generated.Address address = 1; + * @return \Aelf\Protobuf\Generated\Address + */ + public function getAddress() + { + return $this->address; + } + + /** + * Generated from protobuf field .aelf.protobuf.generated.Address address = 1; + * @param \Aelf\Protobuf\Generated\Address $var + * @return $this + */ + public function setAddress($var) + { + GPBUtil::checkMessage($var, \Aelf\Protobuf\Generated\Address::class); + $this->address = $var; + + return $this; + } + + /** + * Generated from protobuf field bytes code = 2; + * @return string + */ + public function getCode() + { + return $this->code; + } + + /** + * Generated from protobuf field bytes code = 2; + * @param string $var + * @return $this + */ + public function setCode($var) + { + GPBUtil::checkString($var, False); + $this->code = $var; + + return $this; + } + +} + diff --git a/src/pro/Aelf/Protobuf/Generated/CrossChainReceiveTokenInput.php b/src/pro/Aelf/Protobuf/Generated/CrossChainReceiveTokenInput.php new file mode 100644 index 00000000..1337affd --- /dev/null +++ b/src/pro/Aelf/Protobuf/Generated/CrossChainReceiveTokenInput.php @@ -0,0 +1,140 @@ +aelf.protobuf.generated.CrossChainReceiveTokenInput + */ +class CrossChainReceiveTokenInput extends \Google\Protobuf\Internal\Message +{ + /** + * Generated from protobuf field int32 from_chain_id = 1; + */ + private $from_chain_id = 0; + /** + * Generated from protobuf field int64 parent_chain_height = 2; + */ + private $parent_chain_height = 0; + /** + * Generated from protobuf field bytes transfer_transaction_bytes = 3; + */ + private $transfer_transaction_bytes = ''; + /** + * Generated from protobuf field .aelf.protobuf.generated.MerklePath merkle_path = 4; + */ + private $merkle_path = null; + + /** + * Constructor. + * + * @param array $data { + * Optional. Data for populating the Message object. + * + * @type int $from_chain_id + * @type int|string $parent_chain_height + * @type string $transfer_transaction_bytes + * @type \Aelf\Protobuf\Generated\MerklePath $merkle_path + * } + */ + public function __construct($data = NULL) { + \GPBMetadata\Types::initOnce(); + parent::__construct($data); + } + + /** + * Generated from protobuf field int32 from_chain_id = 1; + * @return int + */ + public function getFromChainId() + { + return $this->from_chain_id; + } + + /** + * Generated from protobuf field int32 from_chain_id = 1; + * @param int $var + * @return $this + */ + public function setFromChainId($var) + { + GPBUtil::checkInt32($var); + $this->from_chain_id = $var; + + return $this; + } + + /** + * Generated from protobuf field int64 parent_chain_height = 2; + * @return int|string + */ + public function getParentChainHeight() + { + return $this->parent_chain_height; + } + + /** + * Generated from protobuf field int64 parent_chain_height = 2; + * @param int|string $var + * @return $this + */ + public function setParentChainHeight($var) + { + GPBUtil::checkInt64($var); + $this->parent_chain_height = $var; + + return $this; + } + + /** + * Generated from protobuf field bytes transfer_transaction_bytes = 3; + * @return string + */ + public function getTransferTransactionBytes() + { + return $this->transfer_transaction_bytes; + } + + /** + * Generated from protobuf field bytes transfer_transaction_bytes = 3; + * @param string $var + * @return $this + */ + public function setTransferTransactionBytes($var) + { + GPBUtil::checkString($var, False); + $this->transfer_transaction_bytes = $var; + + return $this; + } + + /** + * Generated from protobuf field .aelf.protobuf.generated.MerklePath merkle_path = 4; + * @return \Aelf\Protobuf\Generated\MerklePath + */ + public function getMerklePath() + { + return $this->merkle_path; + } + + /** + * Generated from protobuf field .aelf.protobuf.generated.MerklePath merkle_path = 4; + * @param \Aelf\Protobuf\Generated\MerklePath $var + * @return $this + */ + public function setMerklePath($var) + { + GPBUtil::checkMessage($var, \Aelf\Protobuf\Generated\MerklePath::class); + $this->merkle_path = $var; + + return $this; + } + +} + diff --git a/src/pro/Aelf/Protobuf/Generated/CrossChainTransferInput.php b/src/pro/Aelf/Protobuf/Generated/CrossChainTransferInput.php new file mode 100644 index 00000000..0445afee --- /dev/null +++ b/src/pro/Aelf/Protobuf/Generated/CrossChainTransferInput.php @@ -0,0 +1,194 @@ +aelf.protobuf.generated.CrossChainTransferInput + */ +class CrossChainTransferInput extends \Google\Protobuf\Internal\Message +{ + /** + * Generated from protobuf field .aelf.protobuf.generated.Address to = 1; + */ + private $to = null; + /** + * Generated from protobuf field string symbol = 2; + */ + private $symbol = ''; + /** + * Generated from protobuf field sint64 amount = 3; + */ + private $amount = 0; + /** + * Generated from protobuf field string memo = 4; + */ + private $memo = ''; + /** + * Generated from protobuf field int32 to_chain_id = 5; + */ + private $to_chain_id = 0; + /** + * Generated from protobuf field int32 issue_chain_id = 6; + */ + private $issue_chain_id = 0; + + /** + * Constructor. + * + * @param array $data { + * Optional. Data for populating the Message object. + * + * @type \Aelf\Protobuf\Generated\Address $to + * @type string $symbol + * @type int|string $amount + * @type string $memo + * @type int $to_chain_id + * @type int $issue_chain_id + * } + */ + public function __construct($data = NULL) { + \GPBMetadata\Types::initOnce(); + parent::__construct($data); + } + + /** + * Generated from protobuf field .aelf.protobuf.generated.Address to = 1; + * @return \Aelf\Protobuf\Generated\Address + */ + public function getTo() + { + return $this->to; + } + + /** + * Generated from protobuf field .aelf.protobuf.generated.Address to = 1; + * @param \Aelf\Protobuf\Generated\Address $var + * @return $this + */ + public function setTo($var) + { + GPBUtil::checkMessage($var, \Aelf\Protobuf\Generated\Address::class); + $this->to = $var; + + return $this; + } + + /** + * Generated from protobuf field string symbol = 2; + * @return string + */ + public function getSymbol() + { + return $this->symbol; + } + + /** + * Generated from protobuf field string symbol = 2; + * @param string $var + * @return $this + */ + public function setSymbol($var) + { + GPBUtil::checkString($var, True); + $this->symbol = $var; + + return $this; + } + + /** + * Generated from protobuf field sint64 amount = 3; + * @return int|string + */ + public function getAmount() + { + return $this->amount; + } + + /** + * Generated from protobuf field sint64 amount = 3; + * @param int|string $var + * @return $this + */ + public function setAmount($var) + { + GPBUtil::checkInt64($var); + $this->amount = $var; + + return $this; + } + + /** + * Generated from protobuf field string memo = 4; + * @return string + */ + public function getMemo() + { + return $this->memo; + } + + /** + * Generated from protobuf field string memo = 4; + * @param string $var + * @return $this + */ + public function setMemo($var) + { + GPBUtil::checkString($var, True); + $this->memo = $var; + + return $this; + } + + /** + * Generated from protobuf field int32 to_chain_id = 5; + * @return int + */ + public function getToChainId() + { + return $this->to_chain_id; + } + + /** + * Generated from protobuf field int32 to_chain_id = 5; + * @param int $var + * @return $this + */ + public function setToChainId($var) + { + GPBUtil::checkInt32($var); + $this->to_chain_id = $var; + + return $this; + } + + /** + * Generated from protobuf field int32 issue_chain_id = 6; + * @return int + */ + public function getIssueChainId() + { + return $this->issue_chain_id; + } + + /** + * Generated from protobuf field int32 issue_chain_id = 6; + * @param int $var + * @return $this + */ + public function setIssueChainId($var) + { + GPBUtil::checkInt32($var); + $this->issue_chain_id = $var; + + return $this; + } + +} + diff --git a/src/pro/Aelf/Protobuf/Generated/ElectionVotingRecord.php b/src/pro/Aelf/Protobuf/Generated/ElectionVotingRecord.php new file mode 100644 index 00000000..1839f651 --- /dev/null +++ b/src/pro/Aelf/Protobuf/Generated/ElectionVotingRecord.php @@ -0,0 +1,302 @@ +aelf.protobuf.generated.ElectionVotingRecord + */ +class ElectionVotingRecord extends \Google\Protobuf\Internal\Message +{ + /** + * Generated from protobuf field .aelf.protobuf.generated.Address voter = 1; + */ + private $voter = null; + /** + * Generated from protobuf field string candidate = 2; + */ + private $candidate = ''; + /** + * Generated from protobuf field sint64 amount = 3; + */ + private $amount = 0; + /** + * Generated from protobuf field sint64 term_number = 4; + */ + private $term_number = 0; + /** + * Generated from protobuf field .aelf.protobuf.generated.Hash vote_id = 5; + */ + private $vote_id = null; + /** + * Generated from protobuf field sint64 lock_time = 7; + */ + private $lock_time = 0; + /** + * Generated from protobuf field .google.protobuf.Timestamp unlock_timestamp = 10; + */ + private $unlock_timestamp = null; + /** + * Generated from protobuf field .google.protobuf.Timestamp withdraw_timestamp = 11; + */ + private $withdraw_timestamp = null; + /** + * Generated from protobuf field .google.protobuf.Timestamp vote_timestamp = 12; + */ + private $vote_timestamp = null; + /** + * Generated from protobuf field bool is_withdrawn = 13; + */ + private $is_withdrawn = false; + + /** + * Constructor. + * + * @param array $data { + * Optional. Data for populating the Message object. + * + * @type \Aelf\Protobuf\Generated\Address $voter + * @type string $candidate + * @type int|string $amount + * @type int|string $term_number + * @type \Aelf\Protobuf\Generated\Hash $vote_id + * @type int|string $lock_time + * @type \Google\Protobuf\Timestamp $unlock_timestamp + * @type \Google\Protobuf\Timestamp $withdraw_timestamp + * @type \Google\Protobuf\Timestamp $vote_timestamp + * @type bool $is_withdrawn + * } + */ + public function __construct($data = NULL) { + \GPBMetadata\Types::initOnce(); + parent::__construct($data); + } + + /** + * Generated from protobuf field .aelf.protobuf.generated.Address voter = 1; + * @return \Aelf\Protobuf\Generated\Address + */ + public function getVoter() + { + return $this->voter; + } + + /** + * Generated from protobuf field .aelf.protobuf.generated.Address voter = 1; + * @param \Aelf\Protobuf\Generated\Address $var + * @return $this + */ + public function setVoter($var) + { + GPBUtil::checkMessage($var, \Aelf\Protobuf\Generated\Address::class); + $this->voter = $var; + + return $this; + } + + /** + * Generated from protobuf field string candidate = 2; + * @return string + */ + public function getCandidate() + { + return $this->candidate; + } + + /** + * Generated from protobuf field string candidate = 2; + * @param string $var + * @return $this + */ + public function setCandidate($var) + { + GPBUtil::checkString($var, True); + $this->candidate = $var; + + return $this; + } + + /** + * Generated from protobuf field sint64 amount = 3; + * @return int|string + */ + public function getAmount() + { + return $this->amount; + } + + /** + * Generated from protobuf field sint64 amount = 3; + * @param int|string $var + * @return $this + */ + public function setAmount($var) + { + GPBUtil::checkInt64($var); + $this->amount = $var; + + return $this; + } + + /** + * Generated from protobuf field sint64 term_number = 4; + * @return int|string + */ + public function getTermNumber() + { + return $this->term_number; + } + + /** + * Generated from protobuf field sint64 term_number = 4; + * @param int|string $var + * @return $this + */ + public function setTermNumber($var) + { + GPBUtil::checkInt64($var); + $this->term_number = $var; + + return $this; + } + + /** + * Generated from protobuf field .aelf.protobuf.generated.Hash vote_id = 5; + * @return \Aelf\Protobuf\Generated\Hash + */ + public function getVoteId() + { + return $this->vote_id; + } + + /** + * Generated from protobuf field .aelf.protobuf.generated.Hash vote_id = 5; + * @param \Aelf\Protobuf\Generated\Hash $var + * @return $this + */ + public function setVoteId($var) + { + GPBUtil::checkMessage($var, \Aelf\Protobuf\Generated\Hash::class); + $this->vote_id = $var; + + return $this; + } + + /** + * Generated from protobuf field sint64 lock_time = 7; + * @return int|string + */ + public function getLockTime() + { + return $this->lock_time; + } + + /** + * Generated from protobuf field sint64 lock_time = 7; + * @param int|string $var + * @return $this + */ + public function setLockTime($var) + { + GPBUtil::checkInt64($var); + $this->lock_time = $var; + + return $this; + } + + /** + * Generated from protobuf field .google.protobuf.Timestamp unlock_timestamp = 10; + * @return \Google\Protobuf\Timestamp + */ + public function getUnlockTimestamp() + { + return $this->unlock_timestamp; + } + + /** + * Generated from protobuf field .google.protobuf.Timestamp unlock_timestamp = 10; + * @param \Google\Protobuf\Timestamp $var + * @return $this + */ + public function setUnlockTimestamp($var) + { + GPBUtil::checkMessage($var, \Google\Protobuf\Timestamp::class); + $this->unlock_timestamp = $var; + + return $this; + } + + /** + * Generated from protobuf field .google.protobuf.Timestamp withdraw_timestamp = 11; + * @return \Google\Protobuf\Timestamp + */ + public function getWithdrawTimestamp() + { + return $this->withdraw_timestamp; + } + + /** + * Generated from protobuf field .google.protobuf.Timestamp withdraw_timestamp = 11; + * @param \Google\Protobuf\Timestamp $var + * @return $this + */ + public function setWithdrawTimestamp($var) + { + GPBUtil::checkMessage($var, \Google\Protobuf\Timestamp::class); + $this->withdraw_timestamp = $var; + + return $this; + } + + /** + * Generated from protobuf field .google.protobuf.Timestamp vote_timestamp = 12; + * @return \Google\Protobuf\Timestamp + */ + public function getVoteTimestamp() + { + return $this->vote_timestamp; + } + + /** + * Generated from protobuf field .google.protobuf.Timestamp vote_timestamp = 12; + * @param \Google\Protobuf\Timestamp $var + * @return $this + */ + public function setVoteTimestamp($var) + { + GPBUtil::checkMessage($var, \Google\Protobuf\Timestamp::class); + $this->vote_timestamp = $var; + + return $this; + } + + /** + * Generated from protobuf field bool is_withdrawn = 13; + * @return bool + */ + public function getIsWithdrawn() + { + return $this->is_withdrawn; + } + + /** + * Generated from protobuf field bool is_withdrawn = 13; + * @param bool $var + * @return $this + */ + public function setIsWithdrawn($var) + { + GPBUtil::checkBool($var); + $this->is_withdrawn = $var; + + return $this; + } + +} + diff --git a/src/pro/Aelf/Protobuf/Generated/ElectorVote.php b/src/pro/Aelf/Protobuf/Generated/ElectorVote.php new file mode 100644 index 00000000..2dfa109b --- /dev/null +++ b/src/pro/Aelf/Protobuf/Generated/ElectorVote.php @@ -0,0 +1,221 @@ +aelf.protobuf.generated.ElectorVote + */ +class ElectorVote extends \Google\Protobuf\Internal\Message +{ + /** + * Generated from protobuf field repeated .aelf.protobuf.generated.Hash active_voting_record_ids = 1; + */ + private $active_voting_record_ids; + /** + * Generated from protobuf field repeated .aelf.protobuf.generated.Hash withdrawn_voting_record_ids = 2; + */ + private $withdrawn_voting_record_ids; + /** + * Generated from protobuf field sint64 active_voted_votes_amount = 3; + */ + private $active_voted_votes_amount = 0; + /** + * Generated from protobuf field sint64 all_voted_votes_amount = 4; + */ + private $all_voted_votes_amount = 0; + /** + * Generated from protobuf field repeated .aelf.protobuf.generated.ElectionVotingRecord active_voting_records = 5; + */ + private $active_voting_records; + /** + * Generated from protobuf field repeated .aelf.protobuf.generated.ElectionVotingRecord withdrawn_votes_records = 6; + */ + private $withdrawn_votes_records; + /** + * Generated from protobuf field bytes public_key = 7; + */ + private $public_key = ''; + + /** + * Constructor. + * + * @param array $data { + * Optional. Data for populating the Message object. + * + * @type \Aelf\Protobuf\Generated\Hash[]|\Google\Protobuf\Internal\RepeatedField $active_voting_record_ids + * @type \Aelf\Protobuf\Generated\Hash[]|\Google\Protobuf\Internal\RepeatedField $withdrawn_voting_record_ids + * @type int|string $active_voted_votes_amount + * @type int|string $all_voted_votes_amount + * @type \Aelf\Protobuf\Generated\ElectionVotingRecord[]|\Google\Protobuf\Internal\RepeatedField $active_voting_records + * @type \Aelf\Protobuf\Generated\ElectionVotingRecord[]|\Google\Protobuf\Internal\RepeatedField $withdrawn_votes_records + * @type string $public_key + * } + */ + public function __construct($data = NULL) { + \GPBMetadata\Types::initOnce(); + parent::__construct($data); + } + + /** + * Generated from protobuf field repeated .aelf.protobuf.generated.Hash active_voting_record_ids = 1; + * @return \Google\Protobuf\Internal\RepeatedField + */ + public function getActiveVotingRecordIds() + { + return $this->active_voting_record_ids; + } + + /** + * Generated from protobuf field repeated .aelf.protobuf.generated.Hash active_voting_record_ids = 1; + * @param \Aelf\Protobuf\Generated\Hash[]|\Google\Protobuf\Internal\RepeatedField $var + * @return $this + */ + public function setActiveVotingRecordIds($var) + { + $arr = GPBUtil::checkRepeatedField($var, \Google\Protobuf\Internal\GPBType::MESSAGE, \Aelf\Protobuf\Generated\Hash::class); + $this->active_voting_record_ids = $arr; + + return $this; + } + + /** + * Generated from protobuf field repeated .aelf.protobuf.generated.Hash withdrawn_voting_record_ids = 2; + * @return \Google\Protobuf\Internal\RepeatedField + */ + public function getWithdrawnVotingRecordIds() + { + return $this->withdrawn_voting_record_ids; + } + + /** + * Generated from protobuf field repeated .aelf.protobuf.generated.Hash withdrawn_voting_record_ids = 2; + * @param \Aelf\Protobuf\Generated\Hash[]|\Google\Protobuf\Internal\RepeatedField $var + * @return $this + */ + public function setWithdrawnVotingRecordIds($var) + { + $arr = GPBUtil::checkRepeatedField($var, \Google\Protobuf\Internal\GPBType::MESSAGE, \Aelf\Protobuf\Generated\Hash::class); + $this->withdrawn_voting_record_ids = $arr; + + return $this; + } + + /** + * Generated from protobuf field sint64 active_voted_votes_amount = 3; + * @return int|string + */ + public function getActiveVotedVotesAmount() + { + return $this->active_voted_votes_amount; + } + + /** + * Generated from protobuf field sint64 active_voted_votes_amount = 3; + * @param int|string $var + * @return $this + */ + public function setActiveVotedVotesAmount($var) + { + GPBUtil::checkInt64($var); + $this->active_voted_votes_amount = $var; + + return $this; + } + + /** + * Generated from protobuf field sint64 all_voted_votes_amount = 4; + * @return int|string + */ + public function getAllVotedVotesAmount() + { + return $this->all_voted_votes_amount; + } + + /** + * Generated from protobuf field sint64 all_voted_votes_amount = 4; + * @param int|string $var + * @return $this + */ + public function setAllVotedVotesAmount($var) + { + GPBUtil::checkInt64($var); + $this->all_voted_votes_amount = $var; + + return $this; + } + + /** + * Generated from protobuf field repeated .aelf.protobuf.generated.ElectionVotingRecord active_voting_records = 5; + * @return \Google\Protobuf\Internal\RepeatedField + */ + public function getActiveVotingRecords() + { + return $this->active_voting_records; + } + + /** + * Generated from protobuf field repeated .aelf.protobuf.generated.ElectionVotingRecord active_voting_records = 5; + * @param \Aelf\Protobuf\Generated\ElectionVotingRecord[]|\Google\Protobuf\Internal\RepeatedField $var + * @return $this + */ + public function setActiveVotingRecords($var) + { + $arr = GPBUtil::checkRepeatedField($var, \Google\Protobuf\Internal\GPBType::MESSAGE, \Aelf\Protobuf\Generated\ElectionVotingRecord::class); + $this->active_voting_records = $arr; + + return $this; + } + + /** + * Generated from protobuf field repeated .aelf.protobuf.generated.ElectionVotingRecord withdrawn_votes_records = 6; + * @return \Google\Protobuf\Internal\RepeatedField + */ + public function getWithdrawnVotesRecords() + { + return $this->withdrawn_votes_records; + } + + /** + * Generated from protobuf field repeated .aelf.protobuf.generated.ElectionVotingRecord withdrawn_votes_records = 6; + * @param \Aelf\Protobuf\Generated\ElectionVotingRecord[]|\Google\Protobuf\Internal\RepeatedField $var + * @return $this + */ + public function setWithdrawnVotesRecords($var) + { + $arr = GPBUtil::checkRepeatedField($var, \Google\Protobuf\Internal\GPBType::MESSAGE, \Aelf\Protobuf\Generated\ElectionVotingRecord::class); + $this->withdrawn_votes_records = $arr; + + return $this; + } + + /** + * Generated from protobuf field bytes public_key = 7; + * @return string + */ + public function getPublicKey() + { + return $this->public_key; + } + + /** + * Generated from protobuf field bytes public_key = 7; + * @param string $var + * @return $this + */ + public function setPublicKey($var) + { + GPBUtil::checkString($var, False); + $this->public_key = $var; + + return $this; + } + +} + diff --git a/src/pro/Aelf/Protobuf/Generated/GetBalanceInput.php b/src/pro/Aelf/Protobuf/Generated/GetBalanceInput.php new file mode 100644 index 00000000..72d31ded --- /dev/null +++ b/src/pro/Aelf/Protobuf/Generated/GetBalanceInput.php @@ -0,0 +1,86 @@ +aelf.protobuf.generated.GetBalanceInput + */ +class GetBalanceInput extends \Google\Protobuf\Internal\Message +{ + /** + * Generated from protobuf field string symbol = 1; + */ + private $symbol = ''; + /** + * Generated from protobuf field .aelf.protobuf.generated.Address owner = 2; + */ + private $owner = null; + + /** + * Constructor. + * + * @param array $data { + * Optional. Data for populating the Message object. + * + * @type string $symbol + * @type \Aelf\Protobuf\Generated\Address $owner + * } + */ + public function __construct($data = NULL) { + \GPBMetadata\Types::initOnce(); + parent::__construct($data); + } + + /** + * Generated from protobuf field string symbol = 1; + * @return string + */ + public function getSymbol() + { + return $this->symbol; + } + + /** + * Generated from protobuf field string symbol = 1; + * @param string $var + * @return $this + */ + public function setSymbol($var) + { + GPBUtil::checkString($var, True); + $this->symbol = $var; + + return $this; + } + + /** + * Generated from protobuf field .aelf.protobuf.generated.Address owner = 2; + * @return \Aelf\Protobuf\Generated\Address + */ + public function getOwner() + { + return $this->owner; + } + + /** + * Generated from protobuf field .aelf.protobuf.generated.Address owner = 2; + * @param \Aelf\Protobuf\Generated\Address $var + * @return $this + */ + public function setOwner($var) + { + GPBUtil::checkMessage($var, \Aelf\Protobuf\Generated\Address::class); + $this->owner = $var; + + return $this; + } + +} + diff --git a/src/pro/Aelf/Protobuf/Generated/GetBalanceOutput.php b/src/pro/Aelf/Protobuf/Generated/GetBalanceOutput.php new file mode 100644 index 00000000..2f5127c1 --- /dev/null +++ b/src/pro/Aelf/Protobuf/Generated/GetBalanceOutput.php @@ -0,0 +1,113 @@ +aelf.protobuf.generated.GetBalanceOutput + */ +class GetBalanceOutput extends \Google\Protobuf\Internal\Message +{ + /** + * Generated from protobuf field string symbol = 1; + */ + private $symbol = ''; + /** + * Generated from protobuf field .aelf.protobuf.generated.Address owner = 2; + */ + private $owner = null; + /** + * Generated from protobuf field sint64 balance = 3; + */ + private $balance = 0; + + /** + * Constructor. + * + * @param array $data { + * Optional. Data for populating the Message object. + * + * @type string $symbol + * @type \Aelf\Protobuf\Generated\Address $owner + * @type int|string $balance + * } + */ + public function __construct($data = NULL) { + \GPBMetadata\Types::initOnce(); + parent::__construct($data); + } + + /** + * Generated from protobuf field string symbol = 1; + * @return string + */ + public function getSymbol() + { + return $this->symbol; + } + + /** + * Generated from protobuf field string symbol = 1; + * @param string $var + * @return $this + */ + public function setSymbol($var) + { + GPBUtil::checkString($var, True); + $this->symbol = $var; + + return $this; + } + + /** + * Generated from protobuf field .aelf.protobuf.generated.Address owner = 2; + * @return \Aelf\Protobuf\Generated\Address + */ + public function getOwner() + { + return $this->owner; + } + + /** + * Generated from protobuf field .aelf.protobuf.generated.Address owner = 2; + * @param \Aelf\Protobuf\Generated\Address $var + * @return $this + */ + public function setOwner($var) + { + GPBUtil::checkMessage($var, \Aelf\Protobuf\Generated\Address::class); + $this->owner = $var; + + return $this; + } + + /** + * Generated from protobuf field sint64 balance = 3; + * @return int|string + */ + public function getBalance() + { + return $this->balance; + } + + /** + * Generated from protobuf field sint64 balance = 3; + * @param int|string $var + * @return $this + */ + public function setBalance($var) + { + GPBUtil::checkInt64($var); + $this->balance = $var; + + return $this; + } + +} + diff --git a/src/pro/Aelf/Protobuf/Generated/GetTokenInfoInput.php b/src/pro/Aelf/Protobuf/Generated/GetTokenInfoInput.php new file mode 100644 index 00000000..6fd633af --- /dev/null +++ b/src/pro/Aelf/Protobuf/Generated/GetTokenInfoInput.php @@ -0,0 +1,59 @@ +aelf.protobuf.generated.GetTokenInfoInput + */ +class GetTokenInfoInput extends \Google\Protobuf\Internal\Message +{ + /** + * Generated from protobuf field string symbol = 1; + */ + private $symbol = ''; + + /** + * Constructor. + * + * @param array $data { + * Optional. Data for populating the Message object. + * + * @type string $symbol + * } + */ + public function __construct($data = NULL) { + \GPBMetadata\Types::initOnce(); + parent::__construct($data); + } + + /** + * Generated from protobuf field string symbol = 1; + * @return string + */ + public function getSymbol() + { + return $this->symbol; + } + + /** + * Generated from protobuf field string symbol = 1; + * @param string $var + * @return $this + */ + public function setSymbol($var) + { + GPBUtil::checkString($var, True); + $this->symbol = $var; + + return $this; + } + +} + diff --git a/src/pro/Aelf/Protobuf/Generated/Hash.php b/src/pro/Aelf/Protobuf/Generated/Hash.php new file mode 100644 index 00000000..b74fabf5 --- /dev/null +++ b/src/pro/Aelf/Protobuf/Generated/Hash.php @@ -0,0 +1,59 @@ +aelf.protobuf.generated.Hash + */ +class Hash extends \Google\Protobuf\Internal\Message +{ + /** + * Generated from protobuf field bytes value = 1; + */ + private $value = ''; + + /** + * Constructor. + * + * @param array $data { + * Optional. Data for populating the Message object. + * + * @type string $value + * } + */ + public function __construct($data = NULL) { + \GPBMetadata\Types::initOnce(); + parent::__construct($data); + } + + /** + * Generated from protobuf field bytes value = 1; + * @return string + */ + public function getValue() + { + return $this->value; + } + + /** + * Generated from protobuf field bytes value = 1; + * @param string $var + * @return $this + */ + public function setValue($var) + { + GPBUtil::checkString($var, False); + $this->value = $var; + + return $this; + } + +} + diff --git a/src/pro/Aelf/Protobuf/Generated/IssueInput.php b/src/pro/Aelf/Protobuf/Generated/IssueInput.php new file mode 100644 index 00000000..322a8054 --- /dev/null +++ b/src/pro/Aelf/Protobuf/Generated/IssueInput.php @@ -0,0 +1,140 @@ +aelf.protobuf.generated.IssueInput + */ +class IssueInput extends \Google\Protobuf\Internal\Message +{ + /** + * Generated from protobuf field string symbol = 1; + */ + private $symbol = ''; + /** + * Generated from protobuf field sint64 amount = 2; + */ + private $amount = 0; + /** + * Generated from protobuf field string memo = 3; + */ + private $memo = ''; + /** + * Generated from protobuf field .aelf.protobuf.generated.Address to = 4; + */ + private $to = null; + + /** + * Constructor. + * + * @param array $data { + * Optional. Data for populating the Message object. + * + * @type string $symbol + * @type int|string $amount + * @type string $memo + * @type \Aelf\Protobuf\Generated\Address $to + * } + */ + public function __construct($data = NULL) { + \GPBMetadata\Types::initOnce(); + parent::__construct($data); + } + + /** + * Generated from protobuf field string symbol = 1; + * @return string + */ + public function getSymbol() + { + return $this->symbol; + } + + /** + * Generated from protobuf field string symbol = 1; + * @param string $var + * @return $this + */ + public function setSymbol($var) + { + GPBUtil::checkString($var, True); + $this->symbol = $var; + + return $this; + } + + /** + * Generated from protobuf field sint64 amount = 2; + * @return int|string + */ + public function getAmount() + { + return $this->amount; + } + + /** + * Generated from protobuf field sint64 amount = 2; + * @param int|string $var + * @return $this + */ + public function setAmount($var) + { + GPBUtil::checkInt64($var); + $this->amount = $var; + + return $this; + } + + /** + * Generated from protobuf field string memo = 3; + * @return string + */ + public function getMemo() + { + return $this->memo; + } + + /** + * Generated from protobuf field string memo = 3; + * @param string $var + * @return $this + */ + public function setMemo($var) + { + GPBUtil::checkString($var, True); + $this->memo = $var; + + return $this; + } + + /** + * Generated from protobuf field .aelf.protobuf.generated.Address to = 4; + * @return \Aelf\Protobuf\Generated\Address + */ + public function getTo() + { + return $this->to; + } + + /** + * Generated from protobuf field .aelf.protobuf.generated.Address to = 4; + * @param \Aelf\Protobuf\Generated\Address $var + * @return $this + */ + public function setTo($var) + { + GPBUtil::checkMessage($var, \Aelf\Protobuf\Generated\Address::class); + $this->to = $var; + + return $this; + } + +} + diff --git a/src/pro/Aelf/Protobuf/Generated/MerklePath.php b/src/pro/Aelf/Protobuf/Generated/MerklePath.php new file mode 100644 index 00000000..baa0179b --- /dev/null +++ b/src/pro/Aelf/Protobuf/Generated/MerklePath.php @@ -0,0 +1,59 @@ +aelf.protobuf.generated.MerklePath + */ +class MerklePath extends \Google\Protobuf\Internal\Message +{ + /** + * Generated from protobuf field repeated .aelf.protobuf.generated.MerklePathNode merkle_path_nodes = 1; + */ + private $merkle_path_nodes; + + /** + * Constructor. + * + * @param array $data { + * Optional. Data for populating the Message object. + * + * @type \Aelf\Protobuf\Generated\MerklePathNode[]|\Google\Protobuf\Internal\RepeatedField $merkle_path_nodes + * } + */ + public function __construct($data = NULL) { + \GPBMetadata\Types::initOnce(); + parent::__construct($data); + } + + /** + * Generated from protobuf field repeated .aelf.protobuf.generated.MerklePathNode merkle_path_nodes = 1; + * @return \Google\Protobuf\Internal\RepeatedField + */ + public function getMerklePathNodes() + { + return $this->merkle_path_nodes; + } + + /** + * Generated from protobuf field repeated .aelf.protobuf.generated.MerklePathNode merkle_path_nodes = 1; + * @param \Aelf\Protobuf\Generated\MerklePathNode[]|\Google\Protobuf\Internal\RepeatedField $var + * @return $this + */ + public function setMerklePathNodes($var) + { + $arr = GPBUtil::checkRepeatedField($var, \Google\Protobuf\Internal\GPBType::MESSAGE, \Aelf\Protobuf\Generated\MerklePathNode::class); + $this->merkle_path_nodes = $arr; + + return $this; + } + +} + diff --git a/src/pro/Aelf/Protobuf/Generated/MerklePathNode.php b/src/pro/Aelf/Protobuf/Generated/MerklePathNode.php new file mode 100644 index 00000000..3d8829ae --- /dev/null +++ b/src/pro/Aelf/Protobuf/Generated/MerklePathNode.php @@ -0,0 +1,86 @@ +aelf.protobuf.generated.MerklePathNode + */ +class MerklePathNode extends \Google\Protobuf\Internal\Message +{ + /** + * Generated from protobuf field .aelf.protobuf.generated.Hash hash = 1; + */ + private $hash = null; + /** + * Generated from protobuf field bool is_left_child_node = 2; + */ + private $is_left_child_node = false; + + /** + * Constructor. + * + * @param array $data { + * Optional. Data for populating the Message object. + * + * @type \Aelf\Protobuf\Generated\Hash $hash + * @type bool $is_left_child_node + * } + */ + public function __construct($data = NULL) { + \GPBMetadata\Types::initOnce(); + parent::__construct($data); + } + + /** + * Generated from protobuf field .aelf.protobuf.generated.Hash hash = 1; + * @return \Aelf\Protobuf\Generated\Hash + */ + public function getHash() + { + return $this->hash; + } + + /** + * Generated from protobuf field .aelf.protobuf.generated.Hash hash = 1; + * @param \Aelf\Protobuf\Generated\Hash $var + * @return $this + */ + public function setHash($var) + { + GPBUtil::checkMessage($var, \Aelf\Protobuf\Generated\Hash::class); + $this->hash = $var; + + return $this; + } + + /** + * Generated from protobuf field bool is_left_child_node = 2; + * @return bool + */ + public function getIsLeftChildNode() + { + return $this->is_left_child_node; + } + + /** + * Generated from protobuf field bool is_left_child_node = 2; + * @param bool $var + * @return $this + */ + public function setIsLeftChildNode($var) + { + GPBUtil::checkBool($var); + $this->is_left_child_node = $var; + + return $this; + } + +} + diff --git a/src/pro/Aelf/Protobuf/Generated/MinerList.php b/src/pro/Aelf/Protobuf/Generated/MinerList.php new file mode 100644 index 00000000..e576c8dc --- /dev/null +++ b/src/pro/Aelf/Protobuf/Generated/MinerList.php @@ -0,0 +1,59 @@ +aelf.protobuf.generated.MinerList + */ +class MinerList extends \Google\Protobuf\Internal\Message +{ + /** + * Generated from protobuf field repeated bytes public_keys = 1; + */ + private $public_keys; + + /** + * Constructor. + * + * @param array $data { + * Optional. Data for populating the Message object. + * + * @type string[]|\Google\Protobuf\Internal\RepeatedField $public_keys + * } + */ + public function __construct($data = NULL) { + \GPBMetadata\Types::initOnce(); + parent::__construct($data); + } + + /** + * Generated from protobuf field repeated bytes public_keys = 1; + * @return \Google\Protobuf\Internal\RepeatedField + */ + public function getPublicKeys() + { + return $this->public_keys; + } + + /** + * Generated from protobuf field repeated bytes public_keys = 1; + * @param string[]|\Google\Protobuf\Internal\RepeatedField $var + * @return $this + */ + public function setPublicKeys($var) + { + $arr = GPBUtil::checkRepeatedField($var, \Google\Protobuf\Internal\GPBType::BYTES); + $this->public_keys = $arr; + + return $this; + } + +} + diff --git a/src/pro/Aelf/Protobuf/Generated/PublicKeysList.php b/src/pro/Aelf/Protobuf/Generated/PublicKeysList.php new file mode 100644 index 00000000..c4efa5a7 --- /dev/null +++ b/src/pro/Aelf/Protobuf/Generated/PublicKeysList.php @@ -0,0 +1,59 @@ +aelf.protobuf.generated.PublicKeysList + */ +class PublicKeysList extends \Google\Protobuf\Internal\Message +{ + /** + * Generated from protobuf field repeated bytes value = 1; + */ + private $value; + + /** + * Constructor. + * + * @param array $data { + * Optional. Data for populating the Message object. + * + * @type string[]|\Google\Protobuf\Internal\RepeatedField $value + * } + */ + public function __construct($data = NULL) { + \GPBMetadata\Types::initOnce(); + parent::__construct($data); + } + + /** + * Generated from protobuf field repeated bytes value = 1; + * @return \Google\Protobuf\Internal\RepeatedField + */ + public function getValue() + { + return $this->value; + } + + /** + * Generated from protobuf field repeated bytes value = 1; + * @param string[]|\Google\Protobuf\Internal\RepeatedField $var + * @return $this + */ + public function setValue($var) + { + $arr = GPBUtil::checkRepeatedField($var, \Google\Protobuf\Internal\GPBType::BYTES); + $this->value = $arr; + + return $this; + } + +} + diff --git a/src/pro/Aelf/Protobuf/Generated/StringInput.php b/src/pro/Aelf/Protobuf/Generated/StringInput.php new file mode 100644 index 00000000..67f81ace --- /dev/null +++ b/src/pro/Aelf/Protobuf/Generated/StringInput.php @@ -0,0 +1,59 @@ +aelf.protobuf.generated.StringInput + */ +class StringInput extends \Google\Protobuf\Internal\Message +{ + /** + * Generated from protobuf field string string_value = 1; + */ + private $string_value = ''; + + /** + * Constructor. + * + * @param array $data { + * Optional. Data for populating the Message object. + * + * @type string $string_value + * } + */ + public function __construct($data = NULL) { + \GPBMetadata\Types::initOnce(); + parent::__construct($data); + } + + /** + * Generated from protobuf field string string_value = 1; + * @return string + */ + public function getStringValue() + { + return $this->string_value; + } + + /** + * Generated from protobuf field string string_value = 1; + * @param string $var + * @return $this + */ + public function setStringValue($var) + { + GPBUtil::checkString($var, True); + $this->string_value = $var; + + return $this; + } + +} + diff --git a/src/pro/Aelf/Protobuf/Generated/Transaction.php b/src/pro/Aelf/Protobuf/Generated/Transaction.php new file mode 100644 index 00000000..f5b450e5 --- /dev/null +++ b/src/pro/Aelf/Protobuf/Generated/Transaction.php @@ -0,0 +1,221 @@ +aelf.protobuf.generated.Transaction + */ +class Transaction extends \Google\Protobuf\Internal\Message +{ + /** + * Generated from protobuf field .aelf.protobuf.generated.Address from_address = 1; + */ + private $from_address = null; + /** + * Generated from protobuf field .aelf.protobuf.generated.Address to_address = 2; + */ + private $to_address = null; + /** + * Generated from protobuf field int64 ref_block_number = 3; + */ + private $ref_block_number = 0; + /** + * Generated from protobuf field bytes ref_block_prefix = 4; + */ + private $ref_block_prefix = ''; + /** + * Generated from protobuf field string method_name = 5; + */ + private $method_name = ''; + /** + * Generated from protobuf field bytes params = 6; + */ + private $params = ''; + /** + * Generated from protobuf field bytes signature = 10000; + */ + private $signature = ''; + + /** + * Constructor. + * + * @param array $data { + * Optional. Data for populating the Message object. + * + * @type \Aelf\Protobuf\Generated\Address $from_address + * @type \Aelf\Protobuf\Generated\Address $to_address + * @type int|string $ref_block_number + * @type string $ref_block_prefix + * @type string $method_name + * @type string $params + * @type string $signature + * } + */ + public function __construct($data = NULL) { + \GPBMetadata\Types::initOnce(); + parent::__construct($data); + } + + /** + * Generated from protobuf field .aelf.protobuf.generated.Address from_address = 1; + * @return \Aelf\Protobuf\Generated\Address + */ + public function getFromAddress() + { + return $this->from_address; + } + + /** + * Generated from protobuf field .aelf.protobuf.generated.Address from_address = 1; + * @param \Aelf\Protobuf\Generated\Address $var + * @return $this + */ + public function setFromAddress($var) + { + + GPBUtil::checkMessage($var, \Aelf\Protobuf\Generated\Address::class); + $this->from_address = $var; + return $this; + } + + /** + * Generated from protobuf field .aelf.protobuf.generated.Address to_address = 2; + * @return \Aelf\Protobuf\Generated\Address + */ + public function getToAddress() + { + return $this->to_address; + } + + /** + * Generated from protobuf field .aelf.protobuf.generated.Address to_address = 2; + * @param \Aelf\Protobuf\Generated\Address $var + * @return $this + */ + public function setToAddress($var) + { + GPBUtil::checkMessage($var, \Aelf\Protobuf\Generated\Address::class); + $this->to_address = $var; + + return $this; + } + + /** + * Generated from protobuf field int64 ref_block_number = 3; + * @return int|string + */ + public function getRefBlockNumber() + { + return $this->ref_block_number; + } + + /** + * Generated from protobuf field int64 ref_block_number = 3; + * @param int|string $var + * @return $this + */ + public function setRefBlockNumber($var) + { + GPBUtil::checkInt64($var); + $this->ref_block_number = $var; + + return $this; + } + + /** + * Generated from protobuf field bytes ref_block_prefix = 4; + * @return string + */ + public function getRefBlockPrefix() + { + return $this->ref_block_prefix; + } + + /** + * Generated from protobuf field bytes ref_block_prefix = 4; + * @param string $var + * @return $this + */ + public function setRefBlockPrefix($var) + { + GPBUtil::checkString($var, False); + $this->ref_block_prefix = $var; + + return $this; + } + + /** + * Generated from protobuf field string method_name = 5; + * @return string + */ + public function getMethodName() + { + return $this->method_name; + } + + /** + * Generated from protobuf field string method_name = 5; + * @param string $var + * @return $this + */ + public function setMethodName($var) + { + GPBUtil::checkString($var, True); + $this->method_name = $var; + + return $this; + } + + /** + * Generated from protobuf field bytes params = 6; + * @return string + */ + public function getParams() + { + return $this->params; + } + + /** + * Generated from protobuf field bytes params = 6; + * @param string $var + * @return $this + */ + public function setParams($var) + { + GPBUtil::checkString($var, False); + $this->params = $var; + + return $this; + } + + /** + * Generated from protobuf field bytes signature = 10000; + * @return string + */ + public function getSignature() + { + return $this->signature; + } + + /** + * Generated from protobuf field bytes signature = 10000; + * @param string $var + * @return $this + */ + public function setSignature($var) + { + GPBUtil::checkString($var, False); + $this->signature = $var; + + return $this; + } + +} + diff --git a/src/pro/Aelf/Protobuf/Generated/TransferInput.php b/src/pro/Aelf/Protobuf/Generated/TransferInput.php new file mode 100644 index 00000000..478b6497 --- /dev/null +++ b/src/pro/Aelf/Protobuf/Generated/TransferInput.php @@ -0,0 +1,140 @@ +aelf.protobuf.generated.TransferInput + */ +class TransferInput extends \Google\Protobuf\Internal\Message +{ + /** + * Generated from protobuf field .aelf.protobuf.generated.Address to = 1; + */ + private $to = null; + /** + * Generated from protobuf field string symbol = 2; + */ + private $symbol = ''; + /** + * Generated from protobuf field sint64 amount = 3; + */ + private $amount = 0; + /** + * Generated from protobuf field string memo = 4; + */ + private $memo = ''; + + /** + * Constructor. + * + * @param array $data { + * Optional. Data for populating the Message object. + * + * @type \Aelf\Protobuf\Generated\Address $to + * @type string $symbol + * @type int|string $amount + * @type string $memo + * } + */ + public function __construct($data = NULL) { + \GPBMetadata\Types::initOnce(); + parent::__construct($data); + } + + /** + * Generated from protobuf field .aelf.protobuf.generated.Address to = 1; + * @return \Aelf\Protobuf\Generated\Address + */ + public function getTo() + { + return $this->to; + } + + /** + * Generated from protobuf field .aelf.protobuf.generated.Address to = 1; + * @param \Aelf\Protobuf\Generated\Address $var + * @return $this + */ + public function setTo($var) + { + GPBUtil::checkMessage($var, \Aelf\Protobuf\Generated\Address::class); + $this->to = $var; + + return $this; + } + + /** + * Generated from protobuf field string symbol = 2; + * @return string + */ + public function getSymbol() + { + return $this->symbol; + } + + /** + * Generated from protobuf field string symbol = 2; + * @param string $var + * @return $this + */ + public function setSymbol($var) + { + GPBUtil::checkString($var, True); + $this->symbol = $var; + + return $this; + } + + /** + * Generated from protobuf field sint64 amount = 3; + * @return int|string + */ + public function getAmount() + { + return $this->amount; + } + + /** + * Generated from protobuf field sint64 amount = 3; + * @param int|string $var + * @return $this + */ + public function setAmount($var) + { + GPBUtil::checkInt64($var); + $this->amount = $var; + + return $this; + } + + /** + * Generated from protobuf field string memo = 4; + * @return string + */ + public function getMemo() + { + return $this->memo; + } + + /** + * Generated from protobuf field string memo = 4; + * @param string $var + * @return $this + */ + public function setMemo($var) + { + GPBUtil::checkString($var, True); + $this->memo = $var; + + return $this; + } + +} + diff --git a/src/pro/GPBMetadata/Timestamp.php b/src/pro/GPBMetadata/Timestamp.php new file mode 100644 index 00000000..beccb3b2 --- /dev/null +++ b/src/pro/GPBMetadata/Timestamp.php @@ -0,0 +1,31 @@ +internalAddGeneratedFile(hex2bin( + "0ad7010a0f74696d657374616d702e70726f746f120f676f6f676c652e70" . + "726f746f627566222b0a0954696d657374616d70120f0a077365636f6e64" . + "73180120012803120d0a056e616e6f73180220012805427e0a13636f6d2e" . + "676f6f676c652e70726f746f627566420e54696d657374616d7050726f74" . + "6f50015a2b6769746875622e636f6d2f676f6c616e672f70726f746f6275" . + "662f7074797065732f74696d657374616d70f80101a20203475042aa021e" . + "476f6f676c652e50726f746f6275662e57656c6c4b6e6f776e5479706573" . + "620670726f746f33" + ), true); + + static::$is_initialized = true; + } +} + diff --git a/src/pro/GPBMetadata/Types.php b/src/pro/GPBMetadata/Types.php new file mode 100644 index 00000000..db92ef38 --- /dev/null +++ b/src/pro/GPBMetadata/Types.php @@ -0,0 +1,117 @@ +internalAddGeneratedFile(hex2bin( + "0ac8150a0b74797065732e70726f746f121761656c662e70726f746f6275" . + "662e67656e65726174656422230a0b537472696e67496e70757412140a0c" . + "737472696e675f76616c756518012001280922200a094d696e65724c6973" . + "7412130a0b7075626c69635f6b65797318012003280c22150a0448617368" . + "120d0a0576616c756518012001280c22180a0741646472657373120d0a05" . + "76616c756518012001280c22e8010a0b5472616e73616374696f6e12360a" . + "0c66726f6d5f6164647265737318012001280b32202e61656c662e70726f" . + "746f6275662e67656e6572617465642e4164647265737312340a0a746f5f" . + "6164647265737318022001280b32202e61656c662e70726f746f6275662e" . + "67656e6572617465642e4164647265737312180a107265665f626c6f636b" . + "5f6e756d62657218032001280312180a107265665f626c6f636b5f707265" . + "66697818042001280c12130a0b6d6574686f645f6e616d65180520012809" . + "120e0a06706172616d7318062001280c12120a097369676e617475726518" . + "904e2001280c22fa020a14456c656374696f6e566f74696e675265636f72" . + "64122f0a05766f74657218012001280b32202e61656c662e70726f746f62" . + "75662e67656e6572617465642e4164647265737312110a0963616e646964" . + "617465180220012809120e0a06616d6f756e7418032001281212130a0b74" . + "65726d5f6e756d626572180420012812122e0a07766f74655f6964180520" . + "01280b321d2e61656c662e70726f746f6275662e67656e6572617465642e" . + "4861736812110a096c6f636b5f74696d6518072001281212340a10756e6c" . + "6f636b5f74696d657374616d70180a2001280b321a2e676f6f676c652e70" . + "726f746f6275662e54696d657374616d7012360a1277697468647261775f" . + "74696d657374616d70180b2001280b321a2e676f6f676c652e70726f746f" . + "6275662e54696d657374616d7012320a0e766f74655f74696d657374616d" . + "70180c2001280b321a2e676f6f676c652e70726f746f6275662e54696d65" . + "7374616d7012140a0c69735f77697468647261776e180d20012808228703" . + "0a0b456c6563746f72566f7465123f0a186163746976655f766f74696e67" . + "5f7265636f72645f69647318012003280b321d2e61656c662e70726f746f" . + "6275662e67656e6572617465642e4861736812420a1b7769746864726177" . + "6e5f766f74696e675f7265636f72645f69647318022003280b321d2e6165" . + "6c662e70726f746f6275662e67656e6572617465642e4861736812210a19" . + "6163746976655f766f7465645f766f7465735f616d6f756e741803200128" . + "12121e0a16616c6c5f766f7465645f766f7465735f616d6f756e74180420" . + "012812124c0a156163746976655f766f74696e675f7265636f7264731805" . + "2003280b322d2e61656c662e70726f746f6275662e67656e657261746564" . + "2e456c656374696f6e566f74696e675265636f7264124e0a177769746864" . + "7261776e5f766f7465735f7265636f72647318062003280b322d2e61656c" . + "662e70726f746f6275662e67656e6572617465642e456c656374696f6e56" . + "6f74696e675265636f726412120a0a7075626c69635f6b65791807200128" . + "0c22bf030a0d43616e646964617465566f746512480a216f627461696e65" . + "645f6163746976655f766f74696e675f7265636f72645f69647318012003" . + "280b321d2e61656c662e70726f746f6275662e67656e6572617465642e48" . + "617368124b0a246f627461696e65645f77697468647261776e5f766f7469" . + "6e675f7265636f72645f69647318022003280b321d2e61656c662e70726f" . + "746f6275662e67656e6572617465642e48617368122a0a226f627461696e" . + "65645f6163746976655f766f7465645f766f7465735f616d6f756e741803" . + "2001281212270a1f616c6c5f6f627461696e65645f766f7465645f766f74" . + "65735f616d6f756e7418042001281212550a1e6f627461696e65645f6163" . + "746976655f766f74696e675f7265636f72647318052003280b322d2e6165" . + "6c662e70726f746f6275662e67656e6572617465642e456c656374696f6e" . + "566f74696e675265636f726412570a206f627461696e65645f7769746864" . + "7261776e5f766f7465735f7265636f72647318062003280b322d2e61656c" . + "662e70726f746f6275662e67656e6572617465642e456c656374696f6e56" . + "6f74696e675265636f726412120a0a7075626c69635f6b65791807200128" . + "0c221f0a0e5075626c69634b6579734c697374120d0a0576616c75651801" . + "2003280c22390a17436f6e74726163744465706c6f796d656e74496e7075" . + "7412100a0863617465676f7279180120012811120c0a04636f6465180220" . + "01280c22560a13436f6e7472616374557064617465496e70757412310a07" . + "6164647265737318012001280b32202e61656c662e70726f746f6275662e" . + "67656e6572617465642e41646472657373120c0a04636f64651802200128" . + "0c22a2010a1743726f7373436861696e5472616e73666572496e70757412" . + "2c0a02746f18012001280b32202e61656c662e70726f746f6275662e6765" . + "6e6572617465642e41646472657373120e0a0673796d626f6c1802200128" . + "09120e0a06616d6f756e74180320012812120c0a046d656d6f1804200128" . + "0912130a0b746f5f636861696e5f696418052001280512160a0e69737375" . + "655f636861696e5f696418062001280522500a0a4d65726b6c6550617468" . + "12420a116d65726b6c655f706174685f6e6f64657318012003280b32272e" . + "61656c662e70726f746f6275662e67656e6572617465642e4d65726b6c65" . + "506174684e6f646522590a0e4d65726b6c65506174684e6f6465122b0a04" . + "6861736818012001280b321d2e61656c662e70726f746f6275662e67656e" . + "6572617465642e48617368121a0a1269735f6c6566745f6368696c645f6e" . + "6f646518022001280822af010a1b43726f7373436861696e526563656976" . + "65546f6b656e496e70757412150a0d66726f6d5f636861696e5f69641801" . + "20012805121b0a13706172656e745f636861696e5f686569676874180220" . + "01280312220a1a7472616e736665725f7472616e73616374696f6e5f6279" . + "74657318032001280c12380a0b6d65726b6c655f7061746818042001280b" . + "32232e61656c662e70726f746f6275662e67656e6572617465642e4d6572" . + "6b6c655061746822230a11476574546f6b656e496e666f496e707574120e" . + "0a0673796d626f6c18012001280922520a0f47657442616c616e6365496e" . + "707574120e0a0673796d626f6c180120012809122f0a056f776e65721802" . + "2001280b32202e61656c662e70726f746f6275662e67656e657261746564" . + "2e4164647265737322640a1047657442616c616e63654f7574707574120e" . + "0a0673796d626f6c180120012809122f0a056f776e657218022001280b32" . + "202e61656c662e70726f746f6275662e67656e6572617465642e41646472" . + "657373120f0a0762616c616e636518032001281222680a0a497373756549" . + "6e707574120e0a0673796d626f6c180120012809120e0a06616d6f756e74" . + "180220012812120c0a046d656d6f180320012809122c0a02746f18042001" . + "280b32202e61656c662e70726f746f6275662e67656e6572617465642e41" . + "646472657373226b0a0d5472616e73666572496e707574122c0a02746f18" . + "012001280b32202e61656c662e70726f746f6275662e67656e6572617465" . + "642e41646472657373120e0a0673796d626f6c180220012809120e0a0661" . + "6d6f756e74180320012812120c0a046d656d6f180420012809620670726f" . + "746f33" + ), true); + + static::$is_initialized = true; + } +} + diff --git a/src/pro/Google/Protobuf/Any.php b/src/pro/Google/Protobuf/Any.php new file mode 100644 index 00000000..166c66a4 --- /dev/null +++ b/src/pro/Google/Protobuf/Any.php @@ -0,0 +1,325 @@ +, + * "lastName": + * } + * 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 `@type` + * field. Example (for message [google.protobuf.Duration][]): + * { + * "@type": "type.googleapis.com/google.protobuf.Duration", + * "value": "1.212s" + * } + * + * Generated from protobuf message google.protobuf.Any + */ +class Any extends \Google\Protobuf\Internal\Message +{ + /** + * A URL/resource name that uniquely identifies the type of the serialized + * protocol buffer message. 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 string type_url = 1; + */ + private $type_url = ''; + /** + * Must be a valid serialized protocol buffer of the above specified type. + * + * Generated from protobuf field bytes value = 2; + */ + private $value = ''; + + const TYPE_URL_PREFIX = 'type.googleapis.com/'; + + /** + * 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. 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. 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 string type_url = 1; + * @return string + */ + public function getTypeUrl() + { + return $this->type_url; + } + + /** + * A URL/resource name that uniquely identifies the type of the serialized + * protocol buffer message. 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 string type_url = 1; + * @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 bytes value = 2; + * @return string + */ + public function getValue() + { + return $this->value; + } + + /** + * Must be a valid serialized protocol buffer of the above specified type. + * + * Generated from protobuf field bytes value = 2; + * @param string $var + * @return $this + */ + public function setValue($var) + { + GPBUtil::checkString($var, False); + $this->value = $var; + + return $this; + } + + /** + * 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 message’s 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.substr( + $fully_qualifed_name, 1, strlen($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.substr( + $fully_qualifed_name, 1, strlen($fully_qualifed_name)); + return $this->type_url === $type_url; + } +} + diff --git a/src/pro/Google/Protobuf/Api.php b/src/pro/Google/Protobuf/Api.php new file mode 100644 index 00000000..db37ffb0 --- /dev/null +++ b/src/pro/Google/Protobuf/Api.php @@ -0,0 +1,350 @@ +google.protobuf.Api + */ +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 string name = 1; + */ + private $name = ''; + /** + * The methods of this interface, in unspecified order. + * + * Generated from protobuf field repeated .google.protobuf.Method methods = 2; + */ + private $methods; + /** + * Any metadata attached to the interface. + * + * Generated from protobuf field repeated .google.protobuf.Option options = 3; + */ + 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`, 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 string version = 4; + */ + private $version = ''; + /** + * Source context for the protocol buffer service represented by this + * message. + * + * Generated from protobuf field .google.protobuf.SourceContext source_context = 5; + */ + private $source_context = null; + /** + * Included interfaces. See [Mixin][]. + * + * Generated from protobuf field repeated .google.protobuf.Mixin mixins = 6; + */ + private $mixins; + /** + * The source syntax of the service. + * + * Generated from protobuf field .google.protobuf.Syntax syntax = 7; + */ + private $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 \Google\Protobuf\Method[]|\Google\Protobuf\Internal\RepeatedField $methods + * The methods of this interface, in unspecified order. + * @type \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`, 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 \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 string name = 1; + * @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 string name = 1; + * @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 repeated .google.protobuf.Method methods = 2; + * @return \Google\Protobuf\Internal\RepeatedField + */ + public function getMethods() + { + return $this->methods; + } + + /** + * The methods of this interface, in unspecified order. + * + * Generated from protobuf field repeated .google.protobuf.Method methods = 2; + * @param \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 repeated .google.protobuf.Option options = 3; + * @return \Google\Protobuf\Internal\RepeatedField + */ + public function getOptions() + { + return $this->options; + } + + /** + * Any metadata attached to the interface. + * + * Generated from protobuf field repeated .google.protobuf.Option options = 3; + * @param \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`, 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 string version = 4; + * @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`, 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 string version = 4; + * @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 .google.protobuf.SourceContext source_context = 5; + * @return \Google\Protobuf\SourceContext + */ + public function getSourceContext() + { + return $this->source_context; + } + + /** + * Source context for the protocol buffer service represented by this + * message. + * + * Generated from protobuf field .google.protobuf.SourceContext source_context = 5; + * @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 repeated .google.protobuf.Mixin mixins = 6; + * @return \Google\Protobuf\Internal\RepeatedField + */ + public function getMixins() + { + return $this->mixins; + } + + /** + * Included interfaces. See [Mixin][]. + * + * Generated from protobuf field repeated .google.protobuf.Mixin mixins = 6; + * @param \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 .google.protobuf.Syntax syntax = 7; + * @return int + */ + public function getSyntax() + { + return $this->syntax; + } + + /** + * The source syntax of the service. + * + * Generated from protobuf field .google.protobuf.Syntax syntax = 7; + * @param int $var + * @return $this + */ + public function setSyntax($var) + { + GPBUtil::checkEnum($var, \Google\Protobuf\Syntax::class); + $this->syntax = $var; + + return $this; + } + +} + diff --git a/src/pro/Google/Protobuf/BoolValue.php b/src/pro/Google/Protobuf/BoolValue.php new file mode 100644 index 00000000..13872eb1 --- /dev/null +++ b/src/pro/Google/Protobuf/BoolValue.php @@ -0,0 +1,68 @@ +google.protobuf.BoolValue + */ +class BoolValue extends \Google\Protobuf\Internal\Message +{ + /** + * The bool value. + * + * Generated from protobuf field bool value = 1; + */ + private $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 bool value = 1; + * @return bool + */ + public function getValue() + { + return $this->value; + } + + /** + * The bool value. + * + * Generated from protobuf field bool value = 1; + * @param bool $var + * @return $this + */ + public function setValue($var) + { + GPBUtil::checkBool($var); + $this->value = $var; + + return $this; + } + +} + diff --git a/src/pro/Google/Protobuf/BytesValue.php b/src/pro/Google/Protobuf/BytesValue.php new file mode 100644 index 00000000..f1b38171 --- /dev/null +++ b/src/pro/Google/Protobuf/BytesValue.php @@ -0,0 +1,68 @@ +google.protobuf.BytesValue + */ +class BytesValue extends \Google\Protobuf\Internal\Message +{ + /** + * The bytes value. + * + * Generated from protobuf field bytes value = 1; + */ + private $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 bytes value = 1; + * @return string + */ + public function getValue() + { + return $this->value; + } + + /** + * The bytes value. + * + * Generated from protobuf field bytes value = 1; + * @param string $var + * @return $this + */ + public function setValue($var) + { + GPBUtil::checkString($var, False); + $this->value = $var; + + return $this; + } + +} + diff --git a/src/pro/Google/Protobuf/Descriptor.php b/src/pro/Google/Protobuf/Descriptor.php new file mode 100644 index 00000000..986b81e1 --- /dev/null +++ b/src/pro/Google/Protobuf/Descriptor.php @@ -0,0 +1,100 @@ +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()); + } +} diff --git a/src/pro/Google/Protobuf/DescriptorPool.php b/src/pro/Google/Protobuf/DescriptorPool.php new file mode 100644 index 00000000..119f0e2e --- /dev/null +++ b/src/pro/Google/Protobuf/DescriptorPool.php @@ -0,0 +1,76 @@ +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(); + } +} diff --git a/src/pro/Google/Protobuf/DoubleValue.php b/src/pro/Google/Protobuf/DoubleValue.php new file mode 100644 index 00000000..236d9182 --- /dev/null +++ b/src/pro/Google/Protobuf/DoubleValue.php @@ -0,0 +1,68 @@ +google.protobuf.DoubleValue + */ +class DoubleValue extends \Google\Protobuf\Internal\Message +{ + /** + * The double value. + * + * Generated from protobuf field double value = 1; + */ + private $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 double value = 1; + * @return float + */ + public function getValue() + { + return $this->value; + } + + /** + * The double value. + * + * Generated from protobuf field double value = 1; + * @param float $var + * @return $this + */ + public function setValue($var) + { + GPBUtil::checkDouble($var); + $this->value = $var; + + return $this; + } + +} + diff --git a/src/pro/Google/Protobuf/Duration.php b/src/pro/Google/Protobuf/Duration.php new file mode 100644 index 00000000..414a1868 --- /dev/null +++ b/src/pro/Google/Protobuf/Duration.php @@ -0,0 +1,173 @@ + 0) { + * duration.seconds += 1; + * duration.nanos -= 1000000000; + * } else if (durations.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 google.protobuf.Duration + */ +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 int64 seconds = 1; + */ + private $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 int32 nanos = 2; + */ + private $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 int64 seconds = 1; + * @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 int64 seconds = 1; + * @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 int32 nanos = 2; + * @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 int32 nanos = 2; + * @param int $var + * @return $this + */ + public function setNanos($var) + { + GPBUtil::checkInt32($var); + $this->nanos = $var; + + return $this; + } + +} + diff --git a/src/pro/Google/Protobuf/Enum.php b/src/pro/Google/Protobuf/Enum.php new file mode 100644 index 00000000..243c40d2 --- /dev/null +++ b/src/pro/Google/Protobuf/Enum.php @@ -0,0 +1,203 @@ +google.protobuf.Enum + */ +class Enum extends \Google\Protobuf\Internal\Message +{ + /** + * Enum type name. + * + * Generated from protobuf field string name = 1; + */ + private $name = ''; + /** + * Enum value definitions. + * + * Generated from protobuf field repeated .google.protobuf.EnumValue enumvalue = 2; + */ + private $enumvalue; + /** + * Protocol buffer options. + * + * Generated from protobuf field repeated .google.protobuf.Option options = 3; + */ + private $options; + /** + * The source context. + * + * Generated from protobuf field .google.protobuf.SourceContext source_context = 4; + */ + private $source_context = null; + /** + * The source syntax. + * + * Generated from protobuf field .google.protobuf.Syntax syntax = 5; + */ + private $syntax = 0; + + /** + * Constructor. + * + * @param array $data { + * Optional. Data for populating the Message object. + * + * @type string $name + * Enum type name. + * @type \Google\Protobuf\EnumValue[]|\Google\Protobuf\Internal\RepeatedField $enumvalue + * Enum value definitions. + * @type \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 string name = 1; + * @return string + */ + public function getName() + { + return $this->name; + } + + /** + * Enum type name. + * + * Generated from protobuf field string name = 1; + * @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 repeated .google.protobuf.EnumValue enumvalue = 2; + * @return \Google\Protobuf\Internal\RepeatedField + */ + public function getEnumvalue() + { + return $this->enumvalue; + } + + /** + * Enum value definitions. + * + * Generated from protobuf field repeated .google.protobuf.EnumValue enumvalue = 2; + * @param \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 repeated .google.protobuf.Option options = 3; + * @return \Google\Protobuf\Internal\RepeatedField + */ + public function getOptions() + { + return $this->options; + } + + /** + * Protocol buffer options. + * + * Generated from protobuf field repeated .google.protobuf.Option options = 3; + * @param \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 .google.protobuf.SourceContext source_context = 4; + * @return \Google\Protobuf\SourceContext + */ + public function getSourceContext() + { + return $this->source_context; + } + + /** + * The source context. + * + * Generated from protobuf field .google.protobuf.SourceContext source_context = 4; + * @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 .google.protobuf.Syntax syntax = 5; + * @return int + */ + public function getSyntax() + { + return $this->syntax; + } + + /** + * The source syntax. + * + * Generated from protobuf field .google.protobuf.Syntax syntax = 5; + * @param int $var + * @return $this + */ + public function setSyntax($var) + { + GPBUtil::checkEnum($var, \Google\Protobuf\Syntax::class); + $this->syntax = $var; + + return $this; + } + +} + diff --git a/src/pro/Google/Protobuf/EnumDescriptor.php b/src/pro/Google/Protobuf/EnumDescriptor.php new file mode 100644 index 00000000..a8b56c0d --- /dev/null +++ b/src/pro/Google/Protobuf/EnumDescriptor.php @@ -0,0 +1,79 @@ +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(); + } +} diff --git a/src/pro/Google/Protobuf/EnumValue.php b/src/pro/Google/Protobuf/EnumValue.php new file mode 100644 index 00000000..1dc3c7a6 --- /dev/null +++ b/src/pro/Google/Protobuf/EnumValue.php @@ -0,0 +1,135 @@ +google.protobuf.EnumValue + */ +class EnumValue extends \Google\Protobuf\Internal\Message +{ + /** + * Enum value name. + * + * Generated from protobuf field string name = 1; + */ + private $name = ''; + /** + * Enum value number. + * + * Generated from protobuf field int32 number = 2; + */ + private $number = 0; + /** + * Protocol buffer options. + * + * Generated from protobuf field repeated .google.protobuf.Option options = 3; + */ + 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 \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 string name = 1; + * @return string + */ + public function getName() + { + return $this->name; + } + + /** + * Enum value name. + * + * Generated from protobuf field string name = 1; + * @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 int32 number = 2; + * @return int + */ + public function getNumber() + { + return $this->number; + } + + /** + * Enum value number. + * + * Generated from protobuf field int32 number = 2; + * @param int $var + * @return $this + */ + public function setNumber($var) + { + GPBUtil::checkInt32($var); + $this->number = $var; + + return $this; + } + + /** + * Protocol buffer options. + * + * Generated from protobuf field repeated .google.protobuf.Option options = 3; + * @return \Google\Protobuf\Internal\RepeatedField + */ + public function getOptions() + { + return $this->options; + } + + /** + * Protocol buffer options. + * + * Generated from protobuf field repeated .google.protobuf.Option options = 3; + * @param \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; + } + +} + diff --git a/src/pro/Google/Protobuf/EnumValueDescriptor.php b/src/pro/Google/Protobuf/EnumValueDescriptor.php new file mode 100644 index 00000000..e76e1997 --- /dev/null +++ b/src/pro/Google/Protobuf/EnumValueDescriptor.php @@ -0,0 +1,64 @@ +name = $name; + $this->number = $number; + } + + /** + * @return string + */ + public function getName() + { + return $this->name; + } + + /** + * @return int + */ + public function getNumber() + { + return $this->number; + } +} diff --git a/src/pro/Google/Protobuf/Field.php b/src/pro/Google/Protobuf/Field.php new file mode 100644 index 00000000..8da43e34 --- /dev/null +++ b/src/pro/Google/Protobuf/Field.php @@ -0,0 +1,381 @@ +google.protobuf.Field + */ +class Field extends \Google\Protobuf\Internal\Message +{ + /** + * The field type. + * + * Generated from protobuf field .google.protobuf.Field.Kind kind = 1; + */ + private $kind = 0; + /** + * The field cardinality. + * + * Generated from protobuf field .google.protobuf.Field.Cardinality cardinality = 2; + */ + private $cardinality = 0; + /** + * The field number. + * + * Generated from protobuf field int32 number = 3; + */ + private $number = 0; + /** + * The field name. + * + * Generated from protobuf field string name = 4; + */ + private $name = ''; + /** + * The field type URL, without the scheme, for message or enumeration + * types. Example: `"type.googleapis.com/google.protobuf.Timestamp"`. + * + * Generated from protobuf field string type_url = 6; + */ + private $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 int32 oneof_index = 7; + */ + private $oneof_index = 0; + /** + * Whether to use alternative packed wire representation. + * + * Generated from protobuf field bool packed = 8; + */ + private $packed = false; + /** + * The protocol buffer options. + * + * Generated from protobuf field repeated .google.protobuf.Option options = 9; + */ + private $options; + /** + * The field JSON name. + * + * Generated from protobuf field string json_name = 10; + */ + private $json_name = ''; + /** + * The string value of the default value of this field. Proto2 syntax only. + * + * Generated from protobuf field string default_value = 11; + */ + private $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 \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 .google.protobuf.Field.Kind kind = 1; + * @return int + */ + public function getKind() + { + return $this->kind; + } + + /** + * The field type. + * + * Generated from protobuf field .google.protobuf.Field.Kind kind = 1; + * @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 .google.protobuf.Field.Cardinality cardinality = 2; + * @return int + */ + public function getCardinality() + { + return $this->cardinality; + } + + /** + * The field cardinality. + * + * Generated from protobuf field .google.protobuf.Field.Cardinality cardinality = 2; + * @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 int32 number = 3; + * @return int + */ + public function getNumber() + { + return $this->number; + } + + /** + * The field number. + * + * Generated from protobuf field int32 number = 3; + * @param int $var + * @return $this + */ + public function setNumber($var) + { + GPBUtil::checkInt32($var); + $this->number = $var; + + return $this; + } + + /** + * The field name. + * + * Generated from protobuf field string name = 4; + * @return string + */ + public function getName() + { + return $this->name; + } + + /** + * The field name. + * + * Generated from protobuf field string name = 4; + * @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 string type_url = 6; + * @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 string type_url = 6; + * @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 int32 oneof_index = 7; + * @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 int32 oneof_index = 7; + * @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 bool packed = 8; + * @return bool + */ + public function getPacked() + { + return $this->packed; + } + + /** + * Whether to use alternative packed wire representation. + * + * Generated from protobuf field bool packed = 8; + * @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 repeated .google.protobuf.Option options = 9; + * @return \Google\Protobuf\Internal\RepeatedField + */ + public function getOptions() + { + return $this->options; + } + + /** + * The protocol buffer options. + * + * Generated from protobuf field repeated .google.protobuf.Option options = 9; + * @param \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 string json_name = 10; + * @return string + */ + public function getJsonName() + { + return $this->json_name; + } + + /** + * The field JSON name. + * + * Generated from protobuf field string json_name = 10; + * @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 string default_value = 11; + * @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 string default_value = 11; + * @param string $var + * @return $this + */ + public function setDefaultValue($var) + { + GPBUtil::checkString($var, True); + $this->default_value = $var; + + return $this; + } + +} + diff --git a/src/pro/Google/Protobuf/Field/Cardinality.php b/src/pro/Google/Protobuf/Field/Cardinality.php new file mode 100644 index 00000000..479dc0bf --- /dev/null +++ b/src/pro/Google/Protobuf/Field/Cardinality.php @@ -0,0 +1,70 @@ +google.protobuf.Field.Cardinality + */ +class Cardinality +{ + /** + * For fields with unknown cardinality. + * + * Generated from protobuf enum CARDINALITY_UNKNOWN = 0; + */ + const CARDINALITY_UNKNOWN = 0; + /** + * For optional fields. + * + * Generated from protobuf enum CARDINALITY_OPTIONAL = 1; + */ + const CARDINALITY_OPTIONAL = 1; + /** + * For required fields. Proto2 syntax only. + * + * Generated from protobuf enum CARDINALITY_REQUIRED = 2; + */ + const CARDINALITY_REQUIRED = 2; + /** + * For repeated fields. + * + * Generated from protobuf enum CARDINALITY_REPEATED = 3; + */ + 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); + diff --git a/src/pro/Google/Protobuf/Field/Kind.php b/src/pro/Google/Protobuf/Field/Kind.php new file mode 100644 index 00000000..f30bd2f5 --- /dev/null +++ b/src/pro/Google/Protobuf/Field/Kind.php @@ -0,0 +1,175 @@ +google.protobuf.Field.Kind + */ +class Kind +{ + /** + * Field type unknown. + * + * Generated from protobuf enum TYPE_UNKNOWN = 0; + */ + const TYPE_UNKNOWN = 0; + /** + * Field type double. + * + * Generated from protobuf enum TYPE_DOUBLE = 1; + */ + const TYPE_DOUBLE = 1; + /** + * Field type float. + * + * Generated from protobuf enum TYPE_FLOAT = 2; + */ + const TYPE_FLOAT = 2; + /** + * Field type int64. + * + * Generated from protobuf enum TYPE_INT64 = 3; + */ + const TYPE_INT64 = 3; + /** + * Field type uint64. + * + * Generated from protobuf enum TYPE_UINT64 = 4; + */ + const TYPE_UINT64 = 4; + /** + * Field type int32. + * + * Generated from protobuf enum TYPE_INT32 = 5; + */ + const TYPE_INT32 = 5; + /** + * Field type fixed64. + * + * Generated from protobuf enum TYPE_FIXED64 = 6; + */ + const TYPE_FIXED64 = 6; + /** + * Field type fixed32. + * + * Generated from protobuf enum TYPE_FIXED32 = 7; + */ + const TYPE_FIXED32 = 7; + /** + * Field type bool. + * + * Generated from protobuf enum TYPE_BOOL = 8; + */ + const TYPE_BOOL = 8; + /** + * Field type string. + * + * Generated from protobuf enum TYPE_STRING = 9; + */ + const TYPE_STRING = 9; + /** + * Field type group. Proto2 syntax only, and deprecated. + * + * Generated from protobuf enum TYPE_GROUP = 10; + */ + const TYPE_GROUP = 10; + /** + * Field type message. + * + * Generated from protobuf enum TYPE_MESSAGE = 11; + */ + const TYPE_MESSAGE = 11; + /** + * Field type bytes. + * + * Generated from protobuf enum TYPE_BYTES = 12; + */ + const TYPE_BYTES = 12; + /** + * Field type uint32. + * + * Generated from protobuf enum TYPE_UINT32 = 13; + */ + const TYPE_UINT32 = 13; + /** + * Field type enum. + * + * Generated from protobuf enum TYPE_ENUM = 14; + */ + const TYPE_ENUM = 14; + /** + * Field type sfixed32. + * + * Generated from protobuf enum TYPE_SFIXED32 = 15; + */ + const TYPE_SFIXED32 = 15; + /** + * Field type sfixed64. + * + * Generated from protobuf enum TYPE_SFIXED64 = 16; + */ + const TYPE_SFIXED64 = 16; + /** + * Field type sint32. + * + * Generated from protobuf enum TYPE_SINT32 = 17; + */ + const TYPE_SINT32 = 17; + /** + * Field type sint64. + * + * Generated from protobuf enum TYPE_SINT64 = 18; + */ + 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); + diff --git a/src/pro/Google/Protobuf/FieldDescriptor.php b/src/pro/Google/Protobuf/FieldDescriptor.php new file mode 100644 index 00000000..ac9271f9 --- /dev/null +++ b/src/pro/Google/Protobuf/FieldDescriptor.php @@ -0,0 +1,117 @@ +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 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(); + } +} diff --git a/src/pro/Google/Protobuf/FieldMask.php b/src/pro/Google/Protobuf/FieldMask.php new file mode 100644 index 00000000..8fb38cbf --- /dev/null +++ b/src/pro/Google/Protobuf/FieldMask.php @@ -0,0 +1,223 @@ +google.protobuf.FieldMask + */ +class FieldMask extends \Google\Protobuf\Internal\Message +{ + /** + * The set of field mask paths. + * + * Generated from protobuf field repeated string paths = 1; + */ + private $paths; + + /** + * Constructor. + * + * @param array $data { + * Optional. Data for populating the Message object. + * + * @type 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 repeated string paths = 1; + * @return \Google\Protobuf\Internal\RepeatedField + */ + public function getPaths() + { + return $this->paths; + } + + /** + * The set of field mask paths. + * + * Generated from protobuf field repeated string paths = 1; + * @param 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; + } + +} + diff --git a/src/pro/Google/Protobuf/Field_Cardinality.php b/src/pro/Google/Protobuf/Field_Cardinality.php new file mode 100644 index 00000000..dff8f893 --- /dev/null +++ b/src/pro/Google/Protobuf/Field_Cardinality.php @@ -0,0 +1,16 @@ +google.protobuf.FloatValue + */ +class FloatValue extends \Google\Protobuf\Internal\Message +{ + /** + * The float value. + * + * Generated from protobuf field float value = 1; + */ + private $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 float value = 1; + * @return float + */ + public function getValue() + { + return $this->value; + } + + /** + * The float value. + * + * Generated from protobuf field float value = 1; + * @param float $var + * @return $this + */ + public function setValue($var) + { + GPBUtil::checkFloat($var); + $this->value = $var; + + return $this; + } + +} + diff --git a/src/pro/Google/Protobuf/GPBEmpty.php b/src/pro/Google/Protobuf/GPBEmpty.php new file mode 100644 index 00000000..2de9c3bc --- /dev/null +++ b/src/pro/Google/Protobuf/GPBEmpty.php @@ -0,0 +1,39 @@ +google.protobuf.Empty + */ +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); + } + +} + diff --git a/src/pro/Google/Protobuf/Int32Value.php b/src/pro/Google/Protobuf/Int32Value.php new file mode 100644 index 00000000..d7fd528d --- /dev/null +++ b/src/pro/Google/Protobuf/Int32Value.php @@ -0,0 +1,68 @@ +google.protobuf.Int32Value + */ +class Int32Value extends \Google\Protobuf\Internal\Message +{ + /** + * The int32 value. + * + * Generated from protobuf field int32 value = 1; + */ + private $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 int32 value = 1; + * @return int + */ + public function getValue() + { + return $this->value; + } + + /** + * The int32 value. + * + * Generated from protobuf field int32 value = 1; + * @param int $var + * @return $this + */ + public function setValue($var) + { + GPBUtil::checkInt32($var); + $this->value = $var; + + return $this; + } + +} + diff --git a/src/pro/Google/Protobuf/Int64Value.php b/src/pro/Google/Protobuf/Int64Value.php new file mode 100644 index 00000000..ca663055 --- /dev/null +++ b/src/pro/Google/Protobuf/Int64Value.php @@ -0,0 +1,68 @@ +google.protobuf.Int64Value + */ +class Int64Value extends \Google\Protobuf\Internal\Message +{ + /** + * The int64 value. + * + * Generated from protobuf field int64 value = 1; + */ + private $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 int64 value = 1; + * @return int|string + */ + public function getValue() + { + return $this->value; + } + + /** + * The int64 value. + * + * Generated from protobuf field int64 value = 1; + * @param int|string $var + * @return $this + */ + public function setValue($var) + { + GPBUtil::checkInt64($var); + $this->value = $var; + + return $this; + } + +} + diff --git a/src/pro/Google/Protobuf/Internal/CodedInputStream.php b/src/pro/Google/Protobuf/Internal/CodedInputStream.php new file mode 100644 index 00000000..2ed2dfde --- /dev/null +++ b/src/pro/Google/Protobuf/Internal/CodedInputStream.php @@ -0,0 +1,382 @@ +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; + } +} diff --git a/src/pro/Google/Protobuf/Internal/CodedOutputStream.php b/src/pro/Google/Protobuf/Internal/CodedOutputStream.php new file mode 100644 index 00000000..f75e9c66 --- /dev/null +++ b/src/pro/Google/Protobuf/Internal/CodedOutputStream.php @@ -0,0 +1,159 @@ +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; + } + +} diff --git a/src/pro/Google/Protobuf/Internal/Descriptor.php b/src/pro/Google/Protobuf/Internal/Descriptor.php new file mode 100644 index 00000000..21ac5de3 --- /dev/null +++ b/src/pro/Google/Protobuf/Internal/Descriptor.php @@ -0,0 +1,222 @@ +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 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 = ""; + $fullname = ""; + GPBUtil::getFullClassName( + $proto, + $containing, + $file_proto, + $message_name_without_package, + $legacy_classname, + $classname, + $fullname); + $desc->setFullName($fullname); + $desc->setClass($classname); + $desc->setLegacyClass($legacy_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; + } +} diff --git a/src/pro/Google/Protobuf/Internal/DescriptorPool.php b/src/pro/Google/Protobuf/Internal/DescriptorPool.php new file mode 100644 index 00000000..f96b0fb7 --- /dev/null +++ b/src/pro/Google/Protobuf/Internal/DescriptorPool.php @@ -0,0 +1,187 @@ +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; + 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(); + $subdesc = $this->getDescriptorByProtoName($proto); + if (is_null($subdesc)) { + trigger_error( + 'proto not added: ' . $proto + . " for " . $desc->getFullName(), E_ERROR); + } + $field->setMessageType($subdesc); + break; + case GPBType::ENUM: + $proto = $field->getEnumType(); + $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); + } +} diff --git a/src/pro/Google/Protobuf/Internal/DescriptorProto.php b/src/pro/Google/Protobuf/Internal/DescriptorProto.php new file mode 100644 index 00000000..7cc689d0 --- /dev/null +++ b/src/pro/Google/Protobuf/Internal/DescriptorProto.php @@ -0,0 +1,386 @@ +google.protobuf.DescriptorProto + */ +class DescriptorProto extends \Google\Protobuf\Internal\Message +{ + /** + * Generated from protobuf field optional string name = 1; + */ + protected $name = ''; + private $has_name = false; + /** + * Generated from protobuf field repeated .google.protobuf.FieldDescriptorProto field = 2; + */ + private $field; + private $has_field = false; + /** + * Generated from protobuf field repeated .google.protobuf.FieldDescriptorProto extension = 6; + */ + private $extension; + private $has_extension = false; + /** + * Generated from protobuf field repeated .google.protobuf.DescriptorProto nested_type = 3; + */ + private $nested_type; + private $has_nested_type = false; + /** + * Generated from protobuf field repeated .google.protobuf.EnumDescriptorProto enum_type = 4; + */ + private $enum_type; + private $has_enum_type = false; + /** + * Generated from protobuf field repeated .google.protobuf.DescriptorProto.ExtensionRange extension_range = 5; + */ + private $extension_range; + private $has_extension_range = false; + /** + * Generated from protobuf field repeated .google.protobuf.OneofDescriptorProto oneof_decl = 8; + */ + private $oneof_decl; + private $has_oneof_decl = false; + /** + * Generated from protobuf field optional .google.protobuf.MessageOptions options = 7; + */ + protected $options = null; + private $has_options = false; + /** + * Generated from protobuf field repeated .google.protobuf.DescriptorProto.ReservedRange reserved_range = 9; + */ + private $reserved_range; + private $has_reserved_range = false; + /** + * 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 repeated string reserved_name = 10; + */ + private $reserved_name; + private $has_reserved_name = false; + + /** + * Constructor. + * + * @param array $data { + * Optional. Data for populating the Message object. + * + * @type string $name + * @type \Google\Protobuf\Internal\FieldDescriptorProto[]|\Google\Protobuf\Internal\RepeatedField $field + * @type \Google\Protobuf\Internal\FieldDescriptorProto[]|\Google\Protobuf\Internal\RepeatedField $extension + * @type \Google\Protobuf\Internal\DescriptorProto[]|\Google\Protobuf\Internal\RepeatedField $nested_type + * @type \Google\Protobuf\Internal\EnumDescriptorProto[]|\Google\Protobuf\Internal\RepeatedField $enum_type + * @type \Google\Protobuf\Internal\DescriptorProto\ExtensionRange[]|\Google\Protobuf\Internal\RepeatedField $extension_range + * @type \Google\Protobuf\Internal\OneofDescriptorProto[]|\Google\Protobuf\Internal\RepeatedField $oneof_decl + * @type \Google\Protobuf\Internal\MessageOptions $options + * @type \Google\Protobuf\Internal\DescriptorProto\ReservedRange[]|\Google\Protobuf\Internal\RepeatedField $reserved_range + * @type 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 optional string name = 1; + * @return string + */ + public function getName() + { + return $this->name; + } + + /** + * Generated from protobuf field optional string name = 1; + * @param string $var + * @return $this + */ + public function setName($var) + { + GPBUtil::checkString($var, True); + $this->name = $var; + $this->has_name = true; + + return $this; + } + + public function hasName() + { + return $this->has_name; + } + + /** + * Generated from protobuf field repeated .google.protobuf.FieldDescriptorProto field = 2; + * @return \Google\Protobuf\Internal\RepeatedField + */ + public function getField() + { + return $this->field; + } + + /** + * Generated from protobuf field repeated .google.protobuf.FieldDescriptorProto field = 2; + * @param \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; + $this->has_field = true; + + return $this; + } + + public function hasField() + { + return $this->has_field; + } + + /** + * Generated from protobuf field repeated .google.protobuf.FieldDescriptorProto extension = 6; + * @return \Google\Protobuf\Internal\RepeatedField + */ + public function getExtension() + { + return $this->extension; + } + + /** + * Generated from protobuf field repeated .google.protobuf.FieldDescriptorProto extension = 6; + * @param \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; + $this->has_extension = true; + + return $this; + } + + public function hasExtension() + { + return $this->has_extension; + } + + /** + * Generated from protobuf field repeated .google.protobuf.DescriptorProto nested_type = 3; + * @return \Google\Protobuf\Internal\RepeatedField + */ + public function getNestedType() + { + return $this->nested_type; + } + + /** + * Generated from protobuf field repeated .google.protobuf.DescriptorProto nested_type = 3; + * @param \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; + $this->has_nested_type = true; + + return $this; + } + + public function hasNestedType() + { + return $this->has_nested_type; + } + + /** + * Generated from protobuf field repeated .google.protobuf.EnumDescriptorProto enum_type = 4; + * @return \Google\Protobuf\Internal\RepeatedField + */ + public function getEnumType() + { + return $this->enum_type; + } + + /** + * Generated from protobuf field repeated .google.protobuf.EnumDescriptorProto enum_type = 4; + * @param \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; + $this->has_enum_type = true; + + return $this; + } + + public function hasEnumType() + { + return $this->has_enum_type; + } + + /** + * Generated from protobuf field repeated .google.protobuf.DescriptorProto.ExtensionRange extension_range = 5; + * @return \Google\Protobuf\Internal\RepeatedField + */ + public function getExtensionRange() + { + return $this->extension_range; + } + + /** + * Generated from protobuf field repeated .google.protobuf.DescriptorProto.ExtensionRange extension_range = 5; + * @param \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; + $this->has_extension_range = true; + + return $this; + } + + public function hasExtensionRange() + { + return $this->has_extension_range; + } + + /** + * Generated from protobuf field repeated .google.protobuf.OneofDescriptorProto oneof_decl = 8; + * @return \Google\Protobuf\Internal\RepeatedField + */ + public function getOneofDecl() + { + return $this->oneof_decl; + } + + /** + * Generated from protobuf field repeated .google.protobuf.OneofDescriptorProto oneof_decl = 8; + * @param \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; + $this->has_oneof_decl = true; + + return $this; + } + + public function hasOneofDecl() + { + return $this->has_oneof_decl; + } + + /** + * Generated from protobuf field optional .google.protobuf.MessageOptions options = 7; + * @return \Google\Protobuf\Internal\MessageOptions + */ + public function getOptions() + { + return $this->options; + } + + /** + * Generated from protobuf field optional .google.protobuf.MessageOptions options = 7; + * @param \Google\Protobuf\Internal\MessageOptions $var + * @return $this + */ + public function setOptions($var) + { + GPBUtil::checkMessage($var, \Google\Protobuf\Internal\MessageOptions::class); + $this->options = $var; + $this->has_options = true; + + return $this; + } + + public function hasOptions() + { + return $this->has_options; + } + + /** + * Generated from protobuf field repeated .google.protobuf.DescriptorProto.ReservedRange reserved_range = 9; + * @return \Google\Protobuf\Internal\RepeatedField + */ + public function getReservedRange() + { + return $this->reserved_range; + } + + /** + * Generated from protobuf field repeated .google.protobuf.DescriptorProto.ReservedRange reserved_range = 9; + * @param \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; + $this->has_reserved_range = true; + + return $this; + } + + public function hasReservedRange() + { + return $this->has_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 repeated string reserved_name = 10; + * @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 repeated string reserved_name = 10; + * @param 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; + $this->has_reserved_name = true; + + return $this; + } + + public function hasReservedName() + { + return $this->has_reserved_name; + } + +} + diff --git a/src/pro/Google/Protobuf/Internal/DescriptorProto/ExtensionRange.php b/src/pro/Google/Protobuf/Internal/DescriptorProto/ExtensionRange.php new file mode 100644 index 00000000..82b5695e --- /dev/null +++ b/src/pro/Google/Protobuf/Internal/DescriptorProto/ExtensionRange.php @@ -0,0 +1,152 @@ +google.protobuf.DescriptorProto.ExtensionRange + */ +class ExtensionRange extends \Google\Protobuf\Internal\Message +{ + /** + * Inclusive. + * + * Generated from protobuf field optional int32 start = 1; + */ + protected $start = 0; + private $has_start = false; + /** + * Exclusive. + * + * Generated from protobuf field optional int32 end = 2; + */ + protected $end = 0; + private $has_end = false; + /** + * Generated from protobuf field optional .google.protobuf.ExtensionRangeOptions options = 3; + */ + protected $options = null; + private $has_options = false; + + /** + * 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 optional int32 start = 1; + * @return int + */ + public function getStart() + { + return $this->start; + } + + /** + * Inclusive. + * + * Generated from protobuf field optional int32 start = 1; + * @param int $var + * @return $this + */ + public function setStart($var) + { + GPBUtil::checkInt32($var); + $this->start = $var; + $this->has_start = true; + + return $this; + } + + public function hasStart() + { + return $this->has_start; + } + + /** + * Exclusive. + * + * Generated from protobuf field optional int32 end = 2; + * @return int + */ + public function getEnd() + { + return $this->end; + } + + /** + * Exclusive. + * + * Generated from protobuf field optional int32 end = 2; + * @param int $var + * @return $this + */ + public function setEnd($var) + { + GPBUtil::checkInt32($var); + $this->end = $var; + $this->has_end = true; + + return $this; + } + + public function hasEnd() + { + return $this->has_end; + } + + /** + * Generated from protobuf field optional .google.protobuf.ExtensionRangeOptions options = 3; + * @return \Google\Protobuf\Internal\ExtensionRangeOptions + */ + public function getOptions() + { + return $this->options; + } + + /** + * Generated from protobuf field optional .google.protobuf.ExtensionRangeOptions options = 3; + * @param \Google\Protobuf\Internal\ExtensionRangeOptions $var + * @return $this + */ + public function setOptions($var) + { + GPBUtil::checkMessage($var, \Google\Protobuf\Internal\ExtensionRangeOptions::class); + $this->options = $var; + $this->has_options = true; + + return $this; + } + + public function hasOptions() + { + return $this->has_options; + } + +} + +// Adding a class alias for backwards compatibility with the previous class name. +class_alias(ExtensionRange::class, \Google\Protobuf\Internal\DescriptorProto_ExtensionRange::class); + diff --git a/src/pro/Google/Protobuf/Internal/DescriptorProto/ReservedRange.php b/src/pro/Google/Protobuf/Internal/DescriptorProto/ReservedRange.php new file mode 100644 index 00000000..8022151a --- /dev/null +++ b/src/pro/Google/Protobuf/Internal/DescriptorProto/ReservedRange.php @@ -0,0 +1,122 @@ +google.protobuf.DescriptorProto.ReservedRange + */ +class ReservedRange extends \Google\Protobuf\Internal\Message +{ + /** + * Inclusive. + * + * Generated from protobuf field optional int32 start = 1; + */ + protected $start = 0; + private $has_start = false; + /** + * Exclusive. + * + * Generated from protobuf field optional int32 end = 2; + */ + protected $end = 0; + private $has_end = false; + + /** + * 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 optional int32 start = 1; + * @return int + */ + public function getStart() + { + return $this->start; + } + + /** + * Inclusive. + * + * Generated from protobuf field optional int32 start = 1; + * @param int $var + * @return $this + */ + public function setStart($var) + { + GPBUtil::checkInt32($var); + $this->start = $var; + $this->has_start = true; + + return $this; + } + + public function hasStart() + { + return $this->has_start; + } + + /** + * Exclusive. + * + * Generated from protobuf field optional int32 end = 2; + * @return int + */ + public function getEnd() + { + return $this->end; + } + + /** + * Exclusive. + * + * Generated from protobuf field optional int32 end = 2; + * @param int $var + * @return $this + */ + public function setEnd($var) + { + GPBUtil::checkInt32($var); + $this->end = $var; + $this->has_end = true; + + return $this; + } + + public function hasEnd() + { + return $this->has_end; + } + +} + +// Adding a class alias for backwards compatibility with the previous class name. +class_alias(ReservedRange::class, \Google\Protobuf\Internal\DescriptorProto_ReservedRange::class); + diff --git a/src/pro/Google/Protobuf/Internal/DescriptorProto_ExtensionRange.php b/src/pro/Google/Protobuf/Internal/DescriptorProto_ExtensionRange.php new file mode 100644 index 00000000..c928fbe5 --- /dev/null +++ b/src/pro/Google/Protobuf/Internal/DescriptorProto_ExtensionRange.php @@ -0,0 +1,16 @@ +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); + } +} diff --git a/src/pro/Google/Protobuf/Internal/EnumDescriptor.php b/src/pro/Google/Protobuf/Internal/EnumDescriptor.php new file mode 100644 index 00000000..7af4f840 --- /dev/null +++ b/src/pro/Google/Protobuf/Internal/EnumDescriptor.php @@ -0,0 +1,115 @@ +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); + $desc->setFullName($fullname); + $desc->setClass($classname); + $desc->setLegacyClass($legacy_classname); + $values = $proto->getValue(); + foreach ($values as $value) { + $desc->addValue($value->getNumber(), $value); + } + + return $desc; + } +} diff --git a/src/pro/Google/Protobuf/Internal/EnumDescriptorProto.php b/src/pro/Google/Protobuf/Internal/EnumDescriptorProto.php new file mode 100644 index 00000000..f5c7fe14 --- /dev/null +++ b/src/pro/Google/Protobuf/Internal/EnumDescriptorProto.php @@ -0,0 +1,231 @@ +google.protobuf.EnumDescriptorProto + */ +class EnumDescriptorProto extends \Google\Protobuf\Internal\Message +{ + /** + * Generated from protobuf field optional string name = 1; + */ + protected $name = ''; + private $has_name = false; + /** + * Generated from protobuf field repeated .google.protobuf.EnumValueDescriptorProto value = 2; + */ + private $value; + private $has_value = false; + /** + * Generated from protobuf field optional .google.protobuf.EnumOptions options = 3; + */ + protected $options = null; + private $has_options = false; + /** + * 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 repeated .google.protobuf.EnumDescriptorProto.EnumReservedRange reserved_range = 4; + */ + private $reserved_range; + private $has_reserved_range = false; + /** + * Reserved enum value names, which may not be reused. A given name may only + * be reserved once. + * + * Generated from protobuf field repeated string reserved_name = 5; + */ + private $reserved_name; + private $has_reserved_name = false; + + /** + * Constructor. + * + * @param array $data { + * Optional. Data for populating the Message object. + * + * @type string $name + * @type \Google\Protobuf\Internal\EnumValueDescriptorProto[]|\Google\Protobuf\Internal\RepeatedField $value + * @type \Google\Protobuf\Internal\EnumOptions $options + * @type \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 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 optional string name = 1; + * @return string + */ + public function getName() + { + return $this->name; + } + + /** + * Generated from protobuf field optional string name = 1; + * @param string $var + * @return $this + */ + public function setName($var) + { + GPBUtil::checkString($var, True); + $this->name = $var; + $this->has_name = true; + + return $this; + } + + public function hasName() + { + return $this->has_name; + } + + /** + * Generated from protobuf field repeated .google.protobuf.EnumValueDescriptorProto value = 2; + * @return \Google\Protobuf\Internal\RepeatedField + */ + public function getValue() + { + return $this->value; + } + + /** + * Generated from protobuf field repeated .google.protobuf.EnumValueDescriptorProto value = 2; + * @param \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; + $this->has_value = true; + + return $this; + } + + public function hasValue() + { + return $this->has_value; + } + + /** + * Generated from protobuf field optional .google.protobuf.EnumOptions options = 3; + * @return \Google\Protobuf\Internal\EnumOptions + */ + public function getOptions() + { + return $this->options; + } + + /** + * Generated from protobuf field optional .google.protobuf.EnumOptions options = 3; + * @param \Google\Protobuf\Internal\EnumOptions $var + * @return $this + */ + public function setOptions($var) + { + GPBUtil::checkMessage($var, \Google\Protobuf\Internal\EnumOptions::class); + $this->options = $var; + $this->has_options = true; + + return $this; + } + + public function hasOptions() + { + return $this->has_options; + } + + /** + * 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 repeated .google.protobuf.EnumDescriptorProto.EnumReservedRange reserved_range = 4; + * @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 repeated .google.protobuf.EnumDescriptorProto.EnumReservedRange reserved_range = 4; + * @param \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; + $this->has_reserved_range = true; + + return $this; + } + + public function hasReservedRange() + { + return $this->has_reserved_range; + } + + /** + * Reserved enum value names, which may not be reused. A given name may only + * be reserved once. + * + * Generated from protobuf field repeated string reserved_name = 5; + * @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 repeated string reserved_name = 5; + * @param 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; + $this->has_reserved_name = true; + + return $this; + } + + public function hasReservedName() + { + return $this->has_reserved_name; + } + +} + diff --git a/src/pro/Google/Protobuf/Internal/EnumDescriptorProto/EnumReservedRange.php b/src/pro/Google/Protobuf/Internal/EnumDescriptorProto/EnumReservedRange.php new file mode 100644 index 00000000..949dd891 --- /dev/null +++ b/src/pro/Google/Protobuf/Internal/EnumDescriptorProto/EnumReservedRange.php @@ -0,0 +1,124 @@ +google.protobuf.EnumDescriptorProto.EnumReservedRange + */ +class EnumReservedRange extends \Google\Protobuf\Internal\Message +{ + /** + * Inclusive. + * + * Generated from protobuf field optional int32 start = 1; + */ + protected $start = 0; + private $has_start = false; + /** + * Inclusive. + * + * Generated from protobuf field optional int32 end = 2; + */ + protected $end = 0; + private $has_end = false; + + /** + * 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 optional int32 start = 1; + * @return int + */ + public function getStart() + { + return $this->start; + } + + /** + * Inclusive. + * + * Generated from protobuf field optional int32 start = 1; + * @param int $var + * @return $this + */ + public function setStart($var) + { + GPBUtil::checkInt32($var); + $this->start = $var; + $this->has_start = true; + + return $this; + } + + public function hasStart() + { + return $this->has_start; + } + + /** + * Inclusive. + * + * Generated from protobuf field optional int32 end = 2; + * @return int + */ + public function getEnd() + { + return $this->end; + } + + /** + * Inclusive. + * + * Generated from protobuf field optional int32 end = 2; + * @param int $var + * @return $this + */ + public function setEnd($var) + { + GPBUtil::checkInt32($var); + $this->end = $var; + $this->has_end = true; + + return $this; + } + + public function hasEnd() + { + return $this->has_end; + } + +} + +// Adding a class alias for backwards compatibility with the previous class name. +class_alias(EnumReservedRange::class, \Google\Protobuf\Internal\EnumDescriptorProto_EnumReservedRange::class); + diff --git a/src/pro/Google/Protobuf/Internal/EnumDescriptorProto_EnumReservedRange.php b/src/pro/Google/Protobuf/Internal/EnumDescriptorProto_EnumReservedRange.php new file mode 100644 index 00000000..b1b59ed9 --- /dev/null +++ b/src/pro/Google/Protobuf/Internal/EnumDescriptorProto_EnumReservedRange.php @@ -0,0 +1,16 @@ +google.protobuf.EnumOptions + */ +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 optional bool allow_alias = 2; + */ + protected $allow_alias = false; + private $has_allow_alias = false; + /** + * 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 optional bool deprecated = 3 [default = false]; + */ + protected $deprecated = false; + private $has_deprecated = false; + /** + * The parser stores options it doesn't recognize here. See above. + * + * Generated from protobuf field repeated .google.protobuf.UninterpretedOption uninterpreted_option = 999; + */ + private $uninterpreted_option; + private $has_uninterpreted_option = false; + + /** + * 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 \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 optional bool allow_alias = 2; + * @return bool + */ + public function getAllowAlias() + { + return $this->allow_alias; + } + + /** + * Set this option to true to allow mapping different tag names to the same + * value. + * + * Generated from protobuf field optional bool allow_alias = 2; + * @param bool $var + * @return $this + */ + public function setAllowAlias($var) + { + GPBUtil::checkBool($var); + $this->allow_alias = $var; + $this->has_allow_alias = true; + + return $this; + } + + public function hasAllowAlias() + { + return $this->has_allow_alias; + } + + /** + * 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 optional bool deprecated = 3 [default = false]; + * @return bool + */ + public function getDeprecated() + { + return $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 optional bool deprecated = 3 [default = false]; + * @param bool $var + * @return $this + */ + public function setDeprecated($var) + { + GPBUtil::checkBool($var); + $this->deprecated = $var; + $this->has_deprecated = true; + + return $this; + } + + public function hasDeprecated() + { + return $this->has_deprecated; + } + + /** + * The parser stores options it doesn't recognize here. See above. + * + * Generated from protobuf field repeated .google.protobuf.UninterpretedOption uninterpreted_option = 999; + * @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 repeated .google.protobuf.UninterpretedOption uninterpreted_option = 999; + * @param \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; + $this->has_uninterpreted_option = true; + + return $this; + } + + public function hasUninterpretedOption() + { + return $this->has_uninterpreted_option; + } + +} + diff --git a/src/pro/Google/Protobuf/Internal/EnumValueDescriptorProto.php b/src/pro/Google/Protobuf/Internal/EnumValueDescriptorProto.php new file mode 100644 index 00000000..3dd95583 --- /dev/null +++ b/src/pro/Google/Protobuf/Internal/EnumValueDescriptorProto.php @@ -0,0 +1,137 @@ +google.protobuf.EnumValueDescriptorProto + */ +class EnumValueDescriptorProto extends \Google\Protobuf\Internal\Message +{ + /** + * Generated from protobuf field optional string name = 1; + */ + protected $name = ''; + private $has_name = false; + /** + * Generated from protobuf field optional int32 number = 2; + */ + protected $number = 0; + private $has_number = false; + /** + * Generated from protobuf field optional .google.protobuf.EnumValueOptions options = 3; + */ + protected $options = null; + private $has_options = false; + + /** + * 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 optional string name = 1; + * @return string + */ + public function getName() + { + return $this->name; + } + + /** + * Generated from protobuf field optional string name = 1; + * @param string $var + * @return $this + */ + public function setName($var) + { + GPBUtil::checkString($var, True); + $this->name = $var; + $this->has_name = true; + + return $this; + } + + public function hasName() + { + return $this->has_name; + } + + /** + * Generated from protobuf field optional int32 number = 2; + * @return int + */ + public function getNumber() + { + return $this->number; + } + + /** + * Generated from protobuf field optional int32 number = 2; + * @param int $var + * @return $this + */ + public function setNumber($var) + { + GPBUtil::checkInt32($var); + $this->number = $var; + $this->has_number = true; + + return $this; + } + + public function hasNumber() + { + return $this->has_number; + } + + /** + * Generated from protobuf field optional .google.protobuf.EnumValueOptions options = 3; + * @return \Google\Protobuf\Internal\EnumValueOptions + */ + public function getOptions() + { + return $this->options; + } + + /** + * Generated from protobuf field optional .google.protobuf.EnumValueOptions options = 3; + * @param \Google\Protobuf\Internal\EnumValueOptions $var + * @return $this + */ + public function setOptions($var) + { + GPBUtil::checkMessage($var, \Google\Protobuf\Internal\EnumValueOptions::class); + $this->options = $var; + $this->has_options = true; + + return $this; + } + + public function hasOptions() + { + return $this->has_options; + } + +} + diff --git a/src/pro/Google/Protobuf/Internal/EnumValueOptions.php b/src/pro/Google/Protobuf/Internal/EnumValueOptions.php new file mode 100644 index 00000000..9f9fb3be --- /dev/null +++ b/src/pro/Google/Protobuf/Internal/EnumValueOptions.php @@ -0,0 +1,127 @@ +google.protobuf.EnumValueOptions + */ +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 optional bool deprecated = 1 [default = false]; + */ + protected $deprecated = false; + private $has_deprecated = false; + /** + * The parser stores options it doesn't recognize here. See above. + * + * Generated from protobuf field repeated .google.protobuf.UninterpretedOption uninterpreted_option = 999; + */ + private $uninterpreted_option; + private $has_uninterpreted_option = false; + + /** + * 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 \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 optional bool deprecated = 1 [default = false]; + * @return bool + */ + public function getDeprecated() + { + return $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 optional bool deprecated = 1 [default = false]; + * @param bool $var + * @return $this + */ + public function setDeprecated($var) + { + GPBUtil::checkBool($var); + $this->deprecated = $var; + $this->has_deprecated = true; + + return $this; + } + + public function hasDeprecated() + { + return $this->has_deprecated; + } + + /** + * The parser stores options it doesn't recognize here. See above. + * + * Generated from protobuf field repeated .google.protobuf.UninterpretedOption uninterpreted_option = 999; + * @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 repeated .google.protobuf.UninterpretedOption uninterpreted_option = 999; + * @param \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; + $this->has_uninterpreted_option = true; + + return $this; + } + + public function hasUninterpretedOption() + { + return $this->has_uninterpreted_option; + } + +} + diff --git a/src/pro/Google/Protobuf/Internal/ExtensionRangeOptions.php b/src/pro/Google/Protobuf/Internal/ExtensionRangeOptions.php new file mode 100644 index 00000000..00fbebec --- /dev/null +++ b/src/pro/Google/Protobuf/Internal/ExtensionRangeOptions.php @@ -0,0 +1,74 @@ +google.protobuf.ExtensionRangeOptions + */ +class ExtensionRangeOptions extends \Google\Protobuf\Internal\Message +{ + /** + * The parser stores options it doesn't recognize here. See above. + * + * Generated from protobuf field repeated .google.protobuf.UninterpretedOption uninterpreted_option = 999; + */ + private $uninterpreted_option; + private $has_uninterpreted_option = false; + + /** + * Constructor. + * + * @param array $data { + * Optional. Data for populating the Message object. + * + * @type \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 repeated .google.protobuf.UninterpretedOption uninterpreted_option = 999; + * @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 repeated .google.protobuf.UninterpretedOption uninterpreted_option = 999; + * @param \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; + $this->has_uninterpreted_option = true; + + return $this; + } + + public function hasUninterpretedOption() + { + return $this->has_uninterpreted_option; + } + +} + diff --git a/src/pro/Google/Protobuf/Internal/FieldDescriptor.php b/src/pro/Google/Protobuf/Internal/FieldDescriptor.php new file mode 100644 index 00000000..98b516fe --- /dev/null +++ b/src/pro/Google/Protobuf/Internal/FieldDescriptor.php @@ -0,0 +1,284 @@ +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 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); + } + + 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; + $packed = false; + $options = $proto->getOptions(); + if ($options !== null) { + $packed = $options->getPacked(); + } + + $field = new FieldDescriptor(); + $field->setName($proto->getName()); + + $json_name = $proto->hasJsonName() ? $proto->getJsonName() : + lcfirst(implode('', array_map('ucwords', explode('_', $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); + + // 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); + } +} diff --git a/src/pro/Google/Protobuf/Internal/FieldDescriptorProto.php b/src/pro/Google/Protobuf/Internal/FieldDescriptorProto.php new file mode 100644 index 00000000..b231c9e1 --- /dev/null +++ b/src/pro/Google/Protobuf/Internal/FieldDescriptorProto.php @@ -0,0 +1,473 @@ +google.protobuf.FieldDescriptorProto + */ +class FieldDescriptorProto extends \Google\Protobuf\Internal\Message +{ + /** + * Generated from protobuf field optional string name = 1; + */ + protected $name = ''; + private $has_name = false; + /** + * Generated from protobuf field optional int32 number = 3; + */ + protected $number = 0; + private $has_number = false; + /** + * Generated from protobuf field optional .google.protobuf.FieldDescriptorProto.Label label = 4; + */ + protected $label = 0; + private $has_label = false; + /** + * 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 optional .google.protobuf.FieldDescriptorProto.Type type = 5; + */ + protected $type = 0; + private $has_type = false; + /** + * 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 optional string type_name = 6; + */ + protected $type_name = ''; + private $has_type_name = false; + /** + * 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 optional string extendee = 2; + */ + protected $extendee = ''; + private $has_extendee = false; + /** + * 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. + * TODO(kenton): Base-64 encode? + * + * Generated from protobuf field optional string default_value = 7; + */ + protected $default_value = ''; + private $has_default_value = false; + /** + * 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 optional int32 oneof_index = 9; + */ + protected $oneof_index = 0; + private $has_oneof_index = false; + /** + * 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 optional string json_name = 10; + */ + protected $json_name = ''; + private $has_json_name = false; + /** + * Generated from protobuf field optional .google.protobuf.FieldOptions options = 8; + */ + protected $options = null; + private $has_options = false; + + /** + * 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. + * TODO(kenton): Base-64 encode? + * @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 + * } + */ + public function __construct($data = NULL) { + \GPBMetadata\Google\Protobuf\Internal\Descriptor::initOnce(); + parent::__construct($data); + } + + /** + * Generated from protobuf field optional string name = 1; + * @return string + */ + public function getName() + { + return $this->name; + } + + /** + * Generated from protobuf field optional string name = 1; + * @param string $var + * @return $this + */ + public function setName($var) + { + GPBUtil::checkString($var, True); + $this->name = $var; + $this->has_name = true; + + return $this; + } + + public function hasName() + { + return $this->has_name; + } + + /** + * Generated from protobuf field optional int32 number = 3; + * @return int + */ + public function getNumber() + { + return $this->number; + } + + /** + * Generated from protobuf field optional int32 number = 3; + * @param int $var + * @return $this + */ + public function setNumber($var) + { + GPBUtil::checkInt32($var); + $this->number = $var; + $this->has_number = true; + + return $this; + } + + public function hasNumber() + { + return $this->has_number; + } + + /** + * Generated from protobuf field optional .google.protobuf.FieldDescriptorProto.Label label = 4; + * @return int + */ + public function getLabel() + { + return $this->label; + } + + /** + * Generated from protobuf field optional .google.protobuf.FieldDescriptorProto.Label label = 4; + * @param int $var + * @return $this + */ + public function setLabel($var) + { + GPBUtil::checkEnum($var, \Google\Protobuf\Internal\FieldDescriptorProto_Label::class); + $this->label = $var; + $this->has_label = true; + + return $this; + } + + public function hasLabel() + { + return $this->has_label; + } + + /** + * 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 optional .google.protobuf.FieldDescriptorProto.Type type = 5; + * @return int + */ + public function getType() + { + return $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 optional .google.protobuf.FieldDescriptorProto.Type type = 5; + * @param int $var + * @return $this + */ + public function setType($var) + { + GPBUtil::checkEnum($var, \Google\Protobuf\Internal\FieldDescriptorProto_Type::class); + $this->type = $var; + $this->has_type = true; + + return $this; + } + + public function hasType() + { + return $this->has_type; + } + + /** + * 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 optional string type_name = 6; + * @return string + */ + public function getTypeName() + { + return $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 optional string type_name = 6; + * @param string $var + * @return $this + */ + public function setTypeName($var) + { + GPBUtil::checkString($var, True); + $this->type_name = $var; + $this->has_type_name = true; + + return $this; + } + + public function hasTypeName() + { + return $this->has_type_name; + } + + /** + * 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 optional string extendee = 2; + * @return string + */ + public function getExtendee() + { + return $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 optional string extendee = 2; + * @param string $var + * @return $this + */ + public function setExtendee($var) + { + GPBUtil::checkString($var, True); + $this->extendee = $var; + $this->has_extendee = true; + + return $this; + } + + public function hasExtendee() + { + return $this->has_extendee; + } + + /** + * 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. + * TODO(kenton): Base-64 encode? + * + * Generated from protobuf field optional string default_value = 7; + * @return string + */ + public function getDefaultValue() + { + return $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. + * TODO(kenton): Base-64 encode? + * + * Generated from protobuf field optional string default_value = 7; + * @param string $var + * @return $this + */ + public function setDefaultValue($var) + { + GPBUtil::checkString($var, True); + $this->default_value = $var; + $this->has_default_value = true; + + return $this; + } + + public function hasDefaultValue() + { + return $this->has_default_value; + } + + /** + * 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 optional int32 oneof_index = 9; + * @return int + */ + public function getOneofIndex() + { + return $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 optional int32 oneof_index = 9; + * @param int $var + * @return $this + */ + public function setOneofIndex($var) + { + GPBUtil::checkInt32($var); + $this->oneof_index = $var; + $this->has_oneof_index = true; + + return $this; + } + + public function hasOneofIndex() + { + return $this->has_oneof_index; + } + + /** + * 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 optional string json_name = 10; + * @return string + */ + public function getJsonName() + { + return $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 optional string json_name = 10; + * @param string $var + * @return $this + */ + public function setJsonName($var) + { + GPBUtil::checkString($var, True); + $this->json_name = $var; + $this->has_json_name = true; + + return $this; + } + + public function hasJsonName() + { + return $this->has_json_name; + } + + /** + * Generated from protobuf field optional .google.protobuf.FieldOptions options = 8; + * @return \Google\Protobuf\Internal\FieldOptions + */ + public function getOptions() + { + return $this->options; + } + + /** + * Generated from protobuf field optional .google.protobuf.FieldOptions options = 8; + * @param \Google\Protobuf\Internal\FieldOptions $var + * @return $this + */ + public function setOptions($var) + { + GPBUtil::checkMessage($var, \Google\Protobuf\Internal\FieldOptions::class); + $this->options = $var; + $this->has_options = true; + + return $this; + } + + public function hasOptions() + { + return $this->has_options; + } + +} + diff --git a/src/pro/Google/Protobuf/Internal/FieldDescriptorProto/Label.php b/src/pro/Google/Protobuf/Internal/FieldDescriptorProto/Label.php new file mode 100644 index 00000000..a54b228f --- /dev/null +++ b/src/pro/Google/Protobuf/Internal/FieldDescriptorProto/Label.php @@ -0,0 +1,58 @@ +google.protobuf.FieldDescriptorProto.Label + */ +class Label +{ + /** + * 0 is reserved for errors + * + * Generated from protobuf enum LABEL_OPTIONAL = 1; + */ + const LABEL_OPTIONAL = 1; + /** + * Generated from protobuf enum LABEL_REQUIRED = 2; + */ + const LABEL_REQUIRED = 2; + /** + * Generated from protobuf enum LABEL_REPEATED = 3; + */ + 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); + diff --git a/src/pro/Google/Protobuf/Internal/FieldDescriptorProto/Type.php b/src/pro/Google/Protobuf/Internal/FieldDescriptorProto/Type.php new file mode 100644 index 00000000..6072e999 --- /dev/null +++ b/src/pro/Google/Protobuf/Internal/FieldDescriptorProto/Type.php @@ -0,0 +1,153 @@ +google.protobuf.FieldDescriptorProto.Type + */ +class Type +{ + /** + * 0 is reserved for errors. + * Order is weird for historical reasons. + * + * Generated from protobuf enum TYPE_DOUBLE = 1; + */ + const TYPE_DOUBLE = 1; + /** + * Generated from protobuf enum TYPE_FLOAT = 2; + */ + const TYPE_FLOAT = 2; + /** + * Not ZigZag encoded. Negative numbers take 10 bytes. Use TYPE_SINT64 if + * negative values are likely. + * + * Generated from protobuf enum TYPE_INT64 = 3; + */ + const TYPE_INT64 = 3; + /** + * Generated from protobuf enum TYPE_UINT64 = 4; + */ + const TYPE_UINT64 = 4; + /** + * Not ZigZag encoded. Negative numbers take 10 bytes. Use TYPE_SINT32 if + * negative values are likely. + * + * Generated from protobuf enum TYPE_INT32 = 5; + */ + const TYPE_INT32 = 5; + /** + * Generated from protobuf enum TYPE_FIXED64 = 6; + */ + const TYPE_FIXED64 = 6; + /** + * Generated from protobuf enum TYPE_FIXED32 = 7; + */ + const TYPE_FIXED32 = 7; + /** + * Generated from protobuf enum TYPE_BOOL = 8; + */ + const TYPE_BOOL = 8; + /** + * Generated from protobuf enum TYPE_STRING = 9; + */ + 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 TYPE_GROUP = 10; + */ + const TYPE_GROUP = 10; + /** + * Length-delimited aggregate. + * + * Generated from protobuf enum TYPE_MESSAGE = 11; + */ + const TYPE_MESSAGE = 11; + /** + * New in version 2. + * + * Generated from protobuf enum TYPE_BYTES = 12; + */ + const TYPE_BYTES = 12; + /** + * Generated from protobuf enum TYPE_UINT32 = 13; + */ + const TYPE_UINT32 = 13; + /** + * Generated from protobuf enum TYPE_ENUM = 14; + */ + const TYPE_ENUM = 14; + /** + * Generated from protobuf enum TYPE_SFIXED32 = 15; + */ + const TYPE_SFIXED32 = 15; + /** + * Generated from protobuf enum TYPE_SFIXED64 = 16; + */ + const TYPE_SFIXED64 = 16; + /** + * Uses ZigZag encoding. + * + * Generated from protobuf enum TYPE_SINT32 = 17; + */ + const TYPE_SINT32 = 17; + /** + * Uses ZigZag encoding. + * + * Generated from protobuf enum TYPE_SINT64 = 18; + */ + 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); + diff --git a/src/pro/Google/Protobuf/Internal/FieldDescriptorProto_Label.php b/src/pro/Google/Protobuf/Internal/FieldDescriptorProto_Label.php new file mode 100644 index 00000000..218a846e --- /dev/null +++ b/src/pro/Google/Protobuf/Internal/FieldDescriptorProto_Label.php @@ -0,0 +1,16 @@ +google.protobuf.FieldOptions + */ +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 optional .google.protobuf.FieldOptions.CType ctype = 1 [default = STRING]; + */ + protected $ctype = 0; + private $has_ctype = false; + /** + * 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 optional bool packed = 2; + */ + protected $packed = false; + private $has_packed = false; + /** + * 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 optional .google.protobuf.FieldOptions.JSType jstype = 6 [default = JS_NORMAL]; + */ + protected $jstype = 0; + private $has_jstype = false; + /** + * 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. + * + * Generated from protobuf field optional bool lazy = 5 [default = false]; + */ + protected $lazy = false; + private $has_lazy = false; + /** + * 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 optional bool deprecated = 3 [default = false]; + */ + protected $deprecated = false; + private $has_deprecated = false; + /** + * For Google-internal migration only. Do not use. + * + * Generated from protobuf field optional bool weak = 10 [default = false]; + */ + protected $weak = false; + private $has_weak = false; + /** + * The parser stores options it doesn't recognize here. See above. + * + * Generated from protobuf field repeated .google.protobuf.UninterpretedOption uninterpreted_option = 999; + */ + private $uninterpreted_option; + private $has_uninterpreted_option = false; + + /** + * 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. + * @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 \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 optional .google.protobuf.FieldOptions.CType ctype = 1 [default = STRING]; + * @return int + */ + public function getCtype() + { + return $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 optional .google.protobuf.FieldOptions.CType ctype = 1 [default = STRING]; + * @param int $var + * @return $this + */ + public function setCtype($var) + { + GPBUtil::checkEnum($var, \Google\Protobuf\Internal\FieldOptions_CType::class); + $this->ctype = $var; + $this->has_ctype = true; + + return $this; + } + + public function hasCtype() + { + return $this->has_ctype; + } + + /** + * 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 optional bool packed = 2; + * @return bool + */ + public function getPacked() + { + return $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 optional bool packed = 2; + * @param bool $var + * @return $this + */ + public function setPacked($var) + { + GPBUtil::checkBool($var); + $this->packed = $var; + $this->has_packed = true; + + return $this; + } + + public function hasPacked() + { + return $this->has_packed; + } + + /** + * 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 optional .google.protobuf.FieldOptions.JSType jstype = 6 [default = JS_NORMAL]; + * @return int + */ + public function getJstype() + { + return $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 optional .google.protobuf.FieldOptions.JSType jstype = 6 [default = JS_NORMAL]; + * @param int $var + * @return $this + */ + public function setJstype($var) + { + GPBUtil::checkEnum($var, \Google\Protobuf\Internal\FieldOptions_JSType::class); + $this->jstype = $var; + $this->has_jstype = true; + + return $this; + } + + public function hasJstype() + { + return $this->has_jstype; + } + + /** + * 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. + * + * Generated from protobuf field optional bool lazy = 5 [default = false]; + * @return bool + */ + public function getLazy() + { + return $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. + * + * Generated from protobuf field optional bool lazy = 5 [default = false]; + * @param bool $var + * @return $this + */ + public function setLazy($var) + { + GPBUtil::checkBool($var); + $this->lazy = $var; + $this->has_lazy = true; + + return $this; + } + + public function hasLazy() + { + return $this->has_lazy; + } + + /** + * 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 optional bool deprecated = 3 [default = false]; + * @return bool + */ + public function getDeprecated() + { + return $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 optional bool deprecated = 3 [default = false]; + * @param bool $var + * @return $this + */ + public function setDeprecated($var) + { + GPBUtil::checkBool($var); + $this->deprecated = $var; + $this->has_deprecated = true; + + return $this; + } + + public function hasDeprecated() + { + return $this->has_deprecated; + } + + /** + * For Google-internal migration only. Do not use. + * + * Generated from protobuf field optional bool weak = 10 [default = false]; + * @return bool + */ + public function getWeak() + { + return $this->weak; + } + + /** + * For Google-internal migration only. Do not use. + * + * Generated from protobuf field optional bool weak = 10 [default = false]; + * @param bool $var + * @return $this + */ + public function setWeak($var) + { + GPBUtil::checkBool($var); + $this->weak = $var; + $this->has_weak = true; + + return $this; + } + + public function hasWeak() + { + return $this->has_weak; + } + + /** + * The parser stores options it doesn't recognize here. See above. + * + * Generated from protobuf field repeated .google.protobuf.UninterpretedOption uninterpreted_option = 999; + * @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 repeated .google.protobuf.UninterpretedOption uninterpreted_option = 999; + * @param \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; + $this->has_uninterpreted_option = true; + + return $this; + } + + public function hasUninterpretedOption() + { + return $this->has_uninterpreted_option; + } + +} + diff --git a/src/pro/Google/Protobuf/Internal/FieldOptions/CType.php b/src/pro/Google/Protobuf/Internal/FieldOptions/CType.php new file mode 100644 index 00000000..ba9eb4ad --- /dev/null +++ b/src/pro/Google/Protobuf/Internal/FieldOptions/CType.php @@ -0,0 +1,58 @@ +google.protobuf.FieldOptions.CType + */ +class CType +{ + /** + * Default mode. + * + * Generated from protobuf enum STRING = 0; + */ + const STRING = 0; + /** + * Generated from protobuf enum CORD = 1; + */ + const CORD = 1; + /** + * Generated from protobuf enum STRING_PIECE = 2; + */ + 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); + diff --git a/src/pro/Google/Protobuf/Internal/FieldOptions/JSType.php b/src/pro/Google/Protobuf/Internal/FieldOptions/JSType.php new file mode 100644 index 00000000..175a4330 --- /dev/null +++ b/src/pro/Google/Protobuf/Internal/FieldOptions/JSType.php @@ -0,0 +1,62 @@ +google.protobuf.FieldOptions.JSType + */ +class JSType +{ + /** + * Use the default type. + * + * Generated from protobuf enum JS_NORMAL = 0; + */ + const JS_NORMAL = 0; + /** + * Use JavaScript strings. + * + * Generated from protobuf enum JS_STRING = 1; + */ + const JS_STRING = 1; + /** + * Use JavaScript numbers. + * + * Generated from protobuf enum JS_NUMBER = 2; + */ + 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); + diff --git a/src/pro/Google/Protobuf/Internal/FieldOptions_CType.php b/src/pro/Google/Protobuf/Internal/FieldOptions_CType.php new file mode 100644 index 00000000..4d18783e --- /dev/null +++ b/src/pro/Google/Protobuf/Internal/FieldOptions_CType.php @@ -0,0 +1,16 @@ +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; + } +} diff --git a/src/pro/Google/Protobuf/Internal/FileDescriptorProto.php b/src/pro/Google/Protobuf/Internal/FileDescriptorProto.php new file mode 100644 index 00000000..c9e3648c --- /dev/null +++ b/src/pro/Google/Protobuf/Internal/FileDescriptorProto.php @@ -0,0 +1,519 @@ +google.protobuf.FileDescriptorProto + */ +class FileDescriptorProto extends \Google\Protobuf\Internal\Message +{ + /** + * file name, relative to root of source tree + * + * Generated from protobuf field optional string name = 1; + */ + protected $name = ''; + private $has_name = false; + /** + * e.g. "foo", "foo.bar", etc. + * + * Generated from protobuf field optional string package = 2; + */ + protected $package = ''; + private $has_package = false; + /** + * Names of files imported by this file. + * + * Generated from protobuf field repeated string dependency = 3; + */ + private $dependency; + private $has_dependency = false; + /** + * Indexes of the public imported files in the dependency list above. + * + * Generated from protobuf field repeated int32 public_dependency = 10; + */ + private $public_dependency; + private $has_public_dependency = false; + /** + * Indexes of the weak imported files in the dependency list. + * For Google-internal migration only. Do not use. + * + * Generated from protobuf field repeated int32 weak_dependency = 11; + */ + private $weak_dependency; + private $has_weak_dependency = false; + /** + * All top-level definitions in this file. + * + * Generated from protobuf field repeated .google.protobuf.DescriptorProto message_type = 4; + */ + private $message_type; + private $has_message_type = false; + /** + * Generated from protobuf field repeated .google.protobuf.EnumDescriptorProto enum_type = 5; + */ + private $enum_type; + private $has_enum_type = false; + /** + * Generated from protobuf field repeated .google.protobuf.ServiceDescriptorProto service = 6; + */ + private $service; + private $has_service = false; + /** + * Generated from protobuf field repeated .google.protobuf.FieldDescriptorProto extension = 7; + */ + private $extension; + private $has_extension = false; + /** + * Generated from protobuf field optional .google.protobuf.FileOptions options = 8; + */ + protected $options = null; + private $has_options = false; + /** + * 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 optional .google.protobuf.SourceCodeInfo source_code_info = 9; + */ + protected $source_code_info = null; + private $has_source_code_info = false; + /** + * The syntax of the proto file. + * The supported values are "proto2" and "proto3". + * + * Generated from protobuf field optional string syntax = 12; + */ + protected $syntax = ''; + private $has_syntax = false; + + /** + * 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 string[]|\Google\Protobuf\Internal\RepeatedField $dependency + * Names of files imported by this file. + * @type int[]|\Google\Protobuf\Internal\RepeatedField $public_dependency + * Indexes of the public imported files in the dependency list above. + * @type 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 \Google\Protobuf\Internal\DescriptorProto[]|\Google\Protobuf\Internal\RepeatedField $message_type + * All top-level definitions in this file. + * @type \Google\Protobuf\Internal\EnumDescriptorProto[]|\Google\Protobuf\Internal\RepeatedField $enum_type + * @type \Google\Protobuf\Internal\ServiceDescriptorProto[]|\Google\Protobuf\Internal\RepeatedField $service + * @type \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" and "proto3". + * } + */ + 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 optional string name = 1; + * @return string + */ + public function getName() + { + return $this->name; + } + + /** + * file name, relative to root of source tree + * + * Generated from protobuf field optional string name = 1; + * @param string $var + * @return $this + */ + public function setName($var) + { + GPBUtil::checkString($var, True); + $this->name = $var; + $this->has_name = true; + + return $this; + } + + public function hasName() + { + return $this->has_name; + } + + /** + * e.g. "foo", "foo.bar", etc. + * + * Generated from protobuf field optional string package = 2; + * @return string + */ + public function getPackage() + { + return $this->package; + } + + /** + * e.g. "foo", "foo.bar", etc. + * + * Generated from protobuf field optional string package = 2; + * @param string $var + * @return $this + */ + public function setPackage($var) + { + GPBUtil::checkString($var, True); + $this->package = $var; + $this->has_package = true; + + return $this; + } + + public function hasPackage() + { + return $this->has_package; + } + + /** + * Names of files imported by this file. + * + * Generated from protobuf field repeated string dependency = 3; + * @return \Google\Protobuf\Internal\RepeatedField + */ + public function getDependency() + { + return $this->dependency; + } + + /** + * Names of files imported by this file. + * + * Generated from protobuf field repeated string dependency = 3; + * @param string[]|\Google\Protobuf\Internal\RepeatedField $var + * @return $this + */ + public function setDependency($var) + { + $arr = GPBUtil::checkRepeatedField($var, \Google\Protobuf\Internal\GPBType::STRING); + $this->dependency = $arr; + $this->has_dependency = true; + + return $this; + } + + public function hasDependency() + { + return $this->has_dependency; + } + + /** + * Indexes of the public imported files in the dependency list above. + * + * Generated from protobuf field repeated int32 public_dependency = 10; + * @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 repeated int32 public_dependency = 10; + * @param 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; + $this->has_public_dependency = true; + + return $this; + } + + public function hasPublicDependency() + { + return $this->has_public_dependency; + } + + /** + * Indexes of the weak imported files in the dependency list. + * For Google-internal migration only. Do not use. + * + * Generated from protobuf field repeated int32 weak_dependency = 11; + * @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 repeated int32 weak_dependency = 11; + * @param 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; + $this->has_weak_dependency = true; + + return $this; + } + + public function hasWeakDependency() + { + return $this->has_weak_dependency; + } + + /** + * All top-level definitions in this file. + * + * Generated from protobuf field repeated .google.protobuf.DescriptorProto message_type = 4; + * @return \Google\Protobuf\Internal\RepeatedField + */ + public function getMessageType() + { + return $this->message_type; + } + + /** + * All top-level definitions in this file. + * + * Generated from protobuf field repeated .google.protobuf.DescriptorProto message_type = 4; + * @param \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; + $this->has_message_type = true; + + return $this; + } + + public function hasMessageType() + { + return $this->has_message_type; + } + + /** + * Generated from protobuf field repeated .google.protobuf.EnumDescriptorProto enum_type = 5; + * @return \Google\Protobuf\Internal\RepeatedField + */ + public function getEnumType() + { + return $this->enum_type; + } + + /** + * Generated from protobuf field repeated .google.protobuf.EnumDescriptorProto enum_type = 5; + * @param \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; + $this->has_enum_type = true; + + return $this; + } + + public function hasEnumType() + { + return $this->has_enum_type; + } + + /** + * Generated from protobuf field repeated .google.protobuf.ServiceDescriptorProto service = 6; + * @return \Google\Protobuf\Internal\RepeatedField + */ + public function getService() + { + return $this->service; + } + + /** + * Generated from protobuf field repeated .google.protobuf.ServiceDescriptorProto service = 6; + * @param \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; + $this->has_service = true; + + return $this; + } + + public function hasService() + { + return $this->has_service; + } + + /** + * Generated from protobuf field repeated .google.protobuf.FieldDescriptorProto extension = 7; + * @return \Google\Protobuf\Internal\RepeatedField + */ + public function getExtension() + { + return $this->extension; + } + + /** + * Generated from protobuf field repeated .google.protobuf.FieldDescriptorProto extension = 7; + * @param \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; + $this->has_extension = true; + + return $this; + } + + public function hasExtension() + { + return $this->has_extension; + } + + /** + * Generated from protobuf field optional .google.protobuf.FileOptions options = 8; + * @return \Google\Protobuf\Internal\FileOptions + */ + public function getOptions() + { + return $this->options; + } + + /** + * Generated from protobuf field optional .google.protobuf.FileOptions options = 8; + * @param \Google\Protobuf\Internal\FileOptions $var + * @return $this + */ + public function setOptions($var) + { + GPBUtil::checkMessage($var, \Google\Protobuf\Internal\FileOptions::class); + $this->options = $var; + $this->has_options = true; + + return $this; + } + + public function hasOptions() + { + return $this->has_options; + } + + /** + * 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 optional .google.protobuf.SourceCodeInfo source_code_info = 9; + * @return \Google\Protobuf\Internal\SourceCodeInfo + */ + public function getSourceCodeInfo() + { + return $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 optional .google.protobuf.SourceCodeInfo source_code_info = 9; + * @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; + $this->has_source_code_info = true; + + return $this; + } + + public function hasSourceCodeInfo() + { + return $this->has_source_code_info; + } + + /** + * The syntax of the proto file. + * The supported values are "proto2" and "proto3". + * + * Generated from protobuf field optional string syntax = 12; + * @return string + */ + public function getSyntax() + { + return $this->syntax; + } + + /** + * The syntax of the proto file. + * The supported values are "proto2" and "proto3". + * + * Generated from protobuf field optional string syntax = 12; + * @param string $var + * @return $this + */ + public function setSyntax($var) + { + GPBUtil::checkString($var, True); + $this->syntax = $var; + $this->has_syntax = true; + + return $this; + } + + public function hasSyntax() + { + return $this->has_syntax; + } + +} + diff --git a/src/pro/Google/Protobuf/Internal/FileDescriptorSet.php b/src/pro/Google/Protobuf/Internal/FileDescriptorSet.php new file mode 100644 index 00000000..9907b17d --- /dev/null +++ b/src/pro/Google/Protobuf/Internal/FileDescriptorSet.php @@ -0,0 +1,70 @@ +google.protobuf.FileDescriptorSet + */ +class FileDescriptorSet extends \Google\Protobuf\Internal\Message +{ + /** + * Generated from protobuf field repeated .google.protobuf.FileDescriptorProto file = 1; + */ + private $file; + private $has_file = false; + + /** + * Constructor. + * + * @param array $data { + * Optional. Data for populating the Message object. + * + * @type \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 repeated .google.protobuf.FileDescriptorProto file = 1; + * @return \Google\Protobuf\Internal\RepeatedField + */ + public function getFile() + { + return $this->file; + } + + /** + * Generated from protobuf field repeated .google.protobuf.FileDescriptorProto file = 1; + * @param \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; + $this->has_file = true; + + return $this; + } + + public function hasFile() + { + return $this->has_file; + } + +} + diff --git a/src/pro/Google/Protobuf/Internal/FileOptions.php b/src/pro/Google/Protobuf/Internal/FileOptions.php new file mode 100644 index 00000000..605d92bf --- /dev/null +++ b/src/pro/Google/Protobuf/Internal/FileOptions.php @@ -0,0 +1,1046 @@ +google.protobuf.FileOptions + */ +class FileOptions extends \Google\Protobuf\Internal\Message +{ + /** + * Sets the Java package where classes generated from this .proto will be + * placed. By default, the proto package is used, but this is often + * inappropriate because proto packages do not normally start with backwards + * domain names. + * + * Generated from protobuf field optional string java_package = 1; + */ + protected $java_package = ''; + private $has_java_package = false; + /** + * If set, all the classes from the .proto file are wrapped in a single + * outer class with the given name. This applies to both Proto1 + * (equivalent to the old "--one_java_file" option) and Proto2 (where + * a .proto always translates to a single class, but you may want to + * explicitly choose the class name). + * + * Generated from protobuf field optional string java_outer_classname = 8; + */ + protected $java_outer_classname = ''; + private $has_java_outer_classname = false; + /** + * If set true, then the Java code generator will generate a separate .java + * file for each top-level message, enum, and service defined in the .proto + * file. Thus, these types will *not* be nested inside the outer class + * named by java_outer_classname. However, the outer class will still be + * generated to contain the file's getDescriptor() method as well as any + * top-level extensions defined in the file. + * + * Generated from protobuf field optional bool java_multiple_files = 10 [default = false]; + */ + protected $java_multiple_files = false; + private $has_java_multiple_files = false; + /** + * This option does nothing. + * + * Generated from protobuf field optional bool java_generate_equals_and_hash = 20 [deprecated = true]; + */ + protected $java_generate_equals_and_hash = false; + private $has_java_generate_equals_and_hash = false; + /** + * If set true, then the Java2 code generator will generate code that + * throws an exception whenever an attempt is made to assign a non-UTF-8 + * byte sequence to a string field. + * Message reflection will do the same. + * However, an extension field still accepts non-UTF-8 byte sequences. + * This option has no effect on when used with the lite runtime. + * + * Generated from protobuf field optional bool java_string_check_utf8 = 27 [default = false]; + */ + protected $java_string_check_utf8 = false; + private $has_java_string_check_utf8 = false; + /** + * Generated from protobuf field optional .google.protobuf.FileOptions.OptimizeMode optimize_for = 9 [default = SPEED]; + */ + protected $optimize_for = 0; + private $has_optimize_for = false; + /** + * Sets the Go package where structs generated from this .proto will be + * placed. If omitted, the Go package will be derived from the following: + * - The basename of the package import path, if provided. + * - Otherwise, the package statement in the .proto file, if present. + * - Otherwise, the basename of the .proto file, without extension. + * + * Generated from protobuf field optional string go_package = 11; + */ + protected $go_package = ''; + private $has_go_package = false; + /** + * Should generic services be generated in each language? "Generic" services + * are not specific to any particular RPC system. They are generated by the + * main code generators in each language (without additional plugins). + * Generic services were the only kind of service generation supported by + * early versions of google.protobuf. + * Generic services are now considered deprecated in favor of using plugins + * that generate code specific to your particular RPC system. Therefore, + * these default to false. Old code which depends on generic services should + * explicitly set them to true. + * + * Generated from protobuf field optional bool cc_generic_services = 16 [default = false]; + */ + protected $cc_generic_services = false; + private $has_cc_generic_services = false; + /** + * Generated from protobuf field optional bool java_generic_services = 17 [default = false]; + */ + protected $java_generic_services = false; + private $has_java_generic_services = false; + /** + * Generated from protobuf field optional bool py_generic_services = 18 [default = false]; + */ + protected $py_generic_services = false; + private $has_py_generic_services = false; + /** + * Generated from protobuf field optional bool php_generic_services = 42 [default = false]; + */ + protected $php_generic_services = false; + private $has_php_generic_services = false; + /** + * Is this file deprecated? + * Depending on the target platform, this can emit Deprecated annotations + * for everything in the file, or it will be completely ignored; in the very + * least, this is a formalization for deprecating files. + * + * Generated from protobuf field optional bool deprecated = 23 [default = false]; + */ + protected $deprecated = false; + private $has_deprecated = false; + /** + * Enables the use of arenas for the proto messages in this file. This applies + * only to generated classes for C++. + * + * Generated from protobuf field optional bool cc_enable_arenas = 31 [default = false]; + */ + protected $cc_enable_arenas = false; + private $has_cc_enable_arenas = false; + /** + * Sets the objective c class prefix which is prepended to all objective c + * generated classes from this .proto. There is no default. + * + * Generated from protobuf field optional string objc_class_prefix = 36; + */ + protected $objc_class_prefix = ''; + private $has_objc_class_prefix = false; + /** + * Namespace for generated classes; defaults to the package. + * + * Generated from protobuf field optional string csharp_namespace = 37; + */ + protected $csharp_namespace = ''; + private $has_csharp_namespace = false; + /** + * By default Swift generators will take the proto package and CamelCase it + * replacing '.' with underscore and use that to prefix the types/symbols + * defined. When this options is provided, they will use this value instead + * to prefix the types/symbols defined. + * + * Generated from protobuf field optional string swift_prefix = 39; + */ + protected $swift_prefix = ''; + private $has_swift_prefix = false; + /** + * Sets the php class prefix which is prepended to all php generated classes + * from this .proto. Default is empty. + * + * Generated from protobuf field optional string php_class_prefix = 40; + */ + protected $php_class_prefix = ''; + private $has_php_class_prefix = false; + /** + * Use this option to change the namespace of php generated classes. Default + * is empty. When this option is empty, the package name will be used for + * determining the namespace. + * + * Generated from protobuf field optional string php_namespace = 41; + */ + protected $php_namespace = ''; + private $has_php_namespace = false; + /** + * Use this option to change the namespace of php generated metadata classes. + * Default is empty. When this option is empty, the proto file name will be + * used for determining the namespace. + * + * Generated from protobuf field optional string php_metadata_namespace = 44; + */ + protected $php_metadata_namespace = ''; + private $has_php_metadata_namespace = false; + /** + * Use this option to change the package of ruby generated classes. Default + * is empty. When this option is not set, the package name will be used for + * determining the ruby package. + * + * Generated from protobuf field optional string ruby_package = 45; + */ + protected $ruby_package = ''; + private $has_ruby_package = false; + /** + * The parser stores options it doesn't recognize here. + * See the documentation for the "Options" section above. + * + * Generated from protobuf field repeated .google.protobuf.UninterpretedOption uninterpreted_option = 999; + */ + private $uninterpreted_option; + private $has_uninterpreted_option = false; + + /** + * Constructor. + * + * @param array $data { + * Optional. Data for populating the Message object. + * + * @type string $java_package + * Sets the Java package where classes generated from this .proto will be + * placed. By default, the proto package is used, but this is often + * inappropriate because proto packages do not normally start with backwards + * domain names. + * @type string $java_outer_classname + * If set, all the classes from the .proto file are wrapped in a single + * outer class with the given name. This applies to both Proto1 + * (equivalent to the old "--one_java_file" option) and Proto2 (where + * a .proto always translates to a single class, but you may want to + * explicitly choose the class name). + * @type bool $java_multiple_files + * If set true, then the Java code generator will generate a separate .java + * file for each top-level message, enum, and service defined in the .proto + * file. Thus, these types will *not* be nested inside the outer class + * named by java_outer_classname. However, the outer class will still be + * generated to contain the file's getDescriptor() method as well as any + * top-level extensions defined in the file. + * @type bool $java_generate_equals_and_hash + * This option does nothing. + * @type bool $java_string_check_utf8 + * If set true, then the Java2 code generator will generate code that + * throws an exception whenever an attempt is made to assign a non-UTF-8 + * byte sequence to a string field. + * Message reflection will do the same. + * However, an extension field still accepts non-UTF-8 byte sequences. + * This option has no effect on when used with the lite runtime. + * @type int $optimize_for + * @type string $go_package + * Sets the Go package where structs generated from this .proto will be + * placed. If omitted, the Go package will be derived from the following: + * - The basename of the package import path, if provided. + * - Otherwise, the package statement in the .proto file, if present. + * - Otherwise, the basename of the .proto file, without extension. + * @type bool $cc_generic_services + * Should generic services be generated in each language? "Generic" services + * are not specific to any particular RPC system. They are generated by the + * main code generators in each language (without additional plugins). + * Generic services were the only kind of service generation supported by + * early versions of google.protobuf. + * Generic services are now considered deprecated in favor of using plugins + * that generate code specific to your particular RPC system. Therefore, + * these default to false. Old code which depends on generic services should + * explicitly set them to true. + * @type bool $java_generic_services + * @type bool $py_generic_services + * @type bool $php_generic_services + * @type bool $deprecated + * Is this file deprecated? + * Depending on the target platform, this can emit Deprecated annotations + * for everything in the file, or it will be completely ignored; in the very + * least, this is a formalization for deprecating files. + * @type bool $cc_enable_arenas + * Enables the use of arenas for the proto messages in this file. This applies + * only to generated classes for C++. + * @type string $objc_class_prefix + * Sets the objective c class prefix which is prepended to all objective c + * generated classes from this .proto. There is no default. + * @type string $csharp_namespace + * Namespace for generated classes; defaults to the package. + * @type string $swift_prefix + * By default Swift generators will take the proto package and CamelCase it + * replacing '.' with underscore and use that to prefix the types/symbols + * defined. When this options is provided, they will use this value instead + * to prefix the types/symbols defined. + * @type string $php_class_prefix + * Sets the php class prefix which is prepended to all php generated classes + * from this .proto. Default is empty. + * @type string $php_namespace + * Use this option to change the namespace of php generated classes. Default + * is empty. When this option is empty, the package name will be used for + * determining the namespace. + * @type string $php_metadata_namespace + * Use this option to change the namespace of php generated metadata classes. + * Default is empty. When this option is empty, the proto file name will be + * used for determining the namespace. + * @type string $ruby_package + * Use this option to change the package of ruby generated classes. Default + * is empty. When this option is not set, the package name will be used for + * determining the ruby package. + * @type \Google\Protobuf\Internal\UninterpretedOption[]|\Google\Protobuf\Internal\RepeatedField $uninterpreted_option + * The parser stores options it doesn't recognize here. + * See the documentation for the "Options" section above. + * } + */ + public function __construct($data = NULL) { + \GPBMetadata\Google\Protobuf\Internal\Descriptor::initOnce(); + parent::__construct($data); + } + + /** + * Sets the Java package where classes generated from this .proto will be + * placed. By default, the proto package is used, but this is often + * inappropriate because proto packages do not normally start with backwards + * domain names. + * + * Generated from protobuf field optional string java_package = 1; + * @return string + */ + public function getJavaPackage() + { + return $this->java_package; + } + + /** + * Sets the Java package where classes generated from this .proto will be + * placed. By default, the proto package is used, but this is often + * inappropriate because proto packages do not normally start with backwards + * domain names. + * + * Generated from protobuf field optional string java_package = 1; + * @param string $var + * @return $this + */ + public function setJavaPackage($var) + { + GPBUtil::checkString($var, True); + $this->java_package = $var; + $this->has_java_package = true; + + return $this; + } + + public function hasJavaPackage() + { + return $this->has_java_package; + } + + /** + * If set, all the classes from the .proto file are wrapped in a single + * outer class with the given name. This applies to both Proto1 + * (equivalent to the old "--one_java_file" option) and Proto2 (where + * a .proto always translates to a single class, but you may want to + * explicitly choose the class name). + * + * Generated from protobuf field optional string java_outer_classname = 8; + * @return string + */ + public function getJavaOuterClassname() + { + return $this->java_outer_classname; + } + + /** + * If set, all the classes from the .proto file are wrapped in a single + * outer class with the given name. This applies to both Proto1 + * (equivalent to the old "--one_java_file" option) and Proto2 (where + * a .proto always translates to a single class, but you may want to + * explicitly choose the class name). + * + * Generated from protobuf field optional string java_outer_classname = 8; + * @param string $var + * @return $this + */ + public function setJavaOuterClassname($var) + { + GPBUtil::checkString($var, True); + $this->java_outer_classname = $var; + $this->has_java_outer_classname = true; + + return $this; + } + + public function hasJavaOuterClassname() + { + return $this->has_java_outer_classname; + } + + /** + * If set true, then the Java code generator will generate a separate .java + * file for each top-level message, enum, and service defined in the .proto + * file. Thus, these types will *not* be nested inside the outer class + * named by java_outer_classname. However, the outer class will still be + * generated to contain the file's getDescriptor() method as well as any + * top-level extensions defined in the file. + * + * Generated from protobuf field optional bool java_multiple_files = 10 [default = false]; + * @return bool + */ + public function getJavaMultipleFiles() + { + return $this->java_multiple_files; + } + + /** + * If set true, then the Java code generator will generate a separate .java + * file for each top-level message, enum, and service defined in the .proto + * file. Thus, these types will *not* be nested inside the outer class + * named by java_outer_classname. However, the outer class will still be + * generated to contain the file's getDescriptor() method as well as any + * top-level extensions defined in the file. + * + * Generated from protobuf field optional bool java_multiple_files = 10 [default = false]; + * @param bool $var + * @return $this + */ + public function setJavaMultipleFiles($var) + { + GPBUtil::checkBool($var); + $this->java_multiple_files = $var; + $this->has_java_multiple_files = true; + + return $this; + } + + public function hasJavaMultipleFiles() + { + return $this->has_java_multiple_files; + } + + /** + * This option does nothing. + * + * Generated from protobuf field optional bool java_generate_equals_and_hash = 20 [deprecated = true]; + * @return bool + */ + public function getJavaGenerateEqualsAndHash() + { + return $this->java_generate_equals_and_hash; + } + + /** + * This option does nothing. + * + * Generated from protobuf field optional bool java_generate_equals_and_hash = 20 [deprecated = true]; + * @param bool $var + * @return $this + */ + public function setJavaGenerateEqualsAndHash($var) + { + GPBUtil::checkBool($var); + $this->java_generate_equals_and_hash = $var; + $this->has_java_generate_equals_and_hash = true; + + return $this; + } + + public function hasJavaGenerateEqualsAndHash() + { + return $this->has_java_generate_equals_and_hash; + } + + /** + * If set true, then the Java2 code generator will generate code that + * throws an exception whenever an attempt is made to assign a non-UTF-8 + * byte sequence to a string field. + * Message reflection will do the same. + * However, an extension field still accepts non-UTF-8 byte sequences. + * This option has no effect on when used with the lite runtime. + * + * Generated from protobuf field optional bool java_string_check_utf8 = 27 [default = false]; + * @return bool + */ + public function getJavaStringCheckUtf8() + { + return $this->java_string_check_utf8; + } + + /** + * If set true, then the Java2 code generator will generate code that + * throws an exception whenever an attempt is made to assign a non-UTF-8 + * byte sequence to a string field. + * Message reflection will do the same. + * However, an extension field still accepts non-UTF-8 byte sequences. + * This option has no effect on when used with the lite runtime. + * + * Generated from protobuf field optional bool java_string_check_utf8 = 27 [default = false]; + * @param bool $var + * @return $this + */ + public function setJavaStringCheckUtf8($var) + { + GPBUtil::checkBool($var); + $this->java_string_check_utf8 = $var; + $this->has_java_string_check_utf8 = true; + + return $this; + } + + public function hasJavaStringCheckUtf8() + { + return $this->has_java_string_check_utf8; + } + + /** + * Generated from protobuf field optional .google.protobuf.FileOptions.OptimizeMode optimize_for = 9 [default = SPEED]; + * @return int + */ + public function getOptimizeFor() + { + return $this->optimize_for; + } + + /** + * Generated from protobuf field optional .google.protobuf.FileOptions.OptimizeMode optimize_for = 9 [default = SPEED]; + * @param int $var + * @return $this + */ + public function setOptimizeFor($var) + { + GPBUtil::checkEnum($var, \Google\Protobuf\Internal\FileOptions_OptimizeMode::class); + $this->optimize_for = $var; + $this->has_optimize_for = true; + + return $this; + } + + public function hasOptimizeFor() + { + return $this->has_optimize_for; + } + + /** + * Sets the Go package where structs generated from this .proto will be + * placed. If omitted, the Go package will be derived from the following: + * - The basename of the package import path, if provided. + * - Otherwise, the package statement in the .proto file, if present. + * - Otherwise, the basename of the .proto file, without extension. + * + * Generated from protobuf field optional string go_package = 11; + * @return string + */ + public function getGoPackage() + { + return $this->go_package; + } + + /** + * Sets the Go package where structs generated from this .proto will be + * placed. If omitted, the Go package will be derived from the following: + * - The basename of the package import path, if provided. + * - Otherwise, the package statement in the .proto file, if present. + * - Otherwise, the basename of the .proto file, without extension. + * + * Generated from protobuf field optional string go_package = 11; + * @param string $var + * @return $this + */ + public function setGoPackage($var) + { + GPBUtil::checkString($var, True); + $this->go_package = $var; + $this->has_go_package = true; + + return $this; + } + + public function hasGoPackage() + { + return $this->has_go_package; + } + + /** + * Should generic services be generated in each language? "Generic" services + * are not specific to any particular RPC system. They are generated by the + * main code generators in each language (without additional plugins). + * Generic services were the only kind of service generation supported by + * early versions of google.protobuf. + * Generic services are now considered deprecated in favor of using plugins + * that generate code specific to your particular RPC system. Therefore, + * these default to false. Old code which depends on generic services should + * explicitly set them to true. + * + * Generated from protobuf field optional bool cc_generic_services = 16 [default = false]; + * @return bool + */ + public function getCcGenericServices() + { + return $this->cc_generic_services; + } + + /** + * Should generic services be generated in each language? "Generic" services + * are not specific to any particular RPC system. They are generated by the + * main code generators in each language (without additional plugins). + * Generic services were the only kind of service generation supported by + * early versions of google.protobuf. + * Generic services are now considered deprecated in favor of using plugins + * that generate code specific to your particular RPC system. Therefore, + * these default to false. Old code which depends on generic services should + * explicitly set them to true. + * + * Generated from protobuf field optional bool cc_generic_services = 16 [default = false]; + * @param bool $var + * @return $this + */ + public function setCcGenericServices($var) + { + GPBUtil::checkBool($var); + $this->cc_generic_services = $var; + $this->has_cc_generic_services = true; + + return $this; + } + + public function hasCcGenericServices() + { + return $this->has_cc_generic_services; + } + + /** + * Generated from protobuf field optional bool java_generic_services = 17 [default = false]; + * @return bool + */ + public function getJavaGenericServices() + { + return $this->java_generic_services; + } + + /** + * Generated from protobuf field optional bool java_generic_services = 17 [default = false]; + * @param bool $var + * @return $this + */ + public function setJavaGenericServices($var) + { + GPBUtil::checkBool($var); + $this->java_generic_services = $var; + $this->has_java_generic_services = true; + + return $this; + } + + public function hasJavaGenericServices() + { + return $this->has_java_generic_services; + } + + /** + * Generated from protobuf field optional bool py_generic_services = 18 [default = false]; + * @return bool + */ + public function getPyGenericServices() + { + return $this->py_generic_services; + } + + /** + * Generated from protobuf field optional bool py_generic_services = 18 [default = false]; + * @param bool $var + * @return $this + */ + public function setPyGenericServices($var) + { + GPBUtil::checkBool($var); + $this->py_generic_services = $var; + $this->has_py_generic_services = true; + + return $this; + } + + public function hasPyGenericServices() + { + return $this->has_py_generic_services; + } + + /** + * Generated from protobuf field optional bool php_generic_services = 42 [default = false]; + * @return bool + */ + public function getPhpGenericServices() + { + return $this->php_generic_services; + } + + /** + * Generated from protobuf field optional bool php_generic_services = 42 [default = false]; + * @param bool $var + * @return $this + */ + public function setPhpGenericServices($var) + { + GPBUtil::checkBool($var); + $this->php_generic_services = $var; + $this->has_php_generic_services = true; + + return $this; + } + + public function hasPhpGenericServices() + { + return $this->has_php_generic_services; + } + + /** + * Is this file deprecated? + * Depending on the target platform, this can emit Deprecated annotations + * for everything in the file, or it will be completely ignored; in the very + * least, this is a formalization for deprecating files. + * + * Generated from protobuf field optional bool deprecated = 23 [default = false]; + * @return bool + */ + public function getDeprecated() + { + return $this->deprecated; + } + + /** + * Is this file deprecated? + * Depending on the target platform, this can emit Deprecated annotations + * for everything in the file, or it will be completely ignored; in the very + * least, this is a formalization for deprecating files. + * + * Generated from protobuf field optional bool deprecated = 23 [default = false]; + * @param bool $var + * @return $this + */ + public function setDeprecated($var) + { + GPBUtil::checkBool($var); + $this->deprecated = $var; + $this->has_deprecated = true; + + return $this; + } + + public function hasDeprecated() + { + return $this->has_deprecated; + } + + /** + * Enables the use of arenas for the proto messages in this file. This applies + * only to generated classes for C++. + * + * Generated from protobuf field optional bool cc_enable_arenas = 31 [default = false]; + * @return bool + */ + public function getCcEnableArenas() + { + return $this->cc_enable_arenas; + } + + /** + * Enables the use of arenas for the proto messages in this file. This applies + * only to generated classes for C++. + * + * Generated from protobuf field optional bool cc_enable_arenas = 31 [default = false]; + * @param bool $var + * @return $this + */ + public function setCcEnableArenas($var) + { + GPBUtil::checkBool($var); + $this->cc_enable_arenas = $var; + $this->has_cc_enable_arenas = true; + + return $this; + } + + public function hasCcEnableArenas() + { + return $this->has_cc_enable_arenas; + } + + /** + * Sets the objective c class prefix which is prepended to all objective c + * generated classes from this .proto. There is no default. + * + * Generated from protobuf field optional string objc_class_prefix = 36; + * @return string + */ + public function getObjcClassPrefix() + { + return $this->objc_class_prefix; + } + + /** + * Sets the objective c class prefix which is prepended to all objective c + * generated classes from this .proto. There is no default. + * + * Generated from protobuf field optional string objc_class_prefix = 36; + * @param string $var + * @return $this + */ + public function setObjcClassPrefix($var) + { + GPBUtil::checkString($var, True); + $this->objc_class_prefix = $var; + $this->has_objc_class_prefix = true; + + return $this; + } + + public function hasObjcClassPrefix() + { + return $this->has_objc_class_prefix; + } + + /** + * Namespace for generated classes; defaults to the package. + * + * Generated from protobuf field optional string csharp_namespace = 37; + * @return string + */ + public function getCsharpNamespace() + { + return $this->csharp_namespace; + } + + /** + * Namespace for generated classes; defaults to the package. + * + * Generated from protobuf field optional string csharp_namespace = 37; + * @param string $var + * @return $this + */ + public function setCsharpNamespace($var) + { + GPBUtil::checkString($var, True); + $this->csharp_namespace = $var; + $this->has_csharp_namespace = true; + + return $this; + } + + public function hasCsharpNamespace() + { + return $this->has_csharp_namespace; + } + + /** + * By default Swift generators will take the proto package and CamelCase it + * replacing '.' with underscore and use that to prefix the types/symbols + * defined. When this options is provided, they will use this value instead + * to prefix the types/symbols defined. + * + * Generated from protobuf field optional string swift_prefix = 39; + * @return string + */ + public function getSwiftPrefix() + { + return $this->swift_prefix; + } + + /** + * By default Swift generators will take the proto package and CamelCase it + * replacing '.' with underscore and use that to prefix the types/symbols + * defined. When this options is provided, they will use this value instead + * to prefix the types/symbols defined. + * + * Generated from protobuf field optional string swift_prefix = 39; + * @param string $var + * @return $this + */ + public function setSwiftPrefix($var) + { + GPBUtil::checkString($var, True); + $this->swift_prefix = $var; + $this->has_swift_prefix = true; + + return $this; + } + + public function hasSwiftPrefix() + { + return $this->has_swift_prefix; + } + + /** + * Sets the php class prefix which is prepended to all php generated classes + * from this .proto. Default is empty. + * + * Generated from protobuf field optional string php_class_prefix = 40; + * @return string + */ + public function getPhpClassPrefix() + { + return $this->php_class_prefix; + } + + /** + * Sets the php class prefix which is prepended to all php generated classes + * from this .proto. Default is empty. + * + * Generated from protobuf field optional string php_class_prefix = 40; + * @param string $var + * @return $this + */ + public function setPhpClassPrefix($var) + { + GPBUtil::checkString($var, True); + $this->php_class_prefix = $var; + $this->has_php_class_prefix = true; + + return $this; + } + + public function hasPhpClassPrefix() + { + return $this->has_php_class_prefix; + } + + /** + * Use this option to change the namespace of php generated classes. Default + * is empty. When this option is empty, the package name will be used for + * determining the namespace. + * + * Generated from protobuf field optional string php_namespace = 41; + * @return string + */ + public function getPhpNamespace() + { + return $this->php_namespace; + } + + /** + * Use this option to change the namespace of php generated classes. Default + * is empty. When this option is empty, the package name will be used for + * determining the namespace. + * + * Generated from protobuf field optional string php_namespace = 41; + * @param string $var + * @return $this + */ + public function setPhpNamespace($var) + { + GPBUtil::checkString($var, True); + $this->php_namespace = $var; + $this->has_php_namespace = true; + + return $this; + } + + public function hasPhpNamespace() + { + return $this->has_php_namespace; + } + + /** + * Use this option to change the namespace of php generated metadata classes. + * Default is empty. When this option is empty, the proto file name will be + * used for determining the namespace. + * + * Generated from protobuf field optional string php_metadata_namespace = 44; + * @return string + */ + public function getPhpMetadataNamespace() + { + return $this->php_metadata_namespace; + } + + /** + * Use this option to change the namespace of php generated metadata classes. + * Default is empty. When this option is empty, the proto file name will be + * used for determining the namespace. + * + * Generated from protobuf field optional string php_metadata_namespace = 44; + * @param string $var + * @return $this + */ + public function setPhpMetadataNamespace($var) + { + GPBUtil::checkString($var, True); + $this->php_metadata_namespace = $var; + $this->has_php_metadata_namespace = true; + + return $this; + } + + public function hasPhpMetadataNamespace() + { + return $this->has_php_metadata_namespace; + } + + /** + * Use this option to change the package of ruby generated classes. Default + * is empty. When this option is not set, the package name will be used for + * determining the ruby package. + * + * Generated from protobuf field optional string ruby_package = 45; + * @return string + */ + public function getRubyPackage() + { + return $this->ruby_package; + } + + /** + * Use this option to change the package of ruby generated classes. Default + * is empty. When this option is not set, the package name will be used for + * determining the ruby package. + * + * Generated from protobuf field optional string ruby_package = 45; + * @param string $var + * @return $this + */ + public function setRubyPackage($var) + { + GPBUtil::checkString($var, True); + $this->ruby_package = $var; + $this->has_ruby_package = true; + + return $this; + } + + public function hasRubyPackage() + { + return $this->has_ruby_package; + } + + /** + * The parser stores options it doesn't recognize here. + * See the documentation for the "Options" section above. + * + * Generated from protobuf field repeated .google.protobuf.UninterpretedOption uninterpreted_option = 999; + * @return \Google\Protobuf\Internal\RepeatedField + */ + public function getUninterpretedOption() + { + return $this->uninterpreted_option; + } + + /** + * The parser stores options it doesn't recognize here. + * See the documentation for the "Options" section above. + * + * Generated from protobuf field repeated .google.protobuf.UninterpretedOption uninterpreted_option = 999; + * @param \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; + $this->has_uninterpreted_option = true; + + return $this; + } + + public function hasUninterpretedOption() + { + return $this->has_uninterpreted_option; + } + +} + diff --git a/src/pro/Google/Protobuf/Internal/FileOptions/OptimizeMode.php b/src/pro/Google/Protobuf/Internal/FileOptions/OptimizeMode.php new file mode 100644 index 00000000..0df27b53 --- /dev/null +++ b/src/pro/Google/Protobuf/Internal/FileOptions/OptimizeMode.php @@ -0,0 +1,64 @@ +google.protobuf.FileOptions.OptimizeMode + */ +class OptimizeMode +{ + /** + * Generate complete code for parsing, serialization, + * + * Generated from protobuf enum SPEED = 1; + */ + const SPEED = 1; + /** + * etc. + * + * Generated from protobuf enum CODE_SIZE = 2; + */ + const CODE_SIZE = 2; + /** + * Generate code using MessageLite and the lite runtime. + * + * Generated from protobuf enum LITE_RUNTIME = 3; + */ + 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); + diff --git a/src/pro/Google/Protobuf/Internal/FileOptions_OptimizeMode.php b/src/pro/Google/Protobuf/Internal/FileOptions_OptimizeMode.php new file mode 100644 index 00000000..8926e63b --- /dev/null +++ b/src/pro/Google/Protobuf/Internal/FileOptions_OptimizeMode.php @@ -0,0 +1,16 @@ +writeRaw("\"", 1); + $field_name = GPBJsonWire::formatFieldName($field); + $output->writeRaw($field_name, strlen($field_name)); + $output->writeRaw("\":", 2); + } + return static::serializeFieldValueToStream( + $value, + $field, + $output, + !$has_field_name); + } + + public static function serializeFieldValueToStream( + $values, + $field, + &$output, + $is_well_known = false) + { + if ($field->isMap()) { + $output->writeRaw("{", 1); + $first = true; + $map_entry = $field->getMessageType(); + $key_field = $map_entry->getFieldByNumber(1); + $value_field = $map_entry->getFieldByNumber(2); + + switch ($key_field->getType()) { + case GPBType::STRING: + case GPBType::SFIXED64: + case GPBType::INT64: + case GPBType::SINT64: + case GPBType::FIXED64: + case GPBType::UINT64: + $additional_quote = false; + break; + default: + $additional_quote = true; + } + + foreach ($values as $key => $value) { + if ($first) { + $first = false; + } else { + $output->writeRaw(",", 1); + } + if ($additional_quote) { + $output->writeRaw("\"", 1); + } + if (!static::serializeSingularFieldValueToStream( + $key, + $key_field, + $output, + $is_well_known)) { + return false; + } + if ($additional_quote) { + $output->writeRaw("\"", 1); + } + $output->writeRaw(":", 1); + if (!static::serializeSingularFieldValueToStream( + $value, + $value_field, + $output, + $is_well_known)) { + return false; + } + } + $output->writeRaw("}", 1); + return true; + } elseif ($field->isRepeated()) { + $output->writeRaw("[", 1); + $first = true; + foreach ($values as $value) { + if ($first) { + $first = false; + } else { + $output->writeRaw(",", 1); + } + if (!static::serializeSingularFieldValueToStream( + $value, + $field, + $output, + $is_well_known)) { + return false; + } + } + $output->writeRaw("]", 1); + return true; + } else { + return static::serializeSingularFieldValueToStream( + $values, + $field, + $output, + $is_well_known); + } + } + + private static function serializeSingularFieldValueToStream( + $value, + $field, + &$output, $is_well_known = false) + { + switch ($field->getType()) { + case GPBType::SFIXED32: + case GPBType::SINT32: + case GPBType::INT32: + $str_value = strval($value); + $output->writeRaw($str_value, strlen($str_value)); + break; + case GPBType::FIXED32: + case GPBType::UINT32: + if ($value < 0) { + $value = bcadd($value, "4294967296"); + } + $str_value = strval($value); + $output->writeRaw($str_value, strlen($str_value)); + break; + case GPBType::FIXED64: + case GPBType::UINT64: + if ($value < 0) { + $value = bcadd($value, "18446744073709551616"); + } + // Intentional fall through. + case GPBType::SFIXED64: + case GPBType::INT64: + case GPBType::SINT64: + $output->writeRaw("\"", 1); + $str_value = strval($value); + $output->writeRaw($str_value, strlen($str_value)); + $output->writeRaw("\"", 1); + break; + case GPBType::FLOAT: + if (is_nan($value)) { + $str_value = "\"NaN\""; + } elseif ($value === INF) { + $str_value = "\"Infinity\""; + } elseif ($value === -INF) { + $str_value = "\"-Infinity\""; + } else { + $str_value = sprintf("%.8g", $value); + } + $output->writeRaw($str_value, strlen($str_value)); + break; + case GPBType::DOUBLE: + if (is_nan($value)) { + $str_value = "\"NaN\""; + } elseif ($value === INF) { + $str_value = "\"Infinity\""; + } elseif ($value === -INF) { + $str_value = "\"-Infinity\""; + } else { + $str_value = sprintf("%.17g", $value); + } + $output->writeRaw($str_value, strlen($str_value)); + break; + case GPBType::ENUM: + $enum_desc = $field->getEnumType(); + if ($enum_desc->getClass() === "Google\Protobuf\NullValue") { + $output->writeRaw("null", 4); + break; + } + $enum_value_desc = $enum_desc->getValueByNumber($value); + if (!is_null($enum_value_desc)) { + $str_value = $enum_value_desc->getName(); + $output->writeRaw("\"", 1); + $output->writeRaw($str_value, strlen($str_value)); + $output->writeRaw("\"", 1); + } else { + $str_value = strval($value); + $output->writeRaw($str_value, strlen($str_value)); + } + break; + case GPBType::BOOL: + if ($value) { + $output->writeRaw("true", 4); + } else { + $output->writeRaw("false", 5); + } + break; + case GPBType::BYTES: + $bytes_value = base64_encode($value); + $output->writeRaw("\"", 1); + $output->writeRaw($bytes_value, strlen($bytes_value)); + $output->writeRaw("\"", 1); + break; + case GPBType::STRING: + $value = json_encode($value, JSON_UNESCAPED_UNICODE); + $output->writeRaw($value, strlen($value)); + break; + // case GPBType::GROUP: + // echo "GROUP\xA"; + // trigger_error("Not implemented.", E_ERROR); + // break; + case GPBType::MESSAGE: + $value->serializeToJsonStream($output); + break; + default: + user_error("Unsupported type."); + return false; + } + return true; + } + + private static function formatFieldName($field) + { + return $field->getJsonName(); + } + + // Used for escaping control chars in strings. + private static $k_control_char_limit = 0x20; + + private static function jsonNiceEscape($c) + { + switch ($c) { + case '"': return "\\\""; + case '\\': return "\\\\"; + case '/': return "\\/"; + case '\b': return "\\b"; + case '\f': return "\\f"; + case '\n': return "\\n"; + case '\r': return "\\r"; + case '\t': return "\\t"; + default: return NULL; + } + } + + private static function isJsonEscaped($c) + { + // See RFC 4627. + return $c < chr($k_control_char_limit) || $c === "\"" || $c === "\\"; + } + + public static function escapedJson($value) + { + $escaped_value = ""; + $unescaped_run = ""; + for ($i = 0; $i < strlen($value); $i++) { + $c = $value[$i]; + // Handle escaping. + if (static::isJsonEscaped($c)) { + // Use a "nice" escape, like \n, if one exists for this + // character. + $escape = static::jsonNiceEscape($c); + if (is_null($escape)) { + $escape = "\\u00" . bin2hex($c); + } + if ($unescaped_run !== "") { + $escaped_value .= $unescaped_run; + $unescaped_run = ""; + } + $escaped_value .= $escape; + } else { + if ($unescaped_run === "") { + $unescaped_run .= $c; + } + } + } + $escaped_value .= $unescaped_run; + return $escaped_value; + } + +} diff --git a/src/pro/Google/Protobuf/Internal/GPBLabel.php b/src/pro/Google/Protobuf/Internal/GPBLabel.php new file mode 100644 index 00000000..0fb23841 --- /dev/null +++ b/src/pro/Google/Protobuf/Internal/GPBLabel.php @@ -0,0 +1,40 @@ + 0) { + $high = (int) bcsub($high, 4294967296); + } else { + $high = (int) $high; + } + if (bccomp($low, 2147483647) > 0) { + $low = (int) bcsub($low, 4294967296); + } else { + $low = (int) $low; + } + + if ($isNeg) { + $high = ~$high; + $low = ~$low; + $low++; + if (!$low) { + $high = (int)($high + 1); + } + } + + if ($trim) { + $high = 0; + } + } + + public static function checkString(&$var, $check_utf8) + { + if (is_array($var) || is_object($var)) { + throw new \InvalidArgumentException("Expect string."); + } + if (!is_string($var)) { + $var = strval($var); + } + if ($check_utf8 && !preg_match('//u', $var)) { + throw new \Exception("Expect utf-8 encoding."); + } + } + + public static function checkEnum(&$var) + { + static::checkInt32($var); + } + + public static function checkInt32(&$var) + { + if (is_numeric($var)) { + $var = intval($var); + } else { + throw new \Exception("Expect integer."); + } + } + + public static function checkUint32(&$var) + { + if (is_numeric($var)) { + if (PHP_INT_SIZE === 8) { + $var = intval($var); + $var |= ((-(($var >> 31) & 0x1)) & ~0xFFFFFFFF); + } else { + if (bccomp($var, 0x7FFFFFFF) > 0) { + $var = bcsub($var, "4294967296"); + } + $var = (int) $var; + } + } else { + throw new \Exception("Expect integer."); + } + } + + public static function checkInt64(&$var) + { + if (is_numeric($var)) { + if (PHP_INT_SIZE == 8) { + $var = intval($var); + } else { + if (is_float($var) || + is_integer($var) || + (is_string($var) && + bccomp($var, "9223372036854774784") < 0)) { + $var = number_format($var, 0, ".", ""); + } + } + } else { + throw new \Exception("Expect integer."); + } + } + + public static function checkUint64(&$var) + { + if (is_numeric($var)) { + if (PHP_INT_SIZE == 8) { + $var = intval($var); + } else { + $var = number_format($var, 0, ".", ""); + } + } else { + throw new \Exception("Expect integer."); + } + } + + public static function checkFloat(&$var) + { + if (is_float($var) || is_numeric($var)) { + $var = floatval($var); + } else { + throw new \Exception("Expect float."); + } + } + + public static function checkDouble(&$var) + { + if (is_float($var) || is_numeric($var)) { + $var = floatval($var); + } else { + throw new \Exception("Expect float."); + } + } + + public static function checkBool(&$var) + { + if (is_array($var) || is_object($var)) { + throw new \Exception("Expect boolean."); + } + $var = boolval($var); + } + + public static function checkMessage(&$var, $klass, $newClass = null) + { + + if (!$var instanceof $klass && !is_null($var)) { + throw new \Exception("Expect $klass."); + } + } + + public static function checkRepeatedField(&$var, $type, $klass = null) + { + if (!$var instanceof RepeatedField && !is_array($var)) { + throw new \Exception("Expect array."); + } + if (is_array($var)) { + $tmp = new RepeatedField($type, $klass); + foreach ($var as $value) { + $tmp[] = $value; + } + return $tmp; + } else { + if ($var->getType() != $type) { + throw new \Exception( + "Expect repeated field of different type."); + } + if ($var->getType() === GPBType::MESSAGE && + $var->getClass() !== $klass && + $var->getLegacyClass() !== $klass) { + throw new \Exception( + "Expect repeated field of " . $klass . "."); + } + return $var; + } + } + + public static function checkMapField(&$var, $key_type, $value_type, $klass = null) + { + if (!$var instanceof MapField && !is_array($var)) { + throw new \Exception("Expect dict."); + } + if (is_array($var)) { + $tmp = new MapField($key_type, $value_type, $klass); + foreach ($var as $key => $value) { + $tmp[$key] = $value; + } + return $tmp; + } else { + if ($var->getKeyType() != $key_type) { + throw new \Exception("Expect map field of key type."); + } + if ($var->getValueType() != $value_type) { + throw new \Exception("Expect map field of value type."); + } + if ($var->getValueType() === GPBType::MESSAGE && + $var->getValueClass() !== $klass && + $var->getLegacyValueClass() !== $klass) { + throw new \Exception( + "Expect map field of " . $klass . "."); + } + return $var; + } + } + + public static function Int64($value) + { + return new Int64($value); + } + + public static function Uint64($value) + { + return new Uint64($value); + } + + public static function getClassNamePrefix( + $classname, + $file_proto) + { + $option = $file_proto->getOptions(); + $prefix = is_null($option) ? "" : $option->getPhpClassPrefix(); + if ($prefix !== "") { + return $prefix; + } + + $reserved_words = array( + "abstract"=>0, "and"=>0, "array"=>0, "as"=>0, "break"=>0, + "callable"=>0, "case"=>0, "catch"=>0, "class"=>0, "clone"=>0, + "const"=>0, "continue"=>0, "declare"=>0, "default"=>0, "die"=>0, + "do"=>0, "echo"=>0, "else"=>0, "elseif"=>0, "empty"=>0, + "enddeclare"=>0, "endfor"=>0, "endforeach"=>0, "endif"=>0, + "endswitch"=>0, "endwhile"=>0, "eval"=>0, "exit"=>0, "extends"=>0, + "final"=>0, "for"=>0, "foreach"=>0, "function"=>0, "global"=>0, + "goto"=>0, "if"=>0, "implements"=>0, "include"=>0, + "include_once"=>0, "instanceof"=>0, "insteadof"=>0, "interface"=>0, + "isset"=>0, "list"=>0, "namespace"=>0, "new"=>0, "or"=>0, + "print"=>0, "private"=>0, "protected"=>0, "public"=>0, "require"=>0, + "require_once"=>0, "return"=>0, "static"=>0, "switch"=>0, + "throw"=>0, "trait"=>0, "try"=>0, "unset"=>0, "use"=>0, "var"=>0, + "while"=>0, "xor"=>0, "int"=>0, "float"=>0, "bool"=>0, "string"=>0, + "true"=>0, "false"=>0, "null"=>0, "void"=>0, "iterable"=>0 + ); + + if (array_key_exists(strtolower($classname), $reserved_words)) { + if ($file_proto->getPackage() === "google.protobuf") { + return "GPB"; + } else { + return "PB"; + } + } + + return ""; + } + + public static function getLegacyClassNameWithoutPackage( + $name, + $file_proto) + { + $classname = implode('_', explode('.', $name)); + return static::getClassNamePrefix($classname, $file_proto) . $classname; + } + + public static function getClassNameWithoutPackage( + $name, + $file_proto) + { + $parts = explode('.', $name); + foreach ($parts as $i => $part) { + $parts[$i] = static::getClassNamePrefix($parts[$i], $file_proto) . $parts[$i]; + } + return implode('\\', $parts); + } + + public static function getFullClassName( + $proto, + $containing, + $file_proto, + &$message_name_without_package, + &$classname, + &$legacy_classname, + &$fullname) + { + // Full name needs to start with '.'. + $message_name_without_package = $proto->getName(); + if ($containing !== "") { + $message_name_without_package = + $containing . "." . $message_name_without_package; + } + + $package = $file_proto->getPackage(); + if ($package === "") { + $fullname = "." . $message_name_without_package; + } else { + $fullname = "." . $package . "." . $message_name_without_package; + } + + $class_name_without_package = + static::getClassNameWithoutPackage($message_name_without_package, $file_proto); + $legacy_class_name_without_package = + static::getLegacyClassNameWithoutPackage( + $message_name_without_package, $file_proto); + + $option = $file_proto->getOptions(); + if (!is_null($option) && $option->hasPhpNamespace()) { + $namespace = $option->getPhpNamespace(); + if ($namespace !== "") { + $classname = $namespace . "\\" . $class_name_without_package; + $legacy_classname = + $namespace . "\\" . $legacy_class_name_without_package; + return; + } else { + $classname = $class_name_without_package; + $legacy_classname = $legacy_class_name_without_package; + return; + } + } + + if ($package === "") { + $classname = $class_name_without_package; + $legacy_classname = $legacy_class_name_without_package; + } else { + $parts = array_map('ucwords', explode('.', $package)); + foreach ($parts as $i => $part) { + $parts[$i] = self::getClassNamePrefix($part, $file_proto).$part; + } + $classname = + implode('\\', $parts) . + "\\".self::getClassNamePrefix($class_name_without_package,$file_proto). + $class_name_without_package; + $legacy_classname = + implode('\\', array_map('ucwords', explode('.', $package))). + "\\".$legacy_class_name_without_package; + } + } + + public static function combineInt32ToInt64($high, $low) + { + $isNeg = $high < 0; + if ($isNeg) { + $high = ~$high; + $low = ~$low; + $low++; + if (!$low) { + $high = (int) ($high + 1); + } + } + $result = bcadd(bcmul($high, 4294967296), $low); + if ($low < 0) { + $result = bcadd($result, 4294967296); + } + if ($isNeg) { + $result = bcsub(0, $result); + } + return $result; + } + + public static function parseTimestamp($timestamp) + { + // prevent parsing timestamps containing with the non-existent year "0000" + // DateTime::createFromFormat parses without failing but as a nonsensical date + if (substr($timestamp, 0, 4) === "0000") { + throw new \Exception("Year cannot be zero."); + } + // prevent parsing timestamps ending with a lowercase z + if (substr($timestamp, -1, 1) === "z") { + throw new \Exception("Timezone cannot be a lowercase z."); + } + + $nanoseconds = 0; + $periodIndex = strpos($timestamp, "."); + if ($periodIndex !== false) { + $nanosecondsLength = 0; + // find the next non-numeric character in the timestamp to calculate + // the length of the nanoseconds text + for ($i = $periodIndex + 1, $length = strlen($timestamp); $i < $length; $i++) { + if (!is_numeric($timestamp[$i])) { + $nanosecondsLength = $i - ($periodIndex + 1); + break; + } + } + if ($nanosecondsLength % 3 !== 0) { + throw new \Exception("Nanoseconds must be disible by 3."); + } + if ($nanosecondsLength > 9) { + throw new \Exception("Nanoseconds must be in the range of 0 to 999,999,999 nanoseconds."); + } + if ($nanosecondsLength > 0) { + $nanoseconds = substr($timestamp, $periodIndex + 1, $nanosecondsLength); + $nanoseconds = intval($nanoseconds); + + // remove the nanoseconds and preceding period from the timestamp + $date = substr($timestamp, 0, $periodIndex); + $timezone = substr($timestamp, $periodIndex + $nanosecondsLength + 1); + $timestamp = $date.$timezone; + } + } + + $date = \DateTime::createFromFormat(\DateTime::RFC3339, $timestamp, new \DateTimeZone("UTC")); + if ($date === false) { + throw new \Exception("Invalid RFC 3339 timestamp."); + } + + $value = new \Google\Protobuf\Timestamp(); + $seconds = $date->format("U"); + $value->setSeconds($seconds); + $value->setNanos($nanoseconds); + return $value; + } + + public static function formatTimestamp($value) + { + if (bccomp($value->getSeconds(), "253402300800") != -1) { + throw new GPBDecodeException("Duration number too large."); + } + if (bccomp($value->getSeconds(), "-62135596801") != 1) { + throw new GPBDecodeException("Duration number too small."); + } + $nanoseconds = static::getNanosecondsForTimestamp($value->getNanos()); + if (!empty($nanoseconds)) { + $nanoseconds = ".".$nanoseconds; + } + $date = new \DateTime('@'.$value->getSeconds(), new \DateTimeZone("UTC")); + return $date->format("Y-m-d\TH:i:s".$nanoseconds."\Z"); + } + + public static function parseDuration($value) + { + if (strlen($value) < 2 || substr($value, -1) !== "s") { + throw new GPBDecodeException("Missing s after duration string"); + } + $number = substr($value, 0, -1); + if (bccomp($number, "315576000001") != -1) { + throw new GPBDecodeException("Duration number too large."); + } + if (bccomp($number, "-315576000001") != 1) { + throw new GPBDecodeException("Duration number too small."); + } + $pos = strrpos($number, "."); + if ($pos !== false) { + $seconds = substr($number, 0, $pos); + if (bccomp($seconds, 0) < 0) { + $nanos = bcmul("0" . substr($number, $pos), -1000000000); + } else { + $nanos = bcmul("0" . substr($number, $pos), 1000000000); + } + } else { + $seconds = $number; + $nanos = 0; + } + $duration = new Duration(); + $duration->setSeconds($seconds); + $duration->setNanos($nanos); + return $duration; + } + + public static function formatDuration($value) + { + if (bccomp($value->getSeconds(), '315576000001') != -1) { + throw new GPBDecodeException('Duration number too large.'); + } + if (bccomp($value->getSeconds(), '-315576000001') != 1) { + throw new GPBDecodeException('Duration number too small.'); + } + + $nanos = $value->getNanos(); + if ($nanos === 0) { + return (string) $value->getSeconds(); + } + + if ($nanos % 1000000 === 0) { + $digits = 3; + } elseif ($nanos % 1000 === 0) { + $digits = 6; + } else { + $digits = 9; + } + + $nanos = bcdiv($nanos, '1000000000', $digits); + return bcadd($value->getSeconds(), $nanos, $digits); + } + + public static function parseFieldMask($paths_string) + { + $field_mask = new FieldMask(); + if (strlen($paths_string) === 0) { + return $field_mask; + } + $path_strings = explode(",", $paths_string); + $paths = $field_mask->getPaths(); + foreach($path_strings as &$path_string) { + $field_strings = explode(".", $path_string); + foreach($field_strings as &$field_string) { + $field_string = camel2underscore($field_string); + } + $path_string = implode(".", $field_strings); + $paths[] = $path_string; + } + return $field_mask; + } + + public static function formatFieldMask($field_mask) + { + $converted_paths = []; + foreach($field_mask->getPaths() as $path) { + $fields = explode('.', $path); + $converted_path = []; + foreach ($fields as $field) { + $segments = explode('_', $field); + $start = true; + $converted_segments = ""; + foreach($segments as $segment) { + if (!$start) { + $converted = ucfirst($segment); + } else { + $converted = $segment; + $start = false; + } + $converted_segments .= $converted; + } + $converted_path []= $converted_segments; + } + $converted_path = implode(".", $converted_path); + $converted_paths []= $converted_path; + } + return implode(",", $converted_paths); + } + + public static function getNanosecondsForTimestamp($nanoseconds) + { + if ($nanoseconds == 0) { + return ''; + } + if ($nanoseconds % static::NANOS_PER_MILLISECOND == 0) { + return sprintf('%03d', $nanoseconds / static::NANOS_PER_MILLISECOND); + } + if ($nanoseconds % static::NANOS_PER_MICROSECOND == 0) { + return sprintf('%06d', $nanoseconds / static::NANOS_PER_MICROSECOND); + } + return sprintf('%09d', $nanoseconds); + } + + public static function hasSpecialJsonMapping($msg) + { + return is_a($msg, 'Google\Protobuf\Any') || + is_a($msg, "Google\Protobuf\ListValue") || + is_a($msg, "Google\Protobuf\Struct") || + is_a($msg, "Google\Protobuf\Value") || + is_a($msg, "Google\Protobuf\Duration") || + is_a($msg, "Google\Protobuf\Timestamp") || + is_a($msg, "Google\Protobuf\FieldMask") || + static::hasJsonValue($msg); + } + + public static function hasJsonValue($msg) + { + return is_a($msg, "Google\Protobuf\DoubleValue") || + is_a($msg, "Google\Protobuf\FloatValue") || + is_a($msg, "Google\Protobuf\Int64Value") || + is_a($msg, "Google\Protobuf\UInt64Value") || + is_a($msg, "Google\Protobuf\Int32Value") || + is_a($msg, "Google\Protobuf\UInt32Value") || + is_a($msg, "Google\Protobuf\BoolValue") || + is_a($msg, "Google\Protobuf\StringValue") || + is_a($msg, "Google\Protobuf\BytesValue"); + } +} diff --git a/src/pro/Google/Protobuf/Internal/GPBWire.php b/src/pro/Google/Protobuf/Internal/GPBWire.php new file mode 100644 index 00000000..7f1eab3c --- /dev/null +++ b/src/pro/Google/Protobuf/Internal/GPBWire.php @@ -0,0 +1,622 @@ +> self::TAG_TYPE_BITS) & + (1 << ((PHP_INT_SIZE * 8) - self::TAG_TYPE_BITS)) - 1; + } + + public static function getTagWireType($tag) + { + return $tag & 0x7; + } + + public static function getWireType($type) + { + switch ($type) { + case GPBType::FLOAT: + case GPBType::FIXED32: + case GPBType::SFIXED32: + return self::WIRETYPE_FIXED32; + case GPBType::DOUBLE: + case GPBType::FIXED64: + case GPBType::SFIXED64: + return self::WIRETYPE_FIXED64; + case GPBType::UINT32: + case GPBType::UINT64: + case GPBType::INT32: + case GPBType::INT64: + case GPBType::SINT32: + case GPBType::SINT64: + case GPBType::ENUM: + case GPBType::BOOL: + return self::WIRETYPE_VARINT; + case GPBType::STRING: + case GPBType::BYTES: + case GPBType::MESSAGE: + return self::WIRETYPE_LENGTH_DELIMITED; + case GPBType::GROUP: + user_error("Unsupported type."); + return 0; + default: + user_error("Unsupported type."); + return 0; + } + } + + // ZigZag Transform: Encodes signed integers so that they can be effectively + // used with varint encoding. + // + // varint operates on unsigned integers, encoding smaller numbers into fewer + // bytes. If you try to use it on a signed integer, it will treat this + // number as a very large unsigned integer, which means that even small + // signed numbers like -1 will take the maximum number of bytes (10) to + // encode. zigZagEncode() maps signed integers to unsigned in such a way + // that those with a small absolute value will have smaller encoded values, + // making them appropriate for encoding using varint. + // + // int32 -> uint32 + // ------------------------- + // 0 -> 0 + // -1 -> 1 + // 1 -> 2 + // -2 -> 3 + // ... -> ... + // 2147483647 -> 4294967294 + // -2147483648 -> 4294967295 + // + // >> encode >> + // << decode << + public static function zigZagEncode32($int32) + { + if (PHP_INT_SIZE == 8) { + $trim_int32 = $int32 & 0xFFFFFFFF; + return (($trim_int32 << 1) ^ ($int32 << 32 >> 63)) & 0xFFFFFFFF; + } else { + return ($int32 << 1) ^ ($int32 >> 31); + } + } + + public static function zigZagDecode32($uint32) + { + // Fill high 32 bits. + if (PHP_INT_SIZE === 8) { + $uint32 |= ($uint32 & 0xFFFFFFFF); + } + + $int32 = (($uint32 >> 1) & 0x7FFFFFFF) ^ (-($uint32 & 1)); + + return $int32; + } + + public static function zigZagEncode64($int64) + { + if (PHP_INT_SIZE == 4) { + if (bccomp($int64, 0) >= 0) { + return bcmul($int64, 2); + } else { + return bcsub(bcmul(bcsub(0, $int64), 2), 1); + } + } else { + return ($int64 << 1) ^ ($int64 >> 63); + } + } + + public static function zigZagDecode64($uint64) + { + if (PHP_INT_SIZE == 4) { + if (bcmod($uint64, 2) == 0) { + return bcdiv($uint64, 2, 0); + } else { + return bcsub(0, bcdiv(bcadd($uint64, 1), 2, 0)); + } + } else { + return (($uint64 >> 1) & 0x7FFFFFFFFFFFFFFF) ^ (-($uint64 & 1)); + } + } + + public static function readInt32(&$input, &$value) + { + return $input->readVarint32($value); + } + + public static function readInt64(&$input, &$value) + { + $success = $input->readVarint64($value); + if (PHP_INT_SIZE == 4 && bccomp($value, "9223372036854775807") > 0) { + $value = bcsub($value, "18446744073709551616"); + } + return $success; + } + + public static function readUint32(&$input, &$value) + { + return self::readInt32($input, $value); + } + + public static function readUint64(&$input, &$value) + { + return self::readInt64($input, $value); + } + + public static function readSint32(&$input, &$value) + { + if (!$input->readVarint32($value)) { + return false; + } + $value = GPBWire::zigZagDecode32($value); + return true; + } + + public static function readSint64(&$input, &$value) + { + if (!$input->readVarint64($value)) { + return false; + } + $value = GPBWire::zigZagDecode64($value); + return true; + } + + public static function readFixed32(&$input, &$value) + { + return $input->readLittleEndian32($value); + } + + public static function readFixed64(&$input, &$value) + { + return $input->readLittleEndian64($value); + } + + public static function readSfixed32(&$input, &$value) + { + if (!self::readFixed32($input, $value)) { + return false; + } + if (PHP_INT_SIZE === 8) { + $value |= (-($value >> 31) << 32); + } + return true; + } + + public static function readSfixed64(&$input, &$value) + { + $success = $input->readLittleEndian64($value); + if (PHP_INT_SIZE == 4 && bccomp($value, "9223372036854775807") > 0) { + $value = bcsub($value, "18446744073709551616"); + } + return $success; + } + + public static function readFloat(&$input, &$value) + { + $data = null; + if (!$input->readRaw(4, $data)) { + return false; + } + $value = unpack('f', $data)[1]; + return true; + } + + public static function readDouble(&$input, &$value) + { + $data = null; + if (!$input->readRaw(8, $data)) { + return false; + } + $value = unpack('d', $data)[1]; + return true; + } + + public static function readBool(&$input, &$value) + { + if (!$input->readVarint64($value)) { + return false; + } + if ($value == 0) { + $value = false; + } else { + $value = true; + } + return true; + } + + public static function readString(&$input, &$value) + { + $length = 0; + return $input->readVarintSizeAsInt($length) && $input->readRaw($length, $value); + } + + public static function readMessage(&$input, &$message) + { + $length = 0; + if (!$input->readVarintSizeAsInt($length)) { + return false; + } + $old_limit = 0; + $recursion_limit = 0; + $input->incrementRecursionDepthAndPushLimit( + $length, + $old_limit, + $recursion_limit); + if ($recursion_limit < 0 || !$message->parseFromStream($input)) { + return false; + } + return $input->decrementRecursionDepthAndPopLimit($old_limit); + } + + public static function writeTag(&$output, $tag) + { + return $output->writeTag($tag); + } + + public static function writeInt32(&$output, $value) + { + return $output->writeVarint32($value, false); + } + + public static function writeInt64(&$output, $value) + { + return $output->writeVarint64($value); + } + + public static function writeUint32(&$output, $value) + { + return $output->writeVarint32($value, true); + } + + public static function writeUint64(&$output, $value) + { + return $output->writeVarint64($value); + } + + public static function writeSint32(&$output, $value) + { + $value = GPBWire::zigZagEncode32($value); + return $output->writeVarint32($value, true); + } + + public static function writeSint64(&$output, $value) + { + $value = GPBWire::zigZagEncode64($value); + return $output->writeVarint64($value); + } + + public static function writeFixed32(&$output, $value) + { + return $output->writeLittleEndian32($value); + } + + public static function writeFixed64(&$output, $value) + { + return $output->writeLittleEndian64($value); + } + + public static function writeSfixed32(&$output, $value) + { + return $output->writeLittleEndian32($value); + } + + public static function writeSfixed64(&$output, $value) + { + return $output->writeLittleEndian64($value); + } + + public static function writeBool(&$output, $value) + { + if ($value) { + return $output->writeVarint32(1, true); + } else { + return $output->writeVarint32(0, true); + } + } + + public static function writeFloat(&$output, $value) + { + $data = pack("f", $value); + return $output->writeRaw($data, 4); + } + + public static function writeDouble(&$output, $value) + { + $data = pack("d", $value); + return $output->writeRaw($data, 8); + } + + public static function writeString(&$output, $value) + { + return self::writeBytes($output, $value); + } + + public static function writeBytes(&$output, $value) + { + $size = strlen($value); + if (!$output->writeVarint32($size, true)) { + return false; + } + return $output->writeRaw($value, $size); + } + + public static function writeMessage(&$output, $value) + { + $size = $value->byteSize(); + if (!$output->writeVarint32($size, true)) { + return false; + } + return $value->serializeToStream($output); + } + + public static function makeTag($number, $type) + { + return ($number << 3) | self::getWireType($type); + } + + public static function tagSize($field) + { + $tag = self::makeTag($field->getNumber(), $field->getType()); + return self::varint32Size($tag); + } + + public static function varint32Size($value, $sign_extended = false) + { + if ($value < 0) { + if ($sign_extended) { + return 10; + } else { + return 5; + } + } + if ($value < (1 << 7)) { + return 1; + } + if ($value < (1 << 14)) { + return 2; + } + if ($value < (1 << 21)) { + return 3; + } + if ($value < (1 << 28)) { + return 4; + } + return 5; + } + + public static function sint32Size($value) + { + $value = self::zigZagEncode32($value); + return self::varint32Size($value); + } + + public static function sint64Size($value) + { + $value = self::zigZagEncode64($value); + return self::varint64Size($value); + } + + public static function varint64Size($value) + { + if (PHP_INT_SIZE == 4) { + if (bccomp($value, 0) < 0 || + bccomp($value, "9223372036854775807") > 0) { + return 10; + } + if (bccomp($value, 1 << 7) < 0) { + return 1; + } + if (bccomp($value, 1 << 14) < 0) { + return 2; + } + if (bccomp($value, 1 << 21) < 0) { + return 3; + } + if (bccomp($value, 1 << 28) < 0) { + return 4; + } + if (bccomp($value, '34359738368') < 0) { + return 5; + } + if (bccomp($value, '4398046511104') < 0) { + return 6; + } + if (bccomp($value, '562949953421312') < 0) { + return 7; + } + if (bccomp($value, '72057594037927936') < 0) { + return 8; + } + return 9; + } else { + if ($value < 0) { + return 10; + } + if ($value < (1 << 7)) { + return 1; + } + if ($value < (1 << 14)) { + return 2; + } + if ($value < (1 << 21)) { + return 3; + } + if ($value < (1 << 28)) { + return 4; + } + if ($value < (1 << 35)) { + return 5; + } + if ($value < (1 << 42)) { + return 6; + } + if ($value < (1 << 49)) { + return 7; + } + if ($value < (1 << 56)) { + return 8; + } + return 9; + } + } + + public static function serializeFieldToStream( + $value, + $field, + $need_tag, + &$output) + { + if ($need_tag) { + if (!GPBWire::writeTag( + $output, + self::makeTag( + $field->getNumber(), + $field->getType()))) { + return false; + } + } + switch ($field->getType()) { + case GPBType::DOUBLE: + if (!GPBWire::writeDouble($output, $value)) { + return false; + } + break; + case GPBType::FLOAT: + if (!GPBWire::writeFloat($output, $value)) { + return false; + } + break; + case GPBType::INT64: + if (!GPBWire::writeInt64($output, $value)) { + return false; + } + break; + case GPBType::UINT64: + if (!GPBWire::writeUint64($output, $value)) { + return false; + } + break; + case GPBType::INT32: + if (!GPBWire::writeInt32($output, $value)) { + return false; + } + break; + case GPBType::FIXED32: + if (!GPBWire::writeFixed32($output, $value)) { + return false; + } + break; + case GPBType::FIXED64: + if (!GPBWire::writeFixed64($output, $value)) { + return false; + } + break; + case GPBType::BOOL: + if (!GPBWire::writeBool($output, $value)) { + return false; + } + break; + case GPBType::STRING: + if (!GPBWire::writeString($output, $value)) { + return false; + } + break; + // case GPBType::GROUP: + // echo "GROUP\xA"; + // trigger_error("Not implemented.", E_ERROR); + // break; + case GPBType::MESSAGE: + if (!GPBWire::writeMessage($output, $value)) { + return false; + } + break; + case GPBType::BYTES: + if (!GPBWire::writeBytes($output, $value)) { + return false; + } + break; + case GPBType::UINT32: + if (PHP_INT_SIZE === 8 && $value < 0) { + $value += 4294967296; + } + if (!GPBWire::writeUint32($output, $value)) { + return false; + } + break; + case GPBType::ENUM: + if (!GPBWire::writeInt32($output, $value)) { + return false; + } + break; + case GPBType::SFIXED32: + if (!GPBWire::writeSfixed32($output, $value)) { + return false; + } + break; + case GPBType::SFIXED64: + if (!GPBWire::writeSfixed64($output, $value)) { + return false; + } + break; + case GPBType::SINT32: + if (!GPBWire::writeSint32($output, $value)) { + return false; + } + break; + case GPBType::SINT64: + if (!GPBWire::writeSint64($output, $value)) { + return false; + } + break; + default: + user_error("Unsupported type."); + return false; + } + + return true; + } +} diff --git a/src/pro/Google/Protobuf/Internal/GPBWireType.php b/src/pro/Google/Protobuf/Internal/GPBWireType.php new file mode 100644 index 00000000..c1ad370e --- /dev/null +++ b/src/pro/Google/Protobuf/Internal/GPBWireType.php @@ -0,0 +1,43 @@ +google.protobuf.GeneratedCodeInfo + */ +class GeneratedCodeInfo extends \Google\Protobuf\Internal\Message +{ + /** + * An Annotation connects some span of text in generated code to an element + * of its generating .proto file. + * + * Generated from protobuf field repeated .google.protobuf.GeneratedCodeInfo.Annotation annotation = 1; + */ + private $annotation; + private $has_annotation = false; + + /** + * Constructor. + * + * @param array $data { + * Optional. Data for populating the Message object. + * + * @type \Google\Protobuf\Internal\GeneratedCodeInfo\Annotation[]|\Google\Protobuf\Internal\RepeatedField $annotation + * An Annotation connects some span of text in generated code to an element + * of its generating .proto file. + * } + */ + public function __construct($data = NULL) { + \GPBMetadata\Google\Protobuf\Internal\Descriptor::initOnce(); + parent::__construct($data); + } + + /** + * An Annotation connects some span of text in generated code to an element + * of its generating .proto file. + * + * Generated from protobuf field repeated .google.protobuf.GeneratedCodeInfo.Annotation annotation = 1; + * @return \Google\Protobuf\Internal\RepeatedField + */ + public function getAnnotation() + { + return $this->annotation; + } + + /** + * An Annotation connects some span of text in generated code to an element + * of its generating .proto file. + * + * Generated from protobuf field repeated .google.protobuf.GeneratedCodeInfo.Annotation annotation = 1; + * @param \Google\Protobuf\Internal\GeneratedCodeInfo\Annotation[]|\Google\Protobuf\Internal\RepeatedField $var + * @return $this + */ + public function setAnnotation($var) + { + $arr = GPBUtil::checkRepeatedField($var, \Google\Protobuf\Internal\GPBType::MESSAGE, \Google\Protobuf\Internal\GeneratedCodeInfo\Annotation::class); + $this->annotation = $arr; + $this->has_annotation = true; + + return $this; + } + + public function hasAnnotation() + { + return $this->has_annotation; + } + +} + diff --git a/src/pro/Google/Protobuf/Internal/GeneratedCodeInfo/Annotation.php b/src/pro/Google/Protobuf/Internal/GeneratedCodeInfo/Annotation.php new file mode 100644 index 00000000..369fea48 --- /dev/null +++ b/src/pro/Google/Protobuf/Internal/GeneratedCodeInfo/Annotation.php @@ -0,0 +1,216 @@ +google.protobuf.GeneratedCodeInfo.Annotation + */ +class Annotation extends \Google\Protobuf\Internal\Message +{ + /** + * Identifies the element in the original source .proto file. This field + * is formatted the same as SourceCodeInfo.Location.path. + * + * Generated from protobuf field repeated int32 path = 1 [packed = true]; + */ + private $path; + private $has_path = false; + /** + * Identifies the filesystem path to the original source .proto. + * + * Generated from protobuf field optional string source_file = 2; + */ + protected $source_file = ''; + private $has_source_file = false; + /** + * Identifies the starting offset in bytes in the generated code + * that relates to the identified object. + * + * Generated from protobuf field optional int32 begin = 3; + */ + protected $begin = 0; + private $has_begin = false; + /** + * Identifies the ending offset in bytes in the generated code that + * relates to the identified offset. The end offset should be one past + * the last relevant byte (so the length of the text = end - begin). + * + * Generated from protobuf field optional int32 end = 4; + */ + protected $end = 0; + private $has_end = false; + + /** + * Constructor. + * + * @param array $data { + * Optional. Data for populating the Message object. + * + * @type int[]|\Google\Protobuf\Internal\RepeatedField $path + * Identifies the element in the original source .proto file. This field + * is formatted the same as SourceCodeInfo.Location.path. + * @type string $source_file + * Identifies the filesystem path to the original source .proto. + * @type int $begin + * Identifies the starting offset in bytes in the generated code + * that relates to the identified object. + * @type int $end + * Identifies the ending offset in bytes in the generated code that + * relates to the identified offset. The end offset should be one past + * the last relevant byte (so the length of the text = end - begin). + * } + */ + public function __construct($data = NULL) { + \GPBMetadata\Google\Protobuf\Internal\Descriptor::initOnce(); + parent::__construct($data); + } + + /** + * Identifies the element in the original source .proto file. This field + * is formatted the same as SourceCodeInfo.Location.path. + * + * Generated from protobuf field repeated int32 path = 1 [packed = true]; + * @return \Google\Protobuf\Internal\RepeatedField + */ + public function getPath() + { + return $this->path; + } + + /** + * Identifies the element in the original source .proto file. This field + * is formatted the same as SourceCodeInfo.Location.path. + * + * Generated from protobuf field repeated int32 path = 1 [packed = true]; + * @param int[]|\Google\Protobuf\Internal\RepeatedField $var + * @return $this + */ + public function setPath($var) + { + $arr = GPBUtil::checkRepeatedField($var, \Google\Protobuf\Internal\GPBType::INT32); + $this->path = $arr; + $this->has_path = true; + + return $this; + } + + public function hasPath() + { + return $this->has_path; + } + + /** + * Identifies the filesystem path to the original source .proto. + * + * Generated from protobuf field optional string source_file = 2; + * @return string + */ + public function getSourceFile() + { + return $this->source_file; + } + + /** + * Identifies the filesystem path to the original source .proto. + * + * Generated from protobuf field optional string source_file = 2; + * @param string $var + * @return $this + */ + public function setSourceFile($var) + { + GPBUtil::checkString($var, True); + $this->source_file = $var; + $this->has_source_file = true; + + return $this; + } + + public function hasSourceFile() + { + return $this->has_source_file; + } + + /** + * Identifies the starting offset in bytes in the generated code + * that relates to the identified object. + * + * Generated from protobuf field optional int32 begin = 3; + * @return int + */ + public function getBegin() + { + return $this->begin; + } + + /** + * Identifies the starting offset in bytes in the generated code + * that relates to the identified object. + * + * Generated from protobuf field optional int32 begin = 3; + * @param int $var + * @return $this + */ + public function setBegin($var) + { + GPBUtil::checkInt32($var); + $this->begin = $var; + $this->has_begin = true; + + return $this; + } + + public function hasBegin() + { + return $this->has_begin; + } + + /** + * Identifies the ending offset in bytes in the generated code that + * relates to the identified offset. The end offset should be one past + * the last relevant byte (so the length of the text = end - begin). + * + * Generated from protobuf field optional int32 end = 4; + * @return int + */ + public function getEnd() + { + return $this->end; + } + + /** + * Identifies the ending offset in bytes in the generated code that + * relates to the identified offset. The end offset should be one past + * the last relevant byte (so the length of the text = end - begin). + * + * Generated from protobuf field optional int32 end = 4; + * @param int $var + * @return $this + */ + public function setEnd($var) + { + GPBUtil::checkInt32($var); + $this->end = $var; + $this->has_end = true; + + return $this; + } + + public function hasEnd() + { + return $this->has_end; + } + +} + +// Adding a class alias for backwards compatibility with the previous class name. +class_alias(Annotation::class, \Google\Protobuf\Internal\GeneratedCodeInfo_Annotation::class); + diff --git a/src/pro/Google/Protobuf/Internal/GeneratedCodeInfo_Annotation.php b/src/pro/Google/Protobuf/Internal/GeneratedCodeInfo_Annotation.php new file mode 100644 index 00000000..e36f1e57 --- /dev/null +++ b/src/pro/Google/Protobuf/Internal/GeneratedCodeInfo_Annotation.php @@ -0,0 +1,16 @@ +getPublicDescriptor(); + } +} diff --git a/src/pro/Google/Protobuf/Internal/HasPublicDescriptorTrait.php b/src/pro/Google/Protobuf/Internal/HasPublicDescriptorTrait.php new file mode 100644 index 00000000..ed5d1660 --- /dev/null +++ b/src/pro/Google/Protobuf/Internal/HasPublicDescriptorTrait.php @@ -0,0 +1,43 @@ +public_desc; + } +} diff --git a/src/pro/Google/Protobuf/Internal/MapEntry.php b/src/pro/Google/Protobuf/Internal/MapEntry.php new file mode 100644 index 00000000..e89481f0 --- /dev/null +++ b/src/pro/Google/Protobuf/Internal/MapEntry.php @@ -0,0 +1,71 @@ +getFieldByNumber(2); + if ($value_field->getType() == GPBType::MESSAGE) { + $klass = $value_field->getMessageType()->getClass(); + $value = new $klass; + $this->setValue($value); + } + } + + public function setKey($key) { + $this->key = $key; + } + + public function getKey() { + return $this->key; + } + + public function setValue($value) { + $this->value = $value; + } + + public function getValue() { + return $this->value; + } +} diff --git a/src/pro/Google/Protobuf/Internal/MapField.php b/src/pro/Google/Protobuf/Internal/MapField.php new file mode 100644 index 00000000..2c66aa0c --- /dev/null +++ b/src/pro/Google/Protobuf/Internal/MapField.php @@ -0,0 +1,290 @@ +container = []; + $this->key_type = $key_type; + $this->value_type = $value_type; + $this->klass = $klass; + + if ($this->value_type == GPBType::MESSAGE) { + $pool = DescriptorPool::getGeneratedPool(); + $desc = $pool->getDescriptorByClassName($klass); + if ($desc == NULL) { + new $klass; // No msg class instance has been created before. + $desc = $pool->getDescriptorByClassName($klass); + } + $this->klass = $desc->getClass(); + $this->legacy_klass = $desc->getLegacyClass(); + } + } + + /** + * @ignore + */ + public function getKeyType() + { + return $this->key_type; + } + + /** + * @ignore + */ + public function getValueType() + { + return $this->value_type; + } + + /** + * @ignore + */ + public function getValueClass() + { + return $this->klass; + } + + /** + * @ignore + */ + public function getLegacyValueClass() + { + return $this->legacy_klass; + } + + /** + * Return the element at the given key. + * + * This will also be called for: $ele = $arr[$key] + * + * @param object $key The key of the element to be fetched. + * @return object The stored element at given key. + * @throws \ErrorException Invalid type for index. + * @throws \ErrorException Non-existing index. + */ + public function offsetGet($key) + { + return $this->container[$key]; + } + + /** + * Assign the element at the given key. + * + * This will also be called for: $arr[$key] = $value + * + * @param object $key The key of the element to be fetched. + * @param object $value The element to be assigned. + * @return void + * @throws \ErrorException Invalid type for key. + * @throws \ErrorException Invalid type for value. + * @throws \ErrorException Non-existing key. + */ + public function offsetSet($key, $value) + { + $this->checkKey($this->key_type, $key); + + switch ($this->value_type) { + case GPBType::SFIXED32: + case GPBType::SINT32: + case GPBType::INT32: + case GPBType::ENUM: + GPBUtil::checkInt32($value); + break; + case GPBType::FIXED32: + case GPBType::UINT32: + GPBUtil::checkUint32($value); + break; + case GPBType::SFIXED64: + case GPBType::SINT64: + case GPBType::INT64: + GPBUtil::checkInt64($value); + break; + case GPBType::FIXED64: + case GPBType::UINT64: + GPBUtil::checkUint64($value); + break; + case GPBType::FLOAT: + GPBUtil::checkFloat($value); + break; + case GPBType::DOUBLE: + GPBUtil::checkDouble($value); + break; + case GPBType::BOOL: + GPBUtil::checkBool($value); + break; + case GPBType::STRING: + GPBUtil::checkString($value, true); + break; + case GPBType::MESSAGE: + if (is_null($value)) { + trigger_error("Map element cannot be null.", E_USER_ERROR); + } + GPBUtil::checkMessage($value, $this->klass); + break; + default: + break; + } + + $this->container[$key] = $value; + } + + /** + * Remove the element at the given key. + * + * This will also be called for: unset($arr) + * + * @param object $key The key of the element to be removed. + * @return void + * @throws \ErrorException Invalid type for key. + */ + public function offsetUnset($key) + { + $this->checkKey($this->key_type, $key); + unset($this->container[$key]); + } + + /** + * Check the existence of the element at the given key. + * + * This will also be called for: isset($arr) + * + * @param object $key The key of the element to be removed. + * @return bool True if the element at the given key exists. + * @throws \ErrorException Invalid type for key. + */ + public function offsetExists($key) + { + $this->checkKey($this->key_type, $key); + return isset($this->container[$key]); + } + + /** + * @ignore + */ + public function getIterator() + { + return new MapFieldIter($this->container, $this->key_type); + } + + /** + * Return the number of stored elements. + * + * This will also be called for: count($arr) + * + * @return integer The number of stored elements. + */ + public function count() + { + return count($this->container); + } + + /** + * @ignore + */ + private function checkKey($key_type, &$key) + { + switch ($key_type) { + case GPBType::SFIXED32: + case GPBType::SINT32: + case GPBType::INT32: + GPBUtil::checkInt32($key); + break; + case GPBType::FIXED32: + case GPBType::UINT32: + GPBUtil::checkUint32($key); + break; + case GPBType::SFIXED64: + case GPBType::SINT64: + case GPBType::INT64: + GPBUtil::checkInt64($key); + break; + case GPBType::FIXED64: + case GPBType::UINT64: + GPBUtil::checkUint64($key); + break; + case GPBType::BOOL: + GPBUtil::checkBool($key); + break; + case GPBType::STRING: + GPBUtil::checkString($key, true); + break; + default: + trigger_error( + "Given type cannot be map key.", + E_USER_ERROR); + break; + } + } +} diff --git a/src/pro/Google/Protobuf/Internal/MapFieldIter.php b/src/pro/Google/Protobuf/Internal/MapFieldIter.php new file mode 100644 index 00000000..4e18005e --- /dev/null +++ b/src/pro/Google/Protobuf/Internal/MapFieldIter.php @@ -0,0 +1,134 @@ +container = $container; + $this->key_type = $key_type; + } + + /** + * Reset the status of the iterator + * + * @return void + */ + public function rewind() + { + return reset($this->container); + } + + /** + * Return the element at the current position. + * + * @return object The element at the current position. + */ + public function current() + { + return current($this->container); + } + + /** + * Return the current key. + * + * @return object The current key. + */ + public function key() + { + $key = key($this->container); + switch ($this->key_type) { + case GPBType::INT64: + case GPBType::UINT64: + case GPBType::FIXED64: + case GPBType::SFIXED64: + case GPBType::SINT64: + if (PHP_INT_SIZE === 8) { + return $key; + } + // Intentionally fall through + case GPBType::STRING: + // PHP associative array stores int string as int for key. + return strval($key); + case GPBType::BOOL: + // PHP associative array stores bool as integer for key. + return boolval($key); + default: + return $key; + } + } + + /** + * Move to the next position. + * + * @return void + */ + public function next() + { + return next($this->container); + } + + /** + * Check whether there are more elements to iterate. + * + * @return bool True if there are more elements to iterate. + */ + public function valid() + { + return key($this->container) !== null; + } +} diff --git a/src/pro/Google/Protobuf/Internal/Message.php b/src/pro/Google/Protobuf/Internal/Message.php new file mode 100644 index 00000000..e292026f --- /dev/null +++ b/src/pro/Google/Protobuf/Internal/Message.php @@ -0,0 +1,2000 @@ +initWithDescriptor($data); + } else { + $this->initWithGeneratedPool(); + if (is_array($data)) { + $this->mergeFromArray($data); + } else if (!empty($data)) { + throw new \InvalidArgumentException( + 'Message constructor must be an array or null.' + ); + } + } + } + + /** + * @ignore + */ + private function initWithGeneratedPool() + { + $pool = DescriptorPool::getGeneratedPool(); + $this->desc = $pool->getDescriptorByClassName(get_class($this)); + if (is_null($this->desc)) { + user_error(get_class($this) . " is not found in descriptor pool."); + return; + } + foreach ($this->desc->getField() as $field) { + $setter = $field->getSetter(); + if ($field->isMap()) { + $message_type = $field->getMessageType(); + $key_field = $message_type->getFieldByNumber(1); + $value_field = $message_type->getFieldByNumber(2); + switch ($value_field->getType()) { + case GPBType::MESSAGE: + case GPBType::GROUP: + $map_field = new MapField( + $key_field->getType(), + $value_field->getType(), + $value_field->getMessageType()->getClass()); + $this->$setter($map_field); + break; + case GPBType::ENUM: + $map_field = new MapField( + $key_field->getType(), + $value_field->getType(), + $value_field->getEnumType()->getClass()); + $this->$setter($map_field); + break; + default: + $map_field = new MapField( + $key_field->getType(), + $value_field->getType()); + $this->$setter($map_field); + break; + } + } else if ($field->getLabel() === GPBLabel::REPEATED) { + switch ($field->getType()) { + case GPBType::MESSAGE: + case GPBType::GROUP: + $repeated_field = new RepeatedField( + $field->getType(), + $field->getMessageType()->getClass()); + $this->$setter($repeated_field); + break; + case GPBType::ENUM: + $repeated_field = new RepeatedField( + $field->getType(), + $field->getEnumType()->getClass()); + $this->$setter($repeated_field); + break; + default: + $repeated_field = new RepeatedField($field->getType()); + $this->$setter($repeated_field); + break; + } + } else if ($field->getOneofIndex() !== -1) { + $oneof = $this->desc->getOneofDecl()[$field->getOneofIndex()]; + $oneof_name = $oneof->getName(); + $this->$oneof_name = new OneofField($oneof); + } else if ($field->getLabel() === GPBLabel::OPTIONAL && + PHP_INT_SIZE == 4) { + switch ($field->getType()) { + case GPBType::INT64: + case GPBType::UINT64: + case GPBType::FIXED64: + case GPBType::SFIXED64: + case GPBType::SINT64: + $this->$setter("0"); + } + } + } + } + + /** + * @ignore + */ + private function initWithDescriptor(Descriptor $desc) + { + $this->desc = $desc; + foreach ($desc->getField() as $field) { + $setter = $field->getSetter(); + $defaultValue = $this->defaultValue($field); + $this->$setter($defaultValue); + } + } + + protected function readWrapperValue($member) + { + $field = $this->desc->getFieldByName($member); + $oneof_index = $field->getOneofIndex(); + if ($oneof_index === -1) { + $wrapper = $this->$member; + } else { + $wrapper = $this->readOneof($field->getNumber()); + } + + if (is_null($wrapper)) { + return NULL; + } else { + return $wrapper->getValue(); + } + } + + protected function writeWrapperValue($member, $value) + { + $field = $this->desc->getFieldByName($member); + $wrapped_value = $value; + if (!is_null($value)) { + $desc = $field->getMessageType(); + $klass = $desc->getClass(); + $wrapped_value = new $klass; + $wrapped_value->setValue($value); + } + + $oneof_index = $field->getOneofIndex(); + if ($oneof_index === -1) { + $this->$member = $wrapped_value; + } else { + $this->writeOneof($field->getNumber(), $wrapped_value); + } + } + + protected function readOneof($number) + { + $field = $this->desc->getFieldByNumber($number); + $oneof = $this->desc->getOneofDecl()[$field->getOneofIndex()]; + $oneof_name = $oneof->getName(); + $oneof_field = $this->$oneof_name; + if ($number === $oneof_field->getNumber()) { + return $oneof_field->getValue(); + } else { + return $this->defaultValue($field); + } + } + + protected function writeOneof($number, $value) + { + $field = $this->desc->getFieldByNumber($number); + $oneof = $this->desc->getOneofDecl()[$field->getOneofIndex()]; + $oneof_name = $oneof->getName(); + $oneof_field = $this->$oneof_name; + $oneof_field->setValue($value); + $oneof_field->setFieldName($field->getName()); + $oneof_field->setNumber($number); + } + + protected function whichOneof($oneof_name) + { + $oneof_field = $this->$oneof_name; + $number = $oneof_field->getNumber(); + if ($number == 0) { + return ""; + } + $field = $this->desc->getFieldByNumber($number); + return $field->getName(); + } + + /** + * @ignore + */ + private function defaultValue($field) + { + $value = null; + + switch ($field->getType()) { + case GPBType::DOUBLE: + case GPBType::FLOAT: + return 0.0; + case GPBType::UINT32: + case GPBType::INT32: + case GPBType::FIXED32: + case GPBType::SFIXED32: + case GPBType::SINT32: + case GPBType::ENUM: + return 0; + case GPBType::INT64: + case GPBType::UINT64: + case GPBType::FIXED64: + case GPBType::SFIXED64: + case GPBType::SINT64: + if (PHP_INT_SIZE === 4) { + return '0'; + } else { + return 0; + } + case GPBType::BOOL: + return false; + case GPBType::STRING: + case GPBType::BYTES: + return ""; + case GPBType::GROUP: + case GPBType::MESSAGE: + return null; + default: + user_error("Unsupported type."); + return false; + } + } + + /** + * @ignore + */ + private function skipField($input, $tag) + { + $number = GPBWire::getTagFieldNumber($tag); + if ($number === 0) { + throw new GPBDecodeException("Illegal field number zero."); + } + + $start = $input->current(); + switch (GPBWire::getTagWireType($tag)) { + case GPBWireType::VARINT: + $uint64 = 0; + if (!$input->readVarint64($uint64)) { + throw new GPBDecodeException( + "Unexpected EOF inside varint."); + } + break; + case GPBWireType::FIXED64: + $uint64 = 0; + if (!$input->readLittleEndian64($uint64)) { + throw new GPBDecodeException( + "Unexpected EOF inside fixed64."); + } + break; + case GPBWireType::FIXED32: + $uint32 = 0; + if (!$input->readLittleEndian32($uint32)) { + throw new GPBDecodeException( + "Unexpected EOF inside fixed32."); + } + break; + case GPBWireType::LENGTH_DELIMITED: + $length = 0; + if (!$input->readVarint32($length)) { + throw new GPBDecodeException( + "Unexpected EOF inside length."); + } + $data = NULL; + if (!$input->readRaw($length, $data)) { + throw new GPBDecodeException( + "Unexpected EOF inside length delimited data."); + } + break; + case GPBWireType::START_GROUP: + case GPBWireType::END_GROUP: + throw new GPBDecodeException("Unexpected wire type."); + default: + throw new GPBDecodeException("Unexpected wire type."); + } + $end = $input->current(); + + $bytes = str_repeat(chr(0), CodedOutputStream::MAX_VARINT64_BYTES); + $size = CodedOutputStream::writeVarintToArray($tag, $bytes, true); + $this->unknown .= substr($bytes, 0, $size) . $input->substr($start, $end); + } + + /** + * @ignore + */ + private static function parseFieldFromStreamNoTag($input, $field, &$value) + { + switch ($field->getType()) { + case GPBType::DOUBLE: + if (!GPBWire::readDouble($input, $value)) { + throw new GPBDecodeException( + "Unexpected EOF inside double field."); + } + break; + case GPBType::FLOAT: + if (!GPBWire::readFloat($input, $value)) { + throw new GPBDecodeException( + "Unexpected EOF inside float field."); + } + break; + case GPBType::INT64: + if (!GPBWire::readInt64($input, $value)) { + throw new GPBDecodeException( + "Unexpected EOF inside int64 field."); + } + break; + case GPBType::UINT64: + if (!GPBWire::readUint64($input, $value)) { + throw new GPBDecodeException( + "Unexpected EOF inside uint64 field."); + } + break; + case GPBType::INT32: + if (!GPBWire::readInt32($input, $value)) { + throw new GPBDecodeException( + "Unexpected EOF inside int32 field."); + } + break; + case GPBType::FIXED64: + if (!GPBWire::readFixed64($input, $value)) { + throw new GPBDecodeException( + "Unexpected EOF inside fixed64 field."); + } + break; + case GPBType::FIXED32: + if (!GPBWire::readFixed32($input, $value)) { + throw new GPBDecodeException( + "Unexpected EOF inside fixed32 field."); + } + break; + case GPBType::BOOL: + if (!GPBWire::readBool($input, $value)) { + throw new GPBDecodeException( + "Unexpected EOF inside bool field."); + } + break; + case GPBType::STRING: + // TODO(teboring): Add utf-8 check. + if (!GPBWire::readString($input, $value)) { + throw new GPBDecodeException( + "Unexpected EOF inside string field."); + } + break; + case GPBType::GROUP: + trigger_error("Not implemented.", E_ERROR); + break; + case GPBType::MESSAGE: + if ($field->isMap()) { + $value = new MapEntry($field->getMessageType()); + } else { + $klass = $field->getMessageType()->getClass(); + $value = new $klass; + } + if (!GPBWire::readMessage($input, $value)) { + throw new GPBDecodeException( + "Unexpected EOF inside message."); + } + break; + case GPBType::BYTES: + if (!GPBWire::readString($input, $value)) { + throw new GPBDecodeException( + "Unexpected EOF inside bytes field."); + } + break; + case GPBType::UINT32: + if (!GPBWire::readUint32($input, $value)) { + throw new GPBDecodeException( + "Unexpected EOF inside uint32 field."); + } + break; + case GPBType::ENUM: + // TODO(teboring): Check unknown enum value. + if (!GPBWire::readInt32($input, $value)) { + throw new GPBDecodeException( + "Unexpected EOF inside enum field."); + } + break; + case GPBType::SFIXED32: + if (!GPBWire::readSfixed32($input, $value)) { + throw new GPBDecodeException( + "Unexpected EOF inside sfixed32 field."); + } + break; + case GPBType::SFIXED64: + if (!GPBWire::readSfixed64($input, $value)) { + throw new GPBDecodeException( + "Unexpected EOF inside sfixed64 field."); + } + break; + case GPBType::SINT32: + if (!GPBWire::readSint32($input, $value)) { + throw new GPBDecodeException( + "Unexpected EOF inside sint32 field."); + } + break; + case GPBType::SINT64: + if (!GPBWire::readSint64($input, $value)) { + throw new GPBDecodeException( + "Unexpected EOF inside sint64 field."); + } + break; + default: + user_error("Unsupported type."); + return false; + } + return true; + } + + /** + * @ignore + */ + private function parseFieldFromStream($tag, $input, $field) + { + $value = null; + + if (is_null($field)) { + $value_format = GPBWire::UNKNOWN; + } elseif (GPBWire::getTagWireType($tag) === + GPBWire::getWireType($field->getType())) { + $value_format = GPBWire::NORMAL_FORMAT; + } elseif ($field->isPackable() && + GPBWire::getTagWireType($tag) === + GPBWire::WIRETYPE_LENGTH_DELIMITED) { + $value_format = GPBWire::PACKED_FORMAT; + } else { + // the wire type doesn't match. Put it in our unknown field set. + $value_format = GPBWire::UNKNOWN; + } + + if ($value_format === GPBWire::UNKNOWN) { + $this->skipField($input, $tag); + return; + } elseif ($value_format === GPBWire::NORMAL_FORMAT) { + self::parseFieldFromStreamNoTag($input, $field, $value); + } elseif ($value_format === GPBWire::PACKED_FORMAT) { + $length = 0; + if (!GPBWire::readInt32($input, $length)) { + throw new GPBDecodeException( + "Unexpected EOF inside packed length."); + } + $limit = $input->pushLimit($length); + $getter = $field->getGetter(); + while ($input->bytesUntilLimit() > 0) { + self::parseFieldFromStreamNoTag($input, $field, $value); + $this->appendHelper($field, $value); + } + $input->popLimit($limit); + return; + } else { + return; + } + + if ($field->isMap()) { + $this->kvUpdateHelper($field, $value->getKey(), $value->getValue()); + } else if ($field->isRepeated()) { + $this->appendHelper($field, $value); + } else { + $setter = $field->getSetter(); + $this->$setter($value); + } + } + + /** + * Clear all containing fields. + * @return null. + */ + public function clear() + { + $this->unknown = ""; + foreach ($this->desc->getField() as $field) { + $setter = $field->getSetter(); + if ($field->isMap()) { + $message_type = $field->getMessageType(); + $key_field = $message_type->getFieldByNumber(1); + $value_field = $message_type->getFieldByNumber(2); + switch ($value_field->getType()) { + case GPBType::MESSAGE: + case GPBType::GROUP: + $map_field = new MapField( + $key_field->getType(), + $value_field->getType(), + $value_field->getMessageType()->getClass()); + $this->$setter($map_field); + break; + case GPBType::ENUM: + $map_field = new MapField( + $key_field->getType(), + $value_field->getType(), + $value_field->getEnumType()->getClass()); + $this->$setter($map_field); + break; + default: + $map_field = new MapField( + $key_field->getType(), + $value_field->getType()); + $this->$setter($map_field); + break; + } + } else if ($field->getLabel() === GPBLabel::REPEATED) { + switch ($field->getType()) { + case GPBType::MESSAGE: + case GPBType::GROUP: + $repeated_field = new RepeatedField( + $field->getType(), + $field->getMessageType()->getClass()); + $this->$setter($repeated_field); + break; + case GPBType::ENUM: + $repeated_field = new RepeatedField( + $field->getType(), + $field->getEnumType()->getClass()); + $this->$setter($repeated_field); + break; + default: + $repeated_field = new RepeatedField($field->getType()); + $this->$setter($repeated_field); + break; + } + } else if ($field->getOneofIndex() !== -1) { + $oneof = $this->desc->getOneofDecl()[$field->getOneofIndex()]; + $oneof_name = $oneof->getName(); + $this->$oneof_name = new OneofField($oneof); + } else if ($field->getLabel() === GPBLabel::OPTIONAL) { + switch ($field->getType()) { + case GPBType::DOUBLE : + case GPBType::FLOAT : + $this->$setter(0.0); + break; + case GPBType::INT32 : + case GPBType::FIXED32 : + case GPBType::UINT32 : + case GPBType::SFIXED32 : + case GPBType::SINT32 : + case GPBType::ENUM : + $this->$setter(0); + break; + case GPBType::BOOL : + $this->$setter(false); + break; + case GPBType::STRING : + case GPBType::BYTES : + $this->$setter(""); + break; + case GPBType::GROUP : + case GPBType::MESSAGE : + $null = null; + $this->$setter($null); + break; + } + if (PHP_INT_SIZE == 4) { + switch ($field->getType()) { + case GPBType::INT64: + case GPBType::UINT64: + case GPBType::FIXED64: + case GPBType::SFIXED64: + case GPBType::SINT64: + $this->$setter("0"); + } + } else { + switch ($field->getType()) { + case GPBType::INT64: + case GPBType::UINT64: + case GPBType::FIXED64: + case GPBType::SFIXED64: + case GPBType::SINT64: + $this->$setter(0); + } + } + } + } + } + + /** + * Clear all unknown fields previously parsed. + * @return null. + */ + public function discardUnknownFields() + { + $this->unknown = ""; + foreach ($this->desc->getField() as $field) { + if ($field->getType() != GPBType::MESSAGE) { + continue; + } + if ($field->isMap()) { + $value_field = $field->getMessageType()->getFieldByNumber(2); + if ($value_field->getType() != GPBType::MESSAGE) { + continue; + } + $getter = $field->getGetter(); + $map = $this->$getter(); + foreach ($map as $key => $value) { + $value->discardUnknownFields(); + } + } else if ($field->getLabel() === GPBLabel::REPEATED) { + $getter = $field->getGetter(); + $arr = $this->$getter(); + foreach ($arr as $sub) { + $sub->discardUnknownFields(); + } + } else if ($field->getLabel() === GPBLabel::OPTIONAL) { + $getter = $field->getGetter(); + $sub = $this->$getter(); + if (!is_null($sub)) { + $sub->discardUnknownFields(); + } + } + } + } + + /** + * Merges the contents of the specified message into current message. + * + * This method merges the contents of the specified message into the + * current message. Singular fields that are set in the specified message + * overwrite the corresponding fields in the current message. Repeated + * fields are appended. Map fields key-value pairs are overwritten. + * Singular/Oneof sub-messages are recursively merged. All overwritten + * sub-messages are deep-copied. + * + * @param object $msg Protobuf message to be merged from. + * @return null. + */ + public function mergeFrom($msg) + { + if (get_class($this) !== get_class($msg)) { + user_error("Cannot merge messages with different class."); + return; + } + + foreach ($this->desc->getField() as $field) { + $setter = $field->getSetter(); + $getter = $field->getGetter(); + if ($field->isMap()) { + if (count($msg->$getter()) != 0) { + $value_field = $field->getMessageType()->getFieldByNumber(2); + foreach ($msg->$getter() as $key => $value) { + if ($value_field->getType() == GPBType::MESSAGE) { + $klass = $value_field->getMessageType()->getClass(); + $copy = new $klass; + $copy->mergeFrom($value); + + $this->kvUpdateHelper($field, $key, $copy); + } else { + $this->kvUpdateHelper($field, $key, $value); + } + } + } + } else if ($field->getLabel() === GPBLabel::REPEATED) { + if (count($msg->$getter()) != 0) { + foreach ($msg->$getter() as $tmp) { + if ($field->getType() == GPBType::MESSAGE) { + $klass = $field->getMessageType()->getClass(); + $copy = new $klass; + $copy->mergeFrom($tmp); + $this->appendHelper($field, $copy); + } else { + $this->appendHelper($field, $tmp); + } + } + } + } else if ($field->getLabel() === GPBLabel::OPTIONAL) { + if($msg->$getter() !== $this->defaultValue($field)) { + $tmp = $msg->$getter(); + if ($field->getType() == GPBType::MESSAGE) { + if (is_null($this->$getter())) { + $klass = $field->getMessageType()->getClass(); + $new_msg = new $klass; + $this->$setter($new_msg); + } + $this->$getter()->mergeFrom($tmp); + } else { + $this->$setter($tmp); + } + } + } + } + } + + /** + * Parses a protocol buffer contained in a string. + * + * This function takes a string in the (non-human-readable) binary wire + * format, matching the encoding output by serializeToString(). + * See mergeFrom() for merging behavior, if the field is already set in the + * specified message. + * + * @param string $data Binary protobuf data. + * @return null. + * @throws \Exception Invalid data. + */ + public function mergeFromString($data) + { + $input = new CodedInputStream($data); + $this->parseFromStream($input); + } + + /** + * Parses a json string to protobuf message. + * + * This function takes a string in the json wire format, matching the + * encoding output by serializeToJsonString(). + * See mergeFrom() for merging behavior, if the field is already set in the + * specified message. + * + * @param string $data Json protobuf data. + * @return null. + * @throws \Exception Invalid data. + */ + public function mergeFromJsonString($data) + { + $input = new RawInputStream($data); + $this->parseFromJsonStream($input); + } + + /** + * @ignore + */ + public function parseFromStream($input) + { + while (true) { + $tag = $input->readTag(); + // End of input. This is a valid place to end, so return true. + if ($tag === 0) { + return true; + } + + $number = GPBWire::getTagFieldNumber($tag); + $field = $this->desc->getFieldByNumber($number); + + $this->parseFieldFromStream($tag, $input, $field); + } + } + + private function convertJsonValueToProtoValue( + $value, + $field, + $is_map_key = false) + { + switch ($field->getType()) { + case GPBType::MESSAGE: + $klass = $field->getMessageType()->getClass(); + $submsg = new $klass; + + if (is_a($submsg, "Google\Protobuf\Duration")) { + if (is_null($value)) { + return $this->defaultValue($field); + } else if (!is_string($value)) { + throw new GPBDecodeException("Expect string."); + } + return GPBUtil::parseDuration($value); + } else if ($field->isTimestamp()) { + if (is_null($value)) { + return $this->defaultValue($field); + } else if (!is_string($value)) { + throw new GPBDecodeException("Expect string."); + } + try { + $timestamp = GPBUtil::parseTimestamp($value); + } catch (\Exception $e) { + throw new GPBDecodeException( + "Invalid RFC 3339 timestamp: ".$e->getMessage()); + } + + $submsg->setSeconds($timestamp->getSeconds()); + $submsg->setNanos($timestamp->getNanos()); + } else if (is_a($submsg, "Google\Protobuf\FieldMask")) { + if (is_null($value)) { + return $this->defaultValue($field); + } + try { + return GPBUtil::parseFieldMask($value); + } catch (\Exception $e) { + throw new GPBDecodeException( + "Invalid FieldMask: ".$e->getMessage()); + } + } else { + if (is_null($value) && + !is_a($submsg, "Google\Protobuf\Value")) { + return $this->defaultValue($field); + } + if (GPBUtil::hasSpecialJsonMapping($submsg)) { + } elseif (!is_object($value) && !is_array($value)) { + throw new GPBDecodeException("Expect message."); + } + $submsg->mergeFromJsonArray($value); + } + return $submsg; + case GPBType::ENUM: + if (is_null($value)) { + return $this->defaultValue($field); + } + if (is_integer($value)) { + return $value; + } + $enum_value = $field->getEnumType()->getValueByName($value); + if (!is_null($enum_value)) { + return $enum_value->getNumber(); + } + throw new GPBDecodeException( + "Enum field only accepts integer or enum value name"); + case GPBType::STRING: + if (is_null($value)) { + return $this->defaultValue($field); + } + if (is_numeric($value)) { + return strval($value); + } + if (!is_string($value)) { + throw new GPBDecodeException( + "String field only accepts string value"); + } + return $value; + case GPBType::BYTES: + if (is_null($value)) { + return $this->defaultValue($field); + } + if (!is_string($value)) { + throw new GPBDecodeException( + "Byte field only accepts string value"); + } + $proto_value = base64_decode($value, true); + if ($proto_value === false) { + throw new GPBDecodeException("Invalid base64 characters"); + } + return $proto_value; + case GPBType::BOOL: + if (is_null($value)) { + return $this->defaultValue($field); + } + if ($is_map_key) { + if ($value === "true") { + return true; + } + if ($value === "false") { + return false; + } + throw new GPBDecodeException( + "Bool field only accepts bool value"); + } + if (!is_bool($value)) { + throw new GPBDecodeException( + "Bool field only accepts bool value"); + } + return $value; + case GPBType::FLOAT: + case GPBType::DOUBLE: + if (is_null($value)) { + return $this->defaultValue($field); + } + if ($value === "Infinity") { + return INF; + } + if ($value === "-Infinity") { + return -INF; + } + if ($value === "NaN") { + return NAN; + } + return $value; + case GPBType::INT32: + case GPBType::SINT32: + case GPBType::SFIXED32: + if (is_null($value)) { + return $this->defaultValue($field); + } + if (!is_numeric($value)) { + throw new GPBDecodeException( + "Invalid data type for int32 field"); + } + if (is_string($value) && trim($value) !== $value) { + throw new GPBDecodeException( + "Invalid data type for int32 field"); + } + if (bccomp($value, "2147483647") > 0) { + throw new GPBDecodeException( + "Int32 too large"); + } + if (bccomp($value, "-2147483648") < 0) { + throw new GPBDecodeException( + "Int32 too small"); + } + return $value; + case GPBType::UINT32: + case GPBType::FIXED32: + if (is_null($value)) { + return $this->defaultValue($field); + } + if (!is_numeric($value)) { + throw new GPBDecodeException( + "Invalid data type for uint32 field"); + } + if (is_string($value) && trim($value) !== $value) { + throw new GPBDecodeException( + "Invalid data type for int32 field"); + } + if (bccomp($value, 4294967295) > 0) { + throw new GPBDecodeException( + "Uint32 too large"); + } + return $value; + case GPBType::INT64: + case GPBType::SINT64: + case GPBType::SFIXED64: + if (is_null($value)) { + return $this->defaultValue($field); + } + if (!is_numeric($value)) { + throw new GPBDecodeException( + "Invalid data type for int64 field"); + } + if (is_string($value) && trim($value) !== $value) { + throw new GPBDecodeException( + "Invalid data type for int64 field"); + } + if (bccomp($value, "9223372036854775807") > 0) { + throw new GPBDecodeException( + "Int64 too large"); + } + if (bccomp($value, "-9223372036854775808") < 0) { + throw new GPBDecodeException( + "Int64 too small"); + } + return $value; + case GPBType::UINT64: + case GPBType::FIXED64: + if (is_null($value)) { + return $this->defaultValue($field); + } + if (!is_numeric($value)) { + throw new GPBDecodeException( + "Invalid data type for int64 field"); + } + if (is_string($value) && trim($value) !== $value) { + throw new GPBDecodeException( + "Invalid data type for int64 field"); + } + if (bccomp($value, "18446744073709551615") > 0) { + throw new GPBDecodeException( + "Uint64 too large"); + } + if (bccomp($value, "9223372036854775807") > 0) { + $value = bcsub($value, "18446744073709551616"); + } + return $value; + default: + return $value; + } + } + + /** + * Populates the message from a user-supplied PHP array. Array keys + * correspond to Message properties and nested message properties. + * + * Example: + * ``` + * $message->mergeFromArray([ + * 'name' => 'This is a message name', + * 'interval' => [ + * 'startTime' => time() - 60, + * 'endTime' => time(), + * ] + * ]); + * ``` + * + * This method will trigger an error if it is passed data that cannot + * be converted to the correct type. For example, a StringValue field + * must receive data that is either a string or a StringValue object. + * + * @param array $array An array containing message properties and values. + * @return null. + */ + protected function mergeFromArray(array $array) + { + // Just call the setters for the field names + foreach ($array as $key => $value) { + $field = $this->desc->getFieldByName($key); + if (is_null($field)) { + throw new \UnexpectedValueException( + 'Invalid message property: ' . $key); + } + $setter = $field->getSetter(); + if ($field->isMap()) { + $valueField = $field->getMessageType()->getFieldByName('value'); + if (!is_null($valueField) && $valueField->isWrapperType()) { + self::normalizeArrayElementsToMessageType($value, $valueField->getMessageType()->getClass()); + } + } elseif ($field->isWrapperType()) { + $class = $field->getMessageType()->getClass(); + if ($field->isRepeated()) { + self::normalizeArrayElementsToMessageType($value, $class); + } else { + self::normalizeToMessageType($value, $class); + } + } + $this->$setter($value); + } + } + + /** + * Tries to normalize the elements in $value into a provided protobuf + * wrapper type $class. If $value is any type other than array, we do + * not do any conversion, and instead rely on the existing protobuf + * type checking. If $value is an array, we process each element and + * try to convert it to an instance of $class. + * + * @param mixed $value The array of values to normalize. + * @param string $class The expected wrapper class name + */ + private static function normalizeArrayElementsToMessageType(&$value, $class) + { + if (!is_array($value)) { + // In the case that $value is not an array, we do not want to + // attempt any conversion. Note that this includes the cases + // when $value is a RepeatedField of MapField. In those cases, + // we do not need to convert the elements, as they should + // already be the correct types. + return; + } else { + // Normalize each element in the array. + foreach ($value as $key => &$elementValue) { + self::normalizeToMessageType($elementValue, $class); + } + } + } + + /** + * Tries to normalize $value into a provided protobuf wrapper type $class. + * If $value is any type other than an object, we attempt to construct an + * instance of $class and assign $value to it using the setValue method + * shared by all wrapper types. + * + * This method will raise an error if it receives a type that cannot be + * assigned to the wrapper type via setValue. + * + * @param mixed $value The value to normalize. + * @param string $class The expected wrapper class name + */ + private static function normalizeToMessageType(&$value, $class) + { + if (is_null($value) || is_object($value)) { + // This handles the case that $value is an instance of $class. We + // choose not to do any more strict checking here, relying on the + // existing type checking done by GPBUtil. + return; + } else { + // Try to instantiate $class and set the value + try { + $msg = new $class; + $msg->setValue($value); + $value = $msg; + return; + } catch (\Exception $exception) { + trigger_error( + "Error normalizing value to type '$class': " . $exception->getMessage(), + E_USER_ERROR + ); + } + } + } + + protected function mergeFromJsonArray($array) + { + if (is_a($this, "Google\Protobuf\Any")) { + $this->clear(); + $this->setTypeUrl($array["@type"]); + $msg = $this->unpack(); + if (GPBUtil::hasSpecialJsonMapping($msg)) { + $msg->mergeFromJsonArray($array["value"]); + } else { + unset($array["@type"]); + $msg->mergeFromJsonArray($array); + } + $this->setValue($msg->serializeToString()); + return; + } + if (is_a($this, "Google\Protobuf\DoubleValue") || + is_a($this, "Google\Protobuf\FloatValue") || + is_a($this, "Google\Protobuf\Int64Value") || + is_a($this, "Google\Protobuf\UInt64Value") || + is_a($this, "Google\Protobuf\Int32Value") || + is_a($this, "Google\Protobuf\UInt32Value") || + is_a($this, "Google\Protobuf\BoolValue") || + is_a($this, "Google\Protobuf\StringValue")) { + $this->setValue($array); + return; + } + if (is_a($this, "Google\Protobuf\BytesValue")) { + $this->setValue(base64_decode($array)); + return; + } + if (is_a($this, "Google\Protobuf\Duration")) { + $this->mergeFrom(GPBUtil::parseDuration($array)); + return; + } + if (is_a($this, "Google\Protobuf\FieldMask")) { + $this->mergeFrom(GPBUtil::parseFieldMask($array)); + return; + } + if (is_a($this, "Google\Protobuf\Timestamp")) { + $this->mergeFrom(GPBUtil::parseTimestamp($array)); + return; + } + if (is_a($this, "Google\Protobuf\Struct")) { + $fields = $this->getFields(); + foreach($array as $key => $value) { + $v = new Value(); + $v->mergeFromJsonArray($value); + $fields[$key] = $v; + } + } + if (is_a($this, "Google\Protobuf\Value")) { + if (is_bool($array)) { + $this->setBoolValue($array); + } elseif (is_string($array)) { + $this->setStringValue($array); + } elseif (is_null($array)) { + $this->setNullValue(0); + } elseif (is_double($array) || is_integer($array)) { + $this->setNumberValue($array); + } elseif (is_array($array)) { + if (array_values($array) !== $array) { + // Associative array + $struct_value = $this->getStructValue(); + if (is_null($struct_value)) { + $struct_value = new Struct(); + $this->setStructValue($struct_value); + } + foreach ($array as $key => $v) { + $value = new Value(); + $value->mergeFromJsonArray($v); + $values = $struct_value->getFields(); + $values[$key]= $value; + } + } else { + // Array + $list_value = $this->getListValue(); + if (is_null($list_value)) { + $list_value = new ListValue(); + $this->setListValue($list_value); + } + foreach ($array as $v) { + $value = new Value(); + $value->mergeFromJsonArray($v); + $values = $list_value->getValues(); + $values[]= $value; + } + } + } else { + throw new GPBDecodeException("Invalid type for Value."); + } + return; + } + $this->mergeFromArrayJsonImpl($array); + } + + private function mergeFromArrayJsonImpl($array) + { + foreach ($array as $key => $value) { + $field = $this->desc->getFieldByJsonName($key); + if (is_null($field)) { + $field = $this->desc->getFieldByName($key); + if (is_null($field)) { + continue; + } + } + if ($field->isMap()) { + if (is_null($value)) { + continue; + } + $key_field = $field->getMessageType()->getFieldByNumber(1); + $value_field = $field->getMessageType()->getFieldByNumber(2); + foreach ($value as $tmp_key => $tmp_value) { + if (is_null($tmp_value)) { + throw new \Exception( + "Map value field element cannot be null."); + } + $proto_key = $this->convertJsonValueToProtoValue( + $tmp_key, + $key_field, + true); + $proto_value = $this->convertJsonValueToProtoValue( + $tmp_value, + $value_field); + self::kvUpdateHelper($field, $proto_key, $proto_value); + } + } else if ($field->isRepeated()) { + if (is_null($value)) { + continue; + } + foreach ($value as $tmp) { + if (is_null($tmp)) { + throw new \Exception( + "Repeated field elements cannot be null."); + } + $proto_value = $this->convertJsonValueToProtoValue( + $tmp, + $field); + self::appendHelper($field, $proto_value); + } + } else { + $setter = $field->getSetter(); + $proto_value = $this->convertJsonValueToProtoValue( + $value, + $field); + if ($field->getType() === GPBType::MESSAGE) { + if (is_null($proto_value)) { + continue; + } + $getter = $field->getGetter(); + $submsg = $this->$getter(); + if (!is_null($submsg)) { + $submsg->mergeFrom($proto_value); + continue; + } + } + $this->$setter($proto_value); + } + } + } + + /** + * @ignore + */ + public function parseFromJsonStream($input) + { + $array = json_decode($input->getData(), true, 512, JSON_BIGINT_AS_STRING); + if ($this instanceof \Google\Protobuf\ListValue) { + $array = ["values"=>$array]; + } + if (is_null($array)) { + if ($this instanceof \Google\Protobuf\Value) { + $this->setNullValue(\Google\Protobuf\NullValue::NULL_VALUE); + return; + } else { + throw new GPBDecodeException( + "Cannot decode json string: " . $input->getData()); + } + } + try { + $this->mergeFromJsonArray($array); + } catch (\Exception $e) { + throw new GPBDecodeException($e->getMessage()); + } + } + + /** + * @ignore + */ + private function serializeSingularFieldToStream($field, &$output) + { + if (!$this->existField($field)) { + return true; + } + $getter = $field->getGetter(); + $value = $this->$getter(); + if (!GPBWire::serializeFieldToStream($value, $field, true, $output)) { + return false; + } + return true; + } + + /** + * @ignore + */ + private function serializeRepeatedFieldToStream($field, &$output) + { + $getter = $field->getGetter(); + $values = $this->$getter(); + $count = count($values); + if ($count === 0) { + return true; + } + + $packed = $field->getPacked(); + if ($packed) { + if (!GPBWire::writeTag( + $output, + GPBWire::makeTag($field->getNumber(), GPBType::STRING))) { + return false; + } + $size = 0; + foreach ($values as $value) { + $size += $this->fieldDataOnlyByteSize($field, $value); + } + if (!$output->writeVarint32($size, true)) { + return false; + } + } + + foreach ($values as $value) { + if (!GPBWire::serializeFieldToStream( + $value, + $field, + !$packed, + $output)) { + return false; + } + } + return true; + } + + /** + * @ignore + */ + private function serializeMapFieldToStream($field, $output) + { + $getter = $field->getGetter(); + $values = $this->$getter(); + $count = count($values); + if ($count === 0) { + return true; + } + + foreach ($values as $key => $value) { + $map_entry = new MapEntry($field->getMessageType()); + $map_entry->setKey($key); + $map_entry->setValue($value); + if (!GPBWire::serializeFieldToStream( + $map_entry, + $field, + true, + $output)) { + return false; + } + } + return true; + } + + /** + * @ignore + */ + private function serializeFieldToStream(&$output, $field) + { + if ($field->isMap()) { + return $this->serializeMapFieldToStream($field, $output); + } elseif ($field->isRepeated()) { + return $this->serializeRepeatedFieldToStream($field, $output); + } else { + return $this->serializeSingularFieldToStream($field, $output); + } + } + + /** + * @ignore + */ + private function serializeFieldToJsonStream(&$output, $field) + { + $getter = $field->getGetter(); + $values = $this->$getter(); + return GPBJsonWire::serializeFieldToStream( + $values, $field, $output, !GPBUtil::hasSpecialJsonMapping($this)); + } + + /** + * @ignore + */ + public function serializeToStream(&$output) + { + $fields = $this->desc->getField(); + foreach ($fields as $field) { + if (!$this->serializeFieldToStream($output, $field)) { + return false; + } + } + $output->writeRaw($this->unknown, strlen($this->unknown)); + return true; + } + + /** + * @ignore + */ + public function serializeToJsonStream(&$output) + { + if (is_a($this, 'Google\Protobuf\Any')) { + $output->writeRaw("{", 1); + $type_field = $this->desc->getFieldByNumber(1); + $value_msg = $this->unpack(); + + // Serialize type url. + $output->writeRaw("\"@type\":", 8); + $output->writeRaw("\"", 1); + $output->writeRaw($this->getTypeUrl(), strlen($this->getTypeUrl())); + $output->writeRaw("\"", 1); + + // Serialize value + if (GPBUtil::hasSpecialJsonMapping($value_msg)) { + $output->writeRaw(",\"value\":", 9); + $value_msg->serializeToJsonStream($output); + } else { + $value_fields = $value_msg->desc->getField(); + foreach ($value_fields as $field) { + if ($value_msg->existField($field)) { + $output->writeRaw(",", 1); + if (!$value_msg->serializeFieldToJsonStream($output, $field)) { + return false; + } + } + } + } + + $output->writeRaw("}", 1); + } elseif (is_a($this, 'Google\Protobuf\FieldMask')) { + $field_mask = GPBUtil::formatFieldMask($this); + $output->writeRaw("\"", 1); + $output->writeRaw($field_mask, strlen($field_mask)); + $output->writeRaw("\"", 1); + } elseif (is_a($this, 'Google\Protobuf\Duration')) { + $duration = GPBUtil::formatDuration($this) . "s"; + $output->writeRaw("\"", 1); + $output->writeRaw($duration, strlen($duration)); + $output->writeRaw("\"", 1); + } elseif (get_class($this) === 'Google\Protobuf\Timestamp') { + $timestamp = GPBUtil::formatTimestamp($this); + $timestamp = json_encode($timestamp); + $output->writeRaw($timestamp, strlen($timestamp)); + } elseif (get_class($this) === 'Google\Protobuf\ListValue') { + $field = $this->desc->getField()[1]; + if (!$this->existField($field)) { + $output->writeRaw("[]", 2); + } else { + if (!$this->serializeFieldToJsonStream($output, $field)) { + return false; + } + } + } elseif (get_class($this) === 'Google\Protobuf\Struct') { + $field = $this->desc->getField()[1]; + if (!$this->existField($field)) { + $output->writeRaw("{}", 2); + } else { + if (!$this->serializeFieldToJsonStream($output, $field)) { + return false; + } + } + } else { + if (!GPBUtil::hasSpecialJsonMapping($this)) { + $output->writeRaw("{", 1); + } + $fields = $this->desc->getField(); + $first = true; + foreach ($fields as $field) { + if ($this->existField($field) || + GPBUtil::hasJsonValue($this)) { + if ($first) { + $first = false; + } else { + $output->writeRaw(",", 1); + } + if (!$this->serializeFieldToJsonStream($output, $field)) { + return false; + } + } + } + if (!GPBUtil::hasSpecialJsonMapping($this)) { + $output->writeRaw("}", 1); + } + } + return true; + } + + /** + * Serialize the message to string. + * @return string Serialized binary protobuf data. + */ + public function serializeToString() + { + $output = new CodedOutputStream($this->byteSize()); + $this->serializeToStream($output); + return $output->getData(); + } + + /** + * Serialize the message to json string. + * @return string Serialized json protobuf data. + */ + public function serializeToJsonString() + { + $output = new CodedOutputStream($this->jsonByteSize()); + $this->serializeToJsonStream($output); + return $output->getData(); + } + + /** + * @ignore + */ + private function existField($field) + { + $oneof_index = $field->getOneofIndex(); + if ($oneof_index !== -1) { + $oneof = $this->desc->getOneofDecl()[$oneof_index]; + $oneof_name = $oneof->getName(); + return $this->$oneof_name->getNumber() === $field->getNumber(); + } + + $getter = $field->getGetter(); + $values = $this->$getter(); + if ($field->isMap()) { + return count($values) !== 0; + } elseif ($field->isRepeated()) { + return count($values) !== 0; + } else { + return $values !== $this->defaultValue($field); + } + } + + /** + * @ignore + */ + private function repeatedFieldDataOnlyByteSize($field) + { + $size = 0; + + $getter = $field->getGetter(); + $values = $this->$getter(); + $count = count($values); + if ($count !== 0) { + $size += $count * GPBWire::tagSize($field); + foreach ($values as $value) { + $size += $this->singularFieldDataOnlyByteSize($field); + } + } + } + + /** + * @ignore + */ + private function fieldDataOnlyByteSize($field, $value) + { + $size = 0; + + switch ($field->getType()) { + case GPBType::BOOL: + $size += 1; + break; + case GPBType::FLOAT: + case GPBType::FIXED32: + case GPBType::SFIXED32: + $size += 4; + break; + case GPBType::DOUBLE: + case GPBType::FIXED64: + case GPBType::SFIXED64: + $size += 8; + break; + case GPBType::INT32: + case GPBType::ENUM: + $size += GPBWire::varint32Size($value, true); + break; + case GPBType::UINT32: + $size += GPBWire::varint32Size($value); + break; + case GPBType::UINT64: + case GPBType::INT64: + $size += GPBWire::varint64Size($value); + break; + case GPBType::SINT32: + $size += GPBWire::sint32Size($value); + break; + case GPBType::SINT64: + $size += GPBWire::sint64Size($value); + break; + case GPBType::STRING: + case GPBType::BYTES: + $size += strlen($value); + $size += GPBWire::varint32Size($size); + break; + case GPBType::MESSAGE: + $size += $value->byteSize(); + $size += GPBWire::varint32Size($size); + break; + case GPBType::GROUP: + // TODO(teboring): Add support. + user_error("Unsupported type."); + break; + default: + user_error("Unsupported type."); + return 0; + } + + return $size; + } + + /** + * @ignore + */ + private function fieldDataOnlyJsonByteSize($field, $value) + { + $size = 0; + + switch ($field->getType()) { + case GPBType::SFIXED32: + case GPBType::SINT32: + case GPBType::INT32: + $size += strlen(strval($value)); + break; + case GPBType::FIXED32: + case GPBType::UINT32: + if ($value < 0) { + $value = bcadd($value, "4294967296"); + } + $size += strlen(strval($value)); + break; + case GPBType::FIXED64: + case GPBType::UINT64: + if ($value < 0) { + $value = bcadd($value, "18446744073709551616"); + } + // Intentional fall through. + case GPBType::SFIXED64: + case GPBType::INT64: + case GPBType::SINT64: + $size += 2; // size for "" + $size += strlen(strval($value)); + break; + case GPBType::FLOAT: + if (is_nan($value)) { + $size += strlen("NaN") + 2; + } elseif ($value === INF) { + $size += strlen("Infinity") + 2; + } elseif ($value === -INF) { + $size += strlen("-Infinity") + 2; + } else { + $size += strlen(sprintf("%.8g", $value)); + } + break; + case GPBType::DOUBLE: + if (is_nan($value)) { + $size += strlen("NaN") + 2; + } elseif ($value === INF) { + $size += strlen("Infinity") + 2; + } elseif ($value === -INF) { + $size += strlen("-Infinity") + 2; + } else { + $size += strlen(sprintf("%.17g", $value)); + } + break; + case GPBType::ENUM: + $enum_desc = $field->getEnumType(); + if ($enum_desc->getClass() === "Google\Protobuf\NullValue") { + $size += 4; + break; + } + $enum_value_desc = $enum_desc->getValueByNumber($value); + if (!is_null($enum_value_desc)) { + $size += 2; // size for "" + $size += strlen($enum_value_desc->getName()); + } else { + $str_value = strval($value); + $size += strlen($str_value); + } + break; + case GPBType::BOOL: + if ($value) { + $size += 4; + } else { + $size += 5; + } + break; + case GPBType::STRING: + $value = json_encode($value, JSON_UNESCAPED_UNICODE); + $size += strlen($value); + break; + case GPBType::BYTES: + # if (is_a($this, "Google\Protobuf\BytesValue")) { + # $size += strlen(json_encode($value)); + # } else { + # $size += strlen(base64_encode($value)); + # $size += 2; // size for \"\" + # } + $size += strlen(base64_encode($value)); + $size += 2; // size for \"\" + break; + case GPBType::MESSAGE: + $size += $value->jsonByteSize(); + break; +# case GPBType::GROUP: +# // TODO(teboring): Add support. +# user_error("Unsupported type."); +# break; + default: + user_error("Unsupported type " . $field->getType()); + return 0; + } + + return $size; + } + + /** + * @ignore + */ + private function fieldByteSize($field) + { + $size = 0; + if ($field->isMap()) { + $getter = $field->getGetter(); + $values = $this->$getter(); + $count = count($values); + if ($count !== 0) { + $size += $count * GPBWire::tagSize($field); + $message_type = $field->getMessageType(); + $key_field = $message_type->getFieldByNumber(1); + $value_field = $message_type->getFieldByNumber(2); + foreach ($values as $key => $value) { + $data_size = 0; + if ($key != $this->defaultValue($key_field)) { + $data_size += $this->fieldDataOnlyByteSize( + $key_field, + $key); + $data_size += GPBWire::tagSize($key_field); + } + if ($value != $this->defaultValue($value_field)) { + $data_size += $this->fieldDataOnlyByteSize( + $value_field, + $value); + $data_size += GPBWire::tagSize($value_field); + } + $size += GPBWire::varint32Size($data_size) + $data_size; + } + } + } elseif ($field->isRepeated()) { + $getter = $field->getGetter(); + $values = $this->$getter(); + $count = count($values); + if ($count !== 0) { + if ($field->getPacked()) { + $data_size = 0; + foreach ($values as $value) { + $data_size += $this->fieldDataOnlyByteSize($field, $value); + } + $size += GPBWire::tagSize($field); + $size += GPBWire::varint32Size($data_size); + $size += $data_size; + } else { + $size += $count * GPBWire::tagSize($field); + foreach ($values as $value) { + $size += $this->fieldDataOnlyByteSize($field, $value); + } + } + } + } elseif ($this->existField($field)) { + $size += GPBWire::tagSize($field); + $getter = $field->getGetter(); + $value = $this->$getter(); + $size += $this->fieldDataOnlyByteSize($field, $value); + } + return $size; + } + + /** + * @ignore + */ + private function fieldJsonByteSize($field) + { + $size = 0; + + if ($field->isMap()) { + $getter = $field->getGetter(); + $values = $this->$getter(); + $count = count($values); + if ($count !== 0) { + if (!GPBUtil::hasSpecialJsonMapping($this)) { + $size += 3; // size for "\"\":". + $size += strlen($field->getJsonName()); // size for field name + } + $size += 2; // size for "{}". + $size += $count - 1; // size for commas + $getter = $field->getGetter(); + $map_entry = $field->getMessageType(); + $key_field = $map_entry->getFieldByNumber(1); + $value_field = $map_entry->getFieldByNumber(2); + switch ($key_field->getType()) { + case GPBType::STRING: + case GPBType::SFIXED64: + case GPBType::INT64: + case GPBType::SINT64: + case GPBType::FIXED64: + case GPBType::UINT64: + $additional_quote = false; + break; + default: + $additional_quote = true; + } + foreach ($values as $key => $value) { + if ($additional_quote) { + $size += 2; // size for "" + } + $size += $this->fieldDataOnlyJsonByteSize($key_field, $key); + $size += $this->fieldDataOnlyJsonByteSize($value_field, $value); + $size += 1; // size for : + } + } + } elseif ($field->isRepeated()) { + $getter = $field->getGetter(); + $values = $this->$getter(); + $count = count($values); + if ($count !== 0) { + if (!GPBUtil::hasSpecialJsonMapping($this)) { + $size += 3; // size for "\"\":". + $size += strlen($field->getJsonName()); // size for field name + } + $size += 2; // size for "[]". + $size += $count - 1; // size for commas + $getter = $field->getGetter(); + foreach ($values as $value) { + $size += $this->fieldDataOnlyJsonByteSize($field, $value); + } + } + } elseif ($this->existField($field) || GPBUtil::hasJsonValue($this)) { + if (!GPBUtil::hasSpecialJsonMapping($this)) { + $size += 3; // size for "\"\":". + $size += strlen($field->getJsonName()); // size for field name + } + $getter = $field->getGetter(); + $value = $this->$getter(); + $size += $this->fieldDataOnlyJsonByteSize($field, $value); + } + return $size; + } + + /** + * @ignore + */ + public function byteSize() + { + $size = 0; + + $fields = $this->desc->getField(); + foreach ($fields as $field) { + $size += $this->fieldByteSize($field); + } + $size += strlen($this->unknown); + return $size; + } + + private function appendHelper($field, $append_value) + { + $getter = $field->getGetter(); + $setter = $field->getSetter(); + + $field_arr_value = $this->$getter(); + $field_arr_value[] = $append_value; + + if (!is_object($field_arr_value)) { + $this->$setter($field_arr_value); + } + } + + private function kvUpdateHelper($field, $update_key, $update_value) + { + $getter = $field->getGetter(); + $setter = $field->getSetter(); + + $field_arr_value = $this->$getter(); + $field_arr_value[$update_key] = $update_value; + + if (!is_object($field_arr_value)) { + $this->$setter($field_arr_value); + } + } + + /** + * @ignore + */ + public function jsonByteSize() + { + $size = 0; + if (is_a($this, 'Google\Protobuf\Any')) { + // Size for "{}". + $size += 2; + + // Size for "\"@type\":". + $size += 8; + + // Size for url. +2 for "" /. + $size += strlen($this->getTypeUrl()) + 2; + + $value_msg = $this->unpack(); + if (GPBUtil::hasSpecialJsonMapping($value_msg)) { + // Size for "\",value\":". + $size += 9; + $size += $value_msg->jsonByteSize(); + } else { + // Size for value. +1 for comma, -2 for "{}". + $size += $value_msg->jsonByteSize() -1; + } + } elseif (get_class($this) === 'Google\Protobuf\FieldMask') { + $field_mask = GPBUtil::formatFieldMask($this); + $size += strlen($field_mask) + 2; // 2 for "" + } elseif (get_class($this) === 'Google\Protobuf\Duration') { + $duration = GPBUtil::formatDuration($this) . "s"; + $size += strlen($duration) + 2; // 2 for "" + } elseif (get_class($this) === 'Google\Protobuf\Timestamp') { + $timestamp = GPBUtil::formatTimestamp($this); + $timestamp = json_encode($timestamp); + $size += strlen($timestamp); + } elseif (get_class($this) === 'Google\Protobuf\ListValue') { + $field = $this->desc->getField()[1]; + if ($this->existField($field)) { + $field_size = $this->fieldJsonByteSize($field); + $size += $field_size; + } else { + // Size for "[]". + $size += 2; + } + } elseif (get_class($this) === 'Google\Protobuf\Struct') { + $field = $this->desc->getField()[1]; + if ($this->existField($field)) { + $field_size = $this->fieldJsonByteSize($field); + $size += $field_size; + } else { + // Size for "{}". + $size += 2; + } + } else { + if (!GPBUtil::hasSpecialJsonMapping($this)) { + // Size for "{}". + $size += 2; + } + + $fields = $this->desc->getField(); + $count = 0; + foreach ($fields as $field) { + $field_size = $this->fieldJsonByteSize($field); + $size += $field_size; + if ($field_size != 0) { + $count++; + } + } + // size for comma + $size += $count > 0 ? ($count - 1) : 0; + } + return $size; + } +} diff --git a/src/pro/Google/Protobuf/Internal/MessageBuilderContext.php b/src/pro/Google/Protobuf/Internal/MessageBuilderContext.php new file mode 100644 index 00000000..2724d267 --- /dev/null +++ b/src/pro/Google/Protobuf/Internal/MessageBuilderContext.php @@ -0,0 +1,120 @@ +descriptor = new Descriptor(); + $this->descriptor->setFullName($full_name); + $this->descriptor->setClass($klass); + $this->pool = $pool; + } + + private function getFieldDescriptor($name, $label, $type, + $number, $type_name = null) + { + $field = new FieldDescriptor(); + $field->setName($name); + $camel_name = implode('', array_map('ucwords', explode('_', $name))); + $field->setGetter('get' . $camel_name); + $field->setSetter('set' . $camel_name); + $field->setType($type); + $field->setNumber($number); + $field->setLabel($label); + + // 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 function optional($name, $type, $number, $type_name = null) + { + $this->descriptor->addField($this->getFieldDescriptor( + $name, + GPBLabel::OPTIONAL, + $type, + $number, + $type_name)); + return $this; + } + + public function repeated($name, $type, $number, $type_name = null) + { + $this->descriptor->addField($this->getFieldDescriptor( + $name, + GPBLabel::REPEATED, + $type, + $number, + $type_name)); + return $this; + } + + public function required($name, $type, $number, $type_name = null) + { + $this->descriptor->addField($this->getFieldDescriptor( + $name, + GPBLabel::REQUIRED, + $type, + $number, + $type_name)); + return $this; + } + + public function finalizeToPool() + { + $this->pool->addDescriptor($this->descriptor); + } +} diff --git a/src/pro/Google/Protobuf/Internal/MessageOptions.php b/src/pro/Google/Protobuf/Internal/MessageOptions.php new file mode 100644 index 00000000..95bb706a --- /dev/null +++ b/src/pro/Google/Protobuf/Internal/MessageOptions.php @@ -0,0 +1,382 @@ +google.protobuf.MessageOptions + */ +class MessageOptions extends \Google\Protobuf\Internal\Message +{ + /** + * Set true to use the old proto1 MessageSet wire format for extensions. + * This is provided for backwards-compatibility with the MessageSet wire + * format. You should not use this for any other reason: It's less + * efficient, has fewer features, and is more complicated. + * The message must be defined exactly as follows: + * message Foo { + * option message_set_wire_format = true; + * extensions 4 to max; + * } + * Note that the message cannot have any defined fields; MessageSets only + * have extensions. + * All extensions of your type must be singular messages; e.g. they cannot + * be int32s, enums, or repeated messages. + * Because this is an option, the above two restrictions are not enforced by + * the protocol compiler. + * + * Generated from protobuf field optional bool message_set_wire_format = 1 [default = false]; + */ + protected $message_set_wire_format = false; + private $has_message_set_wire_format = false; + /** + * Disables the generation of the standard "descriptor()" accessor, which can + * conflict with a field of the same name. This is meant to make migration + * from proto1 easier; new code should avoid fields named "descriptor". + * + * Generated from protobuf field optional bool no_standard_descriptor_accessor = 2 [default = false]; + */ + protected $no_standard_descriptor_accessor = false; + private $has_no_standard_descriptor_accessor = false; + /** + * Is this message deprecated? + * Depending on the target platform, this can emit Deprecated annotations + * for the message, or it will be completely ignored; in the very least, + * this is a formalization for deprecating messages. + * + * Generated from protobuf field optional bool deprecated = 3 [default = false]; + */ + protected $deprecated = false; + private $has_deprecated = false; + /** + * Whether the message is an automatically generated map entry type for the + * maps field. + * For maps fields: + * map map_field = 1; + * The parsed descriptor looks like: + * message MapFieldEntry { + * option map_entry = true; + * optional KeyType key = 1; + * optional ValueType value = 2; + * } + * repeated MapFieldEntry map_field = 1; + * Implementations may choose not to generate the map_entry=true message, but + * use a native map in the target language to hold the keys and values. + * The reflection APIs in such implementations still need to work as + * if the field is a repeated message field. + * NOTE: Do not set the option in .proto files. Always use the maps syntax + * instead. The option should only be implicitly set by the proto compiler + * parser. + * + * Generated from protobuf field optional bool map_entry = 7; + */ + protected $map_entry = false; + private $has_map_entry = false; + /** + * The parser stores options it doesn't recognize here. See above. + * + * Generated from protobuf field repeated .google.protobuf.UninterpretedOption uninterpreted_option = 999; + */ + private $uninterpreted_option; + private $has_uninterpreted_option = false; + + /** + * Constructor. + * + * @param array $data { + * Optional. Data for populating the Message object. + * + * @type bool $message_set_wire_format + * Set true to use the old proto1 MessageSet wire format for extensions. + * This is provided for backwards-compatibility with the MessageSet wire + * format. You should not use this for any other reason: It's less + * efficient, has fewer features, and is more complicated. + * The message must be defined exactly as follows: + * message Foo { + * option message_set_wire_format = true; + * extensions 4 to max; + * } + * Note that the message cannot have any defined fields; MessageSets only + * have extensions. + * All extensions of your type must be singular messages; e.g. they cannot + * be int32s, enums, or repeated messages. + * Because this is an option, the above two restrictions are not enforced by + * the protocol compiler. + * @type bool $no_standard_descriptor_accessor + * Disables the generation of the standard "descriptor()" accessor, which can + * conflict with a field of the same name. This is meant to make migration + * from proto1 easier; new code should avoid fields named "descriptor". + * @type bool $deprecated + * Is this message deprecated? + * Depending on the target platform, this can emit Deprecated annotations + * for the message, or it will be completely ignored; in the very least, + * this is a formalization for deprecating messages. + * @type bool $map_entry + * Whether the message is an automatically generated map entry type for the + * maps field. + * For maps fields: + * map map_field = 1; + * The parsed descriptor looks like: + * message MapFieldEntry { + * option map_entry = true; + * optional KeyType key = 1; + * optional ValueType value = 2; + * } + * repeated MapFieldEntry map_field = 1; + * Implementations may choose not to generate the map_entry=true message, but + * use a native map in the target language to hold the keys and values. + * The reflection APIs in such implementations still need to work as + * if the field is a repeated message field. + * NOTE: Do not set the option in .proto files. Always use the maps syntax + * instead. The option should only be implicitly set by the proto compiler + * parser. + * @type \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 true to use the old proto1 MessageSet wire format for extensions. + * This is provided for backwards-compatibility with the MessageSet wire + * format. You should not use this for any other reason: It's less + * efficient, has fewer features, and is more complicated. + * The message must be defined exactly as follows: + * message Foo { + * option message_set_wire_format = true; + * extensions 4 to max; + * } + * Note that the message cannot have any defined fields; MessageSets only + * have extensions. + * All extensions of your type must be singular messages; e.g. they cannot + * be int32s, enums, or repeated messages. + * Because this is an option, the above two restrictions are not enforced by + * the protocol compiler. + * + * Generated from protobuf field optional bool message_set_wire_format = 1 [default = false]; + * @return bool + */ + public function getMessageSetWireFormat() + { + return $this->message_set_wire_format; + } + + /** + * Set true to use the old proto1 MessageSet wire format for extensions. + * This is provided for backwards-compatibility with the MessageSet wire + * format. You should not use this for any other reason: It's less + * efficient, has fewer features, and is more complicated. + * The message must be defined exactly as follows: + * message Foo { + * option message_set_wire_format = true; + * extensions 4 to max; + * } + * Note that the message cannot have any defined fields; MessageSets only + * have extensions. + * All extensions of your type must be singular messages; e.g. they cannot + * be int32s, enums, or repeated messages. + * Because this is an option, the above two restrictions are not enforced by + * the protocol compiler. + * + * Generated from protobuf field optional bool message_set_wire_format = 1 [default = false]; + * @param bool $var + * @return $this + */ + public function setMessageSetWireFormat($var) + { + GPBUtil::checkBool($var); + $this->message_set_wire_format = $var; + $this->has_message_set_wire_format = true; + + return $this; + } + + public function hasMessageSetWireFormat() + { + return $this->has_message_set_wire_format; + } + + /** + * Disables the generation of the standard "descriptor()" accessor, which can + * conflict with a field of the same name. This is meant to make migration + * from proto1 easier; new code should avoid fields named "descriptor". + * + * Generated from protobuf field optional bool no_standard_descriptor_accessor = 2 [default = false]; + * @return bool + */ + public function getNoStandardDescriptorAccessor() + { + return $this->no_standard_descriptor_accessor; + } + + /** + * Disables the generation of the standard "descriptor()" accessor, which can + * conflict with a field of the same name. This is meant to make migration + * from proto1 easier; new code should avoid fields named "descriptor". + * + * Generated from protobuf field optional bool no_standard_descriptor_accessor = 2 [default = false]; + * @param bool $var + * @return $this + */ + public function setNoStandardDescriptorAccessor($var) + { + GPBUtil::checkBool($var); + $this->no_standard_descriptor_accessor = $var; + $this->has_no_standard_descriptor_accessor = true; + + return $this; + } + + public function hasNoStandardDescriptorAccessor() + { + return $this->has_no_standard_descriptor_accessor; + } + + /** + * Is this message deprecated? + * Depending on the target platform, this can emit Deprecated annotations + * for the message, or it will be completely ignored; in the very least, + * this is a formalization for deprecating messages. + * + * Generated from protobuf field optional bool deprecated = 3 [default = false]; + * @return bool + */ + public function getDeprecated() + { + return $this->deprecated; + } + + /** + * Is this message deprecated? + * Depending on the target platform, this can emit Deprecated annotations + * for the message, or it will be completely ignored; in the very least, + * this is a formalization for deprecating messages. + * + * Generated from protobuf field optional bool deprecated = 3 [default = false]; + * @param bool $var + * @return $this + */ + public function setDeprecated($var) + { + GPBUtil::checkBool($var); + $this->deprecated = $var; + $this->has_deprecated = true; + + return $this; + } + + public function hasDeprecated() + { + return $this->has_deprecated; + } + + /** + * Whether the message is an automatically generated map entry type for the + * maps field. + * For maps fields: + * map map_field = 1; + * The parsed descriptor looks like: + * message MapFieldEntry { + * option map_entry = true; + * optional KeyType key = 1; + * optional ValueType value = 2; + * } + * repeated MapFieldEntry map_field = 1; + * Implementations may choose not to generate the map_entry=true message, but + * use a native map in the target language to hold the keys and values. + * The reflection APIs in such implementations still need to work as + * if the field is a repeated message field. + * NOTE: Do not set the option in .proto files. Always use the maps syntax + * instead. The option should only be implicitly set by the proto compiler + * parser. + * + * Generated from protobuf field optional bool map_entry = 7; + * @return bool + */ + public function getMapEntry() + { + return $this->map_entry; + } + + /** + * Whether the message is an automatically generated map entry type for the + * maps field. + * For maps fields: + * map map_field = 1; + * The parsed descriptor looks like: + * message MapFieldEntry { + * option map_entry = true; + * optional KeyType key = 1; + * optional ValueType value = 2; + * } + * repeated MapFieldEntry map_field = 1; + * Implementations may choose not to generate the map_entry=true message, but + * use a native map in the target language to hold the keys and values. + * The reflection APIs in such implementations still need to work as + * if the field is a repeated message field. + * NOTE: Do not set the option in .proto files. Always use the maps syntax + * instead. The option should only be implicitly set by the proto compiler + * parser. + * + * Generated from protobuf field optional bool map_entry = 7; + * @param bool $var + * @return $this + */ + public function setMapEntry($var) + { + GPBUtil::checkBool($var); + $this->map_entry = $var; + $this->has_map_entry = true; + + return $this; + } + + public function hasMapEntry() + { + return $this->has_map_entry; + } + + /** + * The parser stores options it doesn't recognize here. See above. + * + * Generated from protobuf field repeated .google.protobuf.UninterpretedOption uninterpreted_option = 999; + * @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 repeated .google.protobuf.UninterpretedOption uninterpreted_option = 999; + * @param \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; + $this->has_uninterpreted_option = true; + + return $this; + } + + public function hasUninterpretedOption() + { + return $this->has_uninterpreted_option; + } + +} + diff --git a/src/pro/Google/Protobuf/Internal/MethodDescriptorProto.php b/src/pro/Google/Protobuf/Internal/MethodDescriptorProto.php new file mode 100644 index 00000000..f40f20f0 --- /dev/null +++ b/src/pro/Google/Protobuf/Internal/MethodDescriptorProto.php @@ -0,0 +1,264 @@ +google.protobuf.MethodDescriptorProto + */ +class MethodDescriptorProto extends \Google\Protobuf\Internal\Message +{ + /** + * Generated from protobuf field optional string name = 1; + */ + protected $name = ''; + private $has_name = false; + /** + * Input and output type names. These are resolved in the same way as + * FieldDescriptorProto.type_name, but must refer to a message type. + * + * Generated from protobuf field optional string input_type = 2; + */ + protected $input_type = ''; + private $has_input_type = false; + /** + * Generated from protobuf field optional string output_type = 3; + */ + protected $output_type = ''; + private $has_output_type = false; + /** + * Generated from protobuf field optional .google.protobuf.MethodOptions options = 4; + */ + protected $options = null; + private $has_options = false; + /** + * Identifies if client streams multiple client messages + * + * Generated from protobuf field optional bool client_streaming = 5 [default = false]; + */ + protected $client_streaming = false; + private $has_client_streaming = false; + /** + * Identifies if server streams multiple server messages + * + * Generated from protobuf field optional bool server_streaming = 6 [default = false]; + */ + protected $server_streaming = false; + private $has_server_streaming = false; + + /** + * Constructor. + * + * @param array $data { + * Optional. Data for populating the Message object. + * + * @type string $name + * @type string $input_type + * Input and output type names. These are resolved in the same way as + * FieldDescriptorProto.type_name, but must refer to a message type. + * @type string $output_type + * @type \Google\Protobuf\Internal\MethodOptions $options + * @type bool $client_streaming + * Identifies if client streams multiple client messages + * @type bool $server_streaming + * Identifies if server streams multiple server messages + * } + */ + public function __construct($data = NULL) { + \GPBMetadata\Google\Protobuf\Internal\Descriptor::initOnce(); + parent::__construct($data); + } + + /** + * Generated from protobuf field optional string name = 1; + * @return string + */ + public function getName() + { + return $this->name; + } + + /** + * Generated from protobuf field optional string name = 1; + * @param string $var + * @return $this + */ + public function setName($var) + { + GPBUtil::checkString($var, True); + $this->name = $var; + $this->has_name = true; + + return $this; + } + + public function hasName() + { + return $this->has_name; + } + + /** + * Input and output type names. These are resolved in the same way as + * FieldDescriptorProto.type_name, but must refer to a message type. + * + * Generated from protobuf field optional string input_type = 2; + * @return string + */ + public function getInputType() + { + return $this->input_type; + } + + /** + * Input and output type names. These are resolved in the same way as + * FieldDescriptorProto.type_name, but must refer to a message type. + * + * Generated from protobuf field optional string input_type = 2; + * @param string $var + * @return $this + */ + public function setInputType($var) + { + GPBUtil::checkString($var, True); + $this->input_type = $var; + $this->has_input_type = true; + + return $this; + } + + public function hasInputType() + { + return $this->has_input_type; + } + + /** + * Generated from protobuf field optional string output_type = 3; + * @return string + */ + public function getOutputType() + { + return $this->output_type; + } + + /** + * Generated from protobuf field optional string output_type = 3; + * @param string $var + * @return $this + */ + public function setOutputType($var) + { + GPBUtil::checkString($var, True); + $this->output_type = $var; + $this->has_output_type = true; + + return $this; + } + + public function hasOutputType() + { + return $this->has_output_type; + } + + /** + * Generated from protobuf field optional .google.protobuf.MethodOptions options = 4; + * @return \Google\Protobuf\Internal\MethodOptions + */ + public function getOptions() + { + return $this->options; + } + + /** + * Generated from protobuf field optional .google.protobuf.MethodOptions options = 4; + * @param \Google\Protobuf\Internal\MethodOptions $var + * @return $this + */ + public function setOptions($var) + { + GPBUtil::checkMessage($var, \Google\Protobuf\Internal\MethodOptions::class); + $this->options = $var; + $this->has_options = true; + + return $this; + } + + public function hasOptions() + { + return $this->has_options; + } + + /** + * Identifies if client streams multiple client messages + * + * Generated from protobuf field optional bool client_streaming = 5 [default = false]; + * @return bool + */ + public function getClientStreaming() + { + return $this->client_streaming; + } + + /** + * Identifies if client streams multiple client messages + * + * Generated from protobuf field optional bool client_streaming = 5 [default = false]; + * @param bool $var + * @return $this + */ + public function setClientStreaming($var) + { + GPBUtil::checkBool($var); + $this->client_streaming = $var; + $this->has_client_streaming = true; + + return $this; + } + + public function hasClientStreaming() + { + return $this->has_client_streaming; + } + + /** + * Identifies if server streams multiple server messages + * + * Generated from protobuf field optional bool server_streaming = 6 [default = false]; + * @return bool + */ + public function getServerStreaming() + { + return $this->server_streaming; + } + + /** + * Identifies if server streams multiple server messages + * + * Generated from protobuf field optional bool server_streaming = 6 [default = false]; + * @param bool $var + * @return $this + */ + public function setServerStreaming($var) + { + GPBUtil::checkBool($var); + $this->server_streaming = $var; + $this->has_server_streaming = true; + + return $this; + } + + public function hasServerStreaming() + { + return $this->has_server_streaming; + } + +} + diff --git a/src/pro/Google/Protobuf/Internal/MethodOptions.php b/src/pro/Google/Protobuf/Internal/MethodOptions.php new file mode 100644 index 00000000..6a4c92de --- /dev/null +++ b/src/pro/Google/Protobuf/Internal/MethodOptions.php @@ -0,0 +1,161 @@ +google.protobuf.MethodOptions + */ +class MethodOptions extends \Google\Protobuf\Internal\Message +{ + /** + * Is this method deprecated? + * Depending on the target platform, this can emit Deprecated annotations + * for the method, or it will be completely ignored; in the very least, + * this is a formalization for deprecating methods. + * + * Generated from protobuf field optional bool deprecated = 33 [default = false]; + */ + protected $deprecated = false; + private $has_deprecated = false; + /** + * Generated from protobuf field optional .google.protobuf.MethodOptions.IdempotencyLevel idempotency_level = 34 [default = IDEMPOTENCY_UNKNOWN]; + */ + protected $idempotency_level = 0; + private $has_idempotency_level = false; + /** + * The parser stores options it doesn't recognize here. See above. + * + * Generated from protobuf field repeated .google.protobuf.UninterpretedOption uninterpreted_option = 999; + */ + private $uninterpreted_option; + private $has_uninterpreted_option = false; + + /** + * Constructor. + * + * @param array $data { + * Optional. Data for populating the Message object. + * + * @type bool $deprecated + * Is this method deprecated? + * Depending on the target platform, this can emit Deprecated annotations + * for the method, or it will be completely ignored; in the very least, + * this is a formalization for deprecating methods. + * @type int $idempotency_level + * @type \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 method deprecated? + * Depending on the target platform, this can emit Deprecated annotations + * for the method, or it will be completely ignored; in the very least, + * this is a formalization for deprecating methods. + * + * Generated from protobuf field optional bool deprecated = 33 [default = false]; + * @return bool + */ + public function getDeprecated() + { + return $this->deprecated; + } + + /** + * Is this method deprecated? + * Depending on the target platform, this can emit Deprecated annotations + * for the method, or it will be completely ignored; in the very least, + * this is a formalization for deprecating methods. + * + * Generated from protobuf field optional bool deprecated = 33 [default = false]; + * @param bool $var + * @return $this + */ + public function setDeprecated($var) + { + GPBUtil::checkBool($var); + $this->deprecated = $var; + $this->has_deprecated = true; + + return $this; + } + + public function hasDeprecated() + { + return $this->has_deprecated; + } + + /** + * Generated from protobuf field optional .google.protobuf.MethodOptions.IdempotencyLevel idempotency_level = 34 [default = IDEMPOTENCY_UNKNOWN]; + * @return int + */ + public function getIdempotencyLevel() + { + return $this->idempotency_level; + } + + /** + * Generated from protobuf field optional .google.protobuf.MethodOptions.IdempotencyLevel idempotency_level = 34 [default = IDEMPOTENCY_UNKNOWN]; + * @param int $var + * @return $this + */ + public function setIdempotencyLevel($var) + { + GPBUtil::checkEnum($var, \Google\Protobuf\Internal\MethodOptions_IdempotencyLevel::class); + $this->idempotency_level = $var; + $this->has_idempotency_level = true; + + return $this; + } + + public function hasIdempotencyLevel() + { + return $this->has_idempotency_level; + } + + /** + * The parser stores options it doesn't recognize here. See above. + * + * Generated from protobuf field repeated .google.protobuf.UninterpretedOption uninterpreted_option = 999; + * @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 repeated .google.protobuf.UninterpretedOption uninterpreted_option = 999; + * @param \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; + $this->has_uninterpreted_option = true; + + return $this; + } + + public function hasUninterpretedOption() + { + return $this->has_uninterpreted_option; + } + +} + diff --git a/src/pro/Google/Protobuf/Internal/MethodOptions/IdempotencyLevel.php b/src/pro/Google/Protobuf/Internal/MethodOptions/IdempotencyLevel.php new file mode 100644 index 00000000..ce3c062c --- /dev/null +++ b/src/pro/Google/Protobuf/Internal/MethodOptions/IdempotencyLevel.php @@ -0,0 +1,64 @@ +google.protobuf.MethodOptions.IdempotencyLevel + */ +class IdempotencyLevel +{ + /** + * Generated from protobuf enum IDEMPOTENCY_UNKNOWN = 0; + */ + const IDEMPOTENCY_UNKNOWN = 0; + /** + * implies idempotent + * + * Generated from protobuf enum NO_SIDE_EFFECTS = 1; + */ + const NO_SIDE_EFFECTS = 1; + /** + * idempotent, but may have side effects + * + * Generated from protobuf enum IDEMPOTENT = 2; + */ + const IDEMPOTENT = 2; + + private static $valueToName = [ + self::IDEMPOTENCY_UNKNOWN => 'IDEMPOTENCY_UNKNOWN', + self::NO_SIDE_EFFECTS => 'NO_SIDE_EFFECTS', + self::IDEMPOTENT => 'IDEMPOTENT', + ]; + + 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(IdempotencyLevel::class, \Google\Protobuf\Internal\MethodOptions_IdempotencyLevel::class); + diff --git a/src/pro/Google/Protobuf/Internal/MethodOptions_IdempotencyLevel.php b/src/pro/Google/Protobuf/Internal/MethodOptions_IdempotencyLevel.php new file mode 100644 index 00000000..a2913114 --- /dev/null +++ b/src/pro/Google/Protobuf/Internal/MethodOptions_IdempotencyLevel.php @@ -0,0 +1,16 @@ +public_desc = new \Google\Protobuf\OneofDescriptor($this); + } + + public function setName($name) + { + $this->name = $name; + } + + public function getName() + { + return $this->name; + } + + public function addField(FieldDescriptor $field) + { + $this->fields[] = $field; + } + + public function getFields() + { + return $this->fields; + } + + public static function buildFromProto($oneof_proto, $desc, $index) + { + $oneof = new OneofDescriptor(); + $oneof->setName($oneof_proto->getName()); + foreach ($desc->getField() as $field) { + if ($field->getOneofIndex() == $index) { + $oneof->addField($field); + } + } + return $oneof; + } +} diff --git a/src/pro/Google/Protobuf/Internal/OneofDescriptorProto.php b/src/pro/Google/Protobuf/Internal/OneofDescriptorProto.php new file mode 100644 index 00000000..413b8e55 --- /dev/null +++ b/src/pro/Google/Protobuf/Internal/OneofDescriptorProto.php @@ -0,0 +1,103 @@ +google.protobuf.OneofDescriptorProto + */ +class OneofDescriptorProto extends \Google\Protobuf\Internal\Message +{ + /** + * Generated from protobuf field optional string name = 1; + */ + protected $name = ''; + private $has_name = false; + /** + * Generated from protobuf field optional .google.protobuf.OneofOptions options = 2; + */ + protected $options = null; + private $has_options = false; + + /** + * Constructor. + * + * @param array $data { + * Optional. Data for populating the Message object. + * + * @type string $name + * @type \Google\Protobuf\Internal\OneofOptions $options + * } + */ + public function __construct($data = NULL) { + \GPBMetadata\Google\Protobuf\Internal\Descriptor::initOnce(); + parent::__construct($data); + } + + /** + * Generated from protobuf field optional string name = 1; + * @return string + */ + public function getName() + { + return $this->name; + } + + /** + * Generated from protobuf field optional string name = 1; + * @param string $var + * @return $this + */ + public function setName($var) + { + GPBUtil::checkString($var, True); + $this->name = $var; + $this->has_name = true; + + return $this; + } + + public function hasName() + { + return $this->has_name; + } + + /** + * Generated from protobuf field optional .google.protobuf.OneofOptions options = 2; + * @return \Google\Protobuf\Internal\OneofOptions + */ + public function getOptions() + { + return $this->options; + } + + /** + * Generated from protobuf field optional .google.protobuf.OneofOptions options = 2; + * @param \Google\Protobuf\Internal\OneofOptions $var + * @return $this + */ + public function setOptions($var) + { + GPBUtil::checkMessage($var, \Google\Protobuf\Internal\OneofOptions::class); + $this->options = $var; + $this->has_options = true; + + return $this; + } + + public function hasOptions() + { + return $this->has_options; + } + +} + diff --git a/src/pro/Google/Protobuf/Internal/OneofField.php b/src/pro/Google/Protobuf/Internal/OneofField.php new file mode 100644 index 00000000..2c689e83 --- /dev/null +++ b/src/pro/Google/Protobuf/Internal/OneofField.php @@ -0,0 +1,77 @@ +desc = $desc; + } + + public function setValue($value) + { + $this->value = $value; + } + + public function getValue() + { + return $this->value; + } + + public function setFieldName($field_name) + { + $this->field_name = $field_name; + } + + public function getFieldName() + { + return $this->field_name; + } + + public function setNumber($number) + { + $this->number = $number; + } + + public function getNumber() + { + return $this->number; + } +} diff --git a/src/pro/Google/Protobuf/Internal/OneofOptions.php b/src/pro/Google/Protobuf/Internal/OneofOptions.php new file mode 100644 index 00000000..46b516f3 --- /dev/null +++ b/src/pro/Google/Protobuf/Internal/OneofOptions.php @@ -0,0 +1,74 @@ +google.protobuf.OneofOptions + */ +class OneofOptions extends \Google\Protobuf\Internal\Message +{ + /** + * The parser stores options it doesn't recognize here. See above. + * + * Generated from protobuf field repeated .google.protobuf.UninterpretedOption uninterpreted_option = 999; + */ + private $uninterpreted_option; + private $has_uninterpreted_option = false; + + /** + * Constructor. + * + * @param array $data { + * Optional. Data for populating the Message object. + * + * @type \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 repeated .google.protobuf.UninterpretedOption uninterpreted_option = 999; + * @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 repeated .google.protobuf.UninterpretedOption uninterpreted_option = 999; + * @param \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; + $this->has_uninterpreted_option = true; + + return $this; + } + + public function hasUninterpretedOption() + { + return $this->has_uninterpreted_option; + } + +} + diff --git a/src/pro/Google/Protobuf/Internal/RawInputStream.php b/src/pro/Google/Protobuf/Internal/RawInputStream.php new file mode 100644 index 00000000..4e7ed5cb --- /dev/null +++ b/src/pro/Google/Protobuf/Internal/RawInputStream.php @@ -0,0 +1,50 @@ +buffer = $buffer; + } + + public function getData() + { + return $this->buffer; + } + +} diff --git a/src/pro/Google/Protobuf/Internal/RepeatedField.php b/src/pro/Google/Protobuf/Internal/RepeatedField.php new file mode 100644 index 00000000..ec7a3a6d --- /dev/null +++ b/src/pro/Google/Protobuf/Internal/RepeatedField.php @@ -0,0 +1,258 @@ +container = []; + $this->type = $type; + if ($this->type == GPBType::MESSAGE) { + $pool = DescriptorPool::getGeneratedPool(); + $desc = $pool->getDescriptorByClassName($klass); + if ($desc == NULL) { + new $klass; // No msg class instance has been created before. + $desc = $pool->getDescriptorByClassName($klass); + } + $this->klass = $desc->getClass(); + $this->legacy_klass = $desc->getLegacyClass(); + } + } + + /** + * @ignore + */ + public function getType() + { + return $this->type; + } + + /** + * @ignore + */ + public function getClass() + { + return $this->klass; + } + + /** + * @ignore + */ + public function getLegacyClass() + { + return $this->legacy_klass; + } + + /** + * Return the element at the given index. + * + * This will also be called for: $ele = $arr[0] + * + * @param long $offset The index of the element to be fetched. + * @return object The stored element at given index. + * @throws \ErrorException Invalid type for index. + * @throws \ErrorException Non-existing index. + */ + public function offsetGet($offset) + { + return $this->container[$offset]; + } + + /** + * Assign the element at the given index. + * + * This will also be called for: $arr []= $ele and $arr[0] = ele + * + * @param long $offset The index of the element to be assigned. + * @param object $value The element to be assigned. + * @return void + * @throws \ErrorException Invalid type for index. + * @throws \ErrorException Non-existing index. + * @throws \ErrorException Incorrect type of the element. + */ + public function offsetSet($offset, $value) + { + switch ($this->type) { + case GPBType::SFIXED32: + case GPBType::SINT32: + case GPBType::INT32: + case GPBType::ENUM: + GPBUtil::checkInt32($value); + break; + case GPBType::FIXED32: + case GPBType::UINT32: + GPBUtil::checkUint32($value); + break; + case GPBType::SFIXED64: + case GPBType::SINT64: + case GPBType::INT64: + GPBUtil::checkInt64($value); + break; + case GPBType::FIXED64: + case GPBType::UINT64: + GPBUtil::checkUint64($value); + break; + case GPBType::FLOAT: + GPBUtil::checkFloat($value); + break; + case GPBType::DOUBLE: + GPBUtil::checkDouble($value); + break; + case GPBType::BOOL: + GPBUtil::checkBool($value); + break; + case GPBType::BYTES: + GPBUtil::checkString($value, false); + break; + case GPBType::STRING: + GPBUtil::checkString($value, true); + break; + case GPBType::MESSAGE: + if (is_null($value)) { + trigger_error("RepeatedField element cannot be null.", + E_USER_ERROR); + } + GPBUtil::checkMessage($value, $this->klass); + break; + default: + break; + } + if (is_null($offset)) { + $this->container[] = $value; + } else { + $count = count($this->container); + if (!is_numeric($offset) || $offset < 0 || $offset >= $count) { + trigger_error( + "Cannot modify element at the given index", + E_USER_ERROR); + return; + } + $this->container[$offset] = $value; + } + } + + /** + * Remove the element at the given index. + * + * This will also be called for: unset($arr) + * + * @param long $offset The index of the element to be removed. + * @return void + * @throws \ErrorException Invalid type for index. + * @throws \ErrorException The element to be removed is not at the end of the + * RepeatedField. + */ + public function offsetUnset($offset) + { + $count = count($this->container); + if (!is_numeric($offset) || $count === 0 || $offset !== $count - 1) { + trigger_error( + "Cannot remove element at the given index", + E_USER_ERROR); + return; + } + array_pop($this->container); + } + + /** + * Check the existence of the element at the given index. + * + * This will also be called for: isset($arr) + * + * @param long $offset The index of the element to be removed. + * @return bool True if the element at the given offset exists. + * @throws \ErrorException Invalid type for index. + */ + public function offsetExists($offset) + { + return isset($this->container[$offset]); + } + + /** + * @ignore + */ + public function getIterator() + { + return new RepeatedFieldIter($this->container); + } + + /** + * Return the number of stored elements. + * + * This will also be called for: count($arr) + * + * @return integer The number of stored elements. + */ + public function count() + { + return count($this->container); + } +} diff --git a/src/pro/Google/Protobuf/Internal/RepeatedFieldIter.php b/src/pro/Google/Protobuf/Internal/RepeatedFieldIter.php new file mode 100644 index 00000000..2b6f8230 --- /dev/null +++ b/src/pro/Google/Protobuf/Internal/RepeatedFieldIter.php @@ -0,0 +1,118 @@ +position = 0; + $this->container = $container; + } + + /** + * Reset the status of the iterator + * + * @return void + */ + public function rewind() + { + $this->position = 0; + } + + /** + * Return the element at the current position. + * + * @return object The element at the current position. + */ + public function current() + { + return $this->container[$this->position]; + } + + /** + * Return the current position. + * + * @return integer The current position. + */ + public function key() + { + return $this->position; + } + + /** + * Move to the next position. + * + * @return void + */ + public function next() + { + ++$this->position; + } + + /** + * Check whether there are more elements to iterate. + * + * @return bool True if there are more elements to iterate. + */ + public function valid() + { + return isset($this->container[$this->position]); + } +} diff --git a/src/pro/Google/Protobuf/Internal/ServiceDescriptorProto.php b/src/pro/Google/Protobuf/Internal/ServiceDescriptorProto.php new file mode 100644 index 00000000..aaeefbc9 --- /dev/null +++ b/src/pro/Google/Protobuf/Internal/ServiceDescriptorProto.php @@ -0,0 +1,137 @@ +google.protobuf.ServiceDescriptorProto + */ +class ServiceDescriptorProto extends \Google\Protobuf\Internal\Message +{ + /** + * Generated from protobuf field optional string name = 1; + */ + protected $name = ''; + private $has_name = false; + /** + * Generated from protobuf field repeated .google.protobuf.MethodDescriptorProto method = 2; + */ + private $method; + private $has_method = false; + /** + * Generated from protobuf field optional .google.protobuf.ServiceOptions options = 3; + */ + protected $options = null; + private $has_options = false; + + /** + * Constructor. + * + * @param array $data { + * Optional. Data for populating the Message object. + * + * @type string $name + * @type \Google\Protobuf\Internal\MethodDescriptorProto[]|\Google\Protobuf\Internal\RepeatedField $method + * @type \Google\Protobuf\Internal\ServiceOptions $options + * } + */ + public function __construct($data = NULL) { + \GPBMetadata\Google\Protobuf\Internal\Descriptor::initOnce(); + parent::__construct($data); + } + + /** + * Generated from protobuf field optional string name = 1; + * @return string + */ + public function getName() + { + return $this->name; + } + + /** + * Generated from protobuf field optional string name = 1; + * @param string $var + * @return $this + */ + public function setName($var) + { + GPBUtil::checkString($var, True); + $this->name = $var; + $this->has_name = true; + + return $this; + } + + public function hasName() + { + return $this->has_name; + } + + /** + * Generated from protobuf field repeated .google.protobuf.MethodDescriptorProto method = 2; + * @return \Google\Protobuf\Internal\RepeatedField + */ + public function getMethod() + { + return $this->method; + } + + /** + * Generated from protobuf field repeated .google.protobuf.MethodDescriptorProto method = 2; + * @param \Google\Protobuf\Internal\MethodDescriptorProto[]|\Google\Protobuf\Internal\RepeatedField $var + * @return $this + */ + public function setMethod($var) + { + $arr = GPBUtil::checkRepeatedField($var, \Google\Protobuf\Internal\GPBType::MESSAGE, \Google\Protobuf\Internal\MethodDescriptorProto::class); + $this->method = $arr; + $this->has_method = true; + + return $this; + } + + public function hasMethod() + { + return $this->has_method; + } + + /** + * Generated from protobuf field optional .google.protobuf.ServiceOptions options = 3; + * @return \Google\Protobuf\Internal\ServiceOptions + */ + public function getOptions() + { + return $this->options; + } + + /** + * Generated from protobuf field optional .google.protobuf.ServiceOptions options = 3; + * @param \Google\Protobuf\Internal\ServiceOptions $var + * @return $this + */ + public function setOptions($var) + { + GPBUtil::checkMessage($var, \Google\Protobuf\Internal\ServiceOptions::class); + $this->options = $var; + $this->has_options = true; + + return $this; + } + + public function hasOptions() + { + return $this->has_options; + } + +} + diff --git a/src/pro/Google/Protobuf/Internal/ServiceOptions.php b/src/pro/Google/Protobuf/Internal/ServiceOptions.php new file mode 100644 index 00000000..0581efba --- /dev/null +++ b/src/pro/Google/Protobuf/Internal/ServiceOptions.php @@ -0,0 +1,127 @@ +google.protobuf.ServiceOptions + */ +class ServiceOptions extends \Google\Protobuf\Internal\Message +{ + /** + * Is this service deprecated? + * Depending on the target platform, this can emit Deprecated annotations + * for the service, or it will be completely ignored; in the very least, + * this is a formalization for deprecating services. + * + * Generated from protobuf field optional bool deprecated = 33 [default = false]; + */ + protected $deprecated = false; + private $has_deprecated = false; + /** + * The parser stores options it doesn't recognize here. See above. + * + * Generated from protobuf field repeated .google.protobuf.UninterpretedOption uninterpreted_option = 999; + */ + private $uninterpreted_option; + private $has_uninterpreted_option = false; + + /** + * Constructor. + * + * @param array $data { + * Optional. Data for populating the Message object. + * + * @type bool $deprecated + * Is this service deprecated? + * Depending on the target platform, this can emit Deprecated annotations + * for the service, or it will be completely ignored; in the very least, + * this is a formalization for deprecating services. + * @type \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 service deprecated? + * Depending on the target platform, this can emit Deprecated annotations + * for the service, or it will be completely ignored; in the very least, + * this is a formalization for deprecating services. + * + * Generated from protobuf field optional bool deprecated = 33 [default = false]; + * @return bool + */ + public function getDeprecated() + { + return $this->deprecated; + } + + /** + * Is this service deprecated? + * Depending on the target platform, this can emit Deprecated annotations + * for the service, or it will be completely ignored; in the very least, + * this is a formalization for deprecating services. + * + * Generated from protobuf field optional bool deprecated = 33 [default = false]; + * @param bool $var + * @return $this + */ + public function setDeprecated($var) + { + GPBUtil::checkBool($var); + $this->deprecated = $var; + $this->has_deprecated = true; + + return $this; + } + + public function hasDeprecated() + { + return $this->has_deprecated; + } + + /** + * The parser stores options it doesn't recognize here. See above. + * + * Generated from protobuf field repeated .google.protobuf.UninterpretedOption uninterpreted_option = 999; + * @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 repeated .google.protobuf.UninterpretedOption uninterpreted_option = 999; + * @param \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; + $this->has_uninterpreted_option = true; + + return $this; + } + + public function hasUninterpretedOption() + { + return $this->has_uninterpreted_option; + } + +} + diff --git a/src/pro/Google/Protobuf/Internal/SourceCodeInfo.php b/src/pro/Google/Protobuf/Internal/SourceCodeInfo.php new file mode 100644 index 00000000..dfeb69ff --- /dev/null +++ b/src/pro/Google/Protobuf/Internal/SourceCodeInfo.php @@ -0,0 +1,237 @@ +google.protobuf.SourceCodeInfo + */ +class SourceCodeInfo extends \Google\Protobuf\Internal\Message +{ + /** + * A Location identifies a piece of source code in a .proto file which + * corresponds to a particular definition. This information is intended + * to be useful to IDEs, code indexers, documentation generators, and similar + * tools. + * For example, say we have a file like: + * message Foo { + * optional string foo = 1; + * } + * Let's look at just the field definition: + * optional string foo = 1; + * ^ ^^ ^^ ^ ^^^ + * a bc de f ghi + * We have the following locations: + * span path represents + * [a,i) [ 4, 0, 2, 0 ] The whole field definition. + * [a,b) [ 4, 0, 2, 0, 4 ] The label (optional). + * [c,d) [ 4, 0, 2, 0, 5 ] The type (string). + * [e,f) [ 4, 0, 2, 0, 1 ] The name (foo). + * [g,h) [ 4, 0, 2, 0, 3 ] The number (1). + * Notes: + * - A location may refer to a repeated field itself (i.e. not to any + * particular index within it). This is used whenever a set of elements are + * logically enclosed in a single code segment. For example, an entire + * extend block (possibly containing multiple extension definitions) will + * have an outer location whose path refers to the "extensions" repeated + * field without an index. + * - Multiple locations may have the same path. This happens when a single + * logical declaration is spread out across multiple places. The most + * obvious example is the "extend" block again -- there may be multiple + * extend blocks in the same scope, each of which will have the same path. + * - A location's span is not always a subset of its parent's span. For + * example, the "extendee" of an extension declaration appears at the + * beginning of the "extend" block and is shared by all extensions within + * the block. + * - Just because a location's span is a subset of some other location's span + * does not mean that it is a descendant. For example, a "group" defines + * both a type and a field in a single declaration. Thus, the locations + * corresponding to the type and field and their components will overlap. + * - Code which tries to interpret locations should probably be designed to + * ignore those that it doesn't understand, as more types of locations could + * be recorded in the future. + * + * Generated from protobuf field repeated .google.protobuf.SourceCodeInfo.Location location = 1; + */ + private $location; + private $has_location = false; + + /** + * Constructor. + * + * @param array $data { + * Optional. Data for populating the Message object. + * + * @type \Google\Protobuf\Internal\SourceCodeInfo\Location[]|\Google\Protobuf\Internal\RepeatedField $location + * A Location identifies a piece of source code in a .proto file which + * corresponds to a particular definition. This information is intended + * to be useful to IDEs, code indexers, documentation generators, and similar + * tools. + * For example, say we have a file like: + * message Foo { + * optional string foo = 1; + * } + * Let's look at just the field definition: + * optional string foo = 1; + * ^ ^^ ^^ ^ ^^^ + * a bc de f ghi + * We have the following locations: + * span path represents + * [a,i) [ 4, 0, 2, 0 ] The whole field definition. + * [a,b) [ 4, 0, 2, 0, 4 ] The label (optional). + * [c,d) [ 4, 0, 2, 0, 5 ] The type (string). + * [e,f) [ 4, 0, 2, 0, 1 ] The name (foo). + * [g,h) [ 4, 0, 2, 0, 3 ] The number (1). + * Notes: + * - A location may refer to a repeated field itself (i.e. not to any + * particular index within it). This is used whenever a set of elements are + * logically enclosed in a single code segment. For example, an entire + * extend block (possibly containing multiple extension definitions) will + * have an outer location whose path refers to the "extensions" repeated + * field without an index. + * - Multiple locations may have the same path. This happens when a single + * logical declaration is spread out across multiple places. The most + * obvious example is the "extend" block again -- there may be multiple + * extend blocks in the same scope, each of which will have the same path. + * - A location's span is not always a subset of its parent's span. For + * example, the "extendee" of an extension declaration appears at the + * beginning of the "extend" block and is shared by all extensions within + * the block. + * - Just because a location's span is a subset of some other location's span + * does not mean that it is a descendant. For example, a "group" defines + * both a type and a field in a single declaration. Thus, the locations + * corresponding to the type and field and their components will overlap. + * - Code which tries to interpret locations should probably be designed to + * ignore those that it doesn't understand, as more types of locations could + * be recorded in the future. + * } + */ + public function __construct($data = NULL) { + \GPBMetadata\Google\Protobuf\Internal\Descriptor::initOnce(); + parent::__construct($data); + } + + /** + * A Location identifies a piece of source code in a .proto file which + * corresponds to a particular definition. This information is intended + * to be useful to IDEs, code indexers, documentation generators, and similar + * tools. + * For example, say we have a file like: + * message Foo { + * optional string foo = 1; + * } + * Let's look at just the field definition: + * optional string foo = 1; + * ^ ^^ ^^ ^ ^^^ + * a bc de f ghi + * We have the following locations: + * span path represents + * [a,i) [ 4, 0, 2, 0 ] The whole field definition. + * [a,b) [ 4, 0, 2, 0, 4 ] The label (optional). + * [c,d) [ 4, 0, 2, 0, 5 ] The type (string). + * [e,f) [ 4, 0, 2, 0, 1 ] The name (foo). + * [g,h) [ 4, 0, 2, 0, 3 ] The number (1). + * Notes: + * - A location may refer to a repeated field itself (i.e. not to any + * particular index within it). This is used whenever a set of elements are + * logically enclosed in a single code segment. For example, an entire + * extend block (possibly containing multiple extension definitions) will + * have an outer location whose path refers to the "extensions" repeated + * field without an index. + * - Multiple locations may have the same path. This happens when a single + * logical declaration is spread out across multiple places. The most + * obvious example is the "extend" block again -- there may be multiple + * extend blocks in the same scope, each of which will have the same path. + * - A location's span is not always a subset of its parent's span. For + * example, the "extendee" of an extension declaration appears at the + * beginning of the "extend" block and is shared by all extensions within + * the block. + * - Just because a location's span is a subset of some other location's span + * does not mean that it is a descendant. For example, a "group" defines + * both a type and a field in a single declaration. Thus, the locations + * corresponding to the type and field and their components will overlap. + * - Code which tries to interpret locations should probably be designed to + * ignore those that it doesn't understand, as more types of locations could + * be recorded in the future. + * + * Generated from protobuf field repeated .google.protobuf.SourceCodeInfo.Location location = 1; + * @return \Google\Protobuf\Internal\RepeatedField + */ + public function getLocation() + { + return $this->location; + } + + /** + * A Location identifies a piece of source code in a .proto file which + * corresponds to a particular definition. This information is intended + * to be useful to IDEs, code indexers, documentation generators, and similar + * tools. + * For example, say we have a file like: + * message Foo { + * optional string foo = 1; + * } + * Let's look at just the field definition: + * optional string foo = 1; + * ^ ^^ ^^ ^ ^^^ + * a bc de f ghi + * We have the following locations: + * span path represents + * [a,i) [ 4, 0, 2, 0 ] The whole field definition. + * [a,b) [ 4, 0, 2, 0, 4 ] The label (optional). + * [c,d) [ 4, 0, 2, 0, 5 ] The type (string). + * [e,f) [ 4, 0, 2, 0, 1 ] The name (foo). + * [g,h) [ 4, 0, 2, 0, 3 ] The number (1). + * Notes: + * - A location may refer to a repeated field itself (i.e. not to any + * particular index within it). This is used whenever a set of elements are + * logically enclosed in a single code segment. For example, an entire + * extend block (possibly containing multiple extension definitions) will + * have an outer location whose path refers to the "extensions" repeated + * field without an index. + * - Multiple locations may have the same path. This happens when a single + * logical declaration is spread out across multiple places. The most + * obvious example is the "extend" block again -- there may be multiple + * extend blocks in the same scope, each of which will have the same path. + * - A location's span is not always a subset of its parent's span. For + * example, the "extendee" of an extension declaration appears at the + * beginning of the "extend" block and is shared by all extensions within + * the block. + * - Just because a location's span is a subset of some other location's span + * does not mean that it is a descendant. For example, a "group" defines + * both a type and a field in a single declaration. Thus, the locations + * corresponding to the type and field and their components will overlap. + * - Code which tries to interpret locations should probably be designed to + * ignore those that it doesn't understand, as more types of locations could + * be recorded in the future. + * + * Generated from protobuf field repeated .google.protobuf.SourceCodeInfo.Location location = 1; + * @param \Google\Protobuf\Internal\SourceCodeInfo\Location[]|\Google\Protobuf\Internal\RepeatedField $var + * @return $this + */ + public function setLocation($var) + { + $arr = GPBUtil::checkRepeatedField($var, \Google\Protobuf\Internal\GPBType::MESSAGE, \Google\Protobuf\Internal\SourceCodeInfo\Location::class); + $this->location = $arr; + $this->has_location = true; + + return $this; + } + + public function hasLocation() + { + return $this->has_location; + } + +} + diff --git a/src/pro/Google/Protobuf/Internal/SourceCodeInfo/Location.php b/src/pro/Google/Protobuf/Internal/SourceCodeInfo/Location.php new file mode 100644 index 00000000..0aeea61c --- /dev/null +++ b/src/pro/Google/Protobuf/Internal/SourceCodeInfo/Location.php @@ -0,0 +1,463 @@ +google.protobuf.SourceCodeInfo.Location + */ +class Location extends \Google\Protobuf\Internal\Message +{ + /** + * Identifies which part of the FileDescriptorProto was defined at this + * location. + * Each element is a field number or an index. They form a path from + * the root FileDescriptorProto to the place where the definition. For + * example, this path: + * [ 4, 3, 2, 7, 1 ] + * refers to: + * file.message_type(3) // 4, 3 + * .field(7) // 2, 7 + * .name() // 1 + * This is because FileDescriptorProto.message_type has field number 4: + * repeated DescriptorProto message_type = 4; + * and DescriptorProto.field has field number 2: + * repeated FieldDescriptorProto field = 2; + * and FieldDescriptorProto.name has field number 1: + * optional string name = 1; + * Thus, the above path gives the location of a field name. If we removed + * the last element: + * [ 4, 3, 2, 7 ] + * this path refers to the whole field declaration (from the beginning + * of the label to the terminating semicolon). + * + * Generated from protobuf field repeated int32 path = 1 [packed = true]; + */ + private $path; + private $has_path = false; + /** + * Always has exactly three or four elements: start line, start column, + * end line (optional, otherwise assumed same as start line), end column. + * These are packed into a single field for efficiency. Note that line + * and column numbers are zero-based -- typically you will want to add + * 1 to each before displaying to a user. + * + * Generated from protobuf field repeated int32 span = 2 [packed = true]; + */ + private $span; + private $has_span = false; + /** + * If this SourceCodeInfo represents a complete declaration, these are any + * comments appearing before and after the declaration which appear to be + * attached to the declaration. + * A series of line comments appearing on consecutive lines, with no other + * tokens appearing on those lines, will be treated as a single comment. + * leading_detached_comments will keep paragraphs of comments that appear + * before (but not connected to) the current element. Each paragraph, + * separated by empty lines, will be one comment element in the repeated + * field. + * Only the comment content is provided; comment markers (e.g. //) are + * stripped out. For block comments, leading whitespace and an asterisk + * will be stripped from the beginning of each line other than the first. + * Newlines are included in the output. + * Examples: + * optional int32 foo = 1; // Comment attached to foo. + * // Comment attached to bar. + * optional int32 bar = 2; + * optional string baz = 3; + * // Comment attached to baz. + * // Another line attached to baz. + * // Comment attached to qux. + * // + * // Another line attached to qux. + * optional double qux = 4; + * // Detached comment for corge. This is not leading or trailing comments + * // to qux or corge because there are blank lines separating it from + * // both. + * // Detached comment for corge paragraph 2. + * optional string corge = 5; + * /* Block comment attached + * * to corge. Leading asterisks + * * will be removed. */ + * /* Block comment attached to + * * grault. */ + * optional int32 grault = 6; + * // ignored detached comments. + * + * Generated from protobuf field optional string leading_comments = 3; + */ + protected $leading_comments = ''; + private $has_leading_comments = false; + /** + * Generated from protobuf field optional string trailing_comments = 4; + */ + protected $trailing_comments = ''; + private $has_trailing_comments = false; + /** + * Generated from protobuf field repeated string leading_detached_comments = 6; + */ + private $leading_detached_comments; + private $has_leading_detached_comments = false; + + /** + * Constructor. + * + * @param array $data { + * Optional. Data for populating the Message object. + * + * @type int[]|\Google\Protobuf\Internal\RepeatedField $path + * Identifies which part of the FileDescriptorProto was defined at this + * location. + * Each element is a field number or an index. They form a path from + * the root FileDescriptorProto to the place where the definition. For + * example, this path: + * [ 4, 3, 2, 7, 1 ] + * refers to: + * file.message_type(3) // 4, 3 + * .field(7) // 2, 7 + * .name() // 1 + * This is because FileDescriptorProto.message_type has field number 4: + * repeated DescriptorProto message_type = 4; + * and DescriptorProto.field has field number 2: + * repeated FieldDescriptorProto field = 2; + * and FieldDescriptorProto.name has field number 1: + * optional string name = 1; + * Thus, the above path gives the location of a field name. If we removed + * the last element: + * [ 4, 3, 2, 7 ] + * this path refers to the whole field declaration (from the beginning + * of the label to the terminating semicolon). + * @type int[]|\Google\Protobuf\Internal\RepeatedField $span + * Always has exactly three or four elements: start line, start column, + * end line (optional, otherwise assumed same as start line), end column. + * These are packed into a single field for efficiency. Note that line + * and column numbers are zero-based -- typically you will want to add + * 1 to each before displaying to a user. + * @type string $leading_comments + * If this SourceCodeInfo represents a complete declaration, these are any + * comments appearing before and after the declaration which appear to be + * attached to the declaration. + * A series of line comments appearing on consecutive lines, with no other + * tokens appearing on those lines, will be treated as a single comment. + * leading_detached_comments will keep paragraphs of comments that appear + * before (but not connected to) the current element. Each paragraph, + * separated by empty lines, will be one comment element in the repeated + * field. + * Only the comment content is provided; comment markers (e.g. //) are + * stripped out. For block comments, leading whitespace and an asterisk + * will be stripped from the beginning of each line other than the first. + * Newlines are included in the output. + * Examples: + * optional int32 foo = 1; // Comment attached to foo. + * // Comment attached to bar. + * optional int32 bar = 2; + * optional string baz = 3; + * // Comment attached to baz. + * // Another line attached to baz. + * // Comment attached to qux. + * // + * // Another line attached to qux. + * optional double qux = 4; + * // Detached comment for corge. This is not leading or trailing comments + * // to qux or corge because there are blank lines separating it from + * // both. + * // Detached comment for corge paragraph 2. + * optional string corge = 5; + * /* Block comment attached + * * to corge. Leading asterisks + * * will be removed. */ + * /* Block comment attached to + * * grault. */ + * optional int32 grault = 6; + * // ignored detached comments. + * @type string $trailing_comments + * @type string[]|\Google\Protobuf\Internal\RepeatedField $leading_detached_comments + * } + */ + public function __construct($data = NULL) { + \GPBMetadata\Google\Protobuf\Internal\Descriptor::initOnce(); + parent::__construct($data); + } + + /** + * Identifies which part of the FileDescriptorProto was defined at this + * location. + * Each element is a field number or an index. They form a path from + * the root FileDescriptorProto to the place where the definition. For + * example, this path: + * [ 4, 3, 2, 7, 1 ] + * refers to: + * file.message_type(3) // 4, 3 + * .field(7) // 2, 7 + * .name() // 1 + * This is because FileDescriptorProto.message_type has field number 4: + * repeated DescriptorProto message_type = 4; + * and DescriptorProto.field has field number 2: + * repeated FieldDescriptorProto field = 2; + * and FieldDescriptorProto.name has field number 1: + * optional string name = 1; + * Thus, the above path gives the location of a field name. If we removed + * the last element: + * [ 4, 3, 2, 7 ] + * this path refers to the whole field declaration (from the beginning + * of the label to the terminating semicolon). + * + * Generated from protobuf field repeated int32 path = 1 [packed = true]; + * @return \Google\Protobuf\Internal\RepeatedField + */ + public function getPath() + { + return $this->path; + } + + /** + * Identifies which part of the FileDescriptorProto was defined at this + * location. + * Each element is a field number or an index. They form a path from + * the root FileDescriptorProto to the place where the definition. For + * example, this path: + * [ 4, 3, 2, 7, 1 ] + * refers to: + * file.message_type(3) // 4, 3 + * .field(7) // 2, 7 + * .name() // 1 + * This is because FileDescriptorProto.message_type has field number 4: + * repeated DescriptorProto message_type = 4; + * and DescriptorProto.field has field number 2: + * repeated FieldDescriptorProto field = 2; + * and FieldDescriptorProto.name has field number 1: + * optional string name = 1; + * Thus, the above path gives the location of a field name. If we removed + * the last element: + * [ 4, 3, 2, 7 ] + * this path refers to the whole field declaration (from the beginning + * of the label to the terminating semicolon). + * + * Generated from protobuf field repeated int32 path = 1 [packed = true]; + * @param int[]|\Google\Protobuf\Internal\RepeatedField $var + * @return $this + */ + public function setPath($var) + { + $arr = GPBUtil::checkRepeatedField($var, \Google\Protobuf\Internal\GPBType::INT32); + $this->path = $arr; + $this->has_path = true; + + return $this; + } + + public function hasPath() + { + return $this->has_path; + } + + /** + * Always has exactly three or four elements: start line, start column, + * end line (optional, otherwise assumed same as start line), end column. + * These are packed into a single field for efficiency. Note that line + * and column numbers are zero-based -- typically you will want to add + * 1 to each before displaying to a user. + * + * Generated from protobuf field repeated int32 span = 2 [packed = true]; + * @return \Google\Protobuf\Internal\RepeatedField + */ + public function getSpan() + { + return $this->span; + } + + /** + * Always has exactly three or four elements: start line, start column, + * end line (optional, otherwise assumed same as start line), end column. + * These are packed into a single field for efficiency. Note that line + * and column numbers are zero-based -- typically you will want to add + * 1 to each before displaying to a user. + * + * Generated from protobuf field repeated int32 span = 2 [packed = true]; + * @param int[]|\Google\Protobuf\Internal\RepeatedField $var + * @return $this + */ + public function setSpan($var) + { + $arr = GPBUtil::checkRepeatedField($var, \Google\Protobuf\Internal\GPBType::INT32); + $this->span = $arr; + $this->has_span = true; + + return $this; + } + + public function hasSpan() + { + return $this->has_span; + } + + /** + * If this SourceCodeInfo represents a complete declaration, these are any + * comments appearing before and after the declaration which appear to be + * attached to the declaration. + * A series of line comments appearing on consecutive lines, with no other + * tokens appearing on those lines, will be treated as a single comment. + * leading_detached_comments will keep paragraphs of comments that appear + * before (but not connected to) the current element. Each paragraph, + * separated by empty lines, will be one comment element in the repeated + * field. + * Only the comment content is provided; comment markers (e.g. //) are + * stripped out. For block comments, leading whitespace and an asterisk + * will be stripped from the beginning of each line other than the first. + * Newlines are included in the output. + * Examples: + * optional int32 foo = 1; // Comment attached to foo. + * // Comment attached to bar. + * optional int32 bar = 2; + * optional string baz = 3; + * // Comment attached to baz. + * // Another line attached to baz. + * // Comment attached to qux. + * // + * // Another line attached to qux. + * optional double qux = 4; + * // Detached comment for corge. This is not leading or trailing comments + * // to qux or corge because there are blank lines separating it from + * // both. + * // Detached comment for corge paragraph 2. + * optional string corge = 5; + * /* Block comment attached + * * to corge. Leading asterisks + * * will be removed. */ + * /* Block comment attached to + * * grault. */ + * optional int32 grault = 6; + * // ignored detached comments. + * + * Generated from protobuf field optional string leading_comments = 3; + * @return string + */ + public function getLeadingComments() + { + return $this->leading_comments; + } + + /** + * If this SourceCodeInfo represents a complete declaration, these are any + * comments appearing before and after the declaration which appear to be + * attached to the declaration. + * A series of line comments appearing on consecutive lines, with no other + * tokens appearing on those lines, will be treated as a single comment. + * leading_detached_comments will keep paragraphs of comments that appear + * before (but not connected to) the current element. Each paragraph, + * separated by empty lines, will be one comment element in the repeated + * field. + * Only the comment content is provided; comment markers (e.g. //) are + * stripped out. For block comments, leading whitespace and an asterisk + * will be stripped from the beginning of each line other than the first. + * Newlines are included in the output. + * Examples: + * optional int32 foo = 1; // Comment attached to foo. + * // Comment attached to bar. + * optional int32 bar = 2; + * optional string baz = 3; + * // Comment attached to baz. + * // Another line attached to baz. + * // Comment attached to qux. + * // + * // Another line attached to qux. + * optional double qux = 4; + * // Detached comment for corge. This is not leading or trailing comments + * // to qux or corge because there are blank lines separating it from + * // both. + * // Detached comment for corge paragraph 2. + * optional string corge = 5; + * /* Block comment attached + * * to corge. Leading asterisks + * * will be removed. */ + * /* Block comment attached to + * * grault. */ + * optional int32 grault = 6; + * // ignored detached comments. + * + * Generated from protobuf field optional string leading_comments = 3; + * @param string $var + * @return $this + */ + public function setLeadingComments($var) + { + GPBUtil::checkString($var, True); + $this->leading_comments = $var; + $this->has_leading_comments = true; + + return $this; + } + + public function hasLeadingComments() + { + return $this->has_leading_comments; + } + + /** + * Generated from protobuf field optional string trailing_comments = 4; + * @return string + */ + public function getTrailingComments() + { + return $this->trailing_comments; + } + + /** + * Generated from protobuf field optional string trailing_comments = 4; + * @param string $var + * @return $this + */ + public function setTrailingComments($var) + { + GPBUtil::checkString($var, True); + $this->trailing_comments = $var; + $this->has_trailing_comments = true; + + return $this; + } + + public function hasTrailingComments() + { + return $this->has_trailing_comments; + } + + /** + * Generated from protobuf field repeated string leading_detached_comments = 6; + * @return \Google\Protobuf\Internal\RepeatedField + */ + public function getLeadingDetachedComments() + { + return $this->leading_detached_comments; + } + + /** + * Generated from protobuf field repeated string leading_detached_comments = 6; + * @param string[]|\Google\Protobuf\Internal\RepeatedField $var + * @return $this + */ + public function setLeadingDetachedComments($var) + { + $arr = GPBUtil::checkRepeatedField($var, \Google\Protobuf\Internal\GPBType::STRING); + $this->leading_detached_comments = $arr; + $this->has_leading_detached_comments = true; + + return $this; + } + + public function hasLeadingDetachedComments() + { + return $this->has_leading_detached_comments; + } + +} + +// Adding a class alias for backwards compatibility with the previous class name. +class_alias(Location::class, \Google\Protobuf\Internal\SourceCodeInfo_Location::class); + diff --git a/src/pro/Google/Protobuf/Internal/SourceCodeInfo_Location.php b/src/pro/Google/Protobuf/Internal/SourceCodeInfo_Location.php new file mode 100644 index 00000000..1346492d --- /dev/null +++ b/src/pro/Google/Protobuf/Internal/SourceCodeInfo_Location.php @@ -0,0 +1,16 @@ +google.protobuf.UninterpretedOption + */ +class UninterpretedOption extends \Google\Protobuf\Internal\Message +{ + /** + * Generated from protobuf field repeated .google.protobuf.UninterpretedOption.NamePart name = 2; + */ + private $name; + private $has_name = false; + /** + * The value of the uninterpreted option, in whatever type the tokenizer + * identified it as during parsing. Exactly one of these should be set. + * + * Generated from protobuf field optional string identifier_value = 3; + */ + protected $identifier_value = ''; + private $has_identifier_value = false; + /** + * Generated from protobuf field optional uint64 positive_int_value = 4; + */ + protected $positive_int_value = 0; + private $has_positive_int_value = false; + /** + * Generated from protobuf field optional int64 negative_int_value = 5; + */ + protected $negative_int_value = 0; + private $has_negative_int_value = false; + /** + * Generated from protobuf field optional double double_value = 6; + */ + protected $double_value = 0.0; + private $has_double_value = false; + /** + * Generated from protobuf field optional bytes string_value = 7; + */ + protected $string_value = ''; + private $has_string_value = false; + /** + * Generated from protobuf field optional string aggregate_value = 8; + */ + protected $aggregate_value = ''; + private $has_aggregate_value = false; + + /** + * Constructor. + * + * @param array $data { + * Optional. Data for populating the Message object. + * + * @type \Google\Protobuf\Internal\UninterpretedOption\NamePart[]|\Google\Protobuf\Internal\RepeatedField $name + * @type string $identifier_value + * The value of the uninterpreted option, in whatever type the tokenizer + * identified it as during parsing. Exactly one of these should be set. + * @type int|string $positive_int_value + * @type int|string $negative_int_value + * @type float $double_value + * @type string $string_value + * @type string $aggregate_value + * } + */ + public function __construct($data = NULL) { + \GPBMetadata\Google\Protobuf\Internal\Descriptor::initOnce(); + parent::__construct($data); + } + + /** + * Generated from protobuf field repeated .google.protobuf.UninterpretedOption.NamePart name = 2; + * @return \Google\Protobuf\Internal\RepeatedField + */ + public function getName() + { + return $this->name; + } + + /** + * Generated from protobuf field repeated .google.protobuf.UninterpretedOption.NamePart name = 2; + * @param \Google\Protobuf\Internal\UninterpretedOption\NamePart[]|\Google\Protobuf\Internal\RepeatedField $var + * @return $this + */ + public function setName($var) + { + $arr = GPBUtil::checkRepeatedField($var, \Google\Protobuf\Internal\GPBType::MESSAGE, \Google\Protobuf\Internal\UninterpretedOption\NamePart::class); + $this->name = $arr; + $this->has_name = true; + + return $this; + } + + public function hasName() + { + return $this->has_name; + } + + /** + * The value of the uninterpreted option, in whatever type the tokenizer + * identified it as during parsing. Exactly one of these should be set. + * + * Generated from protobuf field optional string identifier_value = 3; + * @return string + */ + public function getIdentifierValue() + { + return $this->identifier_value; + } + + /** + * The value of the uninterpreted option, in whatever type the tokenizer + * identified it as during parsing. Exactly one of these should be set. + * + * Generated from protobuf field optional string identifier_value = 3; + * @param string $var + * @return $this + */ + public function setIdentifierValue($var) + { + GPBUtil::checkString($var, True); + $this->identifier_value = $var; + $this->has_identifier_value = true; + + return $this; + } + + public function hasIdentifierValue() + { + return $this->has_identifier_value; + } + + /** + * Generated from protobuf field optional uint64 positive_int_value = 4; + * @return int|string + */ + public function getPositiveIntValue() + { + return $this->positive_int_value; + } + + /** + * Generated from protobuf field optional uint64 positive_int_value = 4; + * @param int|string $var + * @return $this + */ + public function setPositiveIntValue($var) + { + GPBUtil::checkUint64($var); + $this->positive_int_value = $var; + $this->has_positive_int_value = true; + + return $this; + } + + public function hasPositiveIntValue() + { + return $this->has_positive_int_value; + } + + /** + * Generated from protobuf field optional int64 negative_int_value = 5; + * @return int|string + */ + public function getNegativeIntValue() + { + return $this->negative_int_value; + } + + /** + * Generated from protobuf field optional int64 negative_int_value = 5; + * @param int|string $var + * @return $this + */ + public function setNegativeIntValue($var) + { + GPBUtil::checkInt64($var); + $this->negative_int_value = $var; + $this->has_negative_int_value = true; + + return $this; + } + + public function hasNegativeIntValue() + { + return $this->has_negative_int_value; + } + + /** + * Generated from protobuf field optional double double_value = 6; + * @return float + */ + public function getDoubleValue() + { + return $this->double_value; + } + + /** + * Generated from protobuf field optional double double_value = 6; + * @param float $var + * @return $this + */ + public function setDoubleValue($var) + { + GPBUtil::checkDouble($var); + $this->double_value = $var; + $this->has_double_value = true; + + return $this; + } + + public function hasDoubleValue() + { + return $this->has_double_value; + } + + /** + * Generated from protobuf field optional bytes string_value = 7; + * @return string + */ + public function getStringValue() + { + return $this->string_value; + } + + /** + * Generated from protobuf field optional bytes string_value = 7; + * @param string $var + * @return $this + */ + public function setStringValue($var) + { + GPBUtil::checkString($var, False); + $this->string_value = $var; + $this->has_string_value = true; + + return $this; + } + + public function hasStringValue() + { + return $this->has_string_value; + } + + /** + * Generated from protobuf field optional string aggregate_value = 8; + * @return string + */ + public function getAggregateValue() + { + return $this->aggregate_value; + } + + /** + * Generated from protobuf field optional string aggregate_value = 8; + * @param string $var + * @return $this + */ + public function setAggregateValue($var) + { + GPBUtil::checkString($var, True); + $this->aggregate_value = $var; + $this->has_aggregate_value = true; + + return $this; + } + + public function hasAggregateValue() + { + return $this->has_aggregate_value; + } + +} + diff --git a/src/pro/Google/Protobuf/Internal/UninterpretedOption/NamePart.php b/src/pro/Google/Protobuf/Internal/UninterpretedOption/NamePart.php new file mode 100644 index 00000000..1956ba7f --- /dev/null +++ b/src/pro/Google/Protobuf/Internal/UninterpretedOption/NamePart.php @@ -0,0 +1,110 @@ +google.protobuf.UninterpretedOption.NamePart + */ +class NamePart extends \Google\Protobuf\Internal\Message +{ + /** + * Generated from protobuf field required string name_part = 1; + */ + protected $name_part = ''; + private $has_name_part = false; + /** + * Generated from protobuf field required bool is_extension = 2; + */ + protected $is_extension = false; + private $has_is_extension = false; + + /** + * Constructor. + * + * @param array $data { + * Optional. Data for populating the Message object. + * + * @type string $name_part + * @type bool $is_extension + * } + */ + public function __construct($data = NULL) { + \GPBMetadata\Google\Protobuf\Internal\Descriptor::initOnce(); + parent::__construct($data); + } + + /** + * Generated from protobuf field required string name_part = 1; + * @return string + */ + public function getNamePart() + { + return $this->name_part; + } + + /** + * Generated from protobuf field required string name_part = 1; + * @param string $var + * @return $this + */ + public function setNamePart($var) + { + GPBUtil::checkString($var, True); + $this->name_part = $var; + $this->has_name_part = true; + + return $this; + } + + public function hasNamePart() + { + return $this->has_name_part; + } + + /** + * Generated from protobuf field required bool is_extension = 2; + * @return bool + */ + public function getIsExtension() + { + return $this->is_extension; + } + + /** + * Generated from protobuf field required bool is_extension = 2; + * @param bool $var + * @return $this + */ + public function setIsExtension($var) + { + GPBUtil::checkBool($var); + $this->is_extension = $var; + $this->has_is_extension = true; + + return $this; + } + + public function hasIsExtension() + { + return $this->has_is_extension; + } + +} + +// Adding a class alias for backwards compatibility with the previous class name. +class_alias(NamePart::class, \Google\Protobuf\Internal\UninterpretedOption_NamePart::class); + diff --git a/src/pro/Google/Protobuf/Internal/UninterpretedOption_NamePart.php b/src/pro/Google/Protobuf/Internal/UninterpretedOption_NamePart.php new file mode 100644 index 00000000..9750eb01 --- /dev/null +++ b/src/pro/Google/Protobuf/Internal/UninterpretedOption_NamePart.php @@ -0,0 +1,16 @@ +google.protobuf.ListValue + */ +class ListValue extends \Google\Protobuf\Internal\Message +{ + /** + * Repeated field of dynamically typed values. + * + * Generated from protobuf field repeated .google.protobuf.Value values = 1; + */ + private $values; + + /** + * Constructor. + * + * @param array $data { + * Optional. Data for populating the Message object. + * + * @type \Google\Protobuf\Value[]|\Google\Protobuf\Internal\RepeatedField $values + * Repeated field of dynamically typed values. + * } + */ + public function __construct($data = NULL) { + \GPBMetadata\Google\Protobuf\Struct::initOnce(); + parent::__construct($data); + } + + /** + * Repeated field of dynamically typed values. + * + * Generated from protobuf field repeated .google.protobuf.Value values = 1; + * @return \Google\Protobuf\Internal\RepeatedField + */ + public function getValues() + { + return $this->values; + } + + /** + * Repeated field of dynamically typed values. + * + * Generated from protobuf field repeated .google.protobuf.Value values = 1; + * @param \Google\Protobuf\Value[]|\Google\Protobuf\Internal\RepeatedField $var + * @return $this + */ + public function setValues($var) + { + $arr = GPBUtil::checkRepeatedField($var, \Google\Protobuf\Internal\GPBType::MESSAGE, \Google\Protobuf\Value::class); + $this->values = $arr; + + return $this; + } + +} + diff --git a/src/pro/Google/Protobuf/Method.php b/src/pro/Google/Protobuf/Method.php new file mode 100644 index 00000000..8e803506 --- /dev/null +++ b/src/pro/Google/Protobuf/Method.php @@ -0,0 +1,271 @@ +google.protobuf.Method + */ +class Method extends \Google\Protobuf\Internal\Message +{ + /** + * The simple name of this method. + * + * Generated from protobuf field string name = 1; + */ + private $name = ''; + /** + * A URL of the input message type. + * + * Generated from protobuf field string request_type_url = 2; + */ + private $request_type_url = ''; + /** + * If true, the request is streamed. + * + * Generated from protobuf field bool request_streaming = 3; + */ + private $request_streaming = false; + /** + * The URL of the output message type. + * + * Generated from protobuf field string response_type_url = 4; + */ + private $response_type_url = ''; + /** + * If true, the response is streamed. + * + * Generated from protobuf field bool response_streaming = 5; + */ + private $response_streaming = false; + /** + * Any metadata attached to the method. + * + * Generated from protobuf field repeated .google.protobuf.Option options = 6; + */ + private $options; + /** + * The source syntax of this method. + * + * Generated from protobuf field .google.protobuf.Syntax syntax = 7; + */ + private $syntax = 0; + + /** + * Constructor. + * + * @param array $data { + * Optional. Data for populating the Message object. + * + * @type string $name + * The simple name of this method. + * @type string $request_type_url + * A URL of the input message type. + * @type bool $request_streaming + * If true, the request is streamed. + * @type string $response_type_url + * The URL of the output message type. + * @type bool $response_streaming + * If true, the response is streamed. + * @type \Google\Protobuf\Option[]|\Google\Protobuf\Internal\RepeatedField $options + * Any metadata attached to the method. + * @type int $syntax + * The source syntax of this method. + * } + */ + public function __construct($data = NULL) { + \GPBMetadata\Google\Protobuf\Api::initOnce(); + parent::__construct($data); + } + + /** + * The simple name of this method. + * + * Generated from protobuf field string name = 1; + * @return string + */ + public function getName() + { + return $this->name; + } + + /** + * The simple name of this method. + * + * Generated from protobuf field string name = 1; + * @param string $var + * @return $this + */ + public function setName($var) + { + GPBUtil::checkString($var, True); + $this->name = $var; + + return $this; + } + + /** + * A URL of the input message type. + * + * Generated from protobuf field string request_type_url = 2; + * @return string + */ + public function getRequestTypeUrl() + { + return $this->request_type_url; + } + + /** + * A URL of the input message type. + * + * Generated from protobuf field string request_type_url = 2; + * @param string $var + * @return $this + */ + public function setRequestTypeUrl($var) + { + GPBUtil::checkString($var, True); + $this->request_type_url = $var; + + return $this; + } + + /** + * If true, the request is streamed. + * + * Generated from protobuf field bool request_streaming = 3; + * @return bool + */ + public function getRequestStreaming() + { + return $this->request_streaming; + } + + /** + * If true, the request is streamed. + * + * Generated from protobuf field bool request_streaming = 3; + * @param bool $var + * @return $this + */ + public function setRequestStreaming($var) + { + GPBUtil::checkBool($var); + $this->request_streaming = $var; + + return $this; + } + + /** + * The URL of the output message type. + * + * Generated from protobuf field string response_type_url = 4; + * @return string + */ + public function getResponseTypeUrl() + { + return $this->response_type_url; + } + + /** + * The URL of the output message type. + * + * Generated from protobuf field string response_type_url = 4; + * @param string $var + * @return $this + */ + public function setResponseTypeUrl($var) + { + GPBUtil::checkString($var, True); + $this->response_type_url = $var; + + return $this; + } + + /** + * If true, the response is streamed. + * + * Generated from protobuf field bool response_streaming = 5; + * @return bool + */ + public function getResponseStreaming() + { + return $this->response_streaming; + } + + /** + * If true, the response is streamed. + * + * Generated from protobuf field bool response_streaming = 5; + * @param bool $var + * @return $this + */ + public function setResponseStreaming($var) + { + GPBUtil::checkBool($var); + $this->response_streaming = $var; + + return $this; + } + + /** + * Any metadata attached to the method. + * + * Generated from protobuf field repeated .google.protobuf.Option options = 6; + * @return \Google\Protobuf\Internal\RepeatedField + */ + public function getOptions() + { + return $this->options; + } + + /** + * Any metadata attached to the method. + * + * Generated from protobuf field repeated .google.protobuf.Option options = 6; + * @param \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 syntax of this method. + * + * Generated from protobuf field .google.protobuf.Syntax syntax = 7; + * @return int + */ + public function getSyntax() + { + return $this->syntax; + } + + /** + * The source syntax of this method. + * + * Generated from protobuf field .google.protobuf.Syntax syntax = 7; + * @param int $var + * @return $this + */ + public function setSyntax($var) + { + GPBUtil::checkEnum($var, \Google\Protobuf\Syntax::class); + $this->syntax = $var; + + return $this; + } + +} + diff --git a/src/pro/Google/Protobuf/Mixin.php b/src/pro/Google/Protobuf/Mixin.php new file mode 100644 index 00000000..a2ea59c7 --- /dev/null +++ b/src/pro/Google/Protobuf/Mixin.php @@ -0,0 +1,166 @@ +google.protobuf.Mixin + */ +class Mixin extends \Google\Protobuf\Internal\Message +{ + /** + * The fully qualified name of the interface which is included. + * + * Generated from protobuf field string name = 1; + */ + private $name = ''; + /** + * If non-empty specifies a path under which inherited HTTP paths + * are rooted. + * + * Generated from protobuf field string root = 2; + */ + private $root = ''; + + /** + * Constructor. + * + * @param array $data { + * Optional. Data for populating the Message object. + * + * @type string $name + * The fully qualified name of the interface which is included. + * @type string $root + * If non-empty specifies a path under which inherited HTTP paths + * are rooted. + * } + */ + public function __construct($data = NULL) { + \GPBMetadata\Google\Protobuf\Api::initOnce(); + parent::__construct($data); + } + + /** + * The fully qualified name of the interface which is included. + * + * Generated from protobuf field string name = 1; + * @return string + */ + public function getName() + { + return $this->name; + } + + /** + * The fully qualified name of the interface which is included. + * + * Generated from protobuf field string name = 1; + * @param string $var + * @return $this + */ + public function setName($var) + { + GPBUtil::checkString($var, True); + $this->name = $var; + + return $this; + } + + /** + * If non-empty specifies a path under which inherited HTTP paths + * are rooted. + * + * Generated from protobuf field string root = 2; + * @return string + */ + public function getRoot() + { + return $this->root; + } + + /** + * If non-empty specifies a path under which inherited HTTP paths + * are rooted. + * + * Generated from protobuf field string root = 2; + * @param string $var + * @return $this + */ + public function setRoot($var) + { + GPBUtil::checkString($var, True); + $this->root = $var; + + return $this; + } + +} + diff --git a/src/pro/Google/Protobuf/NullValue.php b/src/pro/Google/Protobuf/NullValue.php new file mode 100644 index 00000000..a72cbb2e --- /dev/null +++ b/src/pro/Google/Protobuf/NullValue.php @@ -0,0 +1,48 @@ +google.protobuf.NullValue + */ +class NullValue +{ + /** + * Null value. + * + * Generated from protobuf enum NULL_VALUE = 0; + */ + const NULL_VALUE = 0; + + private static $valueToName = [ + self::NULL_VALUE => 'NULL_VALUE', + ]; + + 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); + } +} + diff --git a/src/pro/Google/Protobuf/OneofDescriptor.php b/src/pro/Google/Protobuf/OneofDescriptor.php new file mode 100644 index 00000000..d9736634 --- /dev/null +++ b/src/pro/Google/Protobuf/OneofDescriptor.php @@ -0,0 +1,75 @@ +internal_desc = $internal_desc; + } + + /** + * @return string The name of the oneof + */ + public function getName() + { + return $this->internal_desc->getName(); + } + + /** + * @param int $index Must be >= 0 and < getFieldCount() + * @return FieldDescriptor + */ + public function getField($index) + { + return $this->getPublicDescriptor($this->internal_desc->getFields()[$index]); + } + + /** + * @return int Number of fields in the oneof + */ + public function getFieldCount() + { + return count($this->internal_desc->getFields()); + } +} diff --git a/src/pro/Google/Protobuf/Option.php b/src/pro/Google/Protobuf/Option.php new file mode 100644 index 00000000..22ecfc5f --- /dev/null +++ b/src/pro/Google/Protobuf/Option.php @@ -0,0 +1,126 @@ +google.protobuf.Option + */ +class Option extends \Google\Protobuf\Internal\Message +{ + /** + * The option's name. For protobuf built-in options (options defined in + * descriptor.proto), this is the short name. For example, `"map_entry"`. + * For custom options, it should be the fully-qualified name. For example, + * `"google.api.http"`. + * + * Generated from protobuf field string name = 1; + */ + private $name = ''; + /** + * The option's value packed in an Any message. If the value is a primitive, + * the corresponding wrapper type defined in google/protobuf/wrappers.proto + * should be used. If the value is an enum, it should be stored as an int32 + * value using the google.protobuf.Int32Value type. + * + * Generated from protobuf field .google.protobuf.Any value = 2; + */ + private $value = null; + + /** + * Constructor. + * + * @param array $data { + * Optional. Data for populating the Message object. + * + * @type string $name + * The option's name. For protobuf built-in options (options defined in + * descriptor.proto), this is the short name. For example, `"map_entry"`. + * For custom options, it should be the fully-qualified name. For example, + * `"google.api.http"`. + * @type \Google\Protobuf\Any $value + * The option's value packed in an Any message. If the value is a primitive, + * the corresponding wrapper type defined in google/protobuf/wrappers.proto + * should be used. If the value is an enum, it should be stored as an int32 + * value using the google.protobuf.Int32Value type. + * } + */ + public function __construct($data = NULL) { + \GPBMetadata\Google\Protobuf\Type::initOnce(); + parent::__construct($data); + } + + /** + * The option's name. For protobuf built-in options (options defined in + * descriptor.proto), this is the short name. For example, `"map_entry"`. + * For custom options, it should be the fully-qualified name. For example, + * `"google.api.http"`. + * + * Generated from protobuf field string name = 1; + * @return string + */ + public function getName() + { + return $this->name; + } + + /** + * The option's name. For protobuf built-in options (options defined in + * descriptor.proto), this is the short name. For example, `"map_entry"`. + * For custom options, it should be the fully-qualified name. For example, + * `"google.api.http"`. + * + * Generated from protobuf field string name = 1; + * @param string $var + * @return $this + */ + public function setName($var) + { + GPBUtil::checkString($var, True); + $this->name = $var; + + return $this; + } + + /** + * The option's value packed in an Any message. If the value is a primitive, + * the corresponding wrapper type defined in google/protobuf/wrappers.proto + * should be used. If the value is an enum, it should be stored as an int32 + * value using the google.protobuf.Int32Value type. + * + * Generated from protobuf field .google.protobuf.Any value = 2; + * @return \Google\Protobuf\Any + */ + public function getValue() + { + return $this->value; + } + + /** + * The option's value packed in an Any message. If the value is a primitive, + * the corresponding wrapper type defined in google/protobuf/wrappers.proto + * should be used. If the value is an enum, it should be stored as an int32 + * value using the google.protobuf.Int32Value type. + * + * Generated from protobuf field .google.protobuf.Any value = 2; + * @param \Google\Protobuf\Any $var + * @return $this + */ + public function setValue($var) + { + GPBUtil::checkMessage($var, \Google\Protobuf\Any::class); + $this->value = $var; + + return $this; + } + +} + diff --git a/src/pro/Google/Protobuf/SourceContext.php b/src/pro/Google/Protobuf/SourceContext.php new file mode 100644 index 00000000..cbc50c68 --- /dev/null +++ b/src/pro/Google/Protobuf/SourceContext.php @@ -0,0 +1,72 @@ +google.protobuf.SourceContext + */ +class SourceContext extends \Google\Protobuf\Internal\Message +{ + /** + * The path-qualified name of the .proto file that contained the associated + * protobuf element. For example: `"google/protobuf/source_context.proto"`. + * + * Generated from protobuf field string file_name = 1; + */ + private $file_name = ''; + + /** + * Constructor. + * + * @param array $data { + * Optional. Data for populating the Message object. + * + * @type string $file_name + * The path-qualified name of the .proto file that contained the associated + * protobuf element. For example: `"google/protobuf/source_context.proto"`. + * } + */ + public function __construct($data = NULL) { + \GPBMetadata\Google\Protobuf\SourceContext::initOnce(); + parent::__construct($data); + } + + /** + * The path-qualified name of the .proto file that contained the associated + * protobuf element. For example: `"google/protobuf/source_context.proto"`. + * + * Generated from protobuf field string file_name = 1; + * @return string + */ + public function getFileName() + { + return $this->file_name; + } + + /** + * The path-qualified name of the .proto file that contained the associated + * protobuf element. For example: `"google/protobuf/source_context.proto"`. + * + * Generated from protobuf field string file_name = 1; + * @param string $var + * @return $this + */ + public function setFileName($var) + { + GPBUtil::checkString($var, True); + $this->file_name = $var; + + return $this; + } + +} + diff --git a/src/pro/Google/Protobuf/StringValue.php b/src/pro/Google/Protobuf/StringValue.php new file mode 100644 index 00000000..8fb354f3 --- /dev/null +++ b/src/pro/Google/Protobuf/StringValue.php @@ -0,0 +1,68 @@ +google.protobuf.StringValue + */ +class StringValue extends \Google\Protobuf\Internal\Message +{ + /** + * The string value. + * + * Generated from protobuf field string value = 1; + */ + private $value = ''; + + /** + * Constructor. + * + * @param array $data { + * Optional. Data for populating the Message object. + * + * @type string $value + * The string value. + * } + */ + public function __construct($data = NULL) { + \GPBMetadata\Google\Protobuf\Wrappers::initOnce(); + parent::__construct($data); + } + + /** + * The string value. + * + * Generated from protobuf field string value = 1; + * @return string + */ + public function getValue() + { + return $this->value; + } + + /** + * The string value. + * + * Generated from protobuf field string value = 1; + * @param string $var + * @return $this + */ + public function setValue($var) + { + GPBUtil::checkString($var, True); + $this->value = $var; + + return $this; + } + +} + diff --git a/src/pro/Google/Protobuf/Struct.php b/src/pro/Google/Protobuf/Struct.php new file mode 100644 index 00000000..0456541c --- /dev/null +++ b/src/pro/Google/Protobuf/Struct.php @@ -0,0 +1,73 @@ +google.protobuf.Struct + */ +class Struct extends \Google\Protobuf\Internal\Message +{ + /** + * Unordered map of dynamically typed values. + * + * Generated from protobuf field map fields = 1; + */ + private $fields; + + /** + * Constructor. + * + * @param array $data { + * Optional. Data for populating the Message object. + * + * @type array|\Google\Protobuf\Internal\MapField $fields + * Unordered map of dynamically typed values. + * } + */ + public function __construct($data = NULL) { + \GPBMetadata\Google\Protobuf\Struct::initOnce(); + parent::__construct($data); + } + + /** + * Unordered map of dynamically typed values. + * + * Generated from protobuf field map fields = 1; + * @return \Google\Protobuf\Internal\MapField + */ + public function getFields() + { + return $this->fields; + } + + /** + * Unordered map of dynamically typed values. + * + * Generated from protobuf field map fields = 1; + * @param array|\Google\Protobuf\Internal\MapField $var + * @return $this + */ + public function setFields($var) + { + $arr = GPBUtil::checkMapField($var, \Google\Protobuf\Internal\GPBType::STRING, \Google\Protobuf\Internal\GPBType::MESSAGE, \Google\Protobuf\Value::class); + $this->fields = $arr; + + return $this; + } + +} + diff --git a/src/pro/Google/Protobuf/Syntax.php b/src/pro/Google/Protobuf/Syntax.php new file mode 100644 index 00000000..9812669d --- /dev/null +++ b/src/pro/Google/Protobuf/Syntax.php @@ -0,0 +1,53 @@ +google.protobuf.Syntax + */ +class Syntax +{ + /** + * Syntax `proto2`. + * + * Generated from protobuf enum SYNTAX_PROTO2 = 0; + */ + const SYNTAX_PROTO2 = 0; + /** + * Syntax `proto3`. + * + * Generated from protobuf enum SYNTAX_PROTO3 = 1; + */ + const SYNTAX_PROTO3 = 1; + + private static $valueToName = [ + self::SYNTAX_PROTO2 => 'SYNTAX_PROTO2', + self::SYNTAX_PROTO3 => 'SYNTAX_PROTO3', + ]; + + 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); + } +} + diff --git a/src/pro/Google/Protobuf/Timestamp.php b/src/pro/Google/Protobuf/Timestamp.php new file mode 100644 index 00000000..6d26f6c5 --- /dev/null +++ b/src/pro/Google/Protobuf/Timestamp.php @@ -0,0 +1,200 @@ +google.protobuf.Timestamp + */ +class Timestamp extends \Google\Protobuf\Internal\Message +{ + /** + * Represents seconds of UTC time since Unix epoch + * 1970-01-01T00:00:00Z. Must be from 0001-01-01T00:00:00Z to + * 9999-12-31T23:59:59Z inclusive. + * + * Generated from protobuf field int64 seconds = 1; + */ + private $seconds = 0; + /** + * Non-negative fractions of a second at nanosecond resolution. Negative + * second values with fractions must still have non-negative nanos values + * that count forward in time. Must be from 0 to 999,999,999 + * inclusive. + * + * Generated from protobuf field int32 nanos = 2; + */ + private $nanos = 0; + + /** + * Constructor. + * + * @param array $data { + * Optional. Data for populating the Message object. + * + * @type int|string $seconds + * Represents seconds of UTC time since Unix epoch + * 1970-01-01T00:00:00Z. Must be from 0001-01-01T00:00:00Z to + * 9999-12-31T23:59:59Z inclusive. + * @type int $nanos + * Non-negative fractions of a second at nanosecond resolution. Negative + * second values with fractions must still have non-negative nanos values + * that count forward in time. Must be from 0 to 999,999,999 + * inclusive. + * } + */ + public function __construct($data = NULL) { + \GPBMetadata\Google\Protobuf\Timestamp::initOnce(); + parent::__construct($data); + } + + /** + * Represents seconds of UTC time since Unix epoch + * 1970-01-01T00:00:00Z. Must be from 0001-01-01T00:00:00Z to + * 9999-12-31T23:59:59Z inclusive. + * + * Generated from protobuf field int64 seconds = 1; + * @return int|string + */ + public function getSeconds() + { + return $this->seconds; + } + + /** + * Represents seconds of UTC time since Unix epoch + * 1970-01-01T00:00:00Z. Must be from 0001-01-01T00:00:00Z to + * 9999-12-31T23:59:59Z inclusive. + * + * Generated from protobuf field int64 seconds = 1; + * @param int|string $var + * @return $this + */ + public function setSeconds($var) + { + GPBUtil::checkInt64($var); + $this->seconds = $var; + + return $this; + } + + /** + * Non-negative fractions of a second at nanosecond resolution. Negative + * second values with fractions must still have non-negative nanos values + * that count forward in time. Must be from 0 to 999,999,999 + * inclusive. + * + * Generated from protobuf field int32 nanos = 2; + * @return int + */ + public function getNanos() + { + return $this->nanos; + } + + /** + * Non-negative fractions of a second at nanosecond resolution. Negative + * second values with fractions must still have non-negative nanos values + * that count forward in time. Must be from 0 to 999,999,999 + * inclusive. + * + * Generated from protobuf field int32 nanos = 2; + * @param int $var + * @return $this + */ + public function setNanos($var) + { + GPBUtil::checkInt32($var); + $this->nanos = $var; + + return $this; + } + + /* + * Converts PHP DateTime to Timestamp. + * + * @param \DateTime $datetime + */ + public function fromDateTime(\DateTime $datetime) + { + $this->seconds = $datetime->getTimestamp(); + $this->nanos = 1000 * $datetime->format('u'); + } + + /** + * Converts Timestamp to PHP DateTime. + * + * @return \DateTime $datetime + */ + public function toDateTime() + { + $time = sprintf('%s.%06d', $this->seconds, $this->nanos / 1000); + return \DateTime::createFromFormat('U.u', $time); + } +} + diff --git a/src/pro/Google/Protobuf/Type.php b/src/pro/Google/Protobuf/Type.php new file mode 100644 index 00000000..1b478110 --- /dev/null +++ b/src/pro/Google/Protobuf/Type.php @@ -0,0 +1,237 @@ +google.protobuf.Type + */ +class Type extends \Google\Protobuf\Internal\Message +{ + /** + * The fully qualified message name. + * + * Generated from protobuf field string name = 1; + */ + private $name = ''; + /** + * The list of fields. + * + * Generated from protobuf field repeated .google.protobuf.Field fields = 2; + */ + private $fields; + /** + * The list of types appearing in `oneof` definitions in this type. + * + * Generated from protobuf field repeated string oneofs = 3; + */ + private $oneofs; + /** + * The protocol buffer options. + * + * Generated from protobuf field repeated .google.protobuf.Option options = 4; + */ + private $options; + /** + * The source context. + * + * Generated from protobuf field .google.protobuf.SourceContext source_context = 5; + */ + private $source_context = null; + /** + * The source syntax. + * + * Generated from protobuf field .google.protobuf.Syntax syntax = 6; + */ + private $syntax = 0; + + /** + * Constructor. + * + * @param array $data { + * Optional. Data for populating the Message object. + * + * @type string $name + * The fully qualified message name. + * @type \Google\Protobuf\Field[]|\Google\Protobuf\Internal\RepeatedField $fields + * The list of fields. + * @type string[]|\Google\Protobuf\Internal\RepeatedField $oneofs + * The list of types appearing in `oneof` definitions in this type. + * @type \Google\Protobuf\Option[]|\Google\Protobuf\Internal\RepeatedField $options + * The 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); + } + + /** + * The fully qualified message name. + * + * Generated from protobuf field string name = 1; + * @return string + */ + public function getName() + { + return $this->name; + } + + /** + * The fully qualified message name. + * + * Generated from protobuf field string name = 1; + * @param string $var + * @return $this + */ + public function setName($var) + { + GPBUtil::checkString($var, True); + $this->name = $var; + + return $this; + } + + /** + * The list of fields. + * + * Generated from protobuf field repeated .google.protobuf.Field fields = 2; + * @return \Google\Protobuf\Internal\RepeatedField + */ + public function getFields() + { + return $this->fields; + } + + /** + * The list of fields. + * + * Generated from protobuf field repeated .google.protobuf.Field fields = 2; + * @param \Google\Protobuf\Field[]|\Google\Protobuf\Internal\RepeatedField $var + * @return $this + */ + public function setFields($var) + { + $arr = GPBUtil::checkRepeatedField($var, \Google\Protobuf\Internal\GPBType::MESSAGE, \Google\Protobuf\Field::class); + $this->fields = $arr; + + return $this; + } + + /** + * The list of types appearing in `oneof` definitions in this type. + * + * Generated from protobuf field repeated string oneofs = 3; + * @return \Google\Protobuf\Internal\RepeatedField + */ + public function getOneofs() + { + return $this->oneofs; + } + + /** + * The list of types appearing in `oneof` definitions in this type. + * + * Generated from protobuf field repeated string oneofs = 3; + * @param string[]|\Google\Protobuf\Internal\RepeatedField $var + * @return $this + */ + public function setOneofs($var) + { + $arr = GPBUtil::checkRepeatedField($var, \Google\Protobuf\Internal\GPBType::STRING); + $this->oneofs = $arr; + + return $this; + } + + /** + * The protocol buffer options. + * + * Generated from protobuf field repeated .google.protobuf.Option options = 4; + * @return \Google\Protobuf\Internal\RepeatedField + */ + public function getOptions() + { + return $this->options; + } + + /** + * The protocol buffer options. + * + * Generated from protobuf field repeated .google.protobuf.Option options = 4; + * @param \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 .google.protobuf.SourceContext source_context = 5; + * @return \Google\Protobuf\SourceContext + */ + public function getSourceContext() + { + return $this->source_context; + } + + /** + * The source context. + * + * Generated from protobuf field .google.protobuf.SourceContext source_context = 5; + * @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 .google.protobuf.Syntax syntax = 6; + * @return int + */ + public function getSyntax() + { + return $this->syntax; + } + + /** + * The source syntax. + * + * Generated from protobuf field .google.protobuf.Syntax syntax = 6; + * @param int $var + * @return $this + */ + public function setSyntax($var) + { + GPBUtil::checkEnum($var, \Google\Protobuf\Syntax::class); + $this->syntax = $var; + + return $this; + } + +} + diff --git a/src/pro/Google/Protobuf/UInt32Value.php b/src/pro/Google/Protobuf/UInt32Value.php new file mode 100644 index 00000000..f5a522d2 --- /dev/null +++ b/src/pro/Google/Protobuf/UInt32Value.php @@ -0,0 +1,68 @@ +google.protobuf.UInt32Value + */ +class UInt32Value extends \Google\Protobuf\Internal\Message +{ + /** + * The uint32 value. + * + * Generated from protobuf field uint32 value = 1; + */ + private $value = 0; + + /** + * Constructor. + * + * @param array $data { + * Optional. Data for populating the Message object. + * + * @type int $value + * The uint32 value. + * } + */ + public function __construct($data = NULL) { + \GPBMetadata\Google\Protobuf\Wrappers::initOnce(); + parent::__construct($data); + } + + /** + * The uint32 value. + * + * Generated from protobuf field uint32 value = 1; + * @return int + */ + public function getValue() + { + return $this->value; + } + + /** + * The uint32 value. + * + * Generated from protobuf field uint32 value = 1; + * @param int $var + * @return $this + */ + public function setValue($var) + { + GPBUtil::checkUint32($var); + $this->value = $var; + + return $this; + } + +} + diff --git a/src/pro/Google/Protobuf/UInt64Value.php b/src/pro/Google/Protobuf/UInt64Value.php new file mode 100644 index 00000000..89e69cd8 --- /dev/null +++ b/src/pro/Google/Protobuf/UInt64Value.php @@ -0,0 +1,68 @@ +google.protobuf.UInt64Value + */ +class UInt64Value extends \Google\Protobuf\Internal\Message +{ + /** + * The uint64 value. + * + * Generated from protobuf field uint64 value = 1; + */ + private $value = 0; + + /** + * Constructor. + * + * @param array $data { + * Optional. Data for populating the Message object. + * + * @type int|string $value + * The uint64 value. + * } + */ + public function __construct($data = NULL) { + \GPBMetadata\Google\Protobuf\Wrappers::initOnce(); + parent::__construct($data); + } + + /** + * The uint64 value. + * + * Generated from protobuf field uint64 value = 1; + * @return int|string + */ + public function getValue() + { + return $this->value; + } + + /** + * The uint64 value. + * + * Generated from protobuf field uint64 value = 1; + * @param int|string $var + * @return $this + */ + public function setValue($var) + { + GPBUtil::checkUint64($var); + $this->value = $var; + + return $this; + } + +} + diff --git a/src/pro/Google/Protobuf/Value.php b/src/pro/Google/Protobuf/Value.php new file mode 100644 index 00000000..5c1e864c --- /dev/null +++ b/src/pro/Google/Protobuf/Value.php @@ -0,0 +1,214 @@ +google.protobuf.Value + */ +class Value extends \Google\Protobuf\Internal\Message +{ + protected $kind; + + /** + * Constructor. + * + * @param array $data { + * Optional. Data for populating the Message object. + * + * @type int $null_value + * Represents a null value. + * @type float $number_value + * Represents a double value. + * @type string $string_value + * Represents a string value. + * @type bool $bool_value + * Represents a boolean value. + * @type \Google\Protobuf\Struct $struct_value + * Represents a structured value. + * @type \Google\Protobuf\ListValue $list_value + * Represents a repeated `Value`. + * } + */ + public function __construct($data = NULL) { + \GPBMetadata\Google\Protobuf\Struct::initOnce(); + parent::__construct($data); + } + + /** + * Represents a null value. + * + * Generated from protobuf field .google.protobuf.NullValue null_value = 1; + * @return int + */ + public function getNullValue() + { + return $this->readOneof(1); + } + + /** + * Represents a null value. + * + * Generated from protobuf field .google.protobuf.NullValue null_value = 1; + * @param int $var + * @return $this + */ + public function setNullValue($var) + { + GPBUtil::checkEnum($var, \Google\Protobuf\NullValue::class); + $this->writeOneof(1, $var); + + return $this; + } + + /** + * Represents a double value. + * + * Generated from protobuf field double number_value = 2; + * @return float + */ + public function getNumberValue() + { + return $this->readOneof(2); + } + + /** + * Represents a double value. + * + * Generated from protobuf field double number_value = 2; + * @param float $var + * @return $this + */ + public function setNumberValue($var) + { + GPBUtil::checkDouble($var); + $this->writeOneof(2, $var); + + return $this; + } + + /** + * Represents a string value. + * + * Generated from protobuf field string string_value = 3; + * @return string + */ + public function getStringValue() + { + return $this->readOneof(3); + } + + /** + * Represents a string value. + * + * Generated from protobuf field string string_value = 3; + * @param string $var + * @return $this + */ + public function setStringValue($var) + { + GPBUtil::checkString($var, True); + $this->writeOneof(3, $var); + + return $this; + } + + /** + * Represents a boolean value. + * + * Generated from protobuf field bool bool_value = 4; + * @return bool + */ + public function getBoolValue() + { + return $this->readOneof(4); + } + + /** + * Represents a boolean value. + * + * Generated from protobuf field bool bool_value = 4; + * @param bool $var + * @return $this + */ + public function setBoolValue($var) + { + GPBUtil::checkBool($var); + $this->writeOneof(4, $var); + + return $this; + } + + /** + * Represents a structured value. + * + * Generated from protobuf field .google.protobuf.Struct struct_value = 5; + * @return \Google\Protobuf\Struct + */ + public function getStructValue() + { + return $this->readOneof(5); + } + + /** + * Represents a structured value. + * + * Generated from protobuf field .google.protobuf.Struct struct_value = 5; + * @param \Google\Protobuf\Struct $var + * @return $this + */ + public function setStructValue($var) + { + GPBUtil::checkMessage($var, \Google\Protobuf\Struct::class); + $this->writeOneof(5, $var); + + return $this; + } + + /** + * Represents a repeated `Value`. + * + * Generated from protobuf field .google.protobuf.ListValue list_value = 6; + * @return \Google\Protobuf\ListValue + */ + public function getListValue() + { + return $this->readOneof(6); + } + + /** + * Represents a repeated `Value`. + * + * Generated from protobuf field .google.protobuf.ListValue list_value = 6; + * @param \Google\Protobuf\ListValue $var + * @return $this + */ + public function setListValue($var) + { + GPBUtil::checkMessage($var, \Google\Protobuf\ListValue::class); + $this->writeOneof(6, $var); + + return $this; + } + + /** + * @return string + */ + public function getKind() + { + return $this->whichOneof("kind"); + } + +} + diff --git a/src/pro/timestamp.proto b/src/pro/timestamp.proto new file mode 100644 index 00000000..2b9e26a9 --- /dev/null +++ b/src/pro/timestamp.proto @@ -0,0 +1,137 @@ +// 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. + +syntax = "proto3"; + +package google.protobuf; + +option csharp_namespace = "Google.Protobuf.WellKnownTypes"; +option cc_enable_arenas = true; +option go_package = "github.com/golang/protobuf/ptypes/timestamp"; +option java_package = "com.google.protobuf"; +option java_outer_classname = "TimestampProto"; +option java_multiple_files = true; +option objc_class_prefix = "GPB"; + +// A Timestamp represents a point in time independent of any time zone or local +// calendar, encoded as a count of seconds and fractions of seconds at +// nanosecond resolution. The count is relative to an epoch at UTC midnight on +// January 1, 1970, in the proleptic Gregorian calendar which extends the +// Gregorian calendar backwards to year one. +// +// All minutes are 60 seconds long. Leap seconds are "smeared" so that no leap +// second table is needed for interpretation, using a [24-hour linear +// smear](https://developers.google.com/time/smear). +// +// The range is from 0001-01-01T00:00:00Z to 9999-12-31T23:59:59.999999999Z. By +// restricting to that range, we ensure that we can convert to and from [RFC +// 3339](https://www.ietf.org/rfc/rfc3339.txt) date strings. +// +// # Examples +// +// Example 1: Compute Timestamp from POSIX `time()`. +// +// Timestamp timestamp; +// timestamp.set_seconds(time(NULL)); +// timestamp.set_nanos(0); +// +// Example 2: Compute Timestamp from POSIX `gettimeofday()`. +// +// struct timeval tv; +// gettimeofday(&tv, NULL); +// +// Timestamp timestamp; +// timestamp.set_seconds(tv.tv_sec); +// timestamp.set_nanos(tv.tv_usec * 1000); +// +// Example 3: Compute Timestamp from Win32 `GetSystemTimeAsFileTime()`. +// +// FILETIME ft; +// GetSystemTimeAsFileTime(&ft); +// UINT64 ticks = (((UINT64)ft.dwHighDateTime) << 32) | ft.dwLowDateTime; +// +// // A Windows tick is 100 nanoseconds. Windows epoch 1601-01-01T00:00:00Z +// // is 11644473600 seconds before Unix epoch 1970-01-01T00:00:00Z. +// Timestamp timestamp; +// timestamp.set_seconds((INT64) ((ticks / 10000000) - 11644473600LL)); +// timestamp.set_nanos((INT32) ((ticks % 10000000) * 100)); +// +// Example 4: Compute Timestamp from Java `System.currentTimeMillis()`. +// +// long millis = System.currentTimeMillis(); +// +// Timestamp timestamp = Timestamp.newBuilder().setSeconds(millis / 1000) +// .setNanos((int) ((millis % 1000) * 1000000)).build(); +// +// +// Example 5: Compute Timestamp from current time in Python. +// +// timestamp = Timestamp() +// timestamp.GetCurrentTime() +// +// # JSON Mapping +// +// In JSON format, the Timestamp type is encoded as a string in the +// [RFC 3339](https://www.ietf.org/rfc/rfc3339.txt) format. That is, the +// format is "{year}-{month}-{day}T{hour}:{min}:{sec}[.{frac_sec}]Z" +// where {year} is always expressed using four digits while {month}, {day}, +// {hour}, {min}, and {sec} are zero-padded to two digits each. The fractional +// seconds, which can go up to 9 digits (i.e. up to 1 nanosecond resolution), +// are optional. The "Z" suffix indicates the timezone ("UTC"); the timezone +// is required. A proto3 JSON serializer should always use UTC (as indicated by +// "Z") when printing the Timestamp type and a proto3 JSON parser should be +// able to accept both UTC and other timezones (as indicated by an offset). +// +// For example, "2017-01-15T01:30:15.01Z" encodes 15.01 seconds past +// 01:30 UTC on January 15, 2017. +// +// In JavaScript, one can convert a Date object to this format using the +// standard [toISOString()](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date/toISOString) +// method. In Python, a standard `datetime.datetime` object can be converted +// to this format using [`strftime`](https://docs.python.org/2/library/time.html#time.strftime) +// with the time format spec '%Y-%m-%dT%H:%M:%S.%fZ'. Likewise, in Java, one +// can use the Joda Time's [`ISODateTimeFormat.dateTime()`]( +// http://www.joda.org/joda-time/apidocs/org/joda/time/format/ISODateTimeFormat.html#dateTime%2D%2D +// ) to obtain a formatter capable of generating timestamps in this format. +// +// +message Timestamp { + + // Represents seconds of UTC time since Unix epoch + // 1970-01-01T00:00:00Z. Must be from 0001-01-01T00:00:00Z to + // 9999-12-31T23:59:59Z inclusive. + int64 seconds = 1; + + // Non-negative fractions of a second at nanosecond resolution. Negative + // second values with fractions must still have non-negative nanos values + // that count forward in time. Must be from 0 to 999,999,999 + // inclusive. + int32 nanos = 2; +} diff --git a/src/pro/types.proto b/src/pro/types.proto new file mode 100644 index 00000000..cc0348d0 --- /dev/null +++ b/src/pro/types.proto @@ -0,0 +1,130 @@ +syntax = "proto3"; +package aelf.protobuf.generated; +import "timestamp.proto"; + +message StringInput { + string string_value = 1; +} + +message MinerList { + repeated bytes public_keys = 1; +} + +message Hash { + bytes value = 1; +} + +message Address { + bytes value = 1; +} + +message Transaction { + Address from_address = 1; + Address to_address = 2; + int64 ref_block_number = 3; + bytes ref_block_prefix = 4; + string method_name = 5; + bytes params = 6; + bytes signature = 10000; +} + +message ElectionVotingRecord { + Address voter = 1; + string candidate = 2; + sint64 amount = 3; + sint64 term_number = 4; + Hash vote_id = 5; + sint64 lock_time = 7; + google.protobuf.Timestamp unlock_timestamp = 10; + google.protobuf.Timestamp withdraw_timestamp = 11; + google.protobuf.Timestamp vote_timestamp = 12; + bool is_withdrawn = 13; +} + +message ElectorVote { + repeated Hash active_voting_record_ids = 1; + repeated Hash withdrawn_voting_record_ids = 2; + sint64 active_voted_votes_amount = 3; + sint64 all_voted_votes_amount = 4; + repeated ElectionVotingRecord active_voting_records = 5; + repeated ElectionVotingRecord withdrawn_votes_records = 6; + bytes public_key = 7; +} + +message CandidateVote { + repeated Hash obtained_active_voting_record_ids = 1; + repeated Hash obtained_withdrawn_voting_record_ids = 2; + sint64 obtained_active_voted_votes_amount = 3; + sint64 all_obtained_voted_votes_amount = 4; + repeated ElectionVotingRecord obtained_active_voting_records = 5; + repeated ElectionVotingRecord obtained_withdrawn_votes_records = 6; + bytes public_key = 7; +} + +message PublicKeysList { + repeated bytes value = 1; +} + +message ContractDeploymentInput { + sint32 category = 1; + bytes code = 2; +} + +message ContractUpdateInput { + Address address = 1; + bytes code = 2; +} + +message CrossChainTransferInput { + Address to = 1; + string symbol = 2; + sint64 amount = 3; + string memo = 4; + int32 to_chain_id = 5; + int32 issue_chain_id = 6; +} + +message MerklePath { + repeated MerklePathNode merkle_path_nodes = 1; +} + +message MerklePathNode{ + Hash hash = 1; + bool is_left_child_node = 2; +} + +message CrossChainReceiveTokenInput { + int32 from_chain_id = 1; + int64 parent_chain_height = 2; + bytes transfer_transaction_bytes = 3; + MerklePath merkle_path = 4; +} + +message GetTokenInfoInput { + string symbol = 1; +} + +message GetBalanceInput { + string symbol = 1; + Address owner = 2; +} + +message GetBalanceOutput { + string symbol = 1; + Address owner = 2; + sint64 balance = 3; +} + +message IssueInput { + string symbol = 1; + sint64 amount = 2; + string memo = 3; + Address to = 4; +} + +message TransferInput { + Address to = 1; + string symbol = 2; + sint64 amount = 3; + string memo = 4; +} diff --git a/src/sdk/BlockChainSdk.php b/src/sdk/BlockChainSdk.php new file mode 100644 index 00000000..a316884c --- /dev/null +++ b/src/sdk/BlockChainSdk.php @@ -0,0 +1,377 @@ +AElfClientUrl = $url; + $this->version = $version; + $options = [//The custom options of cURL + CURLOPT_TIMEOUT => 0, + CURLOPT_CONNECTTIMEOUT => 5, + CURLOPT_USERAGENT => 'Multi-cURL client v1.5.0', + ]; + $this->Curl = new Curl(null, $options); + $this->base58 = new Base58(); + } + + + /** + * Get the height of the current chain. wa:/api/blockChain/blockHeight + */ + public function getBlockHeight(){ + + $this->Curl->makeGet($this->AElfClientUrl.self::$WA_BLOCKHEIGHT); + $Success = $this->Curl->exec(); + if ($Success->hasError()) { + //Fail + var_dump($Success->getError()); + } else { + //Success + + return $Success->getBody(); + } + } + + /** + * Get information about a given block by block hash. Otionally with the list of its transactions. + * wa://api/blockChain/block?includeTransactions={includeTransactions} + */ + public function getBlockByHash($blockHash,$includeTransactions=false){ + $this->Curl->makeGet($this->AElfClientUrl.self::$WA_BLOCK.'?blockHash='.$blockHash.'&includeTransactions='.($includeTransactions?'true':'false')); + $Success = $this->Curl->exec(); + if ($Success->hasError()) { + //Fail + var_dump($Success->getError()); + } else { + //Success + // var_dump($Success->getBody()); + return json_decode($Success->getBody(),JSON_UNESCAPED_UNICODE); + // return $Success->getBody(); + } + } + + /** + * Get information of a block by specified height. Optional whether to include transaction + * information. wa://api/blockChain/blockByHeight?includeTransactions={includeTransactions} + */ + public function getBlockByHeight($blockHeight,$includeTransactions = false){ + if ($blockHeight == 0) { + throw new Exception("[20001]Not found"); + } + + $this->Curl->makeGet($this->AElfClientUrl.self::$WA_BLOCKBYHEIGHT.'?blockHeight='.$blockHeight.'&includeTransactions='.($includeTransactions?'true':'false')); + $Success = $this->Curl->exec(); + if ($Success->hasError()) { + //Fail + var_dump($Success->getError()); + } else { + //Success + return json_decode($Success->getBody(),JSON_UNESCAPED_UNICODE); + } + } + + /** + * Get the current status of the block chain. wa:/api/blockChain/chainStatus + */ + public function getChainStatus(){ + $this->Curl->makeGet($this->AElfClientUrl.self::$WA_GETCHAINSTATUS); + $Success = $this->Curl->exec(); + if ($Success->hasError()) { + //Fail + var_dump($Success->getError()); + } else { + //Success + return json_decode($Success->getBody(),JSON_UNESCAPED_UNICODE); + + } + } + + /** + * Get the protobuf definitions related to a contract /api/blockChain/contractFileDescriptorSet. + */ + public function getContractFilCeDescriptorSet($address){ + + $this->Curl->makeGet($this->AElfClientUrl.self::$WA_GETCFCRIPTORSET."?address=".$address); + $Success = $this->Curl->exec(); + if ($Success->hasError()) { + //Fail + var_dump($Success->getError()); + } else { + //Success + + return $Success->getBody(); + } + + } + + /** + * Gets the status information of the task queue wa:/api/blockChain/taskQueueStatus. + */ + public function getTaskQueueStatus(){ + $this->Curl->makeGet($this->AElfClientUrl.self::$WA_GETTASKQUEUESTATUS); + $Success = $this->Curl->exec(); + if ($Success->hasError()) { + //Fail + var_dump($Success->getError()); + } else { + //Success + return json_decode($Success->getBody(),JSON_UNESCAPED_UNICODE); + + } + + } + + /** + * Gets information about the current transaction pool.wa:/api/blockChain/transactionPoolStatus + */ + public function getTransactionPoolStatus(){ + $this->Curl->makeGet($this->AElfClientUrl.self::$WA_GETTRANSACTIONPOOLSTATUS); + $Success = $this->Curl->exec(); + if ($Success->hasError()) { + //Fail + var_dump($Success->getError()); + } else { + //Success + return json_decode($Success->getBody(),JSON_UNESCAPED_UNICODE); + + } + + } + + /** + * Call a read-only method of a contract. wa:/api/blockChain/executeTransaction + */ + public function executeTransaction($input){ + $url = $this->AElfClientUrl.self::$WA_EXECUTETRANSACTION; + + $this->Curl->makePost($url,json_encode($input),array('Content-type: application/json;charset=UTF-8')); + + $response = $this->Curl->exec(); + if ($response->hasError()) { + //Fail + var_dump($response->getError()); + } else { + //Success + + return $response->getBody(); + } + + } + function http_post($sUrl, $aHeader, $aData){ + $ch = curl_init(); + curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); + curl_setopt($ch, CURLOPT_URL, $sUrl); + curl_setopt($ch, CURLOPT_HTTPHEADER, $aHeader); + curl_setopt($ch, CURLOPT_POST, true); + curl_setopt($ch, CURLOPT_POSTFIELDS, http_build_query($aData)); + $sResult = curl_exec($ch); + if($sError=curl_error($ch)){ + die($sError); + } + curl_close($ch); + return $sResult; + } + /** + * Creates an unsigned serialized transaction wa:/api/blockChain/rawTransaction. + */ + public function createRawTransaction($input) { + $url = $this->AElfClientUrl.self::$WA_CREATERAWTRANSACTION; + $this->Curl->makePost($url,json_encode($input),array('Content-type: application/json;charset=UTF-8')); + $response = $this->Curl->exec(); + if ($response->hasError()) { + //Fail + var_dump($response->getError()); + } else { + //Success + return json_decode($response->getBody(),JSON_UNESCAPED_UNICODE); + } + + + } + + /** + * Call a method of a contract by given serialized str wa:/api/blockChain/executeRawTransaction. + */ + public function executeRawTransaction($input){ + $url = $this->AElfClientUrl.self::$WA_EXECUTERAWTRANSACTION; + $this->Curl->makePost($url,json_encode($input),array('Content-type: application/json;charset=UTF-8')); + $response = $this->Curl->exec(); + if ($response->hasError()) { + //Fail + var_dump($response->getError()); + } else { + //Success + return json_decode($response->getBody(),JSON_UNESCAPED_UNICODE); + } + + } + + /** + * Broadcast a serialized transaction. wa:/api/blockChain/sendRawTransaction + */ + public function sendRawTransaction($input){ + $url = $this->AElfClientUrl.self::$WA_SENDRAWTRANSACTION; + + $this->Curl->makePost($url,json_encode($input),array('Content-type: application/json;charset=UTF-8')); + $response = $this->Curl->exec(); + if ($response->hasError()) { + //Fail + var_dump($response->getError()); + } else { + //Success + return json_decode($response->getBody(),JSON_UNESCAPED_UNICODE); + } + } + + + /** + * Broadcast a transaction wa:/api/blockChain/sendTransaction. + */ + public function sendTransaction($input){ + $url = $this->AElfClientUrl.self::$WA_SENDTRANSACTION; + + $this->Curl->makePost($url,json_encode($input),array('Content-type: application/json;charset=UTF-8')); + $response = $this->Curl->exec(); + if ($response->hasError()) { + //Fail + var_dump($response->getError()); + } else { + //Success + return json_decode($response->getBody(),JSON_UNESCAPED_UNICODE); + } + } + + /** + * Broadcast volume transactions wa:/api/blockChain/sendTransactions. + */ + public function sendTransactions($input){ + $url = $this->AElfClientUrl.self::$WA_SENDTRANSACTIONS; + + $this->Curl->makePost($url,json_encode($input),array('Content-type: application/json;charset=UTF-8')); + $response = $this->Curl->exec(); + if ($response->hasError()) { + //Fail + var_dump($response->getError()); + } else { + //Success + return json_decode($response->getBody(),JSON_UNESCAPED_UNICODE); + } + + + } + + /** + * Get the current status of a transaction wa:/api/blockChain/transactionResult. + */ + public function getTransactionResult($transactionId){ + $options = [//The custom options of cURL + CURLOPT_TIMEOUT => 0, + CURLOPT_CONNECTTIMEOUT => 80000, + CURLOPT_USERAGENT => 'Multi-cURL client v1.5.0', + ]; + $c = new Curl(null, $options); + $c->makeGet($this->AElfClientUrl.self::$WA_GETTRANSACTIONRESULT."?transactionId=".$transactionId); + $response = $c->exec(); + if ($response->hasError()) { + //Fail + var_dump($response->getError()); + } else { + //Success + return json_decode($response->getBody(),JSON_UNESCAPED_UNICODE); + //var_dump($response->getBody()); + } + } + + /** + * Get multiple transaction results. wa:/api/blockChain/transactionResults + */ + public function getTransactionResults($blockHash,$offset = 0,$limit = 10) { + if ($offset < 0) { + echo "Error.InvalidOffset"; + exit(); + } + if ($limit <= 0 || $limit > 100) { + echo "Error.InvalidLimit"; + exit(); + } + $this->Curl->makeGet($this->AElfClientUrl.self::$WA_GETTRANSACTIONRESULTS."?blockHash=".$blockHash.'&offset='.$offset."&limit=".$limit); + $Success = $this->Curl->exec(); + if ($Success->hasError()) { + //Fail + var_dump($Success->getError()); + } else { + //Success + return json_decode($Success->getBody(),JSON_UNESCAPED_UNICODE); + + } + + } + + /** + * Get merkle path of a transaction. wa:/api/blockChain/merklePathByTransactionId + */ + public function getMerklePathByTransactionId($transactionId) { + + $this->Curl->makeGet($this->AElfClientUrl.self::$WA_GETMBYTRANSACTIONID."?transactionId=".$transactionId); + $Success = $this->Curl->exec(); + if ($Success->hasError()) { + //Fail + var_dump($Success->getError()); + } else { + //Success + return json_decode($Success->getBody(),JSON_UNESCAPED_UNICODE); + } + } + + + private function createBlockDto($block,$includeTransactions){ + if ($block == null) { + echo "not found"; + exit(); + throw new RuntimeException("not found"); + } + return $block; + } + + /** + * Get id of the chain. + */ + public function getChainId(){ + $chainStatusDto = $this->getChainStatus(); + $bytes = $this->base58->decode($chainStatusDto['ChainId']); + $bytes = Bytes::getBytes($bytes); + return Bytes::bytestointeger($bytes, 0); + } +} \ No newline at end of file diff --git a/src/sdk/NetSdk.php b/src/sdk/NetSdk.php new file mode 100644 index 00000000..07f19dd9 --- /dev/null +++ b/src/sdk/NetSdk.php @@ -0,0 +1,109 @@ +AElfClientUrl = $url; + $this->version = $version; + $this->Curl = new Curl(); + $this->post_request_header = ['Content-Type' => 'application/json;charset=UTF-8'.$version]; + $this->get_request_header = ['Accept'=>'application/json;charset=UTF-8'.$version]; + } + + + /** + * Attempts to add a node to the connected network nodes wa:/api/net/peer. + */ + public function addPeer($input){ + $url = $this->AElfClientUrl.self::$WA_ADDPEER; + + $this->Curl->makePost($url,json_encode(['address'=>$input]),array('Content-type: application/json;charset=UTF-8')); + $response = $this->Curl->exec(); + if ($response->hasError()) { + //Fail + var_dump($response->getError()); + } else { + //Success + return json_decode($response->getBody(),JSON_UNESCAPED_UNICODE); + } + + + } + + /** + * Attempts to remove a node from the connected network nodes wa:/api/net/peer. + */ + public function removePeer($address){ + $url = $this->AElfClientUrl.self::$WA_REMOVEPEER; + + $this->Curl->makeDelete($url.'?address='.$address); + + $response = $this->Curl->exec(); + if ($response->hasError()) { + //Fail + var_dump($response->getError()); + } else { + //Success + + return json_decode($response->getBody(),JSON_UNESCAPED_UNICODE); + } + + + } + + /** + * Gets information about the peer nodes of the current node.Optional whether to include metrics. + * wa:/api/net/peers?withMetrics=false + */ + public function getPeers($withMetrics){ + + $this->Curl->makeGet($this->AElfClientUrl.self::$WA_GETPEERS."?withMetrics=".($withMetrics?'true':'false')); + + $Success = $this->Curl->exec(); + if ($Success->hasError()) { + //Fail + var_dump($Success->getError()); + } else { + //Success + + return json_decode($Success->getBody(),JSON_UNESCAPED_UNICODE); + + } + + } + + /** + * Get information about the node’s connection to the network. wa:/api/net/networkInfo + */ + public function getNetworkInfo(){ + $this->Curl->makeGet($this->AElfClientUrl.self::$WA_GETNETWORKINFO); + $Success = $this->Curl->exec(); + if ($Success->hasError()) { + //Fail + var_dump($Success->getError()); + } else { + //Success + return json_decode($Success->getBody(),JSON_UNESCAPED_UNICODE); + + } + + + } +} \ No newline at end of file