* This type defines a worker response structure. * This structure is used to send back the HTTP response from the worker task. * * Attention, constructor and destructor of the members are not called! */
| 216 | * Attention, constructor and destructor of the members are not called! |
| 217 | */ |
| 218 | struct WorkerResponse |
| 219 | { |
| 220 | HttpJobId jobId; /**< Job id of the HTTP request/response. */ |
| 221 | t_http_codes statusCode; /**< HTTP status code of the response. */ |
| 222 | uint8_t* payload; /**< Payload of the HTTP response. */ |
| 223 | size_t size; /**< Size of the payload in byte. */ |
| 224 | |
| 225 | /** |
| 226 | * Constructs the HTTP response. |
| 227 | */ |
| 228 | WorkerResponse() : |
| 229 | jobId(INVALID_HTTP_JOB_ID), |
| 230 | statusCode(HTTP_CODE_OK), |
| 231 | payload(nullptr), |
| 232 | size(0U) |
| 233 | { |
| 234 | } |
| 235 | |
| 236 | /** |
| 237 | * Copy constructor. |
| 238 | * |
| 239 | * @param[in] other Other HTTP response to copy. |
| 240 | */ |
| 241 | WorkerResponse(const WorkerResponse& other) : |
| 242 | jobId(other.jobId), |
| 243 | statusCode(other.statusCode), |
| 244 | payload(nullptr), |
| 245 | size(other.size) |
| 246 | { |
| 247 | if (nullptr != other.payload) |
| 248 | { |
| 249 | uint8_t* buffer = new (std::nothrow) uint8_t[size]; |
| 250 | |
| 251 | if (nullptr == buffer) |
| 252 | { |
| 253 | size = 0U; |
| 254 | } |
| 255 | else |
| 256 | { |
| 257 | memcpy(buffer, other.payload, size); |
| 258 | payload = buffer; |
| 259 | } |
| 260 | } |
| 261 | } |
| 262 | |
| 263 | /** |
| 264 | * Move constructor. |
| 265 | * |
| 266 | * @param[in] other Other HTTP response to move from. |
| 267 | */ |
| 268 | WorkerResponse(WorkerResponse&& other) noexcept : |
| 269 | jobId(other.jobId), |
| 270 | statusCode(other.statusCode), |
| 271 | payload(other.payload), |
| 272 | size(other.size) |
| 273 | { |
| 274 | other.payload = nullptr; |
| 275 | other.size = 0U; |