def build_packet(packet_type, gateway, bulb, payload_fmt, *payload_args,<EOL>**kwargs):
protocol = kwargs.get('<STR_LIT>', COMMAND_PROTOCOL)<EOL>packet_fmt = BASE_FORMAT + payload_fmt<EOL>packet_size = struct.calcsize(packet_fmt)<EOL>return struct.pack(packet_fmt,<EOL>packet_size,<EOL>protocol,<EOL>bulb,<EOL>gateway,<EOL><NUM_LIT:0>,  <EOL>packet_type,<EOL>*payload_args)<EOL>
Constructs a Lifx packet, returning a bytestring. The arguments are as
follows:

- `packet_type`, an integer
- `gateway`, a 6-byte string containing the mac address of the gateway bulb
- `bulb`, a 6-byte string containing either the mac address of the target
  bulb or `ALL_BULBS`
- `payload_fmt`, a `struct`-compatible string that describes the format
  of the payload part of the packet
- `payload_args`, the values to use to build the payload part of the packet

Additionally, the `protocol` keyword argument can be used to override the
protocol field in the packet.