Generate packet header.

def _gen_packet(self, sequence, payloadtype, payload=None):
        """ Generate packet header. """
        contents = self._gen_header(sequence, payloadtype)

        # add payload
        if payload:
            contents.extend(payload)

        # get packet size
        size = pack("<H", len(contents) + 2)

        # assemble complete packet
        packet = bytearray(size)
        packet.extend(contents)

        return packet