First server executable

This commit is contained in:
2026-06-22 13:20:10 +03:00
parent ea99e81dbf
commit 6ff7c8a6cb
8 changed files with 245 additions and 0 deletions

34
helpers.h Normal file
View File

@@ -0,0 +1,34 @@
#ifndef HELPERS_H_
#define HELPERS_H_
#include <iostream>
#include <string>
#include <stdint.h>
#include "json.hpp"
// Reads configuration json from supplied filename
// cfg - output json
// filename - filepath from which to read json
// log - ostream to log human readable errors to - can be nullptr
// Returns - true if read and parse is successful
bool read_config_json(nlohmann::json& cfg, const std::string& filename, std::ostream* log);
// Reads configuration json from supplied istream
// cfg - output json
// in - istream from which to read json
// log - ostream to log human readable errors to - can be nullptr
// Returns - true if read and parse is successful
bool read_config_json(nlohmann::json& cfg, std::istream& in, std::ostream* log);
// JSON Extraction Helpers
// out value is modified only if an extraction happened
// Returns - whether an extraction happened
bool json_extract(const nlohmann::json& j, const std::string& key, std::string& out);
bool json_extract(const nlohmann::json& j, const std::string& key, int& out);
bool json_extract(const nlohmann::json& j, const std::string& key, bool& out);
bool json_extract(const nlohmann::json& j, const std::string& key, uint16_t& out);
#endif // HELPERS_H_