Hi Thanks a lot for your time. Yes the approach looks very clean as the api getField and setField are in built. I think we would go with this approach.
But i am just curious to know whether protobuf published anywhere the algorithm for deriving getter and setter method names. Thanks, Ravikumar K On Mar 15, 3:09 pm, Dmitriy Ryaboy <[email protected]> wrote: > We needed to do something similar for our project "Elephant-Bird" that > provides support for working with Protocol Buffers in Hadoop. > > Protobufs have Descriptors that allow you to determine all of these things > on the fly, without encoding method naming rules and such. > > Here is the relevant snippet > fromhttps://github.com/kevinweil/elephant-bird/blob/master/src/java/com/t... > > public static Message addField(Message m, String name, Object value) { > Message.Builder builder = m.toBuilder(); > setFieldByName(builder, name, value); > return builder.build(); > > } > > public static void setFieldByName(Message.Builder builder, String > name, Object value) { > FieldDescriptor fieldDescriptor = > builder.getDescriptorForType().findFieldByName(name); > if (value == null) { > builder.clearField(fieldDescriptor); > } else { > builder.setField(fieldDescriptor, value); > } > } > * > * > > On Tue, Mar 15, 2011 at 2:19 AM, Ravi <[email protected]> wrote: > > Hi, > > > We would like to know how to determine the getter and setter method > > names generated in java builder class for a particular field defined > > in proto message. > > > Of course, the simple rule says that > > * Convert first letter of the field name to upper case > > * prefix "get" or "set" to the field name > > > But we want to know all the cases considered while generating builder > > class. > > Like what are the special characters considered? what are the > > exceptional cases? > > > Why we want this is, > > In our framework we would be programmatically generating proto files > > from the xsds which we have already. > > > Along with this we would be generating an adapter class between our > > framework and the java class generated by protoc compiler. > > > This adapter would call getter and setter methods of the builder class > > available in the builder class to retrieve the value and to build the > > object. > > > Any help would be appreciated. > > > Thanks, > > Ravikumar K > > > -- > > 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. -- 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.
