import struct


def write_packet(packet_type, body):
    """
    Write full packet from type and body string.

    :param packet_type: Type of packet
    :param body: Body string
    :return: Packed packet
    """
    body_size = len(body)
    fmt = '!bi%ds' % body_size
    return struct.pack(fmt, packet_type, body_size, body)