I don't think this necessarily has anything to do with the custom option.
FileDescriptorSet is itself just a protocol buffer message, so parsing it
doesn't involve interpreting the meaning of its contents. It's just like
parsing any other proto, so if it's failing then either the descriptors
were somehow corrupted or are not being read from disk successfully.

Here is what I would suggest trying:
1. Run this and make sure the results look reasonable: protoc --decode_raw
< simple.desc
This will print out the raw field numbers and values in the descriptor.
2. Change your code to read in a string and then parse the string (with
ParseFromString instead of ParseFromIstream). This way you can verify that
the string you read in exactly matches the file on disk (or at least do a
quick check to verify that the length is the same).

On Fri, Feb 12, 2021 at 1:37 PM Marc Schafer <[email protected]> wrote:

> I am invoking protoc –descriptor_set_out on the .proto file with contents
> described below that include the definition of the custom option. I’m not
> sure what else you are suggesting I include.
>
>
>
> I attached the .proto file to clarify the reproduction steps.
>
> protoc –descriptor_set_out simple.proto
>
>
>
> Use this snippet of code to parse the resulting .desc file:
>
>
>
>     fdiName = “simple.desc";
>
>     std::ifstream fdi(fdiName);
>
>     google::protobuf::FileDescriptorSet fds;
>
>     auto r = fds.ParseFromIstream(&fdi);
>
>     assert(r);
>
>
>
> The assertion will fail
>
>
>
> Best,
>
> Marc
>
>
>
>
>
> *From: *Adam Cozzette <[email protected]>
> *Sent: *Friday, February 12, 2021 2:56 PM
> *To: *Marc Schafer <[email protected]>
> *Cc: *Protocol Buffers <[email protected]>
> *Subject: *Re: [protobuf] Parsing of .desc fails for message with custom
> option
>
>
>
> I think the easiest solution would be to include the .proto file that
> defines the custom option in the serialized descriptor set. I assume you're
> generating the .desc file by invoking protoc with -o or
> --descriptor_set_out, so just make sure to add the custom option .proto
> file as one of the command line arguments to protoc when you do that.
>
>
>
> On Tue, Feb 9, 2021 at 5:39 AM Marc Schafer <[email protected]> wrote:
>
> Parsing fails on a .desc file generated from a message with a custom
> option as shown below. I understand this is happening because the message
> defined in descriptor.proto doesn't know about my extension but I am not
> sure how to fix it. I'm using C++.
>
>
>
> Here is my .proto:
>
> syntax = "proto3";
>
> package foo;
>
>
>
> // extending MessageOptions prevents parsing of generated .desc
>
> import "google/protobuf/descriptor.proto";
>
>
>
> // extensions start at 1000
>
> extend google.protobuf.MessageOptions {
>
>   optional string my_option = 1992;
>
> }
>
>
>
>
>
> message SearchRequest {
>
>   option (my_option) = "custom";
>
>   string query = 1;
>
>   int32 page_number = 2;
>
>   int32 result_per_page = 3;
>
> }
>
>
>
> -Best
>
> Marc
>
>
>
> --
> You received this message because you are subscribed to the Google Groups
> "Protocol Buffers" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to [email protected].
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/protobuf/614101fd-9571-448b-9b29-0ae050e536cfn%40googlegroups.com
> <https://groups.google.com/d/msgid/protobuf/614101fd-9571-448b-9b29-0ae050e536cfn%40googlegroups.com?utm_medium=email&utm_source=footer>
> .
>
>
>

-- 
You received this message because you are subscribed to the Google Groups 
"Protocol Buffers" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/protobuf/CADqAXr7iXM_y1-ar5kf17o8p3qz68hJ2cZnQCZn_JOvt-_k2Ug%40mail.gmail.com.

Reply via email to