Given that there is no Java version of protoc, it has been tempting to see
how far one can get with just using FileDescriptorSet's and dynamic
messages. I ended up building this short function for iteratively adding all
the dependencies of a particular Message in to a FileDescriptorSet. While it
wasn't too much pain, it was a tad annoying, and I am wondering why this
kind of functionality isn't built in to the Java API. Here's what I ended up

     * Get the entire descriptor set needed to describe a message in
     * dependency order.
     * @param aMessage the message to inspect
     * @return a complete descriptor set containing all the elements needed
to parse this message

    static FileDescriptorSet getDescriptorSetFor(final Message aMessage) {
        final FileDescriptor file =
        final List<FileDescriptor> fileDescriptors = new

        //Don't use an iter as we intend to keep looping until the list
        //stops growing
        for (int i = 0; i < fileDescriptors.size(); ++i) {
            final FileDescriptor nextElement = fileDescriptors.get(i);
            for (FileDescriptor dependency : nextElement.getDependencies())
                if (!fileDescriptors.contains(dependency)) {

        final FileDescriptorSet.Builder builder =
        for (FileDescriptor descriptor : fileDescriptors) {

Is this really the right way to handle this, and if so, any chance we can
get this built in to the protobuf library?



You received this message because you are subscribed to the Google Groups 
"Protocol Buffers" group.
To post to this group, send email to
To unsubscribe from this group, send email to
For more options, visit this group at

Reply via email to