Skip to content

Commit

Permalink
added simplified JSON syntax
Browse files Browse the repository at this point in the history
  • Loading branch information
mdorier committed Jul 5, 2024
1 parent 1fa5357 commit 59272e7
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 0 deletions.
29 changes: 29 additions & 0 deletions src/JsonUtil.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,35 @@ struct JsonValidator {

};

static inline void expandJson(const json& input, json& output) {
for (auto it = input.begin(); it != input.end(); ++it) {
std::istringstream key_stream(it.key());
std::string segment;
json* current = &output;

while (std::getline(key_stream, segment, '.')) {
if (!key_stream.eof()) {
if (current->find(segment) == current->end() || !(*current)[segment].is_object()) {
(*current)[segment] = json::object();
}
current = &(*current)[segment];
} else {
if (it.value().is_object()) {
expandJson(it.value(), (*current)[segment]);
} else {
(*current)[segment] = it.value();
}
}
}
}
}

static inline json expandSimplifiedJSON(const json& input) {
json output = json::object();
expandJson(input, output);
return output;
}

}

#endif
2 changes: 2 additions & 0 deletions src/Server.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
#include <bedrock/Exception.hpp>
#include "MargoLogging.hpp"
#include "ServerImpl.hpp"
#include "JsonUtil.hpp"
#include <spdlog/spdlog.h>
#include <fmt/format.h>
#include <fstream>
Expand Down Expand Up @@ -56,6 +57,7 @@ Server::Server(const std::string& address, const std::string& configString,
} else {
config = json::object();
}
config = expandSimplifiedJSON(config);
spdlog::trace("Parsing done");

// Extract margo section from the config
Expand Down
5 changes: 5 additions & 0 deletions tests/ValidConfigs.json
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,11 @@
"output": {"abt_io":[],"bedrock":{"pool":"__primary__","provider_id":0},"clients":[],"libraries":{"module_a":"./libModuleA.so"},"margo":{"argobots":{"abt_mem_max_num_stacks":8,"abt_thread_stacksize":2097152,"lazy_stack_alloc":false,"pools":[{"access":"mpmc","kind":"fifo_wait","name":"__primary__"}],"profiling_dir":".","xstreams":[{"name":"__primary__","scheduler":{"pools":["__primary__"],"type":"basic_wait"}}]},"enable_abt_profiling":false,"handle_cache_size":32,"progress_pool":"__primary__","progress_timeout_ub_msec":100,"rpc_pool":"__primary__"},"mona":[],"providers":[{"config":{},"dependencies":{},"name":"my_provider","pool":"__primary__","provider_id":123,"tags":[],"type":"module_a"}],"ssg":[]}
},

{
"test": "instantiate a provider from module-a with simplified syntax",
"input": {"libraries.module_a":"./libModuleA.so","providers":[{"name":"my_provider","provider_id":123,"tags":[],"type":"module_a"}]},
"output": {"abt_io":[],"bedrock":{"pool":"__primary__","provider_id":0},"clients":[],"libraries":{"module_a":"./libModuleA.so"},"margo":{"argobots":{"abt_mem_max_num_stacks":8,"abt_thread_stacksize":2097152,"lazy_stack_alloc":false,"pools":[{"access":"mpmc","kind":"fifo_wait","name":"__primary__"}],"profiling_dir":".","xstreams":[{"name":"__primary__","scheduler":{"pools":["__primary__"],"type":"basic_wait"}}]},"enable_abt_profiling":false,"handle_cache_size":32,"progress_pool":"__primary__","progress_timeout_ub_msec":100,"rpc_pool":"__primary__"},"mona":[],"providers":[{"config":{},"dependencies":{},"name":"my_provider","pool":"__primary__","provider_id":123,"tags":[],"type":"module_a"}],"ssg":[]}
},

{
"test": "instantiate a client from module-a",
Expand Down

0 comments on commit 59272e7

Please sign in to comment.