# generated by scripts/generate_messages.py

from twnet_parser.pretty_print import PrettyPrint
from twnet_parser.packer import Unpacker
from twnet_parser.packer import pack_be_uint16
from typing import Literal

class MsgHeartbeat(PrettyPrint):
    def __init__(
            self,
            alt_port: int = 0
    ) -> None:
        self.message_type: Literal['connless'] = 'connless'
        self.message_name: str = 'connless.heartbeat'
        self.message_id: list[int] = [255, 255, 255, 255, 98, 101, 97, 50]

        self.alt_port: int = alt_port

    # first byte of data
    # has to be the first byte of the message payload
    # NOT the chunk header and NOT the message id
    def unpack(self, data: bytes) -> bool:
        unpacker = Unpacker(data)
        self.alt_port = unpacker.get_be_uint16()
        return True

    def pack(self) -> bytes:
        return pack_be_uint16(self.alt_port)