Quoted from our internal discussion by Kenton: You should build a Map<Descriptor, Message> upfront, mapping every descriptor you care about to the corresponding default instance. Avoid using Class objects because that will make your code incompatible with DynamicMessage. Using default instances instead avoids this problem and should cover all the same use cases.
Note that it should be easy to write a function like: void populate(Message root, Map<Descriptor, Message> map); which recursively populates the map with the given message type and all of its dependencies. In C++, we have a singleton MessageFactory::generated_factory() which effectively provides a Descriptor -> default instance map for all compiled-in types. But, this leads to all the usual singleton problems, and code that uses it is often needlessly incompatible with DynamicMessage. People like the idea of being able to look up any compiled-in type because it seems convenient, but in practice the convenience is typically not very large, whereas the loss of reusability can be a big problem down the road. On Tue, Jun 7, 2011 at 7:36 AM, ondrej par <ondrej...@gmail.com> wrote: > Hi all, > > is there a convenient way to extract the name of Java (generated) class > that represents the Message from Descriptors.Descriptor? > > What I need is a method with the following signature: > public Class<? extends Message> extractJavaClass(Descriptors.Descriptor d); > > I can derive class name using file/message descriptors methods, but that > seems quite difficult, since I have to take java_package_name and > java_outer_class_name options into account, and I have to convert > underscores in proto file name to camel case > > Thanks for answer, > Ondrej > > -- > You received this message because you are subscribed to the Google Groups > "Protocol Buffers" group. > To view this discussion on the web visit > https://groups.google.com/d/msg/protobuf/-/ZDBENWpTLVlYdDhK. > To post to this group, send email to protobuf@googlegroups.com. > To unsubscribe from this group, send email to > protobuf+unsubscr...@googlegroups.com. > For more options, visit this group at > http://groups.google.com/group/protobuf?hl=en. > -- You received this message because you are subscribed to the Google Groups "Protocol Buffers" group. To post to this group, send email to protobuf@googlegroups.com. To unsubscribe from this group, send email to protobuf+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/protobuf?hl=en.