import struct


def create_packet(
    connection_id: int,
    sequence_number: int,
    ack_number: int,
    flags: int,
    data: bytes,
) -> bytearray:
    """
    Create a packet in order to send it to the probe on Mars.
    Pack python native data types data to C types using struct.pack()
    """
    packet = bytearray()

    # more at help(struct) or https://docs.python.org/3/library/struct.html
    # '!' is network (= big-endian) endianness format
    # 'I' is unsigned int (4B)
    # 'H' is unsigned short int (2B)
    packet += struct.pack("!IHH", connection_id, sequence_number, ack_number)

    # now the rest is in the native endianness (according to the task)

    # '@' - native endianness (and alignment)
    # 'b' - signed char (1B)
    packet += struct.pack("@b", flags)

    # data are optional, packet must be at minimum 9B header + 0-255B data
    # 's' for 'char *' with length in bytes prefix
    packet += struct.pack(f"@{len(data)}s", data)

    return packet