Skip to content

Commit

Permalink
xmr: serialize - TupleType removed
Browse files Browse the repository at this point in the history
  • Loading branch information
ph4r05 committed Oct 2, 2018
1 parent b9a5698 commit 3b04561
Show file tree
Hide file tree
Showing 2 changed files with 0 additions and 72 deletions.
6 changes: 0 additions & 6 deletions src/apps/monero/xmr/serialize/message_types.py
Original file line number Diff line number Diff line change
Expand Up @@ -71,12 +71,6 @@ class ContainerType(XmrType):
ELEM_TYPE = None


class TupleType(XmrType):
@classmethod
def f_specs(cls):
return ()


class MessageType(XmrType):
def __init__(self, **kwargs):
for kw in kwargs:
Expand Down
66 changes: 0 additions & 66 deletions src/apps/monero/xmr/serialize/xmrserialize.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,6 @@
BlobType,
ContainerType,
MessageType,
TupleType,
UnicodeType,
VariantType,
container_elem_type,
Expand Down Expand Up @@ -193,21 +192,6 @@ def container_val(self, elem, container_type, params=None):
else:
raise ValueError("Not supported")

def tuple(self, elem=None, elem_type=None, params=None):
"""
Loads/dumps tuple
"""
if hasattr(elem_type, "serialize_archive"):
container = elem_type() if elem is None else elem
return container.serialize_archive(
self, elem=elem, elem_type=elem_type, params=params
)

if self.writing:
return self._dump_tuple(self.iobj, elem, elem_type, params)
else:
return self._load_tuple(self.iobj, elem_type, params=params, elem=elem)

def variant(self, elem=None, elem_type=None, params=None, wrapped=None):
"""
Loads/dumps variant type
Expand Down Expand Up @@ -279,7 +263,6 @@ def _get_type(self, elem_type):
UnicodeType,
VariantType,
ContainerType,
TupleType,
MessageType,
)
cname = elem_type.__name__
Expand Down Expand Up @@ -342,9 +325,6 @@ def field(self, elem=None, elem_type=None, params=None):
container=get_elem(elem), container_type=elem_type, params=params
)

elif self._is_type(etype, TupleType): # tuple ~ simple list
fvalue = self.tuple(elem=get_elem(elem), elem_type=elem_type, params=params)

elif self._is_type(etype, MessageType):
fvalue = self.message(get_elem(elem), msg_type=elem_type)

Expand Down Expand Up @@ -420,52 +400,6 @@ def _load_container(self, reader, container_type, params=None, container=None):
res.append(fvalue)
return res

def _dump_tuple(self, writer, elem, elem_type, params=None):
"""
Dumps tuple of elements to the writer.
"""
if len(elem) != len(elem_type.f_specs()):
raise ValueError(
"Fixed size tuple has not defined size: %s" % len(elem_type.f_specs())
)
dump_uvarint(writer, len(elem))

elem_fields = params[0] if params else None
if elem_fields is None:
elem_fields = elem_type.f_specs()
for idx, elem in enumerate(elem):
self.dump_field(
writer, elem, elem_fields[idx], params[1:] if params else None
)

def _load_tuple(self, reader, elem_type, params=None, elem=None):
"""
Loads tuple of elements from the reader. Supports the tuple ref.
Returns loaded tuple.
"""

c_len = load_uvarint(reader)
if elem and c_len != len(elem):
raise ValueError("Size mismatch")
if c_len != len(elem_type.f_specs()):
raise ValueError("Tuple size mismatch")

elem_fields = params[0] if params else None
if elem_fields is None:
elem_fields = elem_type.f_specs()

res = elem if elem else []
for i in range(c_len):
fvalue = self.load_field(
reader,
elem_fields[i],
params[1:] if params else None,
eref(res, i) if elem else None,
)
if not elem:
res.append(fvalue)
return res

def _dump_message_field(self, writer, msg, field, fvalue=None):
"""
Dumps a message field to the writer. Field is defined by the message field specification.
Expand Down

0 comments on commit 3b04561

Please sign in to comment.