diff --git a/serialization/json/CMakeLists.txt b/serialization/json/CMakeLists.txt new file mode 100644 index 0000000..25add92 --- /dev/null +++ b/serialization/json/CMakeLists.txt @@ -0,0 +1,18 @@ + +include(FetchContent) + +FetchContent_Declare(nlohmann_json + URL https://github.com/nlohmann/json/releases/download/v3.10.5/json.tar.xz + EXCLUDE_FROM_ALL + FIND_PACKAGE_ARGS NAMES nlohmann_json +) + +FetchContent_GetProperties(nlohmann_json) +FetchContent_MakeAvailable(nlohmann_json) + +add_executable(json_test json.cpp) +target_link_libraries(json_test + PUBLIC nlohmann_json::nlohmann_json +) + +configure_file(example.json ${CMAKE_CURRENT_BINARY_DIR}/example.json COPYONLY) \ No newline at end of file diff --git a/serialization/json/example.json b/serialization/json/example.json new file mode 100644 index 0000000..2e45565 --- /dev/null +++ b/serialization/json/example.json @@ -0,0 +1,8 @@ +{ + "command": "register", + "register": { + "game_name": "game_name", + "game_version": "game_version", + "token": "token" + } +} \ No newline at end of file diff --git a/serialization/json/json.cpp b/serialization/json/json.cpp new file mode 100644 index 0000000..f256151 --- /dev/null +++ b/serialization/json/json.cpp @@ -0,0 +1,26 @@ +#include +#include + +using json = nlohmann::json; + +int main(int argc, char const *argv[]) +{ + std::string game_name = "the_last_samurai"; + std::string game_version = "0.1.0"; + std::string token = "cc1e240aacb641fed0050d2c2f16db918b4a7c10"; + + json j = { + {"command", "register"}, + {"register", { + {"game_name", game_name}, + {"game_version", game_version}, + {"token", token}, + }} + }; + + std::string data_to_send = j.dump(); + + std::cout << j.dump(4) << std::endl; + + return 0; +}