There is no .proto parser in Java.  However, you can use protoc's
--descriptor_set_out flag to generate a FileDescriptorProto representing the
file (or use FileDescriptor::CopyTo() in C++).  This is a protocol buffer
representation of everything defined in the .proto.  In Java, you can then:
1) Parse the FileDescriptorProto.
2) Construct a FileDescriptor from it.
3) Use FindMessageTypeByName() on the FileDescriptor to get a Descriptor for
the type you are interested in.
4) Construct a DynamicMessage from that.

On Wed, Oct 21, 2009 at 2:11 AM, TinCan <[email protected]> wrote:

>
> Hi,
> My problem:
> I am working on a Java application which is using protocol buffers to
> communicate with an application written in C++. I've met some
> challenges at the Java end, because I do not have the opportunity to
> compile the .proto files into my Java app.
>
> At the C++ end we did not encounter any problems in parsing .proto
> files and constructing protobuf messages (dynamic) at runtime. This
> seems to be a little more tricky at the Java end.
>
> What I try to do:
> The C++ application is using protocol buffers for internal
> communication. This works like a charm, and we are very happy with the
> decision of using this API.
> Now I have been working on a service application which is supposed to
> display protocol buffer data dynamically using reflection. The C++
> application will send .proto descriptions and protobuf data via an UDP
> connection to the Java application.
>
> My question:
> I understand that there is not a .proto file parser available for
> Java. Is this correct?
> If so: How can I construct a message dynamically in a Java
> application?
>
> I've been looking at the classes DynamicMessage, Descriptor,
> DescriptorProto and others (including their Builders). But I am
> struggling to figure out how they are related, and how to use them
> correctly.
>
> Can anyone please help me with more documentation, or a working
> example on how to create a protobuf message (dynamically)?
>
> Regards
> Ole
>
> >
>

--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"Protocol Buffers" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to 
[email protected]
For more options, visit this group at 
http://groups.google.com/group/protobuf?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to