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

View File

@ -7,7 +7,7 @@ namespace sliger::rpc::action {
struct Action {
virtual auto perform_action(
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;
};
@ -15,14 +15,14 @@ class FlameGraph : public Action {
public:
FlameGraph() { }
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 {
public:
CodeCoverage() { }
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 {
@ -32,7 +32,7 @@ public:
{
}
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:
std::vector<uint32_t> instructions;
@ -44,7 +44,7 @@ static auto action_from_json(
auto& obj = value->as<sliger::json::Object>();
auto type = obj.fields.at("type")->as<sliger::json::String>();
if (type.value == "flamegraph") {
if (type.value == "flame-graph") {
auto action = FlameGraph();
return std::make_unique<FlameGraph>(action);
}