I'm using proto3 and have a message in some .proto file defined as:
message Response {
  google.protobuf.BoolValue field = 1;
  ...
}
In order to initialize Response in Python, I need to create a boolean primitive wrapper and attach some value. 
If I were to initialize this value to True, this is fine. From a Python notebook:
In [52]: from google.protobuf import wrappers_pb2 as wrappers
         boo = wrappers.BoolValue(value=True)
         boo
Out [52]: value: true
If I were to initialize this value to False, no wrapped object is created:
In [52]: from google.protobuf import wrappers_pb2 as wrappers
         boo = wrappers.BoolValue(value=False)
         boo
Out [52]: 
How can create a BoolValue initialized to false?
Non-truthy values are removed from the fields list as implemented here.
>> boo = wrappers.BoolValue(value=True)
>> boo.ListFields()
[(<google.protobuf.descriptor.FieldDescriptor object at 0x10a037bd0>, True)]
>> boo = wrappers.BoolValue(value=False)
>> boo.ListFields()
[]
In order to access the message value you can write it like this:
>> boo = wrappers.BoolValue(value=True)
>> boo.value
True
>> boo = wrappers.BoolValue(value=False)
>> boo.value
False
                        If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With