| 79 | } |
| 80 | |
| 81 | C2Payload MQTTC2Protocol::serialize(const C2Payload &payload) { |
| 82 | if (mqtt_service_ == nullptr || !mqtt_service_->isRunning()) { |
| 83 | return C2Payload(payload.getOperation(), state::UpdateState::READ_ERROR); |
| 84 | } |
| 85 | |
| 86 | std::lock_guard<std::mutex> lock(input_mutex_); |
| 87 | |
| 88 | auto stream = c2::PayloadSerializer::serialize(0x00, payload); |
| 89 | |
| 90 | auto transmit_id = mqtt_service_->send(heartbeat_topic_, stream->getBuffer(), stream->size()); |
| 91 | std::vector<uint8_t> response; |
| 92 | if (transmit_id > 0 && mqtt_service_->awaitResponse(5000, transmit_id, in_topic_, response)) { |
| 93 | return c2::PayloadSerializer::deserialize(response); |
| 94 | } |
| 95 | return C2Payload(payload.getOperation(), state::UpdateState::READ_ERROR); |
| 96 | } |
| 97 | |
| 98 | } /* namespace c2 */ |
| 99 | } /* namespace minifi */ |
no test coverage detected