7#ifndef BOOST_REDIS_RESP3_SERIALIZATION_HPP
8#define BOOST_REDIS_RESP3_SERIALIZATION_HPP
10#include <boost/redis/resp3/type.hpp>
11#include <boost/system/system_error.hpp>
12#include <boost/throw_exception.hpp>
13#include <boost/redis/resp3/parser.hpp>
21namespace boost::redis::resp3 {
44template <class T, typename = typename std::enable_if<std::is_integral<T>::value>
::type>
45void boost_redis_to_bulk(std::string& payload, T n)
47 auto const s = std::to_string(n);
48 boost::redis::resp3::boost_redis_to_bulk(payload, std::string_view{s});
53 static void add(std::string& payload, T
const& from)
55 using namespace boost::redis::resp3;
56 boost_redis_to_bulk(payload, from);
61struct add_bulk_impl<std::tuple<Ts...>> {
62 static void add(std::string& payload, std::tuple<Ts...>
const& t)
64 auto f = [&](
auto const&... vs)
66 using namespace boost::redis::resp3;
67 (boost_redis_to_bulk(payload, vs), ...);
74template <
class U,
class V>
75struct add_bulk_impl<std::pair<U, V>> {
76 static void add(std::string& payload, std::pair<U, V>
const& from)
78 using namespace boost::redis::resp3;
79 boost_redis_to_bulk(payload, from.first);
80 boost_redis_to_bulk(payload, from.second);
84void add_header(std::string& payload,
type t, std::size_t size);
87void add_bulk(std::string& payload, T
const& data)
89 add_bulk_impl<T>::add(payload, data);
97 static constexpr auto size = 1U;
100template <
class T,
class U>
101struct bulk_counter<std::pair<T, U>> {
102 static constexpr auto size = 2U;
105void add_blob(std::string& payload, std::string_view blob);
106void add_separator(std::string& payload);
111template <
class Adapter>
112void deserialize(std::string_view
const& data, Adapter adapter, system::error_code& ec)
115 while (!parser.done()) {
116 auto const res = parser.consume(data, ec);
120 BOOST_ASSERT(res.has_value());
122 adapter(res.value(), ec);
127 BOOST_ASSERT(parser.get_consumed() == std::size(data));
130template <
class Adapter>
131void deserialize(std::string_view
const& data, Adapter adapter)
133 system::error_code ec;
134 deserialize(data, adapter, ec);
137 BOOST_THROW_EXCEPTION(system::system_error{ec});
void boost_redis_to_bulk(std::string &payload, std::string_view data)
Adds a bulk to the request.