So the issue I am having is that I am parsing the descriptor files at
runtime, I don't have access to the proto class therefore I can't call
YourProtoFile.registerAllExtensions. Here is how I am reading the
descriptor file and getting the FileDescriptor:
// Open test.desc and get the FileDescriptorSet
FileInputStream fin = new FileInputStream("/path/to/test.desc");
FileDescriptorSet set = FileDescriptorSet.parseFrom(fin);
// This loop handles my imports
List<FileDescriptor> fileDescriptors = new ArrayList<>();
for(int i=0; i<set.getFileCount;i++){
fileDescriptors.add(FileDescriptor.buildFrom(set.getFile(i), new
FileDescriptor[] {})));
}
// Get the FileDescriptor
FileDescriptor descriptor =
FileDescriptor.buildFrom(set.getFile(set.getFileCount()-1),
fileDescriptors.toArray(new FileDescriptor[0]));
On Wednesday, July 22, 2020 at 4:54:56 PM UTC-4 [email protected] wrote:
> Hi Moustafa,
>
> To parse the FileDescriptor:
> 1. create an ExtensionRegistry using ExtensionRegistry.newInstance,
> 2. Use YourProtoFile.registerAllExtensions(registry) (look for that
> generated method)
> 3. Parse using parseFrom(data, registry)
> 4. Access using result.getExtension(TestProto.myOption) // look for the
> exact location in the generated code.
>
> There's more documentation on this here:
> https://developers.google.com/protocol-buffers/docs/reference/java-generated
>
>
> On Wed, Jul 22, 2020 at 1:41 PM Moustafa Nassar <[email protected]> wrote:
>
>> The file I have is:
>>
>> test.proto
>>
>> syntax = "proto3"
>> import "google/protobuf/descriptor.proto"
>> extend google.protobuf.FileOptions{
>> string myOption = 50000;
>> }
>> option (myOption) = "foo";
>>
>> I create a descriptor file by using: protoc --include_imports
>> --descriptor_set_out="test.desc" test.proto
>>
>> I then get the FileDescriptor from test.desc and do
>> System.out.println(FileDescriptor.getOptions()). It prints out 50000: "foo"
>> but I don't know how to get that in a string or something that I can work
>> with.
>>
>> --
>> 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/04cb2072-ce76-450e-a9fc-601de703b683n%40googlegroups.com
>>
>> <https://groups.google.com/d/msgid/protobuf/04cb2072-ce76-450e-a9fc-601de703b683n%40googlegroups.com?utm_medium=email&utm_source=footer>
>> .
>>
>
>
> --
> -Nadav
>
--
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/366a6f6d-098c-4aba-8fc1-28db932fbd8cn%40googlegroups.com.