On Mon, Jun 21, 2010 at 8:23 AM, Ananth Arockia ananth.aroc...@gmail.comwrote:
Hello,
I am exploring protobuf to use it in my project.
I would like to have a message defined in a .proto file. All the
fields in this message would be optional due to the fact that the
message producer in my project context would set just a subset of
fields. Can someone please clarify
1. Is there a way to figure out just the fields that are being set in
the message? I would require this after my message is deserialized.
You can check the has() bits (see the tutorial:
http://code.google.com/apis/protocolbuffers/docs/tutorials.html)
Alternatively, you can define your protocol such that if the field is set,
it is not equal to the default value. Then instead of testing has_foo(), you
could test foo() != 0 (or whatever the default is).
2. does field_count() always return the total number of fields defined
in the message in .proto?
Assuming you mean Descriptor::field_count(), yes.
3. Is Reflection the only option to set fields directly/indirectly via
field numbers?
You could also generate the serialized format by hand and then merge that
into your message...but Reflection is friendlier :-)
Thanks, Ananth
--
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.comprotobuf%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.