Skip to content

Commit 0906b28

Browse files
committed
feat: generate client ResponseVisitor implementations
1 parent bc364ed commit 0906b28

24 files changed

+5913
-64
lines changed

include/ClientGenerator.h

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,48 @@ class [[nodiscard("unnecessary construction")]] Generator
6464
const std::string& outerScope, const ResponseField& responseField) const noexcept;
6565
[[nodiscard("unnecessary memory copy")]] static std::string getTypeModifierList(
6666
const TypeModifierStack& modifiers) noexcept;
67+
void outputResponseFieldVisitorStates(std::ostream& sourceFile,
68+
const ResponseField& responseField, std::string_view parent = {}) const noexcept;
69+
void outputResponseFieldVisitorAddValue(std::ostream& sourceFile,
70+
const ResponseField& responseField, std::string_view parentState = {},
71+
std::string_view parentAccessor = {}, std::string_view parentCppType = {}) const noexcept;
72+
void outputResponseFieldVisitorReserve(std::ostream& sourceFile,
73+
const ResponseField& responseField, std::string_view parentState = {},
74+
std::string_view parentAccessor = {}, std::string_view parentCppType = {}) const noexcept;
75+
void outputResponseFieldVisitorStartObject(std::ostream& sourceFile,
76+
const ResponseField& responseField, std::string_view parentState = {},
77+
std::string_view parentAccessor = {}, std::string_view parentCppType = {}) const noexcept;
78+
void outputResponseFieldVisitorAddMember(std::ostream& sourceFile,
79+
const ResponseFieldList& children, std::string_view parentState = {}) const noexcept;
80+
void outputResponseFieldVisitorEndObject(std::ostream& sourceFile,
81+
const ResponseField& responseField, std::string_view parentState = {}) const noexcept;
82+
void outputResponseFieldVisitorStartArray(std::ostream& sourceFile,
83+
const ResponseField& responseField, std::string_view parentState = {},
84+
std::string_view parentAccessor = {}, std::string_view parentCppType = {}) const noexcept;
85+
void outputResponseFieldVisitorEndArray(std::ostream& sourceFile,
86+
const ResponseField& responseField, std::string_view parentState = {}) const noexcept;
87+
void outputResponseFieldVisitorAddNull(std::ostream& sourceFile,
88+
const ResponseField& responseField, std::string_view parentState = {},
89+
std::string_view parentAccessor = {}) const noexcept;
90+
void outputResponseFieldVisitorAddMovedValue(std::ostream& sourceFile,
91+
const ResponseField& responseField, std::string_view movedCppType,
92+
std::string_view parentState = {}, std::string_view parentAccessor = {}) const noexcept;
93+
void outputResponseFieldVisitorAddString(
94+
std::ostream& sourceFile, const ResponseField& responseField) const noexcept;
95+
void outputResponseFieldVisitorAddEnum(std::ostream& sourceFile,
96+
const ResponseField& responseField, std::string_view parentState = {},
97+
std::string_view parentAccessor = {}, std::string_view parentCppType = {}) const noexcept;
98+
void outputResponseFieldVisitorAddId(
99+
std::ostream& sourceFile, const ResponseField& responseField) const noexcept;
100+
void outputResponseFieldVisitorAddCopiedValue(std::ostream& sourceFile,
101+
const ResponseField& responseField, std::string_view copiedCppType,
102+
std::string_view parentState = {}, std::string_view parentAccessor = {}) const noexcept;
103+
void outputResponseFieldVisitorAddBool(
104+
std::ostream& sourceFile, const ResponseField& responseField) const noexcept;
105+
void outputResponseFieldVisitorAddInt(
106+
std::ostream& sourceFile, const ResponseField& responseField) const noexcept;
107+
void outputResponseFieldVisitorAddFloat(
108+
std::ostream& sourceFile, const ResponseField& responseField) const noexcept;
67109

68110
const SchemaLoader _schemaLoader;
69111
const RequestLoader _requestLoader;

samples/client/benchmark.cpp

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,6 @@ int main(int argc, char** argv)
8686
const auto mockService = today::mock_service();
8787
const auto& service = mockService->service;
8888
std::vector<std::chrono::steady_clock::duration> durationResolve(iterations);
89-
std::vector<std::chrono::steady_clock::duration> durationParseServiceResponse(iterations);
9089
std::vector<std::chrono::steady_clock::duration> durationParseResponse(iterations);
9190
const auto startTime = std::chrono::steady_clock::now();
9291

@@ -96,19 +95,21 @@ int main(int argc, char** argv)
9695

9796
auto query = GetRequestObject();
9897
const auto& name = GetOperationName();
98+
auto visitor = std::make_shared<ResponseVisitor>();
99+
auto responseVisitor = std::make_shared<response::ValueVisitor>(visitor);
99100

100101
for (std::size_t i = 0; i < iterations; ++i)
101102
{
102103
const auto startResolve = std::chrono::steady_clock::now();
103-
auto response = service->resolve({ query, name }).get();
104-
const auto startParseServiceResponse = std::chrono::steady_clock::now();
105-
auto serviceResponse = client::parseServiceResponse(std::move(response));
104+
auto response = service->visit({ query, name }).get();
106105
const auto startParseResponse = std::chrono::steady_clock::now();
107-
const auto parsed = parseResponse(std::move(serviceResponse.data));
106+
107+
std::move(response.data).visit(responseVisitor);
108+
109+
const auto parsed = visitor->response();
108110
const auto endParseResponse = std::chrono::steady_clock::now();
109111

110-
durationResolve[i] = startParseServiceResponse - startResolve;
111-
durationParseServiceResponse[i] = startParseResponse - startParseServiceResponse;
112+
durationResolve[i] = startParseResponse - startResolve;
112113
durationParseResponse[i] = endParseResponse - startParseResponse;
113114
}
114115
}
@@ -124,7 +125,6 @@ int main(int argc, char** argv)
124125
outputOverview(iterations, totalDuration);
125126

126127
outputSegment("Resolve"sv, durationResolve);
127-
outputSegment("ParseServiceResponse"sv, durationParseServiceResponse);
128128
outputSegment("ParseResponse"sv, durationParseResponse);
129129

130130
return 0;

0 commit comments

Comments
 (0)