Add capnp-json serializer script. Also fix bugs in from_dict

This commit is contained in:
Jason Paryani
2013-10-22 13:22:08 -07:00
parent 105450906b
commit 0498d04632
2 changed files with 53 additions and 1 deletions

View File

@@ -568,7 +568,15 @@ import collections as _collections
cdef _from_dict_helper(msg, field, d):
d_type = type(d)
if d_type is dict:
sub_msg = getattr(msg, field)
try:
sub_msg = getattr(msg, field)
except Exception as e:
str_error = str(e)
if 'expected isSetInUnion(field)' in str_error:
msg.init(field)
sub_msg = getattr(msg, field)
else:
raise
for key, val in d.iteritems():
if key != 'which':
_from_dict_helper(sub_msg, key, val)
@@ -584,6 +592,7 @@ cdef _from_dict_helper(msg, field, d):
else:
setattr(msg, field, d)
cdef _from_dict(msg, d):
for key, val in d.iteritems():
if key != 'which':