8000 feat: speed up decoding dns questions when processing incoming data (… · python-zeroconf/python-zeroconf@f927190 · GitHub
[go: up one dir, main page]

Skip to content

Commit f927190

Browse files
authored
feat: speed up decoding dns questions when processing incoming data (#1168)
1 parent e281d35 commit f927190

File tree

2 files changed

+9
-5
lines changed

2 files changed

+9
-5
lines changed

src/zeroconf/_protocol/incoming.pxd

+3-2
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ from .._dns cimport (
3838
DNSHinfo,
3939
DNSNsec,
4040
DNSPointer,
41+
DNSQuestion,
4142
DNSRecord,
4243
DNSService,
4344
DNSText,
@@ -48,11 +49,11 @@ cdef class DNSIncoming:
4849

4950
cdef bint _did_read_others
5051
cdef public unsigned int flags
51-
cdef object offset
52+
cdef cython.uint offset
5253
cdef public bytes data
5354
cdef unsigned int _data_len
5455
cdef public cython.dict name_cache
55-
cdef public object questions
56+
cdef public cython.list questions
5657
cdef object _answers
5758
cdef public object id
5859
cdef public cython.uint num_questions

src/zeroconf/_protocol/incoming.py

+6-3
Original file line numberDiff line numberDiff line change
@@ -211,9 +211,12 @@ def _read_header(self) -> None:
211211

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

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

0 commit comments

Comments
 (0)
0