code: def _write(self, dap_index, transfer_count,
                 transfer_request, transfer_data):
          
          assert dap_index == 0  # dap index currently unsupported
          assert isinstance(transfer_count, six.integer_types)
          assert isinstance(transfer_request, six.integer_types)
          assert transfer_data is None or len(transfer_data) > 0
  
          # Create transfer and add to transfer list
          transfer = None
          if transfer_request & READ:
              transfer = _Transfer(self, dap_index, transfer_count,
                                   transfer_request, transfer_data)
              self._transfer_list.append(transfer)
  
          # Build physical packet by adding it to command
          cmd = self._crnt_cmd
          is_read = transfer_request & READ
          size_to_transfer = transfer_count
          trans_data_pos = 0
          while size_to_transfer > 0:
              # Get the size remaining in the current packet for the given request.
              size = cmd.get_request_space(size_to_transfer, transfer_request, dap_index)
  
              # This request doesn't fit in the packet so send it.
              if size == 0:
                  if LOG_PACKET_BUILDS:
                      self._logger.debug("_write: send packet [size==0]")
                  self._send_packet()
                  cmd = self._crnt_cmd
                  continue
  
              # Add request to packet.
              if transfer_data is None:
                  data = None
              else:
                  data = transfer_data[trans_data_pos:trans_data_pos + size]
              cmd.add(size, transfer_request, data, dap_index)
              size_to_transfer -= size
              trans_data_pos += size
  
              # Packet has been filled so send it
              if cmd.get_full():
                  if LOG_PACKET_BUILDS:
                      self._logger.debug("_write: send packet [full]")
                  self._send_packet()
                  cmd = self._crnt_cmd
  
          if not self._deferred_transfer:
              self.flush()
  
          return transfer
docs: Write one or more commands