code: def _gen_packet(self, sequence, payloadtype, payload=None):
          
          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
docs: Generate packet header.