I am working on a C code base... INIT functions are used in this case instead of a constructor in C++.
Thanks for your reply. On Thu, Jun 2, 2011 at 3:33 PM, Pherl Liu <liuj...@google.com> wrote: > > > On Wed, Jun 1, 2011 at 3:45 PM, aara <aara.cool...@gmail.com> wrote: > >> I actually have 3 questions. >> >> 1.When we specify default values for optional fields,the default value >> gets assigned automatically when we ourselves dont assign it a value. >> But why doesnt the has_member field get set to 1??? It still remains >> zero. >> > > To clarify the default value a bit: > In your code, if you don't set_somefield() explicitly: > 1) has_somefield() will return false. > 2) somefield() will return the default value. > 3) the default value won't be serialized into the wire. that said, if you > don't set any field in your message, the serialized bytes will be empty. > > Each field has a default value, e.g. 0 for int, "" for string. You can > override the default value by set [default=xxx] in the .proto file, but it > won't change the behavior described above. > > >> >> 2.Can we not specify default values for repeated fields too??? The >> protoc-c compiler throws an error. >> > > Do you mean you want to set default values for repeated fields? No, you > can't. > > >> >> 3. In nested submessages, we have to call the INIT function for each >> of the submessages manually. Why doesnt the calling of the INIT >> function for the main message recursively call the INIT functions of >> the nested messages??? This becomes tedious when we have numerous >> nested messages. >> > > What INIT function were you referring to? I'm not aware of this INIT > function in protobuf code base. > > >> >> Please let me know the solutions of these problems as soon as >> possible.... >> >> >> Thanks. >> >> -- >> You received this message because you are subscribed to the Google Groups >> "Protocol Buffers" group. >> To post to this group, send email to protobuf@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. >> >> > -- Regards, Aaradhana -- You received this message because you are subscribed to the Google Groups "Protocol Buffers" group. To post to this group, send email to protobuf@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.