Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Error In PHP when using extensions #6

Closed
luisgon1 opened this issue Jan 18, 2016 · 12 comments
Closed

Error In PHP when using extensions #6

luisgon1 opened this issue Jan 18, 2016 · 12 comments
Assignees

Comments

@luisgon1
Copy link

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

@FabioBatSilva
Copy link
Member

Options currently not supported,

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

@FabioBatSilva
Copy link
Member

@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.

@luisgon1
Copy link
Author

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

@luisgon1
Copy link
Author

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;
}

@FabioBatSilva
Copy link
Member

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

@luisgon1
Copy link
Author

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

image

If I give a number it works.
image

@luisgon1
Copy link
Author

I have updated everything from the latest versions

@luisgon1
Copy link
Author

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;
}

@FabioBatSilva
Copy link
Member

@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

@FabioBatSilva
Copy link
Member

Closing it for now

Please let me know if the problem continues.

@luisgon1
Copy link
Author

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
.

@FabioBatSilva
Copy link
Member

Thanks @luisgon1

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants