MCPcopy Create free account
hub / github.com/Serial-Studio/Serial-Studio / buildCommandMessages

Method buildCommandMessages

app/src/API/GRPC/ProtoGenerator.cpp:108–142  ·  view source on GitHub ↗

* @brief Builds per-command request messages plus the matching RPC lines from CommandRegistry. */

Source from the content-addressed store, hash-verified

106 * @brief Builds per-command request messages plus the matching RPC lines from CommandRegistry.
107 */
108void API::GRPC::ProtoGenerator::buildCommandMessages(QStringList& message_defs,
109 QStringList& rpc_lines)
110{
111 const auto& commands = API::CommandRegistry::instance().commands();
112
113 for (auto it = commands.begin(); it != commands.end(); ++it) {
114 const auto& def = it.value();
115 const auto msg_name = sanitizeName(def.name) + "Request";
116
117 QString msg;
118 QTextStream msg_out(&msg);
119 msg_out << "message " << msg_name << " {\n"
120 << " string id = 1;\n";
121
122 if (!def.inputSchema.isEmpty()) {
123 const auto props = def.inputSchema.value("properties").toObject();
124 int field_num = 2;
125
126 for (auto pit = props.begin(); pit != props.end(); ++pit) {
127 const auto field_schema = pit.value().toObject();
128 const auto field_type = jsonTypeToProtoType(field_schema.value("type").toString());
129 const auto field_name = pit.key();
130
131 msg_out << " " << field_type << " " << field_name << " = " << field_num++ << ";\n";
132 }
133 }
134
135 msg_out << "}\n";
136 message_defs.append(msg);
137
138 const auto rpc_name = sanitizeName(def.name);
139 rpc_lines.append(QStringLiteral(" // %1\n rpc %2(%3) returns (CommandResponse);")
140 .arg(def.description, rpc_name, msg_name));
141 }
142}
143
144/**
145 * @brief Writes per-command request messages and the typed service block with streaming RPCs.

Callers

nothing calls this directly

Calls 6

sanitizeNameFunction · 0.85
beginMethod · 0.80
isEmptyMethod · 0.80
keyMethod · 0.80
valueMethod · 0.45
appendMethod · 0.45

Tested by

no test coverage detected