Skip to content

Commit

Permalink
feat: speed up decoding dns questions when processing incoming data (#…
Browse files Browse the repository at this point in the history
  • Loading branch information
bdraco committed May 1, 2023
1 parent e281d35 commit f927190
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 5 deletions.
5 changes: 3 additions & 2 deletions src/zeroconf/_protocol/incoming.pxd
Expand Up @@ -38,6 +38,7 @@ from .._dns cimport (
DNSHinfo,
DNSNsec,
DNSPointer,
DNSQuestion,
DNSRecord,
DNSService,
DNSText,
Expand All @@ -48,11 +49,11 @@ cdef class DNSIncoming:

cdef bint _did_read_others
cdef public unsigned int flags
cdef object offset
cdef cython.uint offset
cdef public bytes data
cdef unsigned int _data_len
cdef public cython.dict name_cache
cdef public object questions
cdef public cython.list questions
cdef object _answers
cdef public object id
cdef public cython.uint num_questions
Expand Down
9 changes: 6 additions & 3 deletions src/zeroconf/_protocol/incoming.py
Expand Up @@ -211,9 +211,12 @@ def _read_header(self) -> None:

def _read_questions(self) -> None:
"""Reads questions section of packet"""
self.questions = [
DNSQuestion(self._read_name(), *self._unpack(UNPACK_HH, 4)) for _ in range(self.num_questions)
]
for _ in range(self.num_questions):
name = self._read_name()
type_, class_ = UNPACK_HH(self.data, self.offset)
self.offset += 4
question = DNSQuestion(name, type_, class_)
self.questions.append(question)

def _read_character_string(self) -> bytes:
"""Reads a character string from the packet"""
Expand Down

0 comments on commit f927190

Please sign in to comment.