Skip to content

Commit

Permalink
Speed up frame helpers (#696)
Browse files Browse the repository at this point in the history
  • Loading branch information
bdraco authored Nov 24, 2023
1 parent 065c8e7 commit c0a153c
Show file tree
Hide file tree
Showing 6 changed files with 13 additions and 13 deletions.
6 changes: 3 additions & 3 deletions aioesphomeapi/_frame_helper/base.pxd
Original file line number Diff line number Diff line change
Expand Up @@ -26,11 +26,11 @@ cdef class APIFrameHelper:
cdef bytes _read(self, int length)

@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")
cdef _remove_from_buffer(self)
cdef void _remove_from_buffer(self)

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)
12 changes: 6 additions & 6 deletions aioesphomeapi/_frame_helper/noise.pxd
Original file line number Diff line number Diff line change
Expand Up @@ -36,22 +36,22 @@ cdef class APINoiseFrameHelper(APIFrameHelper):
type_high="unsigned char",
type_low="unsigned char"
)
cdef _handle_frame(self, bytes frame)
cdef void _handle_frame(self, bytes frame)

@cython.locals(
chosen_proto=char,
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")
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)
cdef _decode_noise_psk(self)
Expand Down
2 changes: 1 addition & 1 deletion aioesphomeapi/_frame_helper/noise.py
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,7 @@ def connection_made(self, transport: asyncio.BaseTransport) -> None:

def data_received(self, data: bytes | bytearray | memoryview) -> None:
self._add_to_buffer(data)
while self._buffer:
while self._buffer_len:
self._pos = 0
if (header := self._read(3)) is None:
return
Expand Down
2 changes: 1 addition & 1 deletion aioesphomeapi/_frame_helper/plain_text.pxd
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ cdef class APIPlaintextFrameHelper(APIFrameHelper):
)
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(
type_="unsigned int",
Expand Down
2 changes: 1 addition & 1 deletion aioesphomeapi/_frame_helper/plain_text.py
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ def data_received( # pylint: disable=too-many-branches,too-many-return-statemen
self, data: bytes | bytearray | memoryview
) -> None:
self._add_to_buffer(data)
while self._buffer:
while self._buffer_len:
# Read preamble, which should always 0x00
# Also try to get the length and msg type
# to avoid multiple calls to _read
Expand Down
2 changes: 1 addition & 1 deletion aioesphomeapi/connection.pxd
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ cdef class APIConnection:
cdef send_messages(self, tuple messages)

@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)

Expand Down

0 comments on commit c0a153c

Please sign in to comment.