Skip to content

Commit

Permalink
commit
Browse files Browse the repository at this point in the history
  • Loading branch information
joente committed Oct 1, 2024
1 parent 4ebf748 commit 071960a
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 41 deletions.
28 changes: 14 additions & 14 deletions aiogcd/connector/path.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down Expand Up @@ -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)
54 changes: 27 additions & 27 deletions aiogcd/connector/pathelement.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down Expand Up @@ -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)

0 comments on commit 071960a

Please sign in to comment.