mirror of
https://github.com/esphome/aioesphomeapi.git
synced 2024-12-25 17:17:42 +01:00
Speed up frame helpers (#696)
This commit is contained in:
parent
065c8e715d
commit
c0a153c9f3
@ -26,11 +26,11 @@ cdef class APIFrameHelper:
|
|||||||
cdef bytes _read(self, int length)
|
cdef bytes _read(self, int length)
|
||||||
|
|
||||||
@cython.locals(bytes_data=bytes)
|
@cython.locals(bytes_data=bytes)
|
||||||
cdef _add_to_buffer(self, object data)
|
cdef void _add_to_buffer(self, object data)
|
||||||
|
|
||||||
@cython.locals(end_of_frame_pos="unsigned int")
|
@cython.locals(end_of_frame_pos="unsigned int")
|
||||||
cdef _remove_from_buffer(self)
|
cdef void _remove_from_buffer(self)
|
||||||
|
|
||||||
cpdef write_packets(self, list packets, bint debug_enabled)
|
cpdef write_packets(self, list packets, bint debug_enabled)
|
||||||
|
|
||||||
cdef _write_bytes(self, bytes data, bint debug_enabled)
|
cdef void _write_bytes(self, bytes data, bint debug_enabled)
|
||||||
|
@ -36,22 +36,22 @@ cdef class APINoiseFrameHelper(APIFrameHelper):
|
|||||||
type_high="unsigned char",
|
type_high="unsigned char",
|
||||||
type_low="unsigned char"
|
type_low="unsigned char"
|
||||||
)
|
)
|
||||||
cdef _handle_frame(self, bytes frame)
|
cdef void _handle_frame(self, bytes frame)
|
||||||
|
|
||||||
@cython.locals(
|
@cython.locals(
|
||||||
chosen_proto=char,
|
chosen_proto=char,
|
||||||
server_name_i=int
|
server_name_i=int
|
||||||
)
|
)
|
||||||
cdef _handle_hello(self, bytes server_hello)
|
cdef void _handle_hello(self, bytes server_hello)
|
||||||
|
|
||||||
cdef _handle_handshake(self, bytes msg)
|
cdef void _handle_handshake(self, bytes msg)
|
||||||
|
|
||||||
cdef _handle_closed(self, bytes frame)
|
cdef void _handle_closed(self, bytes frame)
|
||||||
|
|
||||||
@cython.locals(handshake_frame=bytearray, frame_len="unsigned int")
|
@cython.locals(handshake_frame=bytearray, frame_len="unsigned int")
|
||||||
cdef _send_hello_handshake(self)
|
cdef void _send_hello_handshake(self)
|
||||||
|
|
||||||
cdef _setup_proto(self)
|
cdef void _setup_proto(self)
|
||||||
|
|
||||||
@cython.locals(psk_bytes=bytes)
|
@cython.locals(psk_bytes=bytes)
|
||||||
cdef _decode_noise_psk(self)
|
cdef _decode_noise_psk(self)
|
||||||
|
@ -135,7 +135,7 @@ class APINoiseFrameHelper(APIFrameHelper):
|
|||||||
|
|
||||||
def data_received(self, data: bytes | bytearray | memoryview) -> None:
|
def data_received(self, data: bytes | bytearray | memoryview) -> None:
|
||||||
self._add_to_buffer(data)
|
self._add_to_buffer(data)
|
||||||
while self._buffer:
|
while self._buffer_len:
|
||||||
self._pos = 0
|
self._pos = 0
|
||||||
if (header := self._read(3)) is None:
|
if (header := self._read(3)) is None:
|
||||||
return
|
return
|
||||||
|
@ -27,7 +27,7 @@ cdef class APIPlaintextFrameHelper(APIFrameHelper):
|
|||||||
)
|
)
|
||||||
cpdef data_received(self, object data)
|
cpdef data_received(self, object data)
|
||||||
|
|
||||||
cdef _error_on_incorrect_preamble(self, object preamble)
|
cdef void _error_on_incorrect_preamble(self, object preamble)
|
||||||
|
|
||||||
@cython.locals(
|
@cython.locals(
|
||||||
type_="unsigned int",
|
type_="unsigned int",
|
||||||
|
@ -80,7 +80,7 @@ class APIPlaintextFrameHelper(APIFrameHelper):
|
|||||||
self, data: bytes | bytearray | memoryview
|
self, data: bytes | bytearray | memoryview
|
||||||
) -> None:
|
) -> None:
|
||||||
self._add_to_buffer(data)
|
self._add_to_buffer(data)
|
||||||
while self._buffer:
|
while self._buffer_len:
|
||||||
# Read preamble, which should always 0x00
|
# Read preamble, which should always 0x00
|
||||||
# Also try to get the length and msg type
|
# Also try to get the length and msg type
|
||||||
# to avoid multiple calls to _read
|
# to avoid multiple calls to _read
|
||||||
|
@ -89,7 +89,7 @@ cdef class APIConnection:
|
|||||||
cdef send_messages(self, tuple messages)
|
cdef send_messages(self, tuple messages)
|
||||||
|
|
||||||
@cython.locals(handlers=set, handlers_copy=set)
|
@cython.locals(handlers=set, handlers_copy=set)
|
||||||
cpdef process_packet(self, object msg_type_proto, object data)
|
cpdef void process_packet(self, object msg_type_proto, object data)
|
||||||
|
|
||||||
cpdef _async_cancel_pong_timer(self)
|
cpdef _async_cancel_pong_timer(self)
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user