Skip to content

Commit

Permalink
Avoid a dict lookup to process every packet
Browse files Browse the repository at this point in the history
  • Loading branch information
bdraco committed Sep 3, 2024
1 parent 8e6673e commit f814f0a
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 2 deletions.
4 changes: 3 additions & 1 deletion aioesphomeapi/_frame_helper/noise.pxd
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,9 @@ cdef class APINoiseFrameHelper(APIFrameHelper):
@cython.locals(
msg=bytes,
type_high="unsigned char",
type_low="unsigned char"
type_low="unsigned char",
msg_type="unsigned int",
payload=bytes
)
cdef void _handle_frame(self, bytes frame)

Expand Down
4 changes: 3 additions & 1 deletion aioesphomeapi/_frame_helper/noise.py
Original file line number Diff line number Diff line change
Expand Up @@ -359,7 +359,9 @@ def _handle_frame(self, frame: bytes) -> None:
# N bytes: message data
type_high = msg[0]
type_low = msg[1]
self._connection.process_packet((type_high << 8) | type_low, msg[4:])
msg_type = (type_high << 8) | type_low
payload = msg[4:]
self._connection.process_packet(msg_type, payload)

def _handle_closed(self, frame: bytes) -> None: # pylint: disable=unused-argument
"""Handle a closed frame."""
Expand Down

0 comments on commit f814f0a

Please sign in to comment.