26#ifndef ROUTER_SRC_REST_MRS_SRC_HELPER_JSON_TEXT_TO_H_
27#define ROUTER_SRC_REST_MRS_SRC_HELPER_JSON_TEXT_TO_H_
32#include <rapidjson/document.h>
33#include <rapidjson/memorystream.h>
34#include <rapidjson/reader.h>
54template <
typename Handler,
typename Container>
62 rapidjson::MemoryStream memory_stream{
63 reinterpret_cast<const char *
>(&*c.begin()), c.size()};
64 rapidjson::Reader read;
66 return !read.Parse<Handler::k_parse_flags>(memory_stream, *
handler).IsError();
69template <
typename Container>
70bool text_to(rapidjson::Document *doc,
const Container &c) {
77 doc->Parse(
reinterpret_cast<const char *
>(&*c.begin()), c.size());
78 return !doc->HasParseError();
81inline bool text_to(rapidjson::Document *doc,
const std::string &
str) {
82 doc->Parse(
str.c_str());
83 return !doc->HasParseError();
86inline bool text_to(rapidjson::Document *doc,
const char *
str) {
88 return !doc->HasParseError();
92 rapidjson::Document doc;
95 if (!doc.IsObject())
return false;
97 *obj = doc.GetObject();
102inline bool text_to(rapidjson::Value *val,
const std::string &
str) {
103 rapidjson::Document doc;
106 if (!doc.IsObject())
return false;
108 *val = doc.GetObject();
128template <
typename Handler,
typename Container,
typename... HandlerArgs>
130 HandlerArgs &&...args) {
131 Handler
handler(std::forward<HandlerArgs>(args)...);
133 text_to<Handler, Container>(&
handler, c);
139 rapidjson::Document
result;
The handler class is the interface for dynamically loadable storage engines.
Definition: handler.h:4618
Define rapidjson::SizeType to be std::uint64_t.
std::string str(const mysqlrouter::ConfigGenerator::Options::Endpoint &ep)
Definition: config_generator.cc:1084
MysqlCacheManager::Object Object
Definition: mysql_cache_manager.cc:101
Handler::Result text_to_handler(const Container &c, HandlerArgs &&...args)
Convert text representation of json object/value to type defined by 'Handler'.
Definition: text_to.h:129
bool text_to(Handler *handler, const Container &c)
Convert text representation of json object/value to type defined by 'Handler'.
Definition: text_to.h:55
rapidjson::Document text_to_document(const std::string &str)
Definition: text_to.h:138
ValueType value(const std::optional< ValueType > &v)
Definition: gtid.h:83
Result
Definition: result.h:34
struct result result
Definition: result.h:34