userver: userver/storages/secdist/helpers.hpp Source File
Loading...
Searching...
No Matches
helpers.hpp
1#pragma once
2
3#include <string>
4
5#include <userver/compiler/demangle.hpp>
6#include <userver/formats/json/value.hpp>
7
8USERVER_NAMESPACE_BEGIN
9
10namespace storages::secdist {
11
12[[noreturn]] void ThrowInvalidSecdistType(const formats::json::Value& val,
13 const std::string& type);
14
15std::string GetString(const formats::json::Value& parent_val,
16 const std::string& name);
17
18int GetInt(const formats::json::Value& parent_val, const std::string& name,
19 int dflt);
20
21template <typename T>
22T GetValue(const formats::json::Value& parent_val, const std::string& key,
23 const T& dflt) {
24 const auto& val = parent_val[key];
25 try {
26 return val.template As<T>(dflt);
27 } catch (const formats::json::TypeMismatchException&) {
28 ThrowInvalidSecdistType(val, compiler::GetTypeName<T>());
29 }
30}
31
32void CheckIsObject(const formats::json::Value& val, const std::string& name);
33
34void CheckIsArray(const formats::json::Value& val, const std::string& name);
35
36} // namespace storages::secdist
37
38USERVER_NAMESPACE_END