Initial project snapshot
This commit is contained in:
@@ -0,0 +1,53 @@
|
||||
#pragma once
|
||||
|
||||
#include <map>
|
||||
#include <optional>
|
||||
#include <string>
|
||||
#include <variant>
|
||||
#include <vector>
|
||||
|
||||
namespace rdp_worker::common {
|
||||
|
||||
struct JsonValue;
|
||||
|
||||
using JsonObject = std::map<std::string, JsonValue>;
|
||||
using JsonArray = std::vector<JsonValue>;
|
||||
|
||||
struct JsonValue {
|
||||
using Variant = std::variant<std::nullptr_t, bool, double, std::string, JsonArray, JsonObject>;
|
||||
|
||||
Variant value;
|
||||
|
||||
JsonValue();
|
||||
JsonValue(std::nullptr_t);
|
||||
JsonValue(bool input);
|
||||
JsonValue(double input);
|
||||
JsonValue(int input);
|
||||
JsonValue(const char* input);
|
||||
JsonValue(std::string input);
|
||||
JsonValue(JsonArray input);
|
||||
JsonValue(JsonObject input);
|
||||
|
||||
[[nodiscard]] bool IsObject() const;
|
||||
[[nodiscard]] bool IsArray() const;
|
||||
[[nodiscard]] bool IsString() const;
|
||||
[[nodiscard]] bool IsBool() const;
|
||||
[[nodiscard]] bool IsNumber() const;
|
||||
|
||||
[[nodiscard]] const JsonObject& AsObject() const;
|
||||
[[nodiscard]] const JsonArray& AsArray() const;
|
||||
[[nodiscard]] const std::string& AsString() const;
|
||||
[[nodiscard]] bool AsBool() const;
|
||||
[[nodiscard]] double AsNumber() const;
|
||||
};
|
||||
|
||||
JsonValue ParseJson(const std::string& input);
|
||||
std::string SerializeJson(const JsonValue& value);
|
||||
|
||||
std::optional<std::string> GetString(const JsonObject& object, const std::string& key);
|
||||
std::optional<bool> GetBool(const JsonObject& object, const std::string& key);
|
||||
std::optional<double> GetNumber(const JsonObject& object, const std::string& key);
|
||||
const JsonObject* GetObject(const JsonObject& object, const std::string& key);
|
||||
const JsonArray* GetArray(const JsonObject& object, const std::string& key);
|
||||
|
||||
} // namespace rdp_worker::common
|
||||
@@ -0,0 +1,31 @@
|
||||
#pragma once
|
||||
|
||||
#include <mutex>
|
||||
#include <string>
|
||||
|
||||
namespace rdp_worker::common {
|
||||
|
||||
enum class LogLevel {
|
||||
kDebug,
|
||||
kInfo,
|
||||
kWarn,
|
||||
kError
|
||||
};
|
||||
|
||||
class Logger {
|
||||
public:
|
||||
explicit Logger(std::string service_name);
|
||||
|
||||
void Debug(const std::string& message);
|
||||
void Info(const std::string& message);
|
||||
void Warn(const std::string& message);
|
||||
void Error(const std::string& message);
|
||||
|
||||
private:
|
||||
void Write(LogLevel level, const std::string& message);
|
||||
|
||||
std::string service_name_;
|
||||
std::mutex mutex_;
|
||||
};
|
||||
|
||||
} // namespace rdp_worker::common
|
||||
@@ -0,0 +1,14 @@
|
||||
#pragma once
|
||||
|
||||
#include <chrono>
|
||||
#include <string>
|
||||
|
||||
namespace rdp_worker::common {
|
||||
|
||||
using Clock = std::chrono::system_clock;
|
||||
|
||||
std::string ToRfc3339(Clock::time_point time_point);
|
||||
Clock::time_point NowUtc();
|
||||
Clock::time_point ParseRfc3339(const std::string& value);
|
||||
|
||||
} // namespace rdp_worker::common
|
||||
Reference in New Issue
Block a user