Feng, Thanks so much. At least I know that what I'm looking for doesn't exist. I am researching a variant of (1) that uses reflection on generated package classes to build a fullname->Message map. Once I have a Message I can ask for a builder and be on my way. So I'll call getDefaultInstance() via reflection and use them to make the builders. I hope this works! Thanks john
On Mon, Jul 9, 2018 at 4:14 PM Feng Xiao <[email protected]> wrote: > > > On Mon, Jul 9, 2018 at 2:45 PM John Lilley <[email protected]> wrote: > >> Well, apparently I am really off base. Given a Descriptor I cannot >> figure out how to create the right message. I *thought* this was the right >> approach: >> Descriptors.Descriptor desc = // look up the descriptor >> Builder builder = desc.toProto().newBuilderForType(); >> Message message = builder.mergeFrom(requestBytes).build(); >> >> >> But no. Can anyone help me with this? I need to go from the full name >> of a message to its builder and I'm not finding anything like >> MessageFactory() or DescriptorPool in Java. >> > There is no DecriptorPool/MessageFactory in Java because there is no easy > way to automatically build such a DescriptorPool/MessageFactory with all > protos in the class path. There are a few options for Java: > 1. Build a registry from message name to proto message type manually. > 2. Use protoc to output a FileDescriptorSet for all of your .proto files, > and use this FileDescriptorSet to build a DescriptorPool-like structure > yourself. You will be using FileDescriptor.buildFile() to convert > FileDescriptorProtos in the FileDescriptorSet to FileDescriptor and then > traverse through the FileDescriptors to build a map from messageName to > Descriptor. > 3. Write a protoc plugin to produce Java code to create a registry for all > of your .proto files. > > All the above options are used by some projects inside Google. (2), (3) > are integrated into our build system with runtime library support and will > take quite some effort to recreate from scratch. Your best option is > probably (1). > > >> Thanks >> john >> >> -- >> 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. >> > -- 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.
