Add nlohmann json

This commit is contained in:
momo5502
2025-04-23 15:30:36 +02:00
parent 1beb95c2b2
commit 6a302aff69
5 changed files with 33 additions and 5 deletions

4
.gitmodules vendored
View File

@@ -18,3 +18,7 @@
[submodule "deps/gtest-parallel"]
path = deps/gtest-parallel
url = https://github.com/google/gtest-parallel.git
[submodule "deps/json"]
path = deps/json
url = https://github.com/nlohmann/json.git
branch = master

4
deps/CMakeLists.txt vendored
View File

@@ -3,6 +3,10 @@ add_subdirectory(unicorn)
##########################################
add_subdirectory(json)
##########################################
add_library(reflect INTERFACE)
target_include_directories(reflect INTERFACE
"${CMAKE_CURRENT_LIST_DIR}/reflect"

1
deps/json vendored Submodule

Submodule deps/json added at 55f93686c0

View File

@@ -16,6 +16,7 @@ endif()
target_link_libraries(debugger PRIVATE
windows-emulator
nlohmann_json
)
set_property(GLOBAL PROPERTY VS_STARTUP_PROJECT debugger)

View File

@@ -2,6 +2,7 @@
#include <windows_emulator.hpp>
#include <cstdio>
#include <nlohmann/json.hpp>
#ifdef OS_EMSCRIPTEN
#include <emscripten.h>
@@ -73,18 +74,35 @@ namespace
#endif
}
void handle_messages()
void send_object(const nlohmann::json& json)
{
const std::string res = json.dump();
send_message(res);
}
nlohmann::json receive_object()
{
auto message = receive_message();
if (message.empty())
{
return {};
}
return nlohmann::json::parse(message);
}
void handle_messages(windows_emulator& win_emu)
{
while (true)
{
suspend_execution(0ms);
const auto message = receive_message();
if (message.empty())
const auto message = receive_object();
if (message.is_null())
{
break;
}
puts(message.c_str());
puts(message.dump().c_str());
}
}
@@ -144,7 +162,7 @@ namespace
windows_emulator win_emu{app_settings, settings};
win_emu.callbacks.on_thread_switch = [&] {
handle_messages(); //
handle_messages(win_emu); //
};
return run_emulation(win_emu);