Skip to content

Commit eb5020d

Browse files
committed
Fix bool parsing bug
1 parent 035793a commit eb5020d

File tree

3 files changed

+11
-0
lines changed

3 files changed

+11
-0
lines changed

betterproto/__init__.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -595,6 +595,9 @@ def _postprocess_single(
595595
elif meta.proto_type in [TYPE_SINT32, TYPE_SINT64]:
596596
# Undo zig-zag encoding
597597
value = (value >> 1) ^ (-(value & 1))
598+
elif meta.proto_type == TYPE_BOOL:
599+
# Booleans use a varint encoding, so convert it to true/false.
600+
value = value > 0
598601
elif wire_type in [WIRE_FIXED_32, WIRE_FIXED_64]:
599602
fmt = _pack_fmt(meta.proto_type)
600603
value = struct.unpack(fmt, value)[0]

betterproto/tests/bool.json

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
{
2+
"value": true
3+
}

betterproto/tests/bool.proto

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
syntax = "proto3";
2+
3+
message Test {
4+
bool value = 1;
5+
}

0 commit comments

Comments
 (0)