MCPcopy Create free account
hub / github.com/chronoxor/FastBinaryEncoding / GenerateClient_Source

Method GenerateClient_Source

source/generator_cpp.cpp:9995–10319  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

9993}
9994
9995void GeneratorCpp::GenerateClient_Source(const std::shared_ptr<Package>& p, bool final)
9996{
9997 std::string client = (final ? "FinalClient" : "Client");
9998 std::string sender = (final ? "FinalSender" : "Sender");
9999 std::string receiver = (final ? "FinalReceiver" : "Receiver");
10000
10001 // Collect responses & rejects collections
10002 std::set<std::string> responses;
10003 std::map<std::string, bool> rejects;
10004 if (p->body)
10005 {
10006 for (const auto& s : p->body->structs)
10007 {
10008 if (s->message && s->request)
10009 {
10010 std::string response_name = (s->response) ? ConvertTypeName(*p->name, *s->response->response, false) : "";
10011
10012 if (!response_name.empty())
10013 {
10014 // Update responses and rejects cache
10015 responses.insert(*s->response->response);
10016 if (s->rejects)
10017 for (const auto& reject : s->rejects->rejects)
10018 rejects[*reject.reject] = reject.global;
10019 }
10020 }
10021 }
10022 }
10023
10024 // Generate request() methods
10025 if (p->body)
10026 {
10027 for (const auto& s : p->body->structs)
10028 {
10029 if (s->message && s->request)
10030 {
10031 std::string request_name = "::" + *p->name + "::" + *s->name;
10032 std::string response_name = (s->response) ? ConvertTypeName(*p->name, *s->response->response, false) : "";
10033 std::string response_field = (s->response) ? *s->response->response : "";
10034 CppCommon::StringUtils::ReplaceAll(response_field, ".", "");
10035
10036 WriteLine();
10037 if (response_name.empty())
10038 {
10039 WriteLineIndent("std::future<void> " + client + "::request(const " + request_name + "& value, uint64_t timeout)");
10040 WriteLineIndent("{");
10041 Indent(1);
10042 WriteLineIndent("std::promise<void> promise;");
10043 WriteLineIndent("std::future<void> future = promise.get_future();");
10044 WriteLine();
10045 WriteLineIndent("// Send the request message");
10046 WriteLineIndent("size_t serialized = " + sender + "::send(value);");
10047 WriteLineIndent("if (serialized > 0)");
10048 Indent(1);
10049 WriteLineIndent("promise.set_value();");
10050 Indent(-1);
10051 WriteLineIndent("else");
10052 Indent(1);

Callers

nothing calls this directly

Calls 5

insertMethod · 0.80
endMethod · 0.80
assignMethod · 0.80
emptyMethod · 0.45
sizeMethod · 0.45

Tested by

no test coverage detected