Fix bool parsing bug

This commit is contained in:
Daniel G. Taylor 2019-10-27 14:59:38 -07:00
parent 035793aec3
commit eb5020db2a
No known key found for this signature in database
GPG Key ID: 7BD6DC99C9A87E22
3 changed files with 11 additions and 0 deletions

View File

@ -595,6 +595,9 @@ class Message(ABC):
elif meta.proto_type in [TYPE_SINT32, TYPE_SINT64]:
# Undo zig-zag encoding
value = (value >> 1) ^ (-(value & 1))
elif meta.proto_type == TYPE_BOOL:
# Booleans use a varint encoding, so convert it to true/false.
value = value > 0
elif wire_type in [WIRE_FIXED_32, WIRE_FIXED_64]:
fmt = _pack_fmt(meta.proto_type)
value = struct.unpack(fmt, value)[0]

View File

@ -0,0 +1,3 @@
{
"value": true
}

View File

@ -0,0 +1,5 @@
syntax = "proto3";
message Test {
bool value = 1;
}