Coverage for src / zmqtt / _internal / packets / properties.py: 99%
319 statements
« prev ^ index » next coverage.py v7.13.4, created at 2026-11-12 08:49 +0000
« prev ^ index » next coverage.py v7.13.4, created at 2026-11-12 08:49 +0000
1"""MQTT 5.0 properties: PropertyID enum, typed dataclasses, and wire encode/decode."""
3import struct
4from dataclasses import dataclass
5from enum import IntEnum
6from typing import Any
8from zmqtt._internal.packets._wire import (
9 decode_bytes_field,
10 decode_str,
11 decode_varint,
12 encode_bytes_field,
13 encode_str,
14 encode_varint,
15)
18class PropertyID(IntEnum):
19 PAYLOAD_FORMAT_INDICATOR = 0x01
20 MESSAGE_EXPIRY_INTERVAL = 0x02
21 CONTENT_TYPE = 0x03
22 RESPONSE_TOPIC = 0x08
23 CORRELATION_DATA = 0x09
24 SUBSCRIPTION_IDENTIFIER = 0x0B
25 SESSION_EXPIRY_INTERVAL = 0x11
26 ASSIGNED_CLIENT_IDENTIFIER = 0x12
27 SERVER_KEEP_ALIVE = 0x13
28 AUTHENTICATION_METHOD = 0x15
29 AUTHENTICATION_DATA = 0x16
30 REQUEST_PROBLEM_INFORMATION = 0x17
31 WILL_DELAY_INTERVAL = 0x18
32 REQUEST_RESPONSE_INFORMATION = 0x19
33 RESPONSE_INFORMATION = 0x1A
34 SERVER_REFERENCE = 0x1C
35 REASON_STRING = 0x1F
36 RECEIVE_MAXIMUM = 0x21
37 TOPIC_ALIAS_MAXIMUM = 0x22
38 TOPIC_ALIAS = 0x23
39 MAXIMUM_QOS = 0x24
40 RETAIN_AVAILABLE = 0x25
41 USER_PROPERTY = 0x26
42 MAXIMUM_PACKET_SIZE = 0x27
43 WILDCARD_SUBSCRIPTION_AVAILABLE = 0x28
44 SUBSCRIPTION_IDENTIFIER_AVAILABLE = 0x29
45 SHARED_SUBSCRIPTION_AVAILABLE = 0x2A
48# Wire type categorisation — drives the generic decoder.
49_WIRE_BYTE = frozenset(
50 {
51 PropertyID.PAYLOAD_FORMAT_INDICATOR,
52 PropertyID.REQUEST_PROBLEM_INFORMATION,
53 PropertyID.REQUEST_RESPONSE_INFORMATION,
54 PropertyID.MAXIMUM_QOS,
55 PropertyID.RETAIN_AVAILABLE,
56 PropertyID.WILDCARD_SUBSCRIPTION_AVAILABLE,
57 PropertyID.SUBSCRIPTION_IDENTIFIER_AVAILABLE,
58 PropertyID.SHARED_SUBSCRIPTION_AVAILABLE,
59 },
60)
61_WIRE_UINT16 = frozenset(
62 {
63 PropertyID.SERVER_KEEP_ALIVE,
64 PropertyID.RECEIVE_MAXIMUM,
65 PropertyID.TOPIC_ALIAS_MAXIMUM,
66 PropertyID.TOPIC_ALIAS,
67 },
68)
69_WIRE_UINT32 = frozenset(
70 {
71 PropertyID.MESSAGE_EXPIRY_INTERVAL,
72 PropertyID.SESSION_EXPIRY_INTERVAL,
73 PropertyID.WILL_DELAY_INTERVAL,
74 PropertyID.MAXIMUM_PACKET_SIZE,
75 },
76)
77_WIRE_VARINT = frozenset({PropertyID.SUBSCRIPTION_IDENTIFIER})
78_WIRE_STR = frozenset(
79 {
80 PropertyID.CONTENT_TYPE,
81 PropertyID.RESPONSE_TOPIC,
82 PropertyID.ASSIGNED_CLIENT_IDENTIFIER,
83 PropertyID.AUTHENTICATION_METHOD,
84 PropertyID.REASON_STRING,
85 PropertyID.RESPONSE_INFORMATION,
86 PropertyID.SERVER_REFERENCE,
87 },
88)
89_WIRE_BYTES_DATA = frozenset(
90 {
91 PropertyID.CORRELATION_DATA,
92 PropertyID.AUTHENTICATION_DATA,
93 },
94)
95# USER_PROPERTY (0x26) is a repeatable string pair — handled separately.
97_PID = PropertyID # shorthand for inside this module
100def encode_props(d: dict[PropertyID, Any]) -> bytes:
101 """Encode a property dict to raw wire bytes (no length prefix)."""
102 buf = bytearray()
103 for pid, value in d.items():
104 if pid in _WIRE_BYTE:
105 buf += struct.pack("!BB", pid, int(value))
106 elif pid in _WIRE_UINT16:
107 buf += struct.pack("!BH", pid, value)
108 elif pid in _WIRE_UINT32:
109 buf += struct.pack("!BI", pid, value)
110 elif pid in _WIRE_VARINT:
111 buf += bytes([pid]) + encode_varint(value)
112 elif pid in _WIRE_STR:
113 buf += bytes([pid]) + encode_str(value)
114 elif pid in _WIRE_BYTES_DATA:
115 buf += bytes([pid]) + encode_bytes_field(value)
116 elif pid == _PID.USER_PROPERTY:
117 for k, v in value:
118 buf += bytes([pid]) + encode_str(k) + encode_str(v)
119 return bytes(buf)
122def encode_props_block(d: dict[PropertyID, Any] | None) -> bytes:
123 """Encode a properties block: varint length prefix + raw wire bytes."""
124 if not d:
125 return encode_varint(0)
126 raw = encode_props(d)
127 return encode_varint(len(raw)) + raw
130def decode_props_block(
131 buf: bytes | memoryview,
132 offset: int,
133) -> tuple[dict[PropertyID, Any], int]:
134 """Decode a properties block.
136 Returns (dict, bytes_consumed) where bytes_consumed includes the length prefix.
137 """
138 props_len, n = decode_varint(buf, offset)
139 pos = offset + n
140 end = pos + props_len
141 d: dict[PropertyID, Any] = {}
142 val: str | int | bytes
143 while pos < end:
144 try:
145 pid = PropertyID(buf[pos])
146 except ValueError as e:
147 msg = f"Unknown property ID: {buf[pos]:#04x}"
148 raise ValueError(msg) from e
149 pos += 1
150 if pid in _WIRE_BYTE:
151 d[pid] = buf[pos]
152 pos += 1
153 elif pid in _WIRE_UINT16:
154 d[pid] = struct.unpack_from("!H", buf, pos)[0]
155 pos += 2
156 elif pid in _WIRE_UINT32:
157 d[pid] = struct.unpack_from("!I", buf, pos)[0]
158 pos += 4
159 elif pid in _WIRE_VARINT:
160 val, vn = decode_varint(buf, pos)
161 d[pid] = val
162 pos += vn
163 elif pid in _WIRE_STR:
164 val, sn = decode_str(buf, pos)
165 d[pid] = val
166 pos += sn
167 elif pid in _WIRE_BYTES_DATA:
168 val, bn = decode_bytes_field(buf, pos)
169 d[pid] = val
170 pos += bn
171 elif pid == _PID.USER_PROPERTY:
172 k, kn = decode_str(buf, pos)
173 pos += kn
174 v, vn = decode_str(buf, pos)
175 pos += vn
176 pairs: list[tuple[str, str]] = list(d.get(pid, []))
177 pairs.append((k, v))
178 d[pid] = pairs
179 return d, n + props_len
182@dataclass(frozen=True, slots=True, kw_only=True)
183class ConnectProperties:
184 """MQTT 5.0 properties sent in the CONNECT packet.
186 Attributes:
187 session_expiry_interval: Seconds before the broker discards the session
188 after disconnect. ``0`` means discard immediately; ``0xFFFFFFFF``
189 means never expire.
190 receive_maximum: Maximum number of QoS 1/2 messages the client will
191 process concurrently.
192 maximum_packet_size: Largest packet size (bytes) the client will accept.
193 topic_alias_maximum: Number of topic aliases the client supports. ``0``
194 disables topic aliases.
195 request_response_information: Ask the broker to include response
196 information in CONNACK.
197 request_problem_information: Ask the broker to include reason strings and
198 user properties on errors.
199 authentication_method: Method name for enhanced authentication.
200 authentication_data: Initial data for enhanced authentication.
201 user_properties: Arbitrary key-value pairs forwarded to the broker.
202 """
204 session_expiry_interval: int | None = None
205 receive_maximum: int | None = None
206 maximum_packet_size: int | None = None
207 topic_alias_maximum: int | None = None
208 request_response_information: bool | None = None
209 request_problem_information: bool | None = None
210 authentication_method: str | None = None
211 authentication_data: bytes | None = None
212 user_properties: tuple[tuple[str, str], ...] = ()
215@dataclass(frozen=True, slots=True, kw_only=True)
216class WillProperties:
217 will_delay_interval: int | None = None
218 payload_format_indicator: int | None = None
219 message_expiry_interval: int | None = None
220 content_type: str | None = None
221 response_topic: str | None = None
222 correlation_data: bytes | None = None
223 user_properties: tuple[tuple[str, str], ...] = ()
226@dataclass(frozen=True, slots=True, kw_only=True)
227class ConnAckProperties:
228 session_expiry_interval: int | None = None
229 receive_maximum: int | None = None
230 maximum_qos: int | None = None
231 retain_available: bool | None = None
232 maximum_packet_size: int | None = None
233 assigned_client_identifier: str | None = None
234 topic_alias_maximum: int | None = None
235 reason_string: str | None = None
236 wildcard_subscription_available: bool | None = None
237 subscription_identifier_available: bool | None = None
238 shared_subscription_available: bool | None = None
239 server_keep_alive: int | None = None
240 response_information: str | None = None
241 server_reference: str | None = None
242 authentication_method: str | None = None
243 authentication_data: bytes | None = None
244 user_properties: tuple[tuple[str, str], ...] = ()
247@dataclass(frozen=True, slots=True, kw_only=True)
248class PublishProperties:
249 """MQTT 5.0 properties attached to a PUBLISH packet.
251 Attributes:
252 payload_format_indicator: ``0`` for unspecified binary, ``1`` for UTF-8
253 encoded character data.
254 message_expiry_interval: Seconds the broker retains the message. Omit to
255 keep indefinitely.
256 topic_alias: Topic alias integer used instead of the full topic string on
257 the wire.
258 response_topic: Topic the receiver should use when replying
259 (request/response pattern).
260 correlation_data: Opaque bytes the sender uses to match a response to a
261 request.
262 subscription_identifier: Identifier of the subscription that caused this
263 message to be delivered.
264 content_type: MIME type describing the payload content.
265 user_properties: Arbitrary key-value pairs forwarded with the message.
266 """
268 payload_format_indicator: int | None = None
269 message_expiry_interval: int | None = None
270 topic_alias: int | None = None
271 response_topic: str | None = None
272 correlation_data: bytes | None = None
273 subscription_identifier: int | None = None
274 content_type: str | None = None
275 user_properties: tuple[tuple[str, str], ...] = ()
278@dataclass(frozen=True, slots=True, kw_only=True)
279class PubAckProperties:
280 """Properties for PUBACK, PUBREC, PUBREL, and PUBCOMP."""
282 reason_string: str | None = None
283 user_properties: tuple[tuple[str, str], ...] = ()
286@dataclass(frozen=True, slots=True, kw_only=True)
287class SubscribeProperties:
288 subscription_identifier: int | None = None
289 user_properties: tuple[tuple[str, str], ...] = ()
292@dataclass(frozen=True, slots=True, kw_only=True)
293class SubAckProperties:
294 reason_string: str | None = None
295 user_properties: tuple[tuple[str, str], ...] = ()
298@dataclass(frozen=True, slots=True, kw_only=True)
299class UnsubscribeProperties:
300 user_properties: tuple[tuple[str, str], ...] = ()
303@dataclass(frozen=True, slots=True, kw_only=True)
304class UnsubAckProperties:
305 reason_string: str | None = None
306 user_properties: tuple[tuple[str, str], ...] = ()
309@dataclass(frozen=True, slots=True, kw_only=True)
310class DisconnectProperties:
311 session_expiry_interval: int | None = None
312 reason_string: str | None = None
313 server_reference: str | None = None
314 user_properties: tuple[tuple[str, str], ...] = ()
317@dataclass(frozen=True, slots=True, kw_only=True)
318class AuthProperties:
319 """MQTT 5.0 properties sent in an AUTH packet.
321 Attributes:
322 authentication_method: Method name for the enhanced authentication
323 exchange.
324 authentication_data: Method-specific data for this step of the
325 authentication exchange.
326 reason_string: Human-readable reason included for diagnostic purposes.
327 user_properties: Arbitrary key-value pairs forwarded with the packet.
328 """
330 authentication_method: str | None = None
331 authentication_data: bytes | None = None
332 reason_string: str | None = None
333 user_properties: tuple[tuple[str, str], ...] = ()
336_UP = _PID.USER_PROPERTY # shorthand
337AnyProperties = (
338 ConnectProperties
339 | WillProperties
340 | ConnAckProperties
341 | PublishProperties
342 | PubAckProperties
343 | SubscribeProperties
344 | SubAckProperties
345 | UnsubscribeProperties
346 | UnsubAckProperties
347 | DisconnectProperties
348 | AuthProperties
349)
352def _up(props: AnyProperties) -> dict[PropertyID, Any]:
353 """Build a dict with user_properties if non-empty."""
354 return {_UP: list(props.user_properties)} if props.user_properties else {}
357def encode_connect_properties(props: ConnectProperties | None) -> bytes:
358 if props is None:
359 return encode_varint(0)
360 d: dict[PropertyID, Any] = {
361 pid: val
362 for pid, val in [
363 (_PID.SESSION_EXPIRY_INTERVAL, props.session_expiry_interval),
364 (_PID.RECEIVE_MAXIMUM, props.receive_maximum),
365 (_PID.MAXIMUM_PACKET_SIZE, props.maximum_packet_size),
366 (_PID.TOPIC_ALIAS_MAXIMUM, props.topic_alias_maximum),
367 (_PID.REQUEST_RESPONSE_INFORMATION, props.request_response_information),
368 (_PID.REQUEST_PROBLEM_INFORMATION, props.request_problem_information),
369 (_PID.AUTHENTICATION_METHOD, props.authentication_method),
370 (_PID.AUTHENTICATION_DATA, props.authentication_data),
371 ]
372 if val is not None
373 }
374 d.update(_up(props))
375 return encode_props_block(d)
378def encode_will_properties(props: WillProperties | None) -> bytes:
379 if props is None:
380 return encode_varint(0)
381 d: dict[PropertyID, Any] = {
382 pid: val
383 for pid, val in [
384 (_PID.WILL_DELAY_INTERVAL, props.will_delay_interval),
385 (_PID.PAYLOAD_FORMAT_INDICATOR, props.payload_format_indicator),
386 (_PID.MESSAGE_EXPIRY_INTERVAL, props.message_expiry_interval),
387 (_PID.CONTENT_TYPE, props.content_type),
388 (_PID.RESPONSE_TOPIC, props.response_topic),
389 (_PID.CORRELATION_DATA, props.correlation_data),
390 ]
391 if val is not None
392 }
393 d.update(_up(props))
394 return encode_props_block(d)
397def encode_connack_properties(props: ConnAckProperties | None) -> bytes:
398 if props is None:
399 return encode_varint(0)
400 d: dict[PropertyID, Any] = {
401 pid: val
402 for pid, val in [
403 (_PID.SESSION_EXPIRY_INTERVAL, props.session_expiry_interval),
404 (_PID.RECEIVE_MAXIMUM, props.receive_maximum),
405 (_PID.MAXIMUM_QOS, props.maximum_qos),
406 (_PID.RETAIN_AVAILABLE, props.retain_available),
407 (_PID.MAXIMUM_PACKET_SIZE, props.maximum_packet_size),
408 (_PID.ASSIGNED_CLIENT_IDENTIFIER, props.assigned_client_identifier),
409 (_PID.TOPIC_ALIAS_MAXIMUM, props.topic_alias_maximum),
410 (_PID.REASON_STRING, props.reason_string),
411 (
412 _PID.WILDCARD_SUBSCRIPTION_AVAILABLE,
413 props.wildcard_subscription_available,
414 ),
415 (
416 _PID.SUBSCRIPTION_IDENTIFIER_AVAILABLE,
417 props.subscription_identifier_available,
418 ),
419 (_PID.SHARED_SUBSCRIPTION_AVAILABLE, props.shared_subscription_available),
420 (_PID.SERVER_KEEP_ALIVE, props.server_keep_alive),
421 (_PID.RESPONSE_INFORMATION, props.response_information),
422 (_PID.SERVER_REFERENCE, props.server_reference),
423 (_PID.AUTHENTICATION_METHOD, props.authentication_method),
424 (_PID.AUTHENTICATION_DATA, props.authentication_data),
425 ]
426 if val is not None
427 }
428 d.update(_up(props))
429 return encode_props_block(d)
432def encode_publish_properties(props: PublishProperties | None) -> bytes:
433 if props is None:
434 return encode_varint(0)
435 d: dict[PropertyID, Any] = {
436 pid: val
437 for pid, val in [
438 (_PID.PAYLOAD_FORMAT_INDICATOR, props.payload_format_indicator),
439 (_PID.MESSAGE_EXPIRY_INTERVAL, props.message_expiry_interval),
440 (_PID.TOPIC_ALIAS, props.topic_alias),
441 (_PID.RESPONSE_TOPIC, props.response_topic),
442 (_PID.CORRELATION_DATA, props.correlation_data),
443 (_PID.SUBSCRIPTION_IDENTIFIER, props.subscription_identifier),
444 (_PID.CONTENT_TYPE, props.content_type),
445 ]
446 if val is not None
447 }
448 d.update(_up(props))
449 return encode_props_block(d)
452def encode_puback_properties(props: PubAckProperties | None) -> bytes:
453 if props is None:
454 return encode_varint(0)
455 d: dict[PropertyID, Any] = {}
456 if props.reason_string is not None:
457 d[_PID.REASON_STRING] = props.reason_string
458 d.update(_up(props))
459 return encode_props_block(d)
462def encode_subscribe_properties(props: SubscribeProperties | None) -> bytes:
463 if props is None:
464 return encode_varint(0)
465 d: dict[PropertyID, Any] = {}
466 if props.subscription_identifier is not None:
467 d[_PID.SUBSCRIPTION_IDENTIFIER] = props.subscription_identifier
468 d.update(_up(props))
469 return encode_props_block(d)
472def encode_suback_properties(props: SubAckProperties | None) -> bytes:
473 if props is None:
474 return encode_varint(0)
475 d: dict[PropertyID, Any] = {}
476 if props.reason_string is not None:
477 d[_PID.REASON_STRING] = props.reason_string
478 d.update(_up(props))
479 return encode_props_block(d)
482def encode_unsubscribe_properties(props: UnsubscribeProperties | None) -> bytes:
483 if props is None:
484 return encode_varint(0)
485 return encode_props_block(_up(props))
488def encode_unsuback_properties(props: UnsubAckProperties | None) -> bytes:
489 if props is None:
490 return encode_varint(0)
491 d: dict[PropertyID, Any] = {}
492 if props.reason_string is not None:
493 d[_PID.REASON_STRING] = props.reason_string
494 d.update(_up(props))
495 return encode_props_block(d)
498def encode_disconnect_properties(props: DisconnectProperties | None) -> bytes:
499 if props is None:
500 return encode_varint(0)
501 d: dict[PropertyID, Any] = {
502 pid: val
503 for pid, val in [
504 (_PID.SESSION_EXPIRY_INTERVAL, props.session_expiry_interval),
505 (_PID.REASON_STRING, props.reason_string),
506 (_PID.SERVER_REFERENCE, props.server_reference),
507 ]
508 if val is not None
509 }
510 d.update(_up(props))
511 return encode_props_block(d)
514def encode_auth_properties(props: AuthProperties | None) -> bytes:
515 if props is None:
516 return encode_varint(0)
517 d: dict[PropertyID, Any] = {
518 pid: val
519 for pid, val in [
520 (_PID.AUTHENTICATION_METHOD, props.authentication_method),
521 (_PID.AUTHENTICATION_DATA, props.authentication_data),
522 (_PID.REASON_STRING, props.reason_string),
523 ]
524 if val is not None
525 }
526 d.update(_up(props))
527 return encode_props_block(d)
530def _up_tuple(d: dict[PropertyID, Any]) -> tuple[tuple[str, str], ...]:
531 return tuple((k, v) for k, v in d.get(_UP, []))
534def decode_connect_properties(
535 buf: bytes | memoryview,
536 offset: int,
537) -> tuple[ConnectProperties | None, int]:
538 d, n = decode_props_block(buf, offset)
539 if not d:
540 return None, n
541 return ConnectProperties(
542 session_expiry_interval=d.get(_PID.SESSION_EXPIRY_INTERVAL),
543 receive_maximum=d.get(_PID.RECEIVE_MAXIMUM),
544 maximum_packet_size=d.get(_PID.MAXIMUM_PACKET_SIZE),
545 topic_alias_maximum=d.get(_PID.TOPIC_ALIAS_MAXIMUM),
546 request_response_information=bool(d[_PID.REQUEST_RESPONSE_INFORMATION])
547 if _PID.REQUEST_RESPONSE_INFORMATION in d
548 else None,
549 request_problem_information=bool(d[_PID.REQUEST_PROBLEM_INFORMATION])
550 if _PID.REQUEST_PROBLEM_INFORMATION in d
551 else None,
552 authentication_method=d.get(_PID.AUTHENTICATION_METHOD),
553 authentication_data=d.get(_PID.AUTHENTICATION_DATA),
554 user_properties=_up_tuple(d),
555 ), n
558def decode_will_properties(
559 buf: bytes | memoryview,
560 offset: int,
561) -> tuple[WillProperties | None, int]:
562 d, n = decode_props_block(buf, offset)
563 if not d:
564 return None, n
565 return WillProperties(
566 will_delay_interval=d.get(_PID.WILL_DELAY_INTERVAL),
567 payload_format_indicator=d.get(_PID.PAYLOAD_FORMAT_INDICATOR),
568 message_expiry_interval=d.get(_PID.MESSAGE_EXPIRY_INTERVAL),
569 content_type=d.get(_PID.CONTENT_TYPE),
570 response_topic=d.get(_PID.RESPONSE_TOPIC),
571 correlation_data=d.get(_PID.CORRELATION_DATA),
572 user_properties=_up_tuple(d),
573 ), n
576def decode_connack_properties(
577 buf: bytes | memoryview,
578 offset: int,
579) -> tuple[ConnAckProperties | None, int]:
580 d, n = decode_props_block(buf, offset)
581 if not d:
582 return None, n
583 return ConnAckProperties(
584 session_expiry_interval=d.get(_PID.SESSION_EXPIRY_INTERVAL),
585 receive_maximum=d.get(_PID.RECEIVE_MAXIMUM),
586 maximum_qos=d.get(_PID.MAXIMUM_QOS),
587 retain_available=bool(d[_PID.RETAIN_AVAILABLE]) if _PID.RETAIN_AVAILABLE in d else None,
588 maximum_packet_size=d.get(_PID.MAXIMUM_PACKET_SIZE),
589 assigned_client_identifier=d.get(_PID.ASSIGNED_CLIENT_IDENTIFIER),
590 topic_alias_maximum=d.get(_PID.TOPIC_ALIAS_MAXIMUM),
591 reason_string=d.get(_PID.REASON_STRING),
592 wildcard_subscription_available=bool(d[_PID.WILDCARD_SUBSCRIPTION_AVAILABLE])
593 if _PID.WILDCARD_SUBSCRIPTION_AVAILABLE in d
594 else None,
595 subscription_identifier_available=bool(
596 d[_PID.SUBSCRIPTION_IDENTIFIER_AVAILABLE],
597 )
598 if _PID.SUBSCRIPTION_IDENTIFIER_AVAILABLE in d
599 else None,
600 shared_subscription_available=bool(d[_PID.SHARED_SUBSCRIPTION_AVAILABLE])
601 if _PID.SHARED_SUBSCRIPTION_AVAILABLE in d
602 else None,
603 server_keep_alive=d.get(_PID.SERVER_KEEP_ALIVE),
604 response_information=d.get(_PID.RESPONSE_INFORMATION),
605 server_reference=d.get(_PID.SERVER_REFERENCE),
606 authentication_method=d.get(_PID.AUTHENTICATION_METHOD),
607 authentication_data=d.get(_PID.AUTHENTICATION_DATA),
608 user_properties=_up_tuple(d),
609 ), n
612def decode_publish_properties(
613 buf: bytes | memoryview,
614 offset: int,
615) -> tuple[PublishProperties | None, int]:
616 d, n = decode_props_block(buf, offset)
617 if not d:
618 return None, n
619 return PublishProperties(
620 payload_format_indicator=d.get(_PID.PAYLOAD_FORMAT_INDICATOR),
621 message_expiry_interval=d.get(_PID.MESSAGE_EXPIRY_INTERVAL),
622 topic_alias=d.get(_PID.TOPIC_ALIAS),
623 response_topic=d.get(_PID.RESPONSE_TOPIC),
624 correlation_data=d.get(_PID.CORRELATION_DATA),
625 subscription_identifier=d.get(_PID.SUBSCRIPTION_IDENTIFIER),
626 content_type=d.get(_PID.CONTENT_TYPE),
627 user_properties=_up_tuple(d),
628 ), n
631def decode_puback_properties(
632 buf: bytes | memoryview,
633 offset: int,
634) -> tuple[PubAckProperties | None, int]:
635 d, n = decode_props_block(buf, offset)
636 if not d:
637 return None, n
638 return PubAckProperties(
639 reason_string=d.get(_PID.REASON_STRING),
640 user_properties=_up_tuple(d),
641 ), n
644def decode_subscribe_properties(
645 buf: bytes | memoryview,
646 offset: int,
647) -> tuple[SubscribeProperties | None, int]:
648 d, n = decode_props_block(buf, offset)
649 if not d:
650 return None, n
651 return SubscribeProperties(
652 subscription_identifier=d.get(_PID.SUBSCRIPTION_IDENTIFIER),
653 user_properties=_up_tuple(d),
654 ), n
657def decode_suback_properties(
658 buf: bytes | memoryview,
659 offset: int,
660) -> tuple[SubAckProperties | None, int]:
661 d, n = decode_props_block(buf, offset)
662 if not d:
663 return None, n
664 return SubAckProperties(
665 reason_string=d.get(_PID.REASON_STRING),
666 user_properties=_up_tuple(d),
667 ), n
670def decode_unsubscribe_properties(
671 buf: bytes | memoryview,
672 offset: int,
673) -> tuple[UnsubscribeProperties | None, int]:
674 d, n = decode_props_block(buf, offset)
675 if not d:
676 return None, n
677 return UnsubscribeProperties(user_properties=_up_tuple(d)), n
680def decode_unsuback_properties(
681 buf: bytes | memoryview,
682 offset: int,
683) -> tuple[UnsubAckProperties | None, int]:
684 d, n = decode_props_block(buf, offset)
685 if not d:
686 return None, n
687 return UnsubAckProperties(
688 reason_string=d.get(_PID.REASON_STRING),
689 user_properties=_up_tuple(d),
690 ), n
693def decode_disconnect_properties(
694 buf: bytes | memoryview,
695 offset: int,
696) -> tuple[DisconnectProperties | None, int]:
697 d, n = decode_props_block(buf, offset)
698 if not d:
699 return None, n
700 return DisconnectProperties(
701 session_expiry_interval=d.get(_PID.SESSION_EXPIRY_INTERVAL),
702 reason_string=d.get(_PID.REASON_STRING),
703 server_reference=d.get(_PID.SERVER_REFERENCE),
704 user_properties=_up_tuple(d),
705 ), n
708def decode_auth_properties(
709 buf: bytes | memoryview,
710 offset: int,
711) -> tuple[AuthProperties | None, int]:
712 d, n = decode_props_block(buf, offset)
713 if not d:
714 return None, n
715 return AuthProperties(
716 authentication_method=d.get(_PID.AUTHENTICATION_METHOD),
717 authentication_data=d.get(_PID.AUTHENTICATION_DATA),
718 reason_string=d.get(_PID.REASON_STRING),
719 user_properties=_up_tuple(d),
720 ), n