input: Write a python function to generate a binary packet from provided init_packet_fields using the Packet class.
  assert Packet({PacketField.PACKET_VERSION: 1, PacketField.COMPRESSION_TYPE: 0, PacketField.DEVICE_TYPE: 1234, PacketField.DEVICE_REVISION: 5678}).generate_packet() == b'\x01\x00\x00\x00\xd2\x04\x2e\x16'
  assert Packet({PacketField.PACKET_VERSION: 1, PacketField.APP_VERSION: 2, PacketField.REQUIRED_SOFTDEVICES_ARRAY: [3, 4]}).generate_packet() == b'\x01\x00\x02\x00\x03\x00\x02\x00\x03\x00\x04\x00'
  assert Packet({PacketField.NORDIC_PROPRIETARY_OPT_DATA_FIRMWARE_CRC16: 12345}).generate_packet() == b'90'
output: class PacketField:
      PACKET_VERSION = 'packet_version'
      COMPRESSION_TYPE = 'compression_type'
      DEVICE_TYPE = 'device_type'
      DEVICE_REVISION = 'device_revision'
      APP_VERSION = 'app_version'
      REQUIRED_SOFTDEVICES_ARRAY = 'required_softdevices_array'
      NORDIC_PROPRIETARY_OPT_DATA_FIRMWARE_CRC16 = 'nordic_proprietary_opt_data_firmware_crc16'
  
  class Packet:
      def __init__(self, init_packet_fields):
          self.fields = init_packet_fields
  
      def generate_packet(self):
          packet = bytearray()
          for field, value in self.fields.items():
              if field == PacketField.PACKET_VERSION:
                  packet.extend(value.to_bytes(1, 'little'))
              elif field == PacketField.COMPRESSION_TYPE:
                  packet.extend(value.to_bytes(1, 'little'))
              elif field == PacketField.DEVICE_TYPE:
                  packet.extend(value.to_bytes(2, 'little'))
              elif field == PacketField.DEVICE_REVISION:
                  packet.extend(value.to_bytes(2, 'little'))
              elif field == PacketField.APP_VERSION:
                  packet.extend(value.to_bytes(2, 'little'))
              elif field == PacketField.REQUIRED_SOFTDEVICES_ARRAY:
                  for softdevice in value:
                      packet.extend(softdevice.to_bytes(2, 'little'))
              elif field == PacketField.NORDIC_PROPRIETARY_OPT_DATA_FIRMWARE_CRC16:
                  packet.extend(value.to_bytes(2, 'little'))
          return bytes(packet)