Git Product home page Git Product logo

php-protocolbuffers's People

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  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  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

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

php-protocolbuffers's Issues

use namespace when generating nested message

currently protoc-gen-php use underscore when generating nested message.
it should use namespace when the (php)generate_package = 1 option.

message should current result
BidRequest BidRequest BidRequest
BidRequest.Hyperlocal BidRequest\Hyperlocal BidRequest_Hyperlocal
BidRequest.Hyperlocal.Point BidRequest\Hyperlocal\Point BidRequest_Hyperlocal_Point

from realtime-bidding.proto
https://developers.google.com/ad-exchange/rtb/downloads/realtime-bidding-proto.txt

this will also consider output multiple files.

No error when using a not initialized message

When using a get*() on a not initialized member of type 'message':
- message is ignored and NO error is throw during serialisation

// proto message:
message Foo {
required int32 a = 1;
}

message Container {
optional Foo foo = 1;
}

// php code:
$c = new Container();
$c->getFoo()->setA(0);
$c->serializeToString(); // no error, empty output. why ?

adding: $c->setFoo( new Foo() ); before calling getFoo() fix the problem...

I propose you to choose between two features:

  • or an error message in getFoo(): "Please, initialize foo before using it"
  • or, like c++ protocol buffer : automatically initialize messages when getFoo() is called for the first time (better)

The actual situation is disturbing.

PHP -> Java -> PHP -> ProtocolBuffersInvalidProtocolBufferException on parseFromString()

Sending to Java over activeMQ as bytes message works perfect on a Windows 7 64 machine using php-5.5.14-nts-Win32-VC11-x86 and PHP PB 0.2.6 alpha 2014-04-15 DLL from PECL.
Recieving the response from Java in PHP makes headaches. Proto file:

package net_x3_service_adapter_jms_barcode_zxing_protobuf_rpc;
option java_package = "net.x3.service.adapter.jms.barcode.zxing.protobuf.rpc";
option java_outer_classname = "zebracrossing";
option optimize_for = SPEED;

message ZXingMultiFormatDecodeImageRequest {
required bytes image = 1;
optional int32 resolution_start = 2;
optional int32 resolution_stop = 3;
optional int32 short_side_step = 4;
}
message ZXingException {
required string exception_type = 1;
required string exception_message = 2;
optional string stack_trace = 3 [default = ""];
}
message ZXingResponse {
optional string result = 1;
optional ZXingException exception = 2;
}

Short version of the Code:

$imageString = file_get_contents('images/test.png');
$request = new \net_x3_service_adapter_jms_barcode_zxing_protobuf_rpc\ZXingMultiFormatDecodeImageRequest();
$request->setImage($imageString);
$request->setResolutionStart('16384');
$request->setResolutionStop('4194304');
$request->setShortSideStep('1');
$serialized = $request->serializeToString();
// until now everything works, java receives and parses the request succesfully and sends return
// get body from returned JMS message which is String, part of the correct return value is visible
$bytes = $msg->body;
$deserialized = \net_x3_service_adapter_jms_barcode_zxing_protobuf_rpc\ZXingResponse::parseFromString(strval($bytes));

Exception on parseFromString()

PHP Fatal error: Uncaught exception 'ProtocolBuffersInvalidProtocolBufferException' with message 'passed variable contains malformed byte sequence. or it contains unsupported tag' in C:\Users\x3.mbetzel\Development\workspaces\php\StompProtoBuf\zxing.php:59
Stack trace:
#0 C:\Users\x3.mbetzel\Development\workspaces\php\StompProtoBuf\zxing.php(59): ProtocolBuffersMessage::parseFromString('\xB3\x02HMM2000123456...')
#1 {main}

thrown in C:\Users\x3.mbetzel\Development\workspaces\php\StompProtoBuf\zxing.php on line 59

The strange thing is that if i return this object from Java with an exception everything is good:

Received message
class net_x3_service_adapter_jms_barcode_zxing_protobuf_rpc\ZXingResponse#9 (2) {
protected $result =>
string(0) ""
protected $exception =>
class net_x3_service_adapter_jms_barcode_zxing_protobuf_rpc\ZXingException#8 (3) {
protected $exception_type =>
string(34) "java.lang.IllegalArgumentException"
protected $exception_message =>
string(16) "No barcode found"
protected $stack_trace =>
string(0) ""
}
}

Any ideas?

data parse error

Fatal error: Uncaught exception 'ProtocolBuffersInvalidProtocolBufferException' with message 'passed variable contains malformed byte sequence. or it contains unsupported tag'

I have got a problem. This error occur with no rule, sometimes it happen.

[root@lnx-search-14-228 pb]# php pbtest.php

Fatal error: Uncaught exception 'ProtocolBuffersInvalidProtocolBufferException' with message 'passed variable contains malformed byte sequence. or it contains unsupported tag' in /usr/local/php/protoc-gen-php/interface/pb/pbtest.php:34
Stack trace:
#0 /usr/local/php/protoc-gen-php/interface/pb/pbtest.php(34): ProtocolBuffersMessage::parseFromString('\x08\x91\x85\x80\x80\xC0\xD2\x86\xF1\xF3\x01\x1A\xF7)\x18...')
#1 {main}

thrown in /usr/local/php/protoc-gen-php/interface/pb/pbtest.php on line 34
[root@lnx-search-14-228 pb]# php pbtest.php
error occured
[root@lnx-search-14-228 pb]# vim pbtest.php
[root@lnx-search-14-228 pb]# php pbtest.php

Fatal error: Uncaught exception 'ProtocolBuffersInvalidProtocolBufferException' with message 'passed variable contains malformed byte sequence. or it contains unsupported tag' in /usr/local/php/protoc-gen-php/interface/pb/pbtest.php:34
Stack trace:
#0 /usr/local/php/protoc-gen-php/interface/pb/pbtest.php(34): ProtocolBuffersMessage::parseFromString('\x08\x93\x85\x80\x80\xC0\xD2\x86\xF1\xF3\x01\x1A\xF7)\x18...')
#1 {main}

thrown in /usr/local/php/protoc-gen-php/interface/pb/pbtest.php on line 34

Memory leak in examples/prefecture.php

I have added the following line to the end of examples/prefecture.php:

printf("# memory: %d\n", memory_get_peak_usage());

Here's the output:

$ php prefecture.php 
# decoding benchmark (protocolbuffers).
# target message size: 1195 bytes.
# start
# Result:
# decoding 10000 messages
# processing time: 1.668647 (0.000167/message)
# total bytes: 11950000 bytes
# memory: 661161504

Even though the message is 11MB (total bytes in the output), memory usage peaked at 630MB! This is extremely high and it looks like there is a memory leak. Maybe it's related to this?

Installing php-protocolbuffers fails at composer step

Hello,

I'm following the setup instructions on ubuntu 14.04 with 5.5.9

When I get to the setup where, in my home directory, where I downloaded php-protocolbuffers.git & protoc-gen-php.git I get this error when I try to run:

composer install

test@server2:/var/www/test/protoc-gen-php$ sudo composer install
Loading composer repositories with package information
Installing dependencies (including require-dev)
Your requirements could not be resolved to an installable set of packages.

Problem 1
- The requested PHP extension ext-protocolbuffers * is missing from your system. Install or enable PHP's protocolbuffers extension.

The phpinfo() function says protocol buffers 0.2.5 is installed but php -m on the command line doesn't show the loaded module.

I think this is the issue but I don't know how to resolve this.

Can you tell me where I went wrong?

When initialize a message with an invalid array, the first invalid key of the given array will be changed to an exception

When initialize a message with an invalid array, the first invalid key of the given array will be changed to an exception. Segmentation fault also.

Message definition

message Person
{
    required bytes name = 1;
    required uint32 age = 2;
}

PHP test code

require 'person.proto.php';
$info = [
    'fake_name' => 'bryce',
    'age' => 18
];
var_dump($info);
$person = new Person();
try {
    $person->setFrom($info);
} catch (Exception $e) {
}
var_dump($info);

PHP output

array(2) {
  'fake_name' =>
  string(5) "bryce"
  'age' =>
  int(18)
}
array(2) {
  'fake_name' =>
  class InvalidArgumentException#4 (8) {
    protected $message =>
    string(23) "fake_name does not find"
    private $string =>
    string(0) ""
    protected $code =>
    int(0)
    protected $file =>
    string(32) "/home/bryceliu/c/person/test.php"
    protected $line =>
    int(10)
    private $trace =>
    array(1) {
      [0] =>
      array(6) {
        ...
      }
    }
    private $previous =>
    NULL
    public $xdebug_message =>
    string(279) "
InvalidArgumentException: fake_name does not find in /home/bryceliu/c/person/test.php on line 10

Call Stack:
    0.0002     223440   1. {main}() /home/bryceliu/c/person/test.php:0
    0.0013     252648   2. ProtocolBuffersMessage->setFrom() /home/bryceliu/c/person/test.php:10
"
  }
  'age' =>
  int(18)
}
Segmentation fault

Parsing large message might cause performance down.

ProtocolBuffersMessage class design is fully representation protocol buffers message into PHP classes.
this makes easy to use with PHP. you can easily to customize message class, convert message into another format.

but this also means parsing large (has many child message) message will slow down performance (it takes many memories and times).
imagine creating 10000 of complicated child message when parsing the data. It's really tough work.

when you want to use this with web services. then you should keep 1 message size between 1.5K ~ 10Kbytes with gzip. (I recommend under 3Kbytes).

see also: https://developers.google.com/protocol-buffers/docs/techniques#large-data

Problems with numbers larger than 2^63-1

There are some issues with large numbers, in addition the 001_fixed_64_max.phpt test references the wrong fixture, which is one of the reason this problem has gone undetected for now.

Also I noticed that calling ProtocolBuffers::encode() will break the original value assigned in some cases.

I poked around in helper.c, trying to fix it, but after several hours I've instead produced this example. The script test several interesting points as I've discovered 2^64-1025 has a different result from 2^64.

<?php
if (8 !== PHP_INT_SIZE) { die('Only for 64-bit platform'); }
class TestCase
{
  protected static $descriptor;
  protected $value;

  public function getValue()
  {
    return $this->value;
  }
  public function setValue($value)
  {
    $this->value = $value;
  }
  public static function getDescriptor()
  {
      if (!isset(self::$descriptor)) {
          $desc = new ProtocolBuffersDescriptorBuilder();
          $desc->addField(1, new ProtocolBuffersFieldDescriptor(array(
              "type"     => ProtocolBuffers::TYPE_FIXED64,
              "name"     => "value",
              "packable" => false,
              "repeated" => false,
              "default"  => null,
          )));

          self::$descriptor = $desc->build();
      }
      return self::$descriptor;
  }
}

// Pretty formatted debug_zval_dump
function debug($v) {
    ob_start();
    debug_zval_dump($v);
    $d = ob_get_contents();
    ob_end_clean();
    return str_replace(PHP_EOL,'',$d);
    return preg_replace('/ refcount\(\d+\)/','',str_replace(PHP_EOL,'',$d));
}

$testCases = array(
    0,
    1,
    9223372036854775807,    // 2^63-1
    9223372036854775808,    // 2^63
    18446744073709550590,   // (2^64-1)-1024-1
    18446744073709551691,   // (2^64-1)-1024
    18446744073709551615    // (2^64-1)
);
$names = array(
    'zero',
    'one',
    '9223372036854775807 aka 2^63-1',
    '9223372036854775808 aka 2^63',
    '18446744073709550590 aka (2^64-1)-1024-1',
    '18446744073709551691 aka (2^64-1)-1024',
    '18446744073709551615 aka (2^64-1)'
);

foreach ($testCases as $i => $t) {
    echo "\n== Testing ".($names[$i] ? $names[$i] : debug($t))." ==\n";
    $a = $t;
    $e = new TestCase();
    $e->setValue($t);

    // Encoding changes variable underneath, make a copy of the variable
    $copy = unserialize(serialize($t));

    printf("Input prior to encode : %s\n",debug($t));
    $data = ProtocolBuffers::encode($e);
    printf("Input after encode    : %s\n",debug($t));
    if ($copy != $t) echo "Encoding changed variable value!\n";

    $d = ProtocolBuffers::decode("TestCase", $data);
    printf("Object  : %s\n",debug($e));
    printf("Data    : %s\n",bin2hex($data));
    printf("Decoded : %s\n",debug($d));

    // Result?
    $r = '';
    if ($e->getValue() == $d->getValue() && $d->getValue() == $copy) {
        $r = 'OK';
    } else if ($d->getValue() == $copy) {
        $r = 'FAIL (Decoded match input)';
    } else {
        $r = 'FAIL';
    }
    printf("Result  : %s\n",$r);
}

[protoc-gen-php] Enum default values: case mismatch

Enum items are converted to upper case in constant definitions while remain in camel case in default values.

enum DocumentType {
    UnknownDocumentType = -1;
...
<?php
 * @enum Diadoc.Api.Proto.Documents.DocumentType
 */
class Diadoc_Api_Proto_Documents_DocumentType
{
  const UNKNOWNDOCUMENTTYPE = -1;

...

      $desc->addField(6, new ProtocolBuffersFieldDescriptor(array(
        "type"     => ProtocolBuffers::TYPE_ENUM,
        "name"     => "DocumentType",
        "required" => false,
        "optional" => true,
        "repeated" => false,
        "packable" => false,
        "default"  => Diadoc_Api_Proto_Documents_DocumentType::UnknownDocumentType,
      )));

zend_error_noreturn

Env: Linux 2.6.32-279.el6.i686 #1 SMP Fri Jun 22 10:59:55 UTC 2012 i686 i686 i386 GNU/Linux
Problem: PHP Startup: Unable to load dynamic library '/usr/lib/php/modules/protocolbuffers.so' - /usr/lib/php/modules/protocolbuffers.so: undefined symbol: zend_error_noreturn in Unknown on line 0
Solved: change "zend_error_noreturn " to "zend_error"

[Feature Request] ProtocolBuffersMessage should implement JsonSerializable interface

Is it possible to make ProtocolBuffersMessage implement JsonSerializable?

Basically, it could return a key/value pair of all fields & values in the message, like this:

public function jsonSerialize()
{
    return array(
        "foo" => $this->get("foo"),
        "bar" => $this->get("bar"),
    );
}

If you can do this all children of ProtocolBuffersMessage can now be serialized with json_encode which would help immensely with logging etc.

Do you think this is feasible?

Fatal error

Fatal error: Uncaught exception 'ProtocolBuffersInvalidProtocolBufferException' with message 'passed variable contains malformed byte sequence. or it contains unsupported tag' in C:\Users\x3.mbetzel\Development\workspaces\php\ProtoBufGen\src\protocolbuffers\Compiler.php on line 186
ProtocolBuffersInvalidProtocolBufferException: passed variable contains malformed byte sequence.
Enviroment:
Windows 7 64 bit
PHP 5.5.14-nts-Win32-VC11-x86
php_protocolbuffers.dll version 0.26 alpha PECL
php_proto_gen GITHUB master

Trying to generate proto.php file from .proto file :

package test_package;

message Person
{
required int32 user_id = 1;
optional string name = 2;
}

CODE:

compile($stdin); var_dump($response); simple.bin works as it produces a proto.php file as third string in array (file[2]).

Error After installation

We have installed this proto buff but while generating class from proto, we are getting below Error
--php_out: protoc-gen-php: Plugin killed by signal 11.
Please reply asap

when serialize , got 'zend_mm_heap corrupted'

we had read the source code , found the bug:
file: serializer.c
line: 76, 101

the 2nd var is 1,

101 if (php_protocolbuffers_serializer_resize(serializer, 1)) {

but look the code bellow; it use 4 or 8

123 serializer->buffer[serializer->buffer_size++] = target[0];
124 serializer->buffer[serializer->buffer_size++] = target[1];
125 serializer->buffer[serializer->buffer_size++] = target[2];
126 serializer->buffer[serializer->buffer_size++] = target[3];
127 serializer->buffer[serializer->buffer_size++] = target[4];
128 serializer->buffer[serializer->buffer_size++] = target[5];
129 serializer->buffer[serializer->buffer_size++] = target[6];
130 serializer->buffer[serializer->buffer_size++] = target[7];

so , this is a bug, I change the 2nd var to 4 or 8, then rebuild the code, it work fine.
plz the author fixed it for everyone. thank you.

Message::append on a repeated field causes segfault, batch assigning it throws exception

I've spent the past 2 hours debugging this. Consider the following proto files:

package wom2.protobuf.messages;

import "webUser.proto";

message SomeMessage
{
    repeated WebUser users = 1;
}

and this one:

package wom2.protobuf.messages;

message WebUser
{
    required int64 id = 1;
    optional int64 fbid = 2;
    optional string ios_gcid = 3;
    optional string and_gpid = 4;
    required bool active = 5;
    optional int32 server_id = 6;
    optional string name = 7;
}

Now, $webUsers is an array of WebUser instances. The following works:

foreach ($webUsers as $u)
{
    $someMessage->appendUsers($u);
}

But the following segfaults:

foreach ($webUsers as $u)
{
    $someMessage->append('users', $u);
}

So I tried batch assigning it:

$someMessage->setFrom(array('users' => $webUsers));

// or this one...

new SomeMessage(array('users' => $webUsers));

which threw this exception:

1Ай9яяя   does not find

segmentation fault if passed invalid data, when ProtocolBuffers::decode is called

if empty data is passed ...

ProtocolBuffers::decode('Test\Sample', '');

PHP Fatal error:  Uncaught exception 'ProtocolBuffersInvalidProtocolBufferException' with message 'passed variable seems null' in ...

but like this with invalid data ...

ProtocolBuffers::decode('Test\Sample', 1);

[1]    10767 segmentation fault

Is it not supported to throw exception when invalid data is passed now?

  • PHP 5.4.31
  • php-protocolbuffers 747a223

[Feature Request] Optional native types for numeric fields

As you've described in the wiki, all numeric types are converted to string in PHP. I understand why you chose this (PHP doesn't handle scalar primitives very well), but maybe you can provide a config option for this?

For example:

ini_set("protocolbuffers.native_scalars",1);

This way we can have this:

.proto type php type
double double
float double
int32 int
int64 int
uint32 int
uint64 int
sint32 int
sint64 int
fixed32 int
fixed64 int
sfixed32 int
sfixed64 int

This would have better performance on 64bit Linux and OS X systems. Any thoughts?

please help me.thanks

so:

parseFromString($data); //$tm = $person->getDescriptor(); //echo $tm->getName(); print_r($data); exit; how to get the "$data" information. and use the class functions

how can i delete item with repeated field

demo:
message A {
required int32 item =1;
}

how can i delete a item ?

I got a idea ,add a function

/**
 * 删掉一个数据
 * @param $index
 */
public function removeItem($index) {
    array_splice($this->item, $index, 1);
}

can you add this feature

Support unknown fields

robust protocol buffer implementation requires to support unknown fileds.
we can safe to store existing pb message if we support it.

fixed64: encoding stringy-numbers fails if the script contain large number literals

Discovered a really weird test case.

<?php
class TestCase
{
  protected static $descriptor;
  protected $value;

  public function getValue()
  {
    return $this->value;
  }
  public function setValue($value)
  {
    $this->value = $value;
  }
  public static function getDescriptor()
  {
      if (!isset(self::$descriptor)) {
          $desc = new ProtocolBuffersDescriptorBuilder();
          $desc->addField(1, new ProtocolBuffersFieldDescriptor(array(
              "type"     => ProtocolBuffers::TYPE_FIXED64,
              "name"     => "value",
              "packable" => false,
              "repeated" => false,
              "default"  => null,
          )));

          self::$descriptor = $desc->build();
      }
      return self::$descriptor;
  }
}

$foo = "1";
debug_zval_dump($foo);
$a = new TestCase();
$a->setValue($foo);
debug_zval_dump($a);
ProtocolBuffers::encode($a);

exit();

// Remove the following line and it works, keep it and it fails
// Yes the line is after the exit() and unrelated, yet it modifies
// the behavior of fixed64 support
$bar = 9223372036854775808;

Outputs:

string(1) "1" refcount(2)
object(TestCase)#1 (1) refcount(2){
  ["value":protected]=>
  string(1) "1" refcount(2)
}
PHP Warning:  pb_encode_element_fixed64: strtoull failed to decode string in /Users/hans/t.php on line 38

Warning: pb_encode_element_fixed64: strtoull failed to decode string in /Users/hans/t.php on line 38

Works fine for uint64 though, removing the large number literal also works. Might a problem in PHP itself?

The message contains a message data that has been serialized

message Hello {
required string type = 1;
required string data = 2;
}

message world {
required string name = 1;
required int32 year = 2;
}

php code:

$h = new Hello();
$w = new world();

$h->setType("world");

$w->setName("earth");
$w->setYear(2014);

$h->setData($w->serializeToString());

$h->serializeToString();

error: this string ,it not is vaild utf-8

0.2.3 has a failing unit test & causes random segfaults in php-fpm

I've just tried to latest 0.2.3 from github with PHP 5.5.11. First, one of the tests fail:

=====================================================================
FAILED TEST SUMMARY
---------------------------------------------------------------------
ProtocolBuffersMessage extension implementation [tests/600_extension_clear.phpt]
=====================================================================

If I ignore this and load the extension, FPM randomly crashes every few requests with:

[14-Apr-2014 09:19:21] WARNING: [pool www] child 10013 exited on signal 11 (SIGSEGV - core dumped) after 1.527762 seconds from start
[14-Apr-2014 09:19:21] NOTICE: [pool www] child 10018 started
[14-Apr-2014 09:19:22] WARNING: [pool www] child 10016 exited on signal 11 (SIGSEGV - core dumped) after 0.779867 seconds from start
[14-Apr-2014 09:19:22] NOTICE: [pool www] child 10020 started
[14-Apr-2014 09:19:22] WARNING: [pool www] child 10018 exited on signal 11 (SIGSEGV - core dumped) after 0.412428 seconds from start
[14-Apr-2014 09:19:22] NOTICE: [pool www] child 10022 started
[14-Apr-2014 09:19:35] WARNING: [pool www] child 10020 exited on signal 11 (SIGSEGV - core dumped) after 13.821716 seconds from start
[14-Apr-2014 09:19:35] NOTICE: [pool www] child 10037 started
[14-Apr-2014 09:19:36] WARNING: [pool www] child 10022 exited on signal 11 (SIGSEGV - core dumped) after 14.274327 seconds from start
[14-Apr-2014 09:19:36] NOTICE: [pool www] child 10040 started
[14-Apr-2014 09:19:36] WARNING: [pool www] child 10037 exited on signal 11 (SIGSEGV - core dumped) after 0.863197 seconds from start
[14-Apr-2014 09:19:36] NOTICE: [pool www] child 10042 started
[14-Apr-2014 09:19:37] WARNING: [pool www] child 10040 exited on signal 11 (SIGSEGV - core dumped) after 0.456663 seconds from start

There are also several warnings during make:

/tmp/php-protocolbuffers/json_serializer.c:353:3: warning: passing argument 4 of ‘add_assoc_stringl_ex’ discards ‘const’ qualifier from pointer target type [enabled by default]
   add_assoc_stringl_ex(result, scheme->original_name, scheme->original_name_len, value, value_len, 1);
   ^
In file included from /usr/include/php/main/php.h:38:0,
                 from /tmp/php-protocolbuffers/php_protocolbuffers.h:41,
                 from /tmp/php-protocolbuffers/protocolbuffers.h:34,
                 from /tmp/php-protocolbuffers/json_serializer.c:1:
/usr/include/php/Zend/zend_API.h:382:14: note: expected ‘char *’ but argument is of type ‘const char *’
 ZEND_API int add_assoc_stringl_ex(zval *arg, const char *key, uint key_len, char *str, uint length, int duplicate);
              ^
/tmp/php-protocolbuffers/json_serializer.c: At top level:
/tmp/php-protocolbuffers/json_serializer.c:388:2: warning: initialization from incompatible pointer type [enabled by default]
  _json_serializer_fixed64,//fixed64
  ^
/tmp/php-protocolbuffers/json_serializer.c:388:2: warning: (near initialization for ‘json_serializer.serialize_fixed64’) [enabled by default]
/tmp/php-protocolbuffers/json_serializer.c: In function ‘php_protocolbuffers_json_encode_value’:
/tmp/php-protocolbuffers/json_serializer.c:637:4: warning: passing argument 2 of ‘convert_to_int64’ from incompatible pointer type [enabled by default]
    convert_to_int64(&value_copy, &v);
    ^
/tmp/php-protocolbuffers/json_serializer.c:421:12: note: expected ‘int64_t *’ but argument is of type ‘int32_t *’
 static int convert_to_int64(zval *value, int64_t *result)
            ^
/tmp/php-protocolbuffers/json_serializer.c: In function ‘php_protocolbuffers_json_encode_element’:
/tmp/php-protocolbuffers/json_serializer.c:687:2: warning: passing argument 3 of ‘php_protocolbuffers_get_property_name’ from incompatible pointer type [enabled by default]
  name = php_protocolbuffers_get_property_name(container, scheme, &name_len);
  ^
/tmp/php-protocolbuffers/json_serializer.c:406:20: note: expected ‘size_t *’ but argument is of type ‘int *’
 static const char* php_protocolbuffers_get_property_name(php_protocolbuffers_scheme_container *container, php_protocolbuffers_scheme *scheme, size_t *name_len)
                    ^
/tmp/php-protocolbuffers/json_serializer.c:687:7: warning: assignment discards ‘const’ qualifier from pointer target type [enabled by default]
  name = php_protocolbuffers_get_property_name(container, scheme, &name_len);
       ^

can you help me,thank you.

my proto file design as
message perm {
ALL = 0;
SYSTEM = 1;
ARTICLE = 2;
PIC = 3;
}

message Admin {
required string name = 1;
required string password = 2;
repeate perm purview = 3;
}

but the generate php file serializeToString the admin message is error,the binary string is different from the protobuf-c pack the admin message。and i use the binary string decode the Admin message ,the object before serialize and after decode is different . so i think when i repeated an enum type ,the serialize function may be not correct.

can you help me solve the problem.thank you very much.

the int64 decode problem

hi chobie:

i found antohter problem,maybe there is a bug in the protocolbuffers extension;

i the a proto named time.proto ,its content is

message Time {
uint64 start;
uint64 end;
}

then , i write a php.

setStart($start _1000); $objin->setEnd($end_1000); var_dump($objin); $bin = $objin->serializeToString(); $objout = ProtocolBuffers::decode('Time', $bin); var_dump($objout); ?>

In theory, the value of the $objin and $objout is the same. but
they are not .

the $objin is present correctly,maybe ,the value of property start and end of $objout present error ,maybe ,there is a numerical overflow。

i use the centos operate system( sixty-four - bit).

best regards.

API documentation lacks details to create stub files

I tried creating a stub (see the predis example here) file to be used for IDE type hinting / autocomplete but the API documentation is quite rudimentary (missing constants values, method parameters etc.)

Can you either update the API documentation with full class definitions and constant values, or maybe create a stub file as an example?

ProtocolBuffersMessage::__construct() is broken with repeated fields

Latest version (0.2.6) seems to be broken with:

ProtocolBuffersMessage::__construct() expects parameter 1 to be array, object given

Sample proto:

message TestMessage
{
    repeated TestUser users = 1;
}

message TestUser
{
    required int64 id = 1;
}

Sample PHP:

$bar = new TestMessage(['users' => [
    new TestUser(['id' => 1])
]]);

Same problem also happens with setFrom() method.

Segfault at parseFromString

This is a very weird issue but I can't debug it myself as I don't have a debug build of PHP.

Here are the proto files in question:

File clientConfigFile.proto:

package wom2.protobuf.messages;

option java_outer_classname = "ClientConfigFileProto";

message ClientConfigFile
{
    required string name = 1;
    optional string value = 2;
    optional int32 version = 3;
}

File webAuthMessage.proto:

package wom2.protobuf.messages;

option java_outer_classname = "WebAuthMessageProto";

import "clientConfigFile.proto";

message WebAuthMessage
{
    required int64 id = 1;
    required int32 pid = 2;
    optional int64 fbid = 3;
    optional string gcid = 4;
    optional string gpid = 5;
    optional string ios_ifv = 6;
    optional string and_id = 7;
    repeated ClientConfigFile configVersions = 8;
}

Here's a simple test.php file that can reproduce the crash:

<?php
require "../vendor/autoload.php";
use wom2\protobuf\messages\WebAuthMessage;

$s = 'CA4QAUIVChF2aXN1YWxjb25maWcuanNvbhgBQhMKD2RvbWFpbmluZm8uanNvbhgC';
$input = base64_decode($s, true);

WebAuthMessage::parseFromString($input);

$input contains a valid WebAuthMessage. Now, trying to execute this, I get the following:

$ php test.php 
Segmentation fault (core dumped)

I'm using PHP 5.5.8 on Linux x86-64.

Any ideas?

Error while installing: `php.h` not found

I am installing it on OSC 10.10 Yosemite. I already have MAMP installed. On running make I am getting:

In file included from ./protocolbuffers.h:34:
./php_protocolbuffers.h:41:10: fatal error: 'php.h' file not found
#include "php.h"
         ^
1 error generated.
make: *** [protocolbuffers.lo] Error 1

Support extension feature

Problem: current implementation does not support extension feature.
at least extension required Descriptor class and more powerful protoc plugin.

Related Issues:

Segmentation fault

Hi~ I found a Segmentation fault when I 'clone' a obj:

// Proto file
message Hero {
optional int32 userId = 1;
}
message User {
optional Hero heroes = 1;
}

// PHP code
$user = new User();
$hero = new Hero();
$anotherHero = clone $hero;
$anotherHero->setUserId(1);
$user->appendHeroes($hero); // Segmentation fault

my PHP version IS 5.4.13.

OS X (10.9) build error (unexpected type name 'pb_globals': expected expression)

Got a "protocol_buffers.c:257:112: error: unexpected type name 'pb_globals': expected expression" error when compiling with clan on OS X.

cc -I. -I/Users/hans/Sites/php-protocolbuffers -DPHP_ATOM_INC -I/Users/hans/Sites/php-protocolbuffers/include -I/Users/hans/Sites/php-protocolbuffers/main -I/Users/hans/Sites/php-protocolbuffers -I/usr/local/Cellar/php54/5.4.20/include/php -I/usr/local/Cellar/php54/5.4.20/include/php/main -I/usr/local/Cellar/php54/5.4.20/include/php/TSRM -I/usr/local/Cellar/php54/5.4.20/include/php/Zend -I/usr/local/Cellar/php54/5.4.20/include/php/ext -I/usr/local/Cellar/php54/5.4.20/include/php/ext/date/lib -DHAVE_CONFIG_H -g -O2 -c /Users/hans/Sites/php-protocolbuffers/protocol_buffers.c -fno-common -DPIC -o .libs/protocol_buffers.o

/Users/hans/Sites/php-protocolbuffers/protocol_buffers.c:257:112: error: unexpected type name 'pb_globals': expected expression
  STD_PHP_INI_BOOLEAN("protocolbuffers.strict_mode", "1", PHP_INI_ALL, OnUpdateLong, strict_mode, pb_globals,   pb_globals)
                                                                                                                ^
/usr/local/Cellar/php54/5.4.20/include/php/Zend/zend_ini.h:154:124: note: expanded from macro 'STD_ZEND_INI_BOOLEAN'
        ZEND_INI_ENTRY3_EX(name, default_value, modifiable, on_modify, (void *) XtOffsetOf(struct_type, property_name), (void *) &struct_ptr, NULL, zend_ini_boolean_displayer_cb)
                                                                                                                                  ^
/usr/local/Cellar/php54/5.4.20/include/php/Zend/zend_ini.h:118:56: note: expanded from macro 'ZEND_INI_ENTRY3_EX'
        { 0, modifiable, name, sizeof(name), on_modify, arg1, arg2, arg3, default_value, sizeof(default_value)-1, NULL, 0, 0, 0, displayer },
                                                              ^
1 error generated.

Suggestion: batch setting of message fields

In addition to current implementation of setting fields one at a time

$message = new Diadoc_Api_Proto_Events_MessageToPost;
$message->setIsDraft(true);
$message->setStrictDraftValidation(false);
$message->setFromBoxId('id1');
$message->setToBoxId('id2');
$message->serializeToString();

it would be nice to have an ability to set all fields at once this way:

$message = new Diadoc_Api_Proto_Events_MessageToPost(array(
  'IsDraft' => true,
  'StrictDraftValidation' => false,
  'FromBoxId' => 'id1',
  'ToBoxId' => 'id2',
));

or this:

$message = new Diadoc_Api_Proto_Events_MessageToPost;
$message->set(array(
  'IsDraft' => true,
  'StrictDraftValidation' => false,
  'FromBoxId' => 'id1',
  'ToBoxId' => 'id2',
));

Try to serialize, then deserialize - got error

Always have a error

Uncaught exception 'ProtocolBuffersInvalidProtocolBufferException' with message 'passed variable contains malformed byte sequence. or it contains unsupported tag

Tried to test serialize/parse

            $request = new BidRequest();
            $request->setId('111');
            $code = $request->serializeToString();
            $response = $request->parseFromString($this->data);

And still not working, why?

conver the protocolbuffer object to array problem

hello,chobie

as example the proto file design like this.
enum perm {
ALL = 0;
SYSTEM = 1;
ARTICLE = 2;
PIC = 3;
}

message Admin {
required string name = 1;
required string password = 2;
repeate perm purview = 3;
}

now,i write a function like this

function object_to_array($protobufobj){
$fields = $protobufobj->getDescriptor()->getFields();
$arr = array();
foreach($fields as $val) {
$keyname = $val->getName();
$arr[$keyname] = $protobufobj->get($keyname);
}
return $arr
}

so when i got a Admin object , i pass it to the object_to_array function ,i hope to get an array ,which the key of array is the property name ,and the value of the array is the value we set the property.

but when i run ,i got an segment fault error and some stack information.

i want to know whether i use the protocolbuffers extension error or the extension exist some problem.

thank you very much.

VC9 build problems

I finally managed to build this extension as a dll with Visual Studio 2008.
I used official manual to prepare the environment: https://wiki.php.net/internals/windows/stepbystepbuild

I had three issues (the first two even in static build mode):

  • kMaxVarintBytes & kMaxVarint32Bytes are not recongized, compilation error at helper.h:143. I replaced them with values.
  • Functions strtoull & atoll are missing - I added to helper.h:
#define strtoull _strtoui64
#define atoll _atoi64
  • Unresolved external symbol __imp__php_pb_globals_id when linker builds a dll. I removed PHPAPI at protocol_buffers.c:47

Please consider fixing them.

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.