feat: add unmarshaller cython typing for SignatureType and SignatureTree (#168)
This commit is contained in:
@@ -3,7 +3,7 @@
|
|||||||
import cython
|
import cython
|
||||||
|
|
||||||
from ..message cimport Message
|
from ..message cimport Message
|
||||||
from ..signature cimport Variant
|
from ..signature cimport SignatureTree, SignatureType, Variant
|
||||||
|
|
||||||
|
|
||||||
cdef object MAX_UNIX_FDS_SIZE
|
cdef object MAX_UNIX_FDS_SIZE
|
||||||
@@ -41,37 +41,37 @@ cdef object INT16_UNPACK_BIG_ENDIAN
|
|||||||
cdef object UINT16_UNPACK_LITTLE_ENDIAN
|
cdef object UINT16_UNPACK_LITTLE_ENDIAN
|
||||||
cdef object UINT16_UNPACK_BIG_ENDIAN
|
cdef object UINT16_UNPACK_BIG_ENDIAN
|
||||||
|
|
||||||
cdef object MESSAGE_TYPE_MAP
|
cdef cython.dict MESSAGE_TYPE_MAP
|
||||||
cdef object MESSAGE_FLAG_MAP
|
cdef cython.dict MESSAGE_FLAG_MAP
|
||||||
cdef object HEADER_MESSAGE_ARG_NAME
|
cdef object HEADER_MESSAGE_ARG_NAME
|
||||||
|
|
||||||
cdef object SIGNATURE_TREE_EMPTY
|
cdef SignatureTree SIGNATURE_TREE_EMPTY
|
||||||
cdef object SIGNATURE_TREE_B
|
cdef SignatureTree SIGNATURE_TREE_B
|
||||||
cdef object SIGNATURE_TREE_N
|
cdef SignatureTree SIGNATURE_TREE_N
|
||||||
cdef object SIGNATURE_TREE_O
|
cdef SignatureTree SIGNATURE_TREE_O
|
||||||
cdef object SIGNATURE_TREE_S
|
cdef SignatureTree SIGNATURE_TREE_S
|
||||||
cdef object SIGNATURE_TREE_U
|
cdef SignatureTree SIGNATURE_TREE_U
|
||||||
cdef object SIGNATURE_TREE_Y
|
cdef SignatureTree SIGNATURE_TREE_Y
|
||||||
|
|
||||||
cdef object SIGNATURE_TREE_AS
|
cdef SignatureTree SIGNATURE_TREE_AS
|
||||||
cdef object SIGNATURE_TREE_AS_TYPES_0
|
cdef SignatureType SIGNATURE_TREE_AS_TYPES_0
|
||||||
cdef object SIGNATURE_TREE_AO
|
cdef SignatureTree SIGNATURE_TREE_AO
|
||||||
cdef object SIGNATURE_TREE_AO_TYPES_0
|
cdef SignatureType SIGNATURE_TREE_AO_TYPES_0
|
||||||
cdef object SIGNATURE_TREE_A_SV
|
cdef SignatureTree SIGNATURE_TREE_A_SV
|
||||||
cdef object SIGNATURE_TREE_A_SV_TYPES_0
|
cdef SignatureType SIGNATURE_TREE_A_SV_TYPES_0
|
||||||
cdef object SIGNATURE_TREE_SA_SV_AS
|
cdef SignatureTree SIGNATURE_TREE_SA_SV_AS
|
||||||
cdef object SIGNATURE_TREE_SA_SV_AS_TYPES_1
|
cdef SignatureType SIGNATURE_TREE_SA_SV_AS_TYPES_1
|
||||||
cdef object SIGNATURE_TREE_SA_SV_AS_TYPES_2
|
cdef SignatureType SIGNATURE_TREE_SA_SV_AS_TYPES_2
|
||||||
cdef object SIGNATURE_TREE_OAS
|
cdef SignatureTree SIGNATURE_TREE_OAS
|
||||||
cdef object SIGNATURE_TREE_OAS_TYPES_1
|
cdef SignatureType SIGNATURE_TREE_OAS_TYPES_1
|
||||||
cdef object SIGNATURE_TREE_OA_SA_SV
|
cdef SignatureTree SIGNATURE_TREE_OA_SA_SV
|
||||||
cdef object SIGNATURE_TREE_OA_SA_SV_TYPES_1
|
cdef SignatureType SIGNATURE_TREE_OA_SA_SV_TYPES_1
|
||||||
cdef object SIGNATURE_TREE_AY
|
cdef SignatureTree SIGNATURE_TREE_AY
|
||||||
cdef object SIGNATURE_TREE_AY_TYPES_0
|
cdef SignatureType SIGNATURE_TREE_AY_TYPES_0
|
||||||
cdef object SIGNATURE_TREE_A_QV
|
cdef SignatureTree SIGNATURE_TREE_A_QV
|
||||||
cdef object SIGNATURE_TREE_A_QV_TYPES_0
|
cdef SignatureType SIGNATURE_TREE_A_QV_TYPES_0
|
||||||
cdef object SIGNATURE_TREE_A_OA_SA_SV
|
cdef SignatureTree SIGNATURE_TREE_A_OA_SA_SV
|
||||||
cdef object SIGNATURE_TREE_A_OA_SA_SV_TYPES_0
|
cdef SignatureType SIGNATURE_TREE_A_OA_SA_SV_TYPES_0
|
||||||
|
|
||||||
cdef unsigned int TOKEN_O_AS_INT
|
cdef unsigned int TOKEN_O_AS_INT
|
||||||
cdef unsigned int TOKEN_S_AS_INT
|
cdef unsigned int TOKEN_S_AS_INT
|
||||||
@@ -133,23 +133,23 @@ cdef class Unmarshaller:
|
|||||||
)
|
)
|
||||||
cdef _read_to_pos(self, unsigned long pos)
|
cdef _read_to_pos(self, unsigned long pos)
|
||||||
|
|
||||||
cpdef read_boolean(self, object type_)
|
cpdef read_boolean(self, SignatureType type_)
|
||||||
|
|
||||||
cdef _read_boolean(self)
|
cdef _read_boolean(self)
|
||||||
|
|
||||||
cpdef read_uint32_unpack(self, object type_)
|
cpdef read_uint32_unpack(self, SignatureType type_)
|
||||||
|
|
||||||
cdef unsigned int _read_uint32_unpack(self)
|
cdef unsigned int _read_uint32_unpack(self)
|
||||||
|
|
||||||
cpdef read_int16_unpack(self, object type_)
|
cpdef read_int16_unpack(self, SignatureType type_)
|
||||||
|
|
||||||
cdef int _read_int16_unpack(self)
|
cdef int _read_int16_unpack(self)
|
||||||
|
|
||||||
cpdef read_uint16_unpack(self, object type_)
|
cpdef read_uint16_unpack(self, SignatureType type_)
|
||||||
|
|
||||||
cdef unsigned int _read_uint16_unpack(self)
|
cdef unsigned int _read_uint16_unpack(self)
|
||||||
|
|
||||||
cpdef read_string_unpack(self, object type_)
|
cpdef read_string_unpack(self, SignatureType type_)
|
||||||
|
|
||||||
@cython.locals(
|
@cython.locals(
|
||||||
str_start=cython.uint,
|
str_start=cython.uint,
|
||||||
@@ -158,15 +158,16 @@ cdef class Unmarshaller:
|
|||||||
|
|
||||||
cdef _read_variant(self)
|
cdef _read_variant(self)
|
||||||
|
|
||||||
cpdef read_array(self, object type_)
|
cpdef read_array(self, SignatureType type_)
|
||||||
|
|
||||||
@cython.locals(
|
@cython.locals(
|
||||||
beginning_pos=cython.ulong,
|
beginning_pos=cython.ulong,
|
||||||
array_length=cython.uint,
|
array_length=cython.uint,
|
||||||
|
child_type=SignatureType,
|
||||||
)
|
)
|
||||||
cdef _read_array(self, object type_)
|
cdef _read_array(self, SignatureType type_)
|
||||||
|
|
||||||
cpdef read_signature(self, object type_)
|
cpdef read_signature(self, SignatureType type_)
|
||||||
|
|
||||||
@cython.locals(
|
@cython.locals(
|
||||||
o=cython.ulong,
|
o=cython.ulong,
|
||||||
|
|||||||
@@ -286,7 +286,7 @@ class Unmarshaller:
|
|||||||
if len(data) + start_len != pos:
|
if len(data) + start_len != pos:
|
||||||
raise MARSHALL_STREAM_END_ERROR
|
raise MARSHALL_STREAM_END_ERROR
|
||||||
|
|
||||||
def read_uint32_unpack(self, type_: SignatureType) -> int:
|
def read_uint32_unpack(self, type_) -> int:
|
||||||
return self._read_uint32_unpack()
|
return self._read_uint32_unpack()
|
||||||
|
|
||||||
def _read_uint32_unpack(self) -> int:
|
def _read_uint32_unpack(self) -> int:
|
||||||
@@ -297,7 +297,7 @@ class Unmarshaller:
|
|||||||
)
|
)
|
||||||
return self._uint32_unpack(self._buf, self._pos - UINT32_SIZE)[0]
|
return self._uint32_unpack(self._buf, self._pos - UINT32_SIZE)[0]
|
||||||
|
|
||||||
def read_uint16_unpack(self, type_: SignatureType) -> int:
|
def read_uint16_unpack(self, type_) -> int:
|
||||||
return self._read_uint16_unpack()
|
return self._read_uint16_unpack()
|
||||||
|
|
||||||
def _read_uint16_unpack(self) -> int:
|
def _read_uint16_unpack(self) -> int:
|
||||||
@@ -308,7 +308,7 @@ class Unmarshaller:
|
|||||||
)
|
)
|
||||||
return self._uint16_unpack(self._buf, self._pos - UINT16_SIZE)[0]
|
return self._uint16_unpack(self._buf, self._pos - UINT16_SIZE)[0]
|
||||||
|
|
||||||
def read_int16_unpack(self, type_: SignatureType) -> int:
|
def read_int16_unpack(self, type_) -> int:
|
||||||
return self._read_int16_unpack()
|
return self._read_int16_unpack()
|
||||||
|
|
||||||
def _read_int16_unpack(self) -> int:
|
def _read_int16_unpack(self) -> int:
|
||||||
@@ -319,13 +319,13 @@ class Unmarshaller:
|
|||||||
)
|
)
|
||||||
return self._int16_unpack(self._buf, self._pos - INT16_SIZE)[0]
|
return self._int16_unpack(self._buf, self._pos - INT16_SIZE)[0]
|
||||||
|
|
||||||
def read_boolean(self, type_: SignatureType) -> bool:
|
def read_boolean(self, type_) -> bool:
|
||||||
return self._read_boolean()
|
return self._read_boolean()
|
||||||
|
|
||||||
def _read_boolean(self) -> bool:
|
def _read_boolean(self) -> bool:
|
||||||
return bool(self._read_uint32_unpack())
|
return bool(self._read_uint32_unpack())
|
||||||
|
|
||||||
def read_string_unpack(self, type_: SignatureType) -> str:
|
def read_string_unpack(self, type_) -> str:
|
||||||
return self._read_string_unpack()
|
return self._read_string_unpack()
|
||||||
|
|
||||||
def _read_string_unpack(self) -> str:
|
def _read_string_unpack(self) -> str:
|
||||||
@@ -341,7 +341,7 @@ class Unmarshaller:
|
|||||||
self._pos += self._uint32_unpack(self._buf, str_start - UINT32_SIZE)[0] + 1
|
self._pos += self._uint32_unpack(self._buf, str_start - UINT32_SIZE)[0] + 1
|
||||||
return self._buf[str_start : self._pos - 1].decode()
|
return self._buf[str_start : self._pos - 1].decode()
|
||||||
|
|
||||||
def read_signature(self, type_: SignatureType) -> str:
|
def read_signature(self, type_) -> str:
|
||||||
return self._read_signature()
|
return self._read_signature()
|
||||||
|
|
||||||
def _read_signature(self) -> str:
|
def _read_signature(self) -> str:
|
||||||
@@ -351,7 +351,7 @@ class Unmarshaller:
|
|||||||
self._pos = o + signature_len + 1
|
self._pos = o + signature_len + 1
|
||||||
return self._buf[o : o + signature_len].decode()
|
return self._buf[o : o + signature_len].decode()
|
||||||
|
|
||||||
def read_variant(self, type_: SignatureType) -> Variant:
|
def read_variant(self, type_) -> Variant:
|
||||||
return self._read_variant()
|
return self._read_variant()
|
||||||
|
|
||||||
def _read_variant(self) -> Variant:
|
def _read_variant(self) -> Variant:
|
||||||
@@ -402,23 +402,23 @@ class Unmarshaller:
|
|||||||
False,
|
False,
|
||||||
)
|
)
|
||||||
|
|
||||||
def read_struct(self, type_: SignatureType) -> List[Any]:
|
def read_struct(self, type_) -> List[Any]:
|
||||||
self._pos += -self._pos & 7 # align 8
|
self._pos += -self._pos & 7 # align 8
|
||||||
readers = self._readers
|
readers = self._readers
|
||||||
return [
|
return [
|
||||||
readers[child_type.token](self, child_type) for child_type in type_.children
|
readers[child_type.token](self, child_type) for child_type in type_.children
|
||||||
]
|
]
|
||||||
|
|
||||||
def read_dict_entry(self, type_: SignatureType) -> Tuple[Any, Any]:
|
def read_dict_entry(self, type_) -> Tuple[Any, Any]:
|
||||||
self._pos += -self._pos & 7 # align 8
|
self._pos += -self._pos & 7 # align 8
|
||||||
return self._readers[type_.children[0].token](
|
return self._readers[type_.children[0].token](
|
||||||
self, type_.children[0]
|
self, type_.children[0]
|
||||||
), self._readers[type_.children[1].token](self, type_.children[1])
|
), self._readers[type_.children[1].token](self, type_.children[1])
|
||||||
|
|
||||||
def read_array(self, type_: SignatureType) -> Iterable[Any]:
|
def read_array(self, type_) -> Iterable[Any]:
|
||||||
return self._read_array(type_)
|
return self._read_array(type_)
|
||||||
|
|
||||||
def _read_array(self, type_: SignatureType) -> Iterable[Any]:
|
def _read_array(self, type_) -> Iterable[Any]:
|
||||||
self._pos += -self._pos & 3 # align 4 for the array
|
self._pos += -self._pos & 3 # align 4 for the array
|
||||||
self._pos += (
|
self._pos += (
|
||||||
-self._pos & (UINT32_SIZE - 1)
|
-self._pos & (UINT32_SIZE - 1)
|
||||||
|
|||||||
Reference in New Issue
Block a user