6#include "proto/main.pb.h"
7#include <protocol/transport.h>
9#include <net/settings.h>
10#include <protocol/protocol.h>
11#include <protocol/protocol_oob.h>
12#include <protocol/registry.h>
13#include <run/run_manager.h>
14#include <utils/StringPrint.h>
15#include <utils/logging.h>
16#include <utils/serial_lines.h>
22#include <utils/streaming_json.h>
26void msg::Broker::handleMessage(transport::Transport &
transport, pb_Envelope &in_envelope) {
27 auto msg_stream =
transport.ctrl_output();
29 int envelope_kind = in_envelope.which_kind;
31 if (envelope_kind == pb_Envelope_generic_tag) {
32 message_kind = in_envelope.kind.generic.which_kind;
33 }
else if (envelope_kind == pb_Envelope_message_v1_tag) {
34 message_kind = in_envelope.kind.message_v1.which_kind;
36 msg_stream->report_error(
"Unknown envelope kind.");
41 auto msg_handler = msg::handlers::Registry::get().lookup(envelope_kind, message_kind);
43 msg_stream->report_error(
"Error unknown handler for message type.");
47 if (msg_handler->handle(in_envelope,
transport))
50 msg_stream->report_error(
"Error while handling streaming message.");
51 LOG_ALWAYS(
"Error while handling message.");
57bool msg::Broker::process(transport::Transport &
transport) {
59 auto result =
transport.ctrl_input()->read(envelope);
62 if (!result.ok_value())
return false;
64 pb_release(pb_Envelope_fields, &envelope);
68 transport.ctrl_output()->report_error(result.err_value());
69 LOG_ALWAYS(std::to_string(envelope.kind.message_v1.which_kind).c_str());
70 LOG_ALWAYS(result.err_value().c_str());
71 LOG_ALWAYS(
"Malformed input. Expecting protobuf.");
utils::SerialLineReader serial_line_reader