diff --git a/aiogcd/connector/path.py b/aiogcd/connector/path.py index 157e4c2..7a8a7d0 100644 --- a/aiogcd/connector/path.py +++ b/aiogcd/connector/path.py @@ -8,20 +8,6 @@ from .buffer import BufferDecodeError -def path_from_decoder(decoder): - pairs = [] - while decoder: - tt = decoder.get_var_int32() - if tt == 11: - pairs.append(path_element_from_decoder(decoder)) - continue - - if tt == 0: - raise BufferDecodeError('corrupted') - - return Path(pairs=pairs) - - class Path: def __init__(self, pairs): @@ -58,3 +44,17 @@ def get_as_tuple(self): """Returns a tuple of pairs (tuples) representing the key path of an entity. Useful for composing entities with a specific ancestor.""" return tuple((pe.kind, pe.id) for pe in self._path) + + +def path_from_decoder(decoder) -> Path: + pairs = [] + while decoder: + tt = decoder.get_var_int32() + if tt == 11: + pairs.append(path_element_from_decoder(decoder)) + continue + + if tt == 0: + raise BufferDecodeError('corrupted') + + return Path(pairs=pairs) diff --git a/aiogcd/connector/pathelement.py b/aiogcd/connector/pathelement.py index f4656a6..5522512 100644 --- a/aiogcd/connector/pathelement.py +++ b/aiogcd/connector/pathelement.py @@ -4,33 +4,6 @@ TYPE_NAME = 1 -def path_element_from_decoder(decoder): - kind = None - name_or_id = None - - while True: - tt = decoder.get_var_int32() - - if tt == 12: - break - if tt == 18: - kind = decoder.get_prefixed_string() - continue - if tt == 24: - name_or_id = decoder.get_var_int64() - continue - if tt == 34: - name_or_id = decoder.get_prefixed_string() - continue - if tt == 0: - raise BufferDecodeError('corrupt') - - assert kind is not None and name_or_id is not None, \ - 'Expecting a path element with a kind and name/id.' - - return PathElement(kind, name_or_id) - - class PathElement: def __init__(self, kind, name_or_id): @@ -90,3 +63,30 @@ def _size_var_int(n): if n == 0: break return result + + +def path_element_from_decoder(decoder) -> PathElement: + kind = None + name_or_id = None + + while True: + tt = decoder.get_var_int32() + + if tt == 12: + break + if tt == 18: + kind = decoder.get_prefixed_string() + continue + if tt == 24: + name_or_id = decoder.get_var_int64() + continue + if tt == 34: + name_or_id = decoder.get_prefixed_string() + continue + if tt == 0: + raise BufferDecodeError('corrupt') + + assert kind is not None and name_or_id is not None, \ + 'Expecting a path element with a kind and name/id.' + + return PathElement(kind, name_or_id) \ No newline at end of file