> > you will have to create your own boolean fields if you need to track > whether the optional is populated or not.
Other approach is to use *repeated* with <=1 element instead of *optional*. Then had_foo() analogue will be (get_foo_size() != 0), presence flag and the data will be kept within the same field and a bonus - optional is compatible with repeated <https://developers.google.com/protocol-buffers/docs/proto#updating>, so this should not break format compatibility. On Wednesday, March 18, 2015 at 9:03:30 PM UTC+3, Alfred Kwan wrote: > > It depends on what protobuf version you are using. There will be a > had_foo() for each optional field if you are using protobuf version 2.xx > (see C++ code reference > <https://developers.google.com/protocol-buffers/docs/reference/cpp-generated>). > > You are out of luck if you are using V3.0 because you will have to create > your own boolean fields if you need to track whether the optional is > populated or not. > > On Tuesday, March 17, 2015 at 2:09:21 PM UTC-4, s_mitra wrote: >> >> Hi, >> >> I have doing some coding related to protobuf where server and client will >> exchange some info via protobuf. >> >> In the response object I have multiple optional message objects. >> How to check which all object is empty and which is not ?? >> > -- You received this message because you are subscribed to the Google Groups "Protocol Buffers" group. To unsubscribe from this group and stop receiving emails from it, send an email to [email protected]. To post to this group, send email to [email protected]. Visit this group at http://groups.google.com/group/protobuf. For more options, visit https://groups.google.com/d/optout.
