1 #ifndef PROTOCOL_GET_OR_THROW_H_
2 #define PROTOCOL_GET_OR_THROW_H_
4 #include <ripple/basics/Buffer.h>
5 #include <ripple/basics/StringUtilities.h>
6 #include <ripple/basics/contract.h>
7 #include <ripple/json/json_value.h>
8 #include <ripple/protocol/SField.h>
18 char const*
const key;
24 what() const noexcept
override
36 char const*
const key;
44 what() const noexcept
override
59 static_assert(
sizeof(T) == -1,
"This function must be specialized");
69 Throw<JsonMissingKeyError>(key);
73 Throw<JsonTypeMismatchError>(key,
"string");
85 Throw<JsonMissingKeyError>(key);
90 Throw<JsonTypeMismatchError>(key,
"bool");
92 return inner.
asInt() != 0;
102 Throw<JsonMissingKeyError>(key);
108 auto const r = inner.
asInt();
110 Throw<JsonTypeMismatchError>(key,
"uint64");
119 auto [p, ec] =
std::from_chars(s.data(), s.data() + s.size(), val, 16);
121 if (ec !=
std::errc() || (p != s.data() + s.size()))
122 Throw<JsonTypeMismatchError>(key,
"uint64");
125 Throw<JsonTypeMismatchError>(key,
"uint64");
139 Throw<JsonTypeMismatchError>(
field.getJsonName(),
"Buffer");
149 return getOrThrow<T>(v, field);
159 #endif // PROTOCOL_GET_OR_THROW_H_
JsonMissingKeyError(Json::StaticString const &k)
const char * what() const noexcept override
ripple::AccountID getOrThrow(Json::Value const &v, ripple::SField const &field)
Like std::vector<char> but better.
constexpr const char * c_str() const
const std::string expectedType
JSON (JavaScript Object Notation).
const char * what() const noexcept override
std::uint8_t const * data() const noexcept
Return a pointer to beginning of the storage.
bool isMember(const char *key) const
Return true if the object has a member named key.
JsonTypeMismatchError(Json::StaticString const &k, std::string et)
field_t< CharT, Traits, Allocator > field(std::basic_string< CharT, Traits, Allocator > const &text, int width=8, int pad=0, bool right=false)
Use hash_* containers for keys that do not need a cryptographically secure hashing algorithm.
Lightweight wrapper to tag static string.
std::optional< T > getOptional(Json::Value const &v, ripple::SField const &field)
std::optional< Blob > strUnHex(std::size_t strSize, Iterator begin, Iterator end)
std::string asString() const
Returns the unquoted string value.