feat: improve unmarshalling performance (#18)
This commit is contained in:
@@ -94,6 +94,24 @@ class Unmarshaller:
|
|||||||
unpack: Dict[str, Struct]
|
unpack: Dict[str, Struct]
|
||||||
readers: READER_TYPE
|
readers: READER_TYPE
|
||||||
|
|
||||||
|
__slots__ = (
|
||||||
|
"unix_fds",
|
||||||
|
"can_cast",
|
||||||
|
"buf",
|
||||||
|
"view",
|
||||||
|
"offset",
|
||||||
|
"stream",
|
||||||
|
"sock",
|
||||||
|
"message",
|
||||||
|
"readers",
|
||||||
|
"body_len",
|
||||||
|
"serial",
|
||||||
|
"header_len",
|
||||||
|
"message_type",
|
||||||
|
"flag",
|
||||||
|
"msg_len",
|
||||||
|
)
|
||||||
|
|
||||||
def __init__(self, stream: io.BufferedRWPair, sock=None):
|
def __init__(self, stream: io.BufferedRWPair, sock=None):
|
||||||
self.unix_fds: List[int] = []
|
self.unix_fds: List[int] = []
|
||||||
self.can_cast = False
|
self.can_cast = False
|
||||||
@@ -109,6 +127,7 @@ class Unmarshaller:
|
|||||||
self.header_len: int | None = None
|
self.header_len: int | None = None
|
||||||
self.message_type: MessageType | None = None
|
self.message_type: MessageType | None = None
|
||||||
self.flag: MessageFlag | None = None
|
self.flag: MessageFlag | None = None
|
||||||
|
self.msg_len = 0
|
||||||
|
|
||||||
def read_sock(self, length: int) -> bytes:
|
def read_sock(self, length: int) -> bytes:
|
||||||
"""reads from the socket, storing any fds sent and handling errors
|
"""reads from the socket, storing any fds sent and handling errors
|
||||||
@@ -220,8 +239,7 @@ class Unmarshaller:
|
|||||||
|
|
||||||
def read_argument(self, type_: SignatureType) -> Any:
|
def read_argument(self, type_: SignatureType) -> Any:
|
||||||
"""Dispatch to an argument reader or cast/unpack a C type."""
|
"""Dispatch to an argument reader or cast/unpack a C type."""
|
||||||
token = type_.token
|
reader, ctype, size, struct = self.readers[type_.token]
|
||||||
reader, ctype, size, struct = self.readers[token]
|
|
||||||
if reader: # complex type
|
if reader: # complex type
|
||||||
return reader(self, type_)
|
return reader(self, type_)
|
||||||
self.offset += size + (-self.offset & (size - 1)) # align
|
self.offset += size + (-self.offset & (size - 1)) # align
|
||||||
|
|||||||
@@ -76,6 +76,23 @@ class Message:
|
|||||||
- :class:`InvalidInterfaceNameError` - If ``error_name`` or ``interface`` is not a valid interface name.
|
- :class:`InvalidInterfaceNameError` - If ``error_name`` or ``interface`` is not a valid interface name.
|
||||||
"""
|
"""
|
||||||
|
|
||||||
|
__slots__ = (
|
||||||
|
"destination",
|
||||||
|
"path",
|
||||||
|
"interface",
|
||||||
|
"member",
|
||||||
|
"message_type",
|
||||||
|
"flags",
|
||||||
|
"error_name",
|
||||||
|
"reply_serial",
|
||||||
|
"sender",
|
||||||
|
"unix_fds",
|
||||||
|
"signature",
|
||||||
|
"signature_tree",
|
||||||
|
"body",
|
||||||
|
"serial",
|
||||||
|
)
|
||||||
|
|
||||||
def __init__(
|
def __init__(
|
||||||
self,
|
self,
|
||||||
destination: str = None,
|
destination: str = None,
|
||||||
|
|||||||
@@ -398,6 +398,8 @@ class Variant:
|
|||||||
:class:`SignatureBodyMismatchError` if the signature does not match the body.
|
:class:`SignatureBodyMismatchError` if the signature does not match the body.
|
||||||
"""
|
"""
|
||||||
|
|
||||||
|
__slots__ = ("type", "signature", "value")
|
||||||
|
|
||||||
def __init__(
|
def __init__(
|
||||||
self,
|
self,
|
||||||
signature: Union[str, SignatureTree, SignatureType],
|
signature: Union[str, SignatureTree, SignatureType],
|
||||||
|
|||||||
@@ -49,7 +49,7 @@ def is_bus_name_valid(name: str) -> bool:
|
|||||||
return True
|
return True
|
||||||
|
|
||||||
|
|
||||||
@lru_cache(maxsize=512)
|
@lru_cache(maxsize=1024)
|
||||||
def is_object_path_valid(path: str) -> bool:
|
def is_object_path_valid(path: str) -> bool:
|
||||||
"""Whether this is a valid object path.
|
"""Whether this is a valid object path.
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user