diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 7ccf47e8..3fe46a04 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -67,8 +67,8 @@ jobs: platform_version: ${{env.BOOST_PLATFORM_VERSION}} arch: null - - name: Install packages - run: cinst openssl + - name: Install openssl + run: choco install openssl - name: Create build directory run: mkdir build diff --git a/CMakeLists.txt b/CMakeLists.txt index 43938a63..1ba1d657 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -111,10 +111,11 @@ set(examples_cpp20 cpp20_streams cpp20_containers cpp20_echo_server - cpp20_resolve_with_sentinel cpp20_json cpp20_subscriber - cpp20_intro_tls) + cpp20_intro_tls + cpp20_resolve_with_sentinel +) if (Protobuf_FOUND) list(APPEND examples_cpp20 cpp20_protobuf) diff --git a/examples/cpp20_json.cpp b/examples/cpp20_json.cpp index 68c0879f..063614b1 100644 --- a/examples/cpp20_json.cpp +++ b/examples/cpp20_json.cpp @@ -7,9 +7,9 @@ #include #include #include -#include #include #include +#include #include #include @@ -17,14 +17,16 @@ #define BOOST_JSON_NO_LIB #define BOOST_CONTAINER_NO_LIB -#include "json.hpp" +#include +#include +#include +#include #include namespace net = boost::asio; using namespace boost::describe; using boost::redis::request; using boost::redis::response; -using boost::redis::operation; using boost::redis::ignore_t; using boost::redis::config; using connection = net::deferred_t::as_default_on_t; @@ -41,10 +43,10 @@ BOOST_DESCRIBE_STRUCT(user, (), (name, age, country)) // Boost.Redis customization points (examples/json.hpp) void boost_redis_to_bulk(std::string& to, user const& u) - { boost::redis::json::to_bulk(to, u); } + { boost::redis::resp3::boost_redis_to_bulk(to, boost::json::serialize(boost::json::value_from(u))); } -void boost_redis_from_bulk(user& u, std::string_view sv, boost::system::error_code& ec) - { boost::redis::json::from_bulk(u, sv, ec); } +void boost_redis_from_bulk(user& u, std::string_view sv, boost::system::error_code&) + { u = boost::json::value_to(boost::json::parse(sv)); } auto co_main(config cfg) -> net::awaitable { diff --git a/examples/cpp20_protobuf.cpp b/examples/cpp20_protobuf.cpp index d372798f..32e92396 100644 --- a/examples/cpp20_protobuf.cpp +++ b/examples/cpp20_protobuf.cpp @@ -5,12 +5,13 @@ */ #include +#include #include #include #include #include +#include #include -#include "protobuf.hpp" // See the definition in person.proto. This header is automatically // generated by CMakeLists.txt. @@ -33,11 +34,24 @@ using tutorial::person; namespace tutorial { +// Below I am using a Boost.Redis to indicate a protobuf error, this +// is ok for an example, users however might want to define their own +// error codes. void boost_redis_to_bulk(std::string& to, person const& u) - { boost::redis::protobuf::to_bulk(to, u); } +{ + std::string tmp; + if (!u.SerializeToString(&tmp)) + throw boost::system::system_error(boost::redis::error::invalid_data_type); + + boost::redis::resp3::boost_redis_to_bulk(to, tmp); +} void boost_redis_from_bulk(person& u, std::string_view sv, boost::system::error_code& ec) - { boost::redis::protobuf::from_bulk(u, sv, ec); } +{ + std::string const tmp {sv}; + if (!u.ParseFromString(tmp)) + ec = boost::redis::error::invalid_data_type; +} } // tutorial diff --git a/examples/json.hpp b/examples/json.hpp deleted file mode 100644 index ca7e26f8..00000000 --- a/examples/json.hpp +++ /dev/null @@ -1,33 +0,0 @@ -/* Copyright (c) 2018-2022 Marcelo Zimbres Silva (mzimbres@gmail.com) - * - * Distributed under the Boost Software License, Version 1.0. (See - * accompanying file LICENSE.txt) - */ - -#ifndef BOOST_REDIS_JSON_HPP -#define BOOST_REDIS_JSON_HPP - -#include -#include -#include -#include - -namespace boost::redis::json -{ - -template -void to_bulk(std::string& to, T const& u) -{ - redis::resp3::boost_redis_to_bulk(to, boost::json::serialize(boost::json::value_from(u))); -} - -template -void from_bulk(T& u, std::string_view sv, system::error_code&) -{ - auto const jv = boost::json::parse(sv); - u = boost::json::value_to(jv); -} - -} // boost::redis::json - -#endif // BOOST_REDIS_JSON_HPP diff --git a/examples/protobuf.hpp b/examples/protobuf.hpp deleted file mode 100644 index b1ba1231..00000000 --- a/examples/protobuf.hpp +++ /dev/null @@ -1,40 +0,0 @@ -/* Copyright (c) 2018-2022 Marcelo Zimbres Silva (mzimbres@gmail.com) - * - * Distributed under the Boost Software License, Version 1.0. (See - * accompanying file LICENSE.txt) - */ - -#ifndef BOOST_REDIS_PROTOBUF_HPP -#define BOOST_REDIS_PROTOBUF_HPP - -#include -#include - -namespace boost::redis::protobuf -{ - -// Below I am using a Boost.Redis to indicate a protobuf error, this -// is ok for an example, users however might want to define their own -// error codes. - -template -void to_bulk(std::string& to, T const& u) -{ - std::string tmp; - if (!u.SerializeToString(&tmp)) - throw system::system_error(redis::error::invalid_data_type); - - boost::redis::resp3::boost_redis_to_bulk(to, tmp); -} - -template -void from_bulk(T& u, std::string_view sv, system::error_code& ec) -{ - std::string const tmp {sv}; - if (!u.ParseFromString(tmp)) - ec = redis::error::invalid_data_type; -} - -} // boost::redis::json - -#endif // BOOST_REDIS_PROTOBUF_HPP