#ifndef SCPI_RESPONSE_HELPER_H
#define SCPI_RESPONSE_HELPER_H

  // @scpi_response_helper
  // Helper function. Helps to implement correct data output from the QUERY.
  // Copies the query data and updates the @sRead.nDataLength and @common_ctx->status
  // to the appropriate values, also returns actual query data offset.
  // @common_ctx - common context pointer passed to the handler;
  // @idx - current data offset in the handler;
  // @source - the data source pointer;
  // @source_max - maximum length of @source
  // @isdone - optional, if passed, specifies wheither to set DONE status or not;
  // Returns: actual data offset for the handler after the data pushed into the output buffer
  size_t scpi_response_helper( sProcessProgramDataCommonContext_t * common_ctx, size_t idx, void * source, size_t source_max, bool * isdone );
  
  // @scpi_response_done_helper
  // Helper function. Helps to implement setting of the status
  // @isdone - DONE status for handler
  void scpi_response_done_helper( sProcessProgramDataCommonContext_t * common_ctx, bool isdone );

  #define SCPI_RESPONSE_HELPER(_common_ctx_,idx_value)                            idx_value  = scpi_response_helper( _common_ctx_, idx_value, common_ctx->tempBuffer, sizeof(common_ctx->tempBuffer), NULL )
  #define SCPI_RESPONSE_HELPER_EX(_common_ctx_,idx_value,src,srcmax)              idx_value  = scpi_response_helper( _common_ctx_, idx_value, src, srcmax, NULL )
  #define SCPI_RESPONSE_HELPER_EXTDONE_IDXINC(_common_ctx_,idx_value,BOOL_ISDONE) idx_value += scpi_response_helper( _common_ctx_, idx_value, common_ctx->tempBuffer, sizeof(common_ctx->tempBuffer), &(BOOL_ISDONE) )
  #define SCPI_RESPONSE_HELPER_EXTDONE_SET(_common_ctx_,BOOL_ISDONE)              scpi_response_done_helper( _common_ctx_, BOOL_ISDONE )

#endif