Boost.Redis: include/boost/redis/adapter/result.hpp Source File

Boost.Redis 1.84.0 A redis client library

Loading...
Searching...
No Matches
result.hpp
1
2/* Copyright (c) 2018-2024 Marcelo Zimbres Silva (mzimbres@gmail.com)
3 *
4 * Distributed under the Boost Software License, Version 1.0. (See
5 * accompanying file LICENSE.txt)
6 */
7
8#ifndef BOOST_REDIS_ADAPTER_RESULT_HPP
9#define BOOST_REDIS_ADAPTER_RESULT_HPP
10
11#include <boost/redis/resp3/type.hpp>
12#include <boost/redis/error.hpp>
13#include <boost/system/result.hpp>
14#include <string>
15
16namespace boost::redis::adapter
17{
18
22 struct error {
24 resp3::type data_type = resp3::type::invalid;
25
27 std::string diagnostic;
28};
29
36 inline bool operator==(error const& a, error const& b)
37{
38 return a.data_type == b.data_type && a.diagnostic == b.diagnostic;
39}
40
47 inline bool operator!=(error const& a, error const& b)
48{
49 return !(a == b);
50}
51
55template <class Value>
56 using result = system::result<Value, error>;
57
58BOOST_NORETURN inline void
59throw_exception_from_error(error const & e, boost::source_location const &)
60{
61 system::error_code ec;
62 switch (e.data_type) {
63 case resp3::type::simple_error:
64 ec = redis::error::resp3_simple_error;
65 break;
66 case resp3::type::blob_error:
67 ec = redis::error::resp3_blob_error;
68 break;
69 case resp3::type::null:
70 ec = redis::error::resp3_null;
71 break;
72 default:
73 BOOST_ASSERT_MSG(false, "Unexpected data type.");
74 }
75
76 throw system::system_error(ec, e.diagnostic);
77}
78
79} // boost::redis::adapter
80
81#endif // BOOST_REDIS_ADAPTER_RESULT_HPP
boost::redis::resp3::type
type
RESP3 data types.
Definition type.hpp:23
boost::redis::adapter::result
system::result< Value, error > result
Stores response to individual Redis commands.
Definition result.hpp:56
boost::redis::resp3::type::null
@ null
Simple.
boost::redis::resp3::type::simple_error
@ simple_error
Simple.
boost::redis::resp3::type::blob_error
@ blob_error
Simple.
boost::redis::resp3::type::invalid
@ invalid
Invalid.
boost::redis::error::resp3_blob_error
@ resp3_blob_error
Got RESP3 blob_error.
boost::redis::error::resp3_null
@ resp3_null
Got RESP3 null.
boost::redis::error::resp3_simple_error
@ resp3_simple_error
Got RESP3 simple error.
boost::redis::adapter::error
Stores any resp3 error.
Definition result.hpp:22
boost::redis::adapter::error::data_type
resp3::type data_type
RESP3 error data type.
Definition result.hpp:24
boost::redis::adapter::error::operator!=
bool operator!=(error const &a, error const &b)
Compares two error objects for difference.
Definition result.hpp:47
boost::redis::adapter::error::operator==
bool operator==(error const &a, error const &b)
Compares two error objects for equality.
Definition result.hpp:36
boost::redis::adapter::error::diagnostic
std::string diagnostic
Diagnostic error message sent by Redis.
Definition result.hpp:27