* @brief Builds per-command request messages plus the matching RPC lines from CommandRegistry. */
| 106 | * @brief Builds per-command request messages plus the matching RPC lines from CommandRegistry. |
| 107 | */ |
| 108 | void 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. |