Skip to content

Commit 26efeb0

Browse files
authored
feat: optimize incoming parser by adding pxd files (#1111)
1 parent 8d84ebb commit 26efeb0

4 files changed

Lines changed: 167 additions & 70 deletions

File tree

src/zeroconf/_protocol/__init__.py

Lines changed: 0 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -19,28 +19,3 @@
1919
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301
2020
USA
2121
"""
22-
23-
from ..const import _FLAGS_QR_MASK, _FLAGS_QR_QUERY, _FLAGS_QR_RESPONSE, _FLAGS_TC
24-
25-
26-
class DNSMessage:
27-
"""A base class for DNS messages."""
28-
29-
__slots__ = ('flags',)
30-
31-
def __init__(self, flags: int) -> None:
32-
"""Construct a DNS message."""
33-
self.flags = flags
34-
35-
def is_query(self) -> bool:
36-
"""Returns true if this is a query."""
37-
return (self.flags & _FLAGS_QR_MASK) == _FLAGS_QR_QUERY
38-
39-
def is_response(self) -> bool:
40-
"""Returns true if this is a response."""
41-
return (self.flags & _FLAGS_QR_MASK) == _FLAGS_QR_RESPONSE
42-
43-
@property
44-
def truncated(self) -> bool:
45-
"""Returns true if this is a truncated."""
46-
return (self.flags & _FLAGS_TC) == _FLAGS_TC
Lines changed: 80 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,80 @@
1+
2+
import cython
3+
4+
5+
cdef cython.uint DNS_COMPRESSION_HEADER_LEN
6+
cdef cython.uint MAX_DNS_LABELS
7+
cdef cython.uint DNS_COMPRESSION_POINTER_LEN
8+
cdef cython.uint MAX_NAME_LENGTH
9+
10+
11+
cdef cython.uint _TYPE_A
12+
cdef cython.uint _TYPE_CNAME
13+
cdef cython.uint _TYPE_PTR
14+
cdef cython.uint _TYPE_TXT
15+
cdef cython.uint _TYPE_SRV
16+
cdef cython.uint _TYPE_HINFO
17+
cdef cython.uint _TYPE_AAAA
18+
cdef cython.uint _TYPE_NSEC
19+
cdef cython.uint _FLAGS_QR_MASK
20+
cdef cython.uint _FLAGS_QR_MASK
21+
cdef cython.uint _FLAGS_TC
22+
cdef cython.uint _FLAGS_QR_QUERY
23+
cdef cython.uint _FLAGS_QR_RESPONSE
24+
25+
cdef object UNPACK_3H
26+
cdef object UNPACK_6H
27+
cdef object UNPACK_HH
28+
cdef object UNPACK_HHiH
29+
30+
cdef object DECODE_EXCEPTIONS
31+
32+
cdef object IncomingDecodeError
33+
34+
cdef class DNSIncoming:
35+
36+
cdef bint _did_read_others
37+
cdef public unsigned int flags
38+
cdef unsigned int offset
39+
cdef public bytes data
40+
cdef unsigned int _data_len
41+
cdef public object name_cache
42+
cdef public object questions
43+
cdef object _answers
44+
cdef public object id
45+
cdef public object num_questions
46+
cdef public object num_answers
47+
cdef public object num_authorities
48+
cdef public object num_additionals
49+
cdef public object valid
50+
cdef public object now
51+
cdef public object scope_id
52+
cdef public object source
53+
54+
@cython.locals(
55+
off=cython.uint,
56+
label_idx=cython.uint,
57+
length=cython.uint,
58+
link=cython.uint
59+
)
60+
cdef _decode_labels_at_offset(self, unsigned int off, cython.list labels, object seen_pointers)
61+
62+
cdef _read_header(self)
63+
64+
cdef _read_questions(self)
65+
66+
@cython.locals(
67+
length=cython.uint
68+
)
69+
cdef bytes _read_character_string(self)
70+
71+
cdef _read_string(self, unsigned int length)
72+
73+
@cython.locals(
74+
name_start=cython.uint
75+
)
76+
cdef _read_record(self, object domain, unsigned int type_, object class_, object ttl, object length)
77+
78+
cdef _read_bitmap(self, unsigned int end)
79+
80+
cdef _read_name(self)

0 commit comments

Comments
 (0)