From ca4305c2d2698b6a98a5af5a6123aa82016d10b0 Mon Sep 17 00:00:00 2001 From: Jordan Goulder Date: Wed, 29 Apr 2020 10:57:17 -0400 Subject: [PATCH 1/2] Add bool type support, Fixes #5 --- lib/types.py | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/lib/types.py b/lib/types.py index 0efcf58..42ffa25 100644 --- a/lib/types.py +++ b/lib/types.py @@ -23,7 +23,7 @@ def __init__(self): self.groups_observed = False types_to_register = { - 0: ["varint", "sint32", "sint64", "int32", "int64", "uint32", "uint64", "enum"], + 0: ["varint", "sint32", "sint64", "int32", "int64", "uint32", "uint64", "enum", "bool"], 1: ["64bit", "sfixed64", "fixed64", "double"], 2: ["chunk", "bytes", "string", "message", "packed", "dump"], 5: ["32bit", "sfixed32", "fixed32", "float"], @@ -181,6 +181,10 @@ def parse_uint64(self, x, type): assert(0 <= x < (1 << 64)) return fg3(str(x)) + def parse_bool(self, x, type): + assert(0 <= x < (1 << 2)) + return fg3(str(bool(x))) + def parse_string(self, file, type): string = file.read().decode("utf-8") return fg2('"%s"' % (repr(string)[1:-1])) From 008276075ecd9caf2dbc19f351297ab9cf05e1c1 Mon Sep 17 00:00:00 2001 From: Jordan Goulder Date: Wed, 29 Apr 2020 11:44:02 -0400 Subject: [PATCH 2/2] Correct bool range assertion --- lib/types.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/types.py b/lib/types.py index 42ffa25..a9b8d6e 100644 --- a/lib/types.py +++ b/lib/types.py @@ -182,7 +182,7 @@ def parse_uint64(self, x, type): return fg3(str(x)) def parse_bool(self, x, type): - assert(0 <= x < (1 << 2)) + assert(0 <= x < (1 << 1)) return fg3(str(bool(x))) def parse_string(self, file, type):