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 <
dvrya...@gmail.com> 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);
> }
> }
> *
> *