What I meant is that I have the .proto file, but not the generated
types it has (I am using Java on the server side). What I am looking
for is something like this:

Map<String, Descriptor> descriptorsByMessageName = new HashMap<>();

for (protoFile : all proto files) {
    InputStream is = // open input stream against .proto located on FS/
ClassLoader
    FileDescriptor fd = // how do I do this? basically, parse it from
is
    for (Desc desc : fd.getMessageDesc()) {
           descriptorsByMessageName(desc.getName(), desc);
    }
}

Then, once I have the map constructed, I can create DynamicMessage
based on message Names lookup keys to get the appropriate Descriptor,
and an InputStream that holds the actual message content. This will
allow me to write code on the server side that works without actually
needing the Java types generated from the proto files, but instead use
the DynamicMessage to get values out of a protobuf stream.

Cheers,
Shay


On Mar 23, 11:47 pm, Kenton Varda <ken...@google.com> wrote:
> I'm a little confused by your message.  You say you have the .proto files,
> but you don't know the types?  But don't the .proto files define the types?
>  Did you mean to say that you only have actual data encoded as these types,
> and you don't have the type definitions (the .proto files) at all?  In that
> case, no, you can't construct a DynamicMessage from them -- the best you can
> do is decode them as an UnknownFieldSet, which doesn't give you much
> information.
> If you want your data to be self-describing, you could send along a
> FileDescriptorSet (defined in google/protobuf/descriptor.proto) containing
> the type definitions.  From that you can construct descriptors and thus
> DynamicMessages.
>
>
>
> On Mon, Mar 23, 2009 at 2:34 PM, kimchy <kim...@gmail.com> wrote:
>
> > Hi,
>
> >  I am trying to use protocol buffer on the server side without
> > knowing the types it needs to use, just based on the .proto files, is
> > that possible? Basically, what I was hoping for is some way to be able
> > to read proto files into a Descriptor, and then use DynamicMessage to
> > get values from it. Is that even possible?
>
> > Cheers,
> > Shay
--~--~---------~--~----~------------~-------~--~----~
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
-~----------~----~----~----~------~----~------~--~---

Reply via email to