I found the solution,
the API actually isn't intuitive - I had to Use FileDescriptorSet over
FileDescriptor (this moment isn't clean for me, at least why it does work
vice versa - but just doesn't builds fields, suppose it just bad API design.
Solution is
...
val data = Files.readAllBytes(Paths.get(uri))
val fileSet = FileDescriptorSet.parseFrom(data)
...
and fileSet has not empty getMessageTypeList field.
Stas
On Thursday, October 4, 2018 at 12:13:59 PM UTC+2, Stas Shevchenko wrote:
>
> 1. I'm compiling valid .proto file into .desc file
> 2. The original proto file contains few message declarations with dozen
> fields per message.
>
> I have to read from JVM code the list of allowed fields per message, I do
> it via Scala:
>
> val uri = this.getClass.getClassLoader.getResource("protoDescFile.desc").toURI
> val data = Files.readAllBytes(Paths.get(uri))
> val descriptorProto: DescriptorProtos.FileDescriptorProto =
> DescriptorProtos.FileDescriptorProto.parseFrom(data)
> val descriptor: Descriptors.FileDescriptor =
> Descriptors.FileDescriptor.buildFrom(descriptorProto, Array.empty)
>
>
> the code builds well descriptor - but when I call the
>
> descriptor.getMessageTypes.size()
>
>
> it always returns 0 - despite the expected value is 3
>
> Apparently all the fields are empty including
>
> descriptor.getPackage
>
>
> that is set to
>
> package com.prototest.pacakge;
>
>
> but the only one field in descriptor aren't empty :
>
> descriptor.getSyntax
>
> descriptor.getName
>
>
> getName returns me the full String representation of data(byte[]) were
> passed to FileDescriptorProto.parseFrom during it's initialization.
>
>
> What is the way to get the list of available messages and the get the list
> of fields per message?
>
> Stas
>
--
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 post to this group, send email to [email protected].
Visit this group at https://groups.google.com/group/protobuf.
For more options, visit https://groups.google.com/d/optout.