Skip to content

Commit 635b360

Browse files
committed
Removes unnecessary files.
1 parent a8a78c3 commit 635b360

File tree

5 files changed

+28
-84
lines changed

5 files changed

+28
-84
lines changed

CMakeLists.txt

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -111,10 +111,11 @@ set(examples_cpp20
111111
cpp20_streams
112112
cpp20_containers
113113
cpp20_echo_server
114-
cpp20_resolve_with_sentinel
115114
cpp20_json
116115
cpp20_subscriber
117-
cpp20_intro_tls)
116+
cpp20_intro_tls
117+
cpp20_resolve_with_sentinel
118+
)
118119

119120
if (Protobuf_FOUND)
120121
list(APPEND examples_cpp20 cpp20_protobuf)

examples/cpp20_json.cpp

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -7,24 +7,26 @@
77
#include <boost/redis/connection.hpp>
88
#include <boost/asio/deferred.hpp>
99
#include <boost/asio/detached.hpp>
10-
#include <boost/asio/co_spawn.hpp>
1110
#include <boost/describe.hpp>
1211
#include <boost/asio/consign.hpp>
12+
#include <boost/asio/use_awaitable.hpp>
1313
#include <string>
1414
#include <iostream>
1515

1616
#if defined(BOOST_ASIO_HAS_CO_AWAIT)
1717

1818
#define BOOST_JSON_NO_LIB
1919
#define BOOST_CONTAINER_NO_LIB
20-
#include "json.hpp"
20+
#include <boost/json/serialize.hpp>
21+
#include <boost/json/parse.hpp>
22+
#include <boost/json/value_from.hpp>
23+
#include <boost/redis/resp3/serialization.hpp>
2124
#include <boost/json/src.hpp>
2225

2326
namespace net = boost::asio;
2427
using namespace boost::describe;
2528
using boost::redis::request;
2629
using boost::redis::response;
27-
using boost::redis::operation;
2830
using boost::redis::ignore_t;
2931
using boost::redis::config;
3032
using connection = net::deferred_t::as_default_on_t<boost::redis::connection>;
@@ -41,10 +43,10 @@ BOOST_DESCRIBE_STRUCT(user, (), (name, age, country))
4143

4244
// Boost.Redis customization points (examples/json.hpp)
4345
void boost_redis_to_bulk(std::string& to, user const& u)
44-
{ boost::redis::json::to_bulk(to, u); }
46+
{ boost::redis::resp3::boost_redis_to_bulk(to, boost::json::serialize(boost::json::value_from(u))); }
4547

46-
void boost_redis_from_bulk(user& u, std::string_view sv, boost::system::error_code& ec)
47-
{ boost::redis::json::from_bulk(u, sv, ec); }
48+
void boost_redis_from_bulk(user& u, std::string_view sv, boost::system::error_code&)
49+
{ u = boost::json::value_to<user>(boost::json::parse(sv)); }
4850

4951
auto co_main(config cfg) -> net::awaitable<void>
5052
{

examples/cpp20_protobuf.cpp

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,13 @@
55
*/
66

77
#include <boost/redis/connection.hpp>
8+
#include <boost/redis/resp3/serialization.hpp>
89
#include <boost/asio/deferred.hpp>
910
#include <boost/asio/co_spawn.hpp>
1011
#include <boost/asio/detached.hpp>
1112
#include <boost/asio/consign.hpp>
13+
#include <boost/system/errc.hpp>
1214
#include <iostream>
13-
#include "protobuf.hpp"
1415

1516
// See the definition in person.proto. This header is automatically
1617
// generated by CMakeLists.txt.
@@ -33,11 +34,24 @@ using tutorial::person;
3334
namespace tutorial
3435
{
3536

37+
// Below I am using a Boost.Redis to indicate a protobuf error, this
38+
// is ok for an example, users however might want to define their own
39+
// error codes.
3640
void boost_redis_to_bulk(std::string& to, person const& u)
37-
{ boost::redis::protobuf::to_bulk(to, u); }
41+
{
42+
std::string tmp;
43+
if (!u.SerializeToString(&tmp))
44+
throw boost::system::system_error(boost::redis::error::invalid_data_type);
45+
46+
boost::redis::resp3::boost_redis_to_bulk(to, tmp);
47+
}
3848

3949
void boost_redis_from_bulk(person& u, std::string_view sv, boost::system::error_code& ec)
40-
{ boost::redis::protobuf::from_bulk(u, sv, ec); }
50+
{
51+
std::string const tmp {sv};
52+
if (!u.ParseFromString(tmp))
53+
ec = boost::redis::error::invalid_data_type;
54+
}
4155

4256
} // tutorial
4357

examples/json.hpp

Lines changed: 0 additions & 33 deletions
This file was deleted.

examples/protobuf.hpp

Lines changed: 0 additions & 40 deletions
This file was deleted.

0 commit comments

Comments
 (0)