7 TaggedObject = collections.namedtuple(
15 def _make_tag_only_serializer(tag, expected_value):
19 assert to.instance == expected_value
24 _TAGS_TO_SERIALIZERS = {
25 TAG_NULL: _make_tag_only_serializer(TAG_NULL, None),
26 TAG_TRUE: _make_tag_only_serializer(TAG_TRUE, True),
27 TAG_FALSE: _make_tag_only_serializer(TAG_FALSE, False),
31 return _TAGS_TO_SERIALIZERS[to.tag](to)
33 def _make_tag_only_parser(tag, value):
35 return TaggedObject(tag = tag, instance = value), b
40 TAG_NULL: _make_tag_only_parser(TAG_NULL, None),
41 TAG_TRUE: _make_tag_only_parser(TAG_TRUE, True),
42 TAG_FALSE: _make_tag_only_parser(TAG_FALSE, False),
46 result, remainder = _TAGS_TO_PARSERS[b[0]](b[1:])
48 if len(remainder) == 0:
51 raise Exception('Unable to parse remainder: {}'.format(remainder))