Coverage for src / zmqtt / _internal / packets / publish.py: 100%

30 statements  

« prev     ^ index     » next       coverage.py v7.13.4, created at 2026-11-12 08:49 +0000

1from dataclasses import dataclass 

2from typing import ClassVar 

3 

4from zmqtt._internal.packets.properties import PubAckProperties, PublishProperties 

5from zmqtt._internal.packets.types import Packet, PacketType 

6from zmqtt._internal.types.qos import QoS 

7 

8 

9@dataclass(frozen=True, slots=True, kw_only=True) 

10class Publish(Packet): 

11 packet_type: ClassVar[PacketType] = PacketType.PUBLISH 

12 

13 topic: str 

14 payload: bytes 

15 qos: QoS 

16 retain: bool 

17 dup: bool 

18 packet_id: int | None = None # required for QoS 1 and 2 

19 properties: PublishProperties | None = None # v5 only 

20 

21 

22@dataclass(frozen=True, slots=True, kw_only=True) 

23class PubAck(Packet): 

24 packet_type: ClassVar[PacketType] = PacketType.PUBACK 

25 

26 packet_id: int 

27 reason_code: int = 0 # v5 only; 0 = success 

28 properties: PubAckProperties | None = None # v5 only 

29 

30 

31@dataclass(frozen=True, slots=True, kw_only=True) 

32class PubRec(Packet): 

33 packet_type: ClassVar[PacketType] = PacketType.PUBREC 

34 

35 packet_id: int 

36 reason_code: int = 0 # v5 only; 0 = success 

37 properties: PubAckProperties | None = None # v5 only 

38 

39 

40@dataclass(frozen=True, slots=True, kw_only=True) 

41class PubRel(Packet): 

42 packet_type: ClassVar[PacketType] = PacketType.PUBREL 

43 

44 packet_id: int 

45 reason_code: int = 0 # v5 only; 0 = success 

46 properties: PubAckProperties | None = None # v5 only 

47 

48 

49@dataclass(frozen=True, slots=True, kw_only=True) 

50class PubComp(Packet): 

51 packet_type: ClassVar[PacketType] = PacketType.PUBCOMP 

52 

53 packet_id: int 

54 reason_code: int = 0 # v5 only; 0 = success 

55 properties: PubAckProperties | None = None # v5 only