You can't just parse any message type into *DescriptorProto. Those are protocol buffers which represent the type definition of other protocol buffers (e.g. your Request msg). You want to use DynamicMessage in order to operate on generic messages.
On Wed, Oct 27, 2010 at 9:55 AM, maninder batth <batth.manin...@gmail.com>wrote: > I have a PB like > message Request { > required int64 supplierId = 1; > optional string message_type = 2; > } > > Then i constructed the message as follows :- > Request request = Request.newBuilder() > .setSupplierId(100L) > .setMessageType("blah").build(); > > Then i check the values by parsing it from the "known" Request type > as > Request request1 = Request.parseFrom(request.toByteArray()); > System.out.println(request1.getSupplierId()); > > It correctly responds with 100. > > Then i try to parse it via generic fashion > > FileDescriptorProto fdp = > FileDescriptorProto.parseFrom(request.toByteArray()); > FieldDescriptor supp = > fdp.getDescriptor().findFieldByNumber(1); > System.out.println(fdp.getField(supp)); // Nothing prints > > FieldDescriptor supp1 = > fdp.getDescriptor().findFieldByNumber(2); > System.out.println(fdp.getField(supp1)); // Prints correctly > the > value "blah" > > 1. My question is what happened to my supplierId field in the above > case? > FieldDescriptorProto gives me a correct FIeldDescriptor for field > number 2, but it acts like it has no awarness of field name 1. > > 2. Given a FieldDescriptor, how can i find the name of the field? I > would like to see field names such as supplierId or message_type. > FieldDescriptor.getName() returns the value "package"... i dont > understand why it returns the word "package" > > -- > You received this message because you are subscribed to the Google Groups > "Protocol Buffers" group. > To post to this group, send email to proto...@googlegroups.com. > To unsubscribe from this group, send email to > protobuf+unsubscr...@googlegroups.com<protobuf%2bunsubscr...@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 proto...@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.