def encode_struct_tree(self, validator, value):
assert type(value) in validator.definition._pytype_to_tag_and_subtype_, \
'%r is not a serializable subtype of %r.' % (type(value), validator.definition)
tags, subtype = validator.definition._pytype_to_tag_and_subtype_[type(value)]
assert len(tags) == 1, tags
assert not isinstance(subtype, bv.StructTree), \
'Cannot serialize type %r because it enumerates subtypes.' % subtype.definition
if self.old_style:
d = {
tags[0]: self.encode_struct(subtype, value),
}
else:
d = collections.OrderedDict()
d['.tag'] = tags[0]
d.update(self.encode_struct(subtype, value))
return d
评论列表
文章目录