fix json return values; borrow VmProvider instead of copy

This commit is contained in:
Theis Pieter Hollebeek 2024-12-12 11:57:18 +01:00
parent c69dd1efb2
commit 242d5b16eb
2 changed files with 10 additions and 10 deletions

View File

@ -3,7 +3,7 @@
auto sliger::rpc::action::RunDebug::perform_action( auto sliger::rpc::action::RunDebug::perform_action(
std::unique_ptr<sliger::rpc::BufferedWriter> writer, std::unique_ptr<sliger::rpc::BufferedWriter> writer,
vm_provider::VmProvider vm) -> void vm_provider::VmProvider& vm) -> void
{ {
auto program = this->instructions; auto program = this->instructions;
vm.load_and_run(program); vm.load_and_run(program);
@ -13,12 +13,12 @@ auto sliger::rpc::action::RunDebug::perform_action(
auto sliger::rpc::action::FlameGraph::perform_action( auto sliger::rpc::action::FlameGraph::perform_action(
std::unique_ptr<sliger::rpc::BufferedWriter> writer, std::unique_ptr<sliger::rpc::BufferedWriter> writer,
vm_provider::VmProvider vm) -> void vm_provider::VmProvider& vm) -> void
{ {
auto json = vm.flame_graph_json(); auto json = vm.flame_graph_json();
if (json) { if (json) {
writer->write(std::format( writer->write(std::format(
"{{ \"ok\": true, \"flameGraph\": \"{}\" }}", json.value())); "{{ \"ok\": true, \"flameGraph\": {} }}", json.value()));
} else { } else {
writer->write("{ \"ok\": false }"); writer->write("{ \"ok\": false }");
} }
@ -27,12 +27,12 @@ auto sliger::rpc::action::FlameGraph::perform_action(
auto sliger::rpc::action::CodeCoverage::perform_action( auto sliger::rpc::action::CodeCoverage::perform_action(
std::unique_ptr<sliger::rpc::BufferedWriter> writer, std::unique_ptr<sliger::rpc::BufferedWriter> writer,
vm_provider::VmProvider vm) -> void vm_provider::VmProvider& vm) -> void
{ {
auto json = vm.code_coverage_json(); auto json = vm.code_coverage_json();
if (json) { if (json) {
writer->write(std::format( writer->write(std::format(
"{{ \"ok\": true, \"codeCoverage\": \"{}\" }}", json.value())); "{{ \"ok\": true, \"codeCoverage\": {} }}", json.value()));
} else { } else {
writer->write("{ \"ok\": false }"); writer->write("{ \"ok\": false }");
} }

View File

@ -7,7 +7,7 @@ namespace sliger::rpc::action {
struct Action { struct Action {
virtual auto perform_action( virtual auto perform_action(
std::unique_ptr<sliger::rpc::BufferedWriter> writer, std::unique_ptr<sliger::rpc::BufferedWriter> writer,
sliger::rpc::vm_provider::VmProvider vm_provider) -> void = 0; sliger::rpc::vm_provider::VmProvider& vm_provider) -> void = 0;
virtual ~Action() = default; virtual ~Action() = default;
}; };
@ -15,14 +15,14 @@ class FlameGraph : public Action {
public: public:
FlameGraph() { } FlameGraph() { }
auto perform_action(std::unique_ptr<sliger::rpc::BufferedWriter> writer, auto perform_action(std::unique_ptr<sliger::rpc::BufferedWriter> writer,
sliger::rpc::vm_provider::VmProvider vm_provider) -> void; sliger::rpc::vm_provider::VmProvider& vm_provider) -> void;
}; };
class CodeCoverage : public Action { class CodeCoverage : public Action {
public: public:
CodeCoverage() { } CodeCoverage() { }
auto perform_action(std::unique_ptr<sliger::rpc::BufferedWriter> writer, auto perform_action(std::unique_ptr<sliger::rpc::BufferedWriter> writer,
sliger::rpc::vm_provider::VmProvider vm_provider) -> void; sliger::rpc::vm_provider::VmProvider& vm_provider) -> void;
}; };
class RunDebug : public Action { class RunDebug : public Action {
@ -32,7 +32,7 @@ public:
{ {
} }
auto perform_action(std::unique_ptr<sliger::rpc::BufferedWriter> writer, auto perform_action(std::unique_ptr<sliger::rpc::BufferedWriter> writer,
sliger::rpc::vm_provider::VmProvider vm_provider) -> void; sliger::rpc::vm_provider::VmProvider& vm_provider) -> void;
private: private:
std::vector<uint32_t> instructions; std::vector<uint32_t> instructions;
@ -44,7 +44,7 @@ static auto action_from_json(
auto& obj = value->as<sliger::json::Object>(); auto& obj = value->as<sliger::json::Object>();
auto type = obj.fields.at("type")->as<sliger::json::String>(); auto type = obj.fields.at("type")->as<sliger::json::String>();
if (type.value == "flamegraph") { if (type.value == "flame-graph") {
auto action = FlameGraph(); auto action = FlameGraph();
return std::make_unique<FlameGraph>(action); return std::make_unique<FlameGraph>(action);
} }