mirror of
https://github.com/XRPLF/clio.git
synced 2026-09-28 07:58:10 +00:00
Introduce rpcspec 0.1.3 dependency
This commit is contained in:
@@ -84,6 +84,9 @@ include(deps/cassandra)
|
||||
include(deps/libbacktrace)
|
||||
include(deps/spdlog)
|
||||
|
||||
include(deps/rpcspec)
|
||||
target_link_libraries(clio_options INTERFACE rpcspec::rpcspec)
|
||||
|
||||
add_subdirectory(src)
|
||||
add_subdirectory(tests)
|
||||
|
||||
|
||||
@@ -3,6 +3,7 @@
|
||||
"requires": [
|
||||
"zlib/1.3.2#1cb806da49011867778ffb6ac7190fcb%1782392402.122708",
|
||||
"xxhash/0.8.3#681d36a0a6111fc56e5e45ea182c19cc%1782392402.420688",
|
||||
"xrpl-rpc-spec/0.1.3#e0552b7fdcb26d9249498fa4273474f1%1786463175.210094",
|
||||
"xrpl/3.3.0-rc1-custom#cdfb12fc2671eaea72d5920bea800fd2%1785426802.141277",
|
||||
"sqlite3/3.53.0#324ada52333108388a9a6108bfa96734%1782392403.185447",
|
||||
"spdlog/1.17.0#bcbaaf7147bda6ad24ffbd1ac3d7142c%1782736610.443882",
|
||||
|
||||
@@ -17,6 +17,7 @@ class ClioConan(ConanFile):
|
||||
"fmt/12.1.0",
|
||||
"libbacktrace/cci.20210118",
|
||||
"spdlog/1.17.0",
|
||||
"xrpl-rpc-spec/0.1.3",
|
||||
"xrpl/3.3.0-rc1-custom",
|
||||
]
|
||||
|
||||
|
||||
@@ -1,58 +1,13 @@
|
||||
#pragma once
|
||||
|
||||
#include <boost/json/conversion.hpp>
|
||||
#include <boost/json/kind.hpp>
|
||||
#include <boost/json/value.hpp>
|
||||
#include <boost/json/value_to.hpp>
|
||||
|
||||
#include <stdexcept>
|
||||
#include <rpcspec/JsonBool.hpp>
|
||||
|
||||
namespace rpc {
|
||||
|
||||
/**
|
||||
* @brief A wrapper around bool that allows to convert from any JSON value
|
||||
*/
|
||||
struct JsonBool {
|
||||
bool value = false;
|
||||
|
||||
/** @cond */
|
||||
operator bool() const
|
||||
{
|
||||
return value;
|
||||
}
|
||||
/** @endcond */
|
||||
};
|
||||
|
||||
/**
|
||||
* @brief Convert a JSON value to a JsonBool
|
||||
* @brief A wrapper around bool that allows conversion from any JSON value.
|
||||
*
|
||||
* @param jsonValue The JSON value to convert
|
||||
* @return The converted JsonBool
|
||||
*/
|
||||
inline JsonBool
|
||||
tag_invoke(boost::json::value_to_tag<JsonBool> const&, boost::json::value const& jsonValue)
|
||||
{
|
||||
switch (jsonValue.kind()) {
|
||||
case boost::json::kind::null:
|
||||
return JsonBool{false};
|
||||
case boost::json::kind::bool_:
|
||||
return JsonBool{jsonValue.as_bool()};
|
||||
case boost::json::kind::uint64:
|
||||
[[fallthrough]];
|
||||
case boost::json::kind::int64:
|
||||
return JsonBool{jsonValue.as_int64() != 0};
|
||||
case boost::json::kind::double_:
|
||||
return JsonBool{jsonValue.as_double() != 0.0};
|
||||
case boost::json::kind::string:
|
||||
// Also should be `jsonValue.as_string() != "false"` but rippled doesn't do
|
||||
// that. Anyway for v2 api we have bool validation
|
||||
return JsonBool{!jsonValue.as_string().empty() && jsonValue.as_string()[0] != 0};
|
||||
case boost::json::kind::array:
|
||||
return JsonBool{!jsonValue.as_array().empty()};
|
||||
case boost::json::kind::object:
|
||||
return JsonBool{!jsonValue.as_object().empty()};
|
||||
}
|
||||
throw std::runtime_error("Invalid json value");
|
||||
}
|
||||
using JsonBool = spec::JsonBool;
|
||||
|
||||
} // namespace rpc
|
||||
|
||||
Reference in New Issue
Block a user