protobuf-php/protobuf

Error In PHP when using extensions

luisgon1 opened this issue · 12 comments

Proto code bellow:

message BookVersion {
    required uint32 major = 1;
    required uint32 minor = 2;
    required uint32 patch = 3;
}
extend google.protobuf.MessageOptions {
    optional BookVersion version = 50001;
}
message BookData {
    required fixed64 timestamp   = 1;
    required BookInfo version    = 2;
}
message BookAlive {
    option (version).major = 1;
    option (version).minor = 0;
    option (version).patch = 1;

    required BookData data = 1;
}

I am getting php error calling version method not found in class version on BookVersion class

Options currently not supported,

I'll be adding support for it. I'll ping you once i get it merged..

@luisgon1 This protobuf-php/protobuf-plugin@2000dd4 should fix the problem with option (only messages options are supported for now).

<?php

/** @var $version \YourNamespace\BookVersion(); */
$version = \YourNamespace\BookAlive::descriptor()
    ->getOptions()
    ->extensions()
    ->get(\YourNamespace\Extension::version());

Please let me know if it works for you.

It is not working, bellow is the $options set in the class built:

$options = \google\protobuf\MessageOptions::fromArray([
]);

    $options->extensions()->put(\Extension::version(), \BookVersion::__set_state(array(
       'unknownFieldSet' => NULL,
       'extensions' => NULL,
       'major' => NULL,
       'minor' => NULL,
       'patch' => 9,
    )));

It is not defining major or minor

in another code I created it is not even defining the extensions

import "google/protobuf/descriptor.proto";

message BookVersion {
    required uint32 major = 1;
    required uint32 minor = 2;
    required uint32 patch = 3;
}
extend google.protobuf.MessageOptions {
    optional BookVersion version = 50001;
}
message BookData {
    required fixed64 timestamp   = 1;
    required BookVersion version    = 2;
}
message BookAlive {
    option (version).major = 9;
    option (version).minor = 5;
    option (version).patch = 9;

    required BookData data = 1;
}

After protobuf-php/protobuf-plugin@b9c91c2 it should generate the following :

$options->extensions()->add(\Extension::version(), \BookVersion::__set_state(array(
   'unknownFieldSet' => NULL,
   'extensions' => NULL,
   'major' => 9,
   'minor' => 5,
   'patch' => 9,
)));

please make sure you have the latest version of :

  • protobuf-php/google-protobuf-proto
  • protobuf-php/protobuf-plugin
  • protobuf-php/protobuf

So if I use 0 as an option value it gives NULL.
image

image

If I give a number it works.
image

I have updated everything from the latest versions

Also it only works if you compile everything from 1 proto file.
If I use 2 proto files it does not work.

bookInfo.proto

import "google/protobuf/descriptor.proto";

message BookVersion {
    required uint32 major = 1;
    required uint32 minor = 2;
    required uint32 patch = 3;
}

extend google.protobuf.MessageOptions {
    optional BookVersion version = 50001;
}

message BookData {
    required fixed64 timestamp   = 1;
    required BookVersion version    = 2;
}

books.proto

import "google/protobuf/descriptor.proto";
import "bookInfo.proto";
message BookAlive {
    option (version).major = 4;
    option (version).minor = 4;
    option (version).patch = 5;

    required BookData data = 1;
}

@luisgon1 The 0 value issue should be fixed by protobuf-php/protobuf-plugin@5763220,

Please make sure you generate both files otherwise the plugin considers bookInfo.proto a import and wont generate the BookVersion extension.

Something like :

./vendor/bin/protobuf \
    -o ./path-to-php-src\
    -i ./path-to-protos \
    ./path-to-protos/bookInfo.proto \
    ./path-to-protos/books.proto

Closing it for now

Please let me know if the problem continues.

Its working perfect, thanks for the support
On Jun 18, 2016 10:49 AM, "Fabio B. Silva" notifications@github.com wrote:

Closing it for now

Please let me know if the problem continues.


You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub
#6 (comment),
or mute the thread
https://github.com/notifications/unsubscribe/AGIoqJaC9hL1bk65DTADRUCTiiqw-Cbvks5qNBN-gaJpZM4HHEu6
.