Skip to content

Commit

Permalink
xmr: serializer simplified
Browse files Browse the repository at this point in the history
  • Loading branch information
ph4r05 committed Oct 3, 2018
1 parent 471213b commit cb3813a
Showing 1 changed file with 11 additions and 23 deletions.
34 changes: 11 additions & 23 deletions src/apps/monero/xmr/serialize/xmrserialize.py
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ class Archive:
in C++ code. see: eref(), get_elem(), set_elem()
"""

def __init__(self, iobj, writing=True, **kwargs):
def __init__(self, iobj, writing=True):
self.writing = writing
self.iobj = iobj

Expand Down Expand Up @@ -99,9 +99,9 @@ def blob(self, elem=None, elem_type=None, params=None):
"""
elem_type = elem_type if elem_type else elem.__class__
if self.writing:
return dump_blob(self.iobj, elem=elem, elem_type=elem_type, params=params)
return dump_blob(self.iobj, elem, elem_type, params)
else:
return load_blob(self.iobj, elem_type=elem_type, params=params, elem=elem)
return load_blob(self.iobj, elem_type, params, elem)

def container(self, container=None, container_type=None, params=None):
"""
Expand All @@ -110,9 +110,7 @@ def container(self, container=None, container_type=None, params=None):
if self.writing:
return self._dump_container(container, container_type, params)
else:
return self._load_container(
container_type, params=params, container=container
)
return self._load_container(container_type, params, container)

def container_size(self, container_len=None, container_type=None, params=None):
"""
Expand All @@ -130,16 +128,11 @@ def variant(self, elem=None, elem_type=None, params=None, wrapped=None):
elem_type = elem_type if elem_type else elem.__class__
if self.writing:
return self._dump_variant(
elem=elem,
elem_type=elem_type if elem_type else elem.__class__,
params=params,
elem, elem_type if elem_type else elem.__class__, params
)
else:
return self._load_variant(
elem_type=elem_type if elem_type else elem.__class__,
params=params,
elem=elem,
wrapped=wrapped,
elem_type if elem_type else elem.__class__, params, elem, wrapped
)

def message(self, msg, msg_type=None):
Expand All @@ -148,16 +141,16 @@ def message(self, msg, msg_type=None):
"""
msg_type = msg_type if msg_type is not None else msg.__class__
if self.writing:
return self._dump_message(msg, msg_type=msg_type)
return self._dump_message(msg, msg_type)
else:
return self._load_message(msg_type, msg=msg)
return self._load_message(msg_type, msg)

def message_field(self, msg, field, fvalue=None):
"""
Dumps/Loads message field
"""
if self.writing:
return self._dump_message_field(msg, field, fvalue=fvalue)
return self._dump_message_field(msg, field, fvalue)
else:
return self._load_message_field(field)

Expand Down Expand Up @@ -247,13 +240,8 @@ def _load_container(self, container_type, params=None, container=None):
elem_type = container_elem_type(container_type, params)
res = container if container else []
for i in range(c_len):
fvalue = self.load_field(
elem_type,
params[1:] if params else None,
None,
)
if not container:
res.append(fvalue)
fvalue = self.load_field(elem_type, params[1:] if params else None)
res.append(fvalue)
return res

def _dump_message_field(self, msg, field, fvalue=None):
Expand Down

0 comments on commit cb3813a

Please sign in to comment.