C++. Reflection. ListFields doesn't contain a bool value which is set on 'false'.

48 views
Skip to first unread message

Даниил Ибрагимов

unread,
Aug 2, 2022, 9:26:02 AM8/2/22
to Protocol Buffers
   I need to get all fields of Message, which are set, with reflection, so i usegoogle::protobuf::Reflection::ListFields. google::protobuf::Reflection::ListFields returns a vector, that contains google::protobuf::FieldDescriptor(variables of Proto Message) of google::protobuf::Message, which are currently set
    I have two variables in proto message of type bool, which i set on false and true,  so when i call ListFields, it returns a vector without bool, which set on false, but with bool, which set on true. I suggest it happens because bool in binary format in protobuf messages is Varint type. Снимок экрана от 2022-08-02 18-13-22.png
And when Varint is zero(because 'false' becomes a zero) ListFields thinks that this variable is not set, because it set on zero. 
    So the question: how can i get this variable if it isn't in Listfields vector?

Deanna Garcia

unread,
Aug 2, 2022, 4:12:27 PM8/2/22
to Protocol Buffers
Do you have/can you make a simple example of this for me to reproduce it? How are you setting the bool to false? Is this proto2 or proto3?

In proto3 if you did not qualify your field with "optional", this is unfortunately working as intended. I think if you explicitly list the field as "optional" ListFields should work like you want it to.

If this is happening in proto2 after you explicitly set the bool to false, this is not expected behavior and you should file a bug in our repository with more details.

Reply all
Reply to author
Forward
0 new messages