Re: [protobuf] Java reflection package resolution
Ah, okay - that would make sense. I was using the builders after the user input the data to build a new message, so it would make sense to use them before as well. I'll try it soon. On Tue, Sep 7, 2010 at 8:09 PM, Kenton Varda wrote: > Descriptors are just descriptors, not implementations. Several > implementations can have the same Descriptor. E.g. you can have a generated > class instance and a DynamicMessage instance that have the same Descriptor. > Therefore, you cannot instantiate a message class given just its > Descriptor. > > I think what you're looking for is Builder.newBuilderForField(). E.g.: > > builder.setField(field, > builder.newBuilderForField(field).setField(...).build()); > > Thus as long as you start out with a builder for the root message, you can > construct builders for all sub-messages. > > You can look at com.google.protobuf.TextFormat for a good example of how to > use the protobuf reflection interface. > > On Tue, Sep 7, 2010 at 6:29 AM, narfm...@yahoo.com wrote: > >> Hello, >> >> I am using the google protocol buffer reflection api to try to >> dynamically create a gui for users to fill in Messages manually. I had >> done this completely using Java reflection alone, but this eventually >> led to problems synchronizing the data, and was all around more work >> than google's reflection api should be. >> >> I have implemented as follows: I pass a Descriptor into the main >> JPanel building function. From here, it iterates over the fields, and >> if it is integral, it makes a JTextField, and if it is a Message, it >> calls the same function again. What I can not find out is the type >> that the fielddescriptor as I am iterating over the fields from the >> descriptor. It appears that one "should" be able to figure this out in >> several ways, but none work for me. >> >> First I thought it must be soemthing in JavaType, but that appears to >> only be what google protocol buffers converted the .proto into. Next I >> thought I could get the full package name and me a newInstance of it, >> but when calling fullName, it only returns the class name and no >> package name. Next, I tried getting the file and querying it's package >> name, but it returns "". >> >> Like I said above, I implemented all of this in pure java reflection, >> and the .proto generates the .class files correctly with fully >> qualified names, but the google protocol buffer reflection api (using >> descriptors and field descriptors) does not give me enough >> information. Anyone have any ideas as to why it's not giving me what I >> want? >> >> -- >> 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. >> >> > -- 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.
Re: [protobuf] Java reflection package resolution
Descriptors are just descriptors, not implementations. Several implementations can have the same Descriptor. E.g. you can have a generated class instance and a DynamicMessage instance that have the same Descriptor. Therefore, you cannot instantiate a message class given just its Descriptor. I think what you're looking for is Builder.newBuilderForField(). E.g.: builder.setField(field, builder.newBuilderForField(field).setField(...).build()); Thus as long as you start out with a builder for the root message, you can construct builders for all sub-messages. You can look at com.google.protobuf.TextFormat for a good example of how to use the protobuf reflection interface. On Tue, Sep 7, 2010 at 6:29 AM, narfm...@yahoo.com wrote: > Hello, > > I am using the google protocol buffer reflection api to try to > dynamically create a gui for users to fill in Messages manually. I had > done this completely using Java reflection alone, but this eventually > led to problems synchronizing the data, and was all around more work > than google's reflection api should be. > > I have implemented as follows: I pass a Descriptor into the main > JPanel building function. From here, it iterates over the fields, and > if it is integral, it makes a JTextField, and if it is a Message, it > calls the same function again. What I can not find out is the type > that the fielddescriptor as I am iterating over the fields from the > descriptor. It appears that one "should" be able to figure this out in > several ways, but none work for me. > > First I thought it must be soemthing in JavaType, but that appears to > only be what google protocol buffers converted the .proto into. Next I > thought I could get the full package name and me a newInstance of it, > but when calling fullName, it only returns the class name and no > package name. Next, I tried getting the file and querying it's package > name, but it returns "". > > Like I said above, I implemented all of this in pure java reflection, > and the .proto generates the .class files correctly with fully > qualified names, but the google protocol buffer reflection api (using > descriptors and field descriptors) does not give me enough > information. Anyone have any ideas as to why it's not giving me what I > want? > > -- > 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. > > -- 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.
Re: [protobuf] Java reflection package resolution
I'm confused. You mention using pure Java reflection, yet you also said you are trying to do some stuff with protobuf reflection. You should not be using Java reflection at all. To get the field type, as defined in the .proto file, use FieldDescriptor.getType() On Tue, Sep 7, 2010 at 6:29 AM, narfm...@yahoo.com wrote: > Hello, > > I am using the google protocol buffer reflection api to try to > dynamically create a gui for users to fill in Messages manually. I had > done this completely using Java reflection alone, but this eventually > led to problems synchronizing the data, and was all around more work > than google's reflection api should be. > > I have implemented as follows: I pass a Descriptor into the main > JPanel building function. From here, it iterates over the fields, and > if it is integral, it makes a JTextField, and if it is a Message, it > calls the same function again. What I can not find out is the type > that the fielddescriptor as I am iterating over the fields from the > descriptor. It appears that one "should" be able to figure this out in > several ways, but none work for me. > > First I thought it must be soemthing in JavaType, but that appears to > only be what google protocol buffers converted the .proto into. Next I > thought I could get the full package name and me a newInstance of it, > but when calling fullName, it only returns the class name and no > package name. Next, I tried getting the file and querying it's package > name, but it returns "". > > Like I said above, I implemented all of this in pure java reflection, > and the .proto generates the .class files correctly with fully > qualified names, but the google protocol buffer reflection api (using > descriptors and field descriptors) does not give me enough > information. Anyone have any ideas as to why it's not giving me what I > want? > > -- > 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. > > -- 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.