Fix bool parsing bug
This commit is contained in:
parent
035793aec3
commit
eb5020db2a
@ -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]
|
||||
|
3
betterproto/tests/bool.json
Normal file
3
betterproto/tests/bool.json
Normal file
@ -0,0 +1,3 @@
|
||||
{
|
||||
"value": true
|
||||
}
|
5
betterproto/tests/bool.proto
Normal file
5
betterproto/tests/bool.proto
Normal file
@ -0,0 +1,5 @@
|
||||
syntax = "proto3";
|
||||
|
||||
message Test {
|
||||
bool value = 1;
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user