# Path: cbus/common.py
# class DestinationAddressType(IntEnum):
#     """
#     Destination Address Type (DAT).
# 
#     Ref: Serial Interface Guide, s3.4. Other values reserved.
#     """
#     UNSET = 0x00
#     POINT_TO_POINT_TO_MULTIPOINT = 0x03
#     POINT_TO_MULTIPOINT = 0x05
#     POINT_TO_POINT = 0x06
# 
# class PriorityClass(IntEnum):
#     CLASS_4 = 0x00  # lowest
#     CLASS_3 = 0x01  # medium low
#     CLASS_2 = 0x02  # medium high
#     CLASS_1 = 0x03  # highest


import abc
from base64 import b16encode
from dataclasses import dataclass
from typing import Optional
from cbus.common import DestinationAddressType, PriorityClass
            self,
            checksum: bool = True,
            destination_address_type:
            DestinationAddressType = DestinationAddressType.UNSET,
            rc: int = 0,
            dp: bool = False,
            priority_class: PriorityClass = PriorityClass.CLASS_4):
        # base packet implementation.
        self.checksum = checksum

        self.destination_address_type = destination_address_type
        self.rc = rc
        self.dp = dp
        self.priority_class = priority_class
        self.confirmation = None
        self.source_address = None

    @property
    def flags(self) -> int:
        return ((self.destination_address_type & 0x07) |
                ((self.rc & 0x02) << 3) |
                (0x20 if self.dp else 0) |
                ((self.priority_class & 0x03) << 6))

    @abc.abstractmethod
    def encode(self) -> bytes:
        if self.source_address is None:
            return bytes([self.flags])
        else:
            source_address = self.source_address & 0xff

# Path: cbus/common.py
# class DestinationAddressType(IntEnum):
#     """
#     Destination Address Type (DAT).
# 
#     Ref: Serial Interface Guide, s3.4. Other values reserved.
#     """
#     UNSET = 0x00
#     POINT_TO_POINT_TO_MULTIPOINT = 0x03
#     POINT_TO_MULTIPOINT = 0x05
#     POINT_TO_POINT = 0x06
# 
# class PriorityClass(IntEnum):
#     CLASS_4 = 0x00  # lowest
#     CLASS_3 = 0x01  # medium low
#     CLASS_2 = 0x02  # medium high
#     CLASS_1 = 0x03  # highest


# Path: cbus/protocol/base_packet.py
import abc
from base64 import b16encode
from dataclasses import dataclass
from typing import Optional
from cbus.common import DestinationAddressType, PriorityClass

            self,
            checksum: bool = True,
            destination_address_type:
            DestinationAddressType = DestinationAddressType.UNSET,
            rc: int = 0,
            dp: bool = False,
            priority_class: PriorityClass = PriorityClass.CLASS_4):
        # base packet implementation.
        self.checksum = checksum

        self.destination_address_type = destination_address_type
        self.rc = rc
        self.dp = dp
        self.priority_class = priority_class
        self.confirmation = None
        self.source_address = None

    @property
    def flags(self) -> int:
        return ((self.destination_address_type & 0x07) |
                ((self.rc & 0x02) << 3) |
                (0x20 if self.dp else 0) |
                ((self.priority_class & 0x03) << 6))

    @abc.abstractmethod
    def encode(self) -> bytes:
        if self.source_address is None:
            return bytes([self.flags])
        else:
            source_address = self.source_address & 0xff

            return bytes([self.flags, source_address])