Git Product home page Git Product logo

protoc-gen-php's Introduction

PHP Protocol Buffer Generator

This is a plugin for Google's Protocol Buffer Generator, protoc. It generates PHP code from a .proto file. by Andrew Brampton (bramp.net) (c) 2010,2016

Minimum PHP Version Minimum HHVM Version Build Status

Supports:

  • Proto2 and Proto3
  • All features (Messages, Enums, Oneof, Maps)
  • Designed to be quick
  • Passes all compliance tests
  • PHP 5.5+ or HHVM 3.6.6+

Future:

  • JSON encoding
  • Support optimize_for=CODE_SIZE

Use

Once compiled and installed you can use it via protoc like so:

protoc --php_out=. your.proto

This should generate the file "your.proto.php", which should be able to encode and decode protocol buffer messages. When using the generated PHP code you must include the "protocolbuffers.inc.php" file.

Notes on Numbers

PHP uses signed integers, and depending on the platform may be 32 bit or 64 bit in size. Additionally PHP is typically compiled with IEEE 754 double precision floating point numbers, but may be compiled with single precision. This causes multiple problems for PHP using large numbers. As such the best appropimation is used when an exact representation is not available. On 32 bit platforms, signed integers are correct between -2^31 and 2^31-1, outside of that range floats are used. Double precision floats maintain integer accurancy up to 2^53, beyond that integers may not be precisce.

| Proto type | PHP type (32 bit) | PHP type (64 bit) | -------------------------------------------------------------------------------------- | bool | bool | bool | float / double | float | float | int32 | int | int | int64 / uint32 | int (between -2^31 and 2^31-1) otherwise float | int | uint64 | int (between 0 and 2^31-1) otherwise float | int (between 0 and 2^63-1) otherwise float | byte / string | string | string | enum | int | int

Install

This has only been tested on Linux and Mac. You will need the following libraries:

# For Debian based Linux
sudo apt-get install libprotobuf-dev protobuf-compiler

# For Mac
brew install protobuf

To build:

./autogen.sh
./configure
make
sudo make install

Licence (Simplified BSD License)

Copyright (c) 2010-2013, Andrew Brampton All rights reserved.

Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:

  1. Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.
  2. 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.

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.

protoc-gen-php's People

Contributors

alanpoulain avatar bramp avatar iamamused avatar stuporglue avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar

protoc-gen-php's Issues

google/protobuf/descriptor.proto: File not found

When building on ubuntu (following the steps in the readme)

Making all in src
make[1]: Entering directory '/home/donal/dev/service-proto/protoc-gen-php/src'
make  all-am
make[2]: Entering directory '/home/donal/dev/service-proto/protoc-gen-php/src'
protoc --proto_path=. --cpp_out=.  php_options.proto
google/protobuf/descriptor.proto: File not found.
php_options.proto: Import "google/protobuf/descriptor.proto" was not found or had errors.
php_options.proto:16:8: "google.protobuf.FileOptions" is not defined.
Makefile:636: recipe for target 'php_options.pb.cc' failed
make[2]: *** [php_options.pb.cc] Error 1
make[2]: Leaving directory '/home/donal/devservice-proto/protoc-gen-php/src'
Makefile:294: recipe for target 'all' failed
make[1]: *** [all] Error 2
make[1]: Leaving directory '/home/donal/dev/service-proto/protoc-gen-php/src'
Makefile:364: recipe for target 'all-recursive' failed
make: *** [all-recursive] Error 1

Generating ..., but no file found

After getting everything installed,

I am calling protoc --php_out=. -I=/some/include/path /path/to/proto

The terminal reports 'Generating my.proto.php', but no file shows up in my target directory .

Any help?

Call to undefined function gmp_init

Following the instructions, I received this error:

PHP Fatal error:  Call to undefined function gmp_init() in /Library/WebServer/Code/protoc-gen-php/protocolbuffers.inc.php on line 285

Fix:

brew install php56-gmp

Suggestion:

  • include the GMP extension as part of the requirements
  • Check this extension is enabled and throw a useful error before attempting to install
  • provide extension install instructions for mac/linux

How to pass php_namespace option? (option unknown)

I am updating old code using protoc-gen-php which use option (php).namespace = "........";, but it seems that it won't work with newest versions of protobuf (3.0.0) and protoc-gen-php.

option php_namespace = "....." also gives a unknown option. Is it a problem related to protoc-gen-php?

Proto files syntax is proto2.

Error at make with libprotoc 2.6.0

protoc php_options.proto --cpp_out=. -I. -I/usr/include -I/usr/local/include
g++ -Wall -g -c php_options.pb.cc -o php_options.pb.o
In file included from php_options.pb.cc:5:0:
php_options.pb.h:12:2: error: #error This file was generated by a newer version of protoc which is
php_options.pb.h:13:2: error: #error incompatible with your Protocol Buffer headers. Please update
php_options.pb.h:14:2: error: #error your headers.
In file included from php_options.pb.cc:5:0:
php_options.pb.h: In member function ‘void PHPFileOptions::clear_namespace_()’:
php_options.pb.h:153:23: error: ‘GetEmptyStringAlreadyInited’ is not a member of ‘google::protobuf::internal’
php_options.pb.h: In member function ‘void PHPFileOptions::set_namespace_(const string&)’:
php_options.pb.h:164:23: error: ‘GetEmptyStringAlreadyInited’ is not a member of ‘google::protobuf::internal’
php_options.pb.h: In member function ‘void PHPFileOptions::set_namespace_(const char_)’:
php_options.pb.h:172:23: error: ‘GetEmptyStringAlreadyInited’ is not a member of ‘google::protobuf::internal’
php_options.pb.h: In member function ‘void PHPFileOptions::set_namespace_(const char_, size_t)’:
php_options.pb.h:180:23: error: ‘GetEmptyStringAlreadyInited’ is not a member of ‘google::protobuf::internal’
php_options.pb.h: In member function ‘std::string* PHPFileOptions::mutable_namespace_()’:
php_options.pb.h:188:23: error: ‘GetEmptyStringAlreadyInited’ is not a member of ‘google::protobuf::internal’
php_options.pb.h: In member function ‘std::string* PHPFileOptions::release_namespace_()’:
php_options.pb.h:196:23: error: ‘GetEmptyStringAlreadyInited’ is not a member of ‘google::protobuf::internal’
php_options.pb.h:200:48: error: ‘GetEmptyStringAlreadyInited’ is not a member of ‘google::protobuf::internal’
php_options.pb.h: In member function ‘void PHPFileOptions::set_allocated_namespace_(std::string_)’:
php_options.pb.h:205:23: error: ‘GetEmptyStringAlreadyInited’ is not a member of ‘google::protobuf::internal’
php_options.pb.h:213:48: error: ‘GetEmptyStringAlreadyInited’ is not a member of ‘google::protobuf::internal’
php_options.pb.cc: In member function ‘void PHPFileOptions::SharedCtor()’:
php_options.pb.cc:128:3: error: ‘GetEmptyString’ is not a member of ‘google::protobuf::internal’
php_options.pb.cc:130:46: error: ‘GetEmptyStringAlreadyInited’ is not a member of ‘google::protobuf::internal’
php_options.pb.cc: In member function ‘void PHPFileOptions::SharedDtor()’:
php_options.pb.cc:141:23: error: ‘GetEmptyStringAlreadyInited’ is not a member of ‘google::protobuf::internal’
php_options.pb.cc: In member function ‘virtual void PHPFileOptions::Clear()’:
php_options.pb.cc:172:27: error: ‘GetEmptyStringAlreadyInited’ is not a member of ‘google::protobuf::internal’
php_options.pb.cc: In member function ‘virtual bool PHPFileOptions::MergePartialFromCodedStream(google::protobuf::io::CodedInputStream_)’:
php_options.pb.cc:188:63: error: ‘class google::protobuf::io::CodedInputStream’ has no member named ‘ReadTagWithCutoff’
php_options.pb.cc:197:11: error: ‘VerifyUTF8StringNamedField’ is not a member of ‘google::protobuf::internal::WireFormat’
php_options.pb.cc: In member function ‘virtual void PHPFileOptions::SerializeWithCachedSizes(google::protobuf::io::CodedOutputStream_) const’:
php_options.pb.cc:250:5: error: ‘VerifyUTF8StringNamedField’ is not a member of ‘google::protobuf::internal::WireFormat’
php_options.pb.cc:254:5: error: ‘WriteStringMaybeAliased’ is not a member of ‘google::protobuf::internal::WireFormatLite’
php_options.pb.cc: In member function ‘virtual google::protobuf::uint8_ PHPFileOptions::SerializeWithCachedSizesToArray(google::protobuf::uint8_) const’:
php_options.pb.cc:275:5: error: ‘VerifyUTF8StringNamedField’ is not a member of ‘google::protobuf::internal::WireFormat’
make: *_* [php_options.pb.o] Erreur 1

In Windows, It do not auto make sub directory

if the protoc file has namespace, or enum nested in message. the compiler report "no such file or directory" error. example proto file:

namespace foo;
message AuthResponse {
    enum Err {
        SUCC = 0;
        FAIL = 1;
    }
    required Err err = 1;   
}

Undefined variable: name

I keep getting this error after the recent changes.
An example proto which causes this error, some thing like this

message App {

    optional group ExtendedInfo = 12 {  //This line gives the warning, removing this fixes everyting
           //something here
    }
}  

I never got this error with the old files i was using.
Decided to try the recent changes today but they didnt work.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.