Skip to content

Commit 4b07b6d

Browse files
committed
Prefix to_ and from_bulk with boost_redis_ (boost review).
1 parent c1ce835 commit 4b07b6d

File tree

4 files changed

+38
-33
lines changed

4 files changed

+38
-33
lines changed

README.md

Lines changed: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -303,21 +303,21 @@ Sending a request to Redis is performed with `boost::redis::connection::async_ex
303303
304304
The `resp3::request::push` and `resp3::request::push_range` member functions work
305305
with integer data types e.g. `int` and `std::string` out of the box.
306-
To send your own data type define a `to_bulk` function like this
306+
To send your own data type define a `boost_redis_to_bulk` function like this
307307
308308
```cpp
309309
// User defined type.
310310
struct mystruct {...};
311311
312-
// Serialize it in to_bulk.
313-
void to_bulk(std::pmr::string& to, mystruct const& obj)
312+
// Serialize it in boost_redis_to_bulk.
313+
void boost_redis_to_bulk(std::pmr::string& to, mystruct const& obj)
314314
{
315315
std::string dummy = "Dummy serializaiton string.";
316-
boost::redis::resp3::to_bulk(to, dummy);
316+
boost::redis::resp3::boost_redis_to_bulk(to, dummy);
317317
}
318318
```
319319

320-
Once `to_bulk` is defined and visible over ADL `mystruct` can
320+
Once `boost_redis_to_bulk` is defined and visible over ADL `mystruct` can
321321
be passed to the `request`
322322

323323
```cpp
@@ -535,11 +535,11 @@ As mentioned in the serialization section, it is common practice to
535535
serialize data before sending it to Redis e.g. as json strings. For
536536
performance and convenience reasons, we may also want to deserialize
537537
responses directly in their final data structure. Boost.Redis supports this
538-
use case by calling a user provided `from_bulk` function while parsing
538+
use case by calling a user provided `boost_redis_from_bulk` function while parsing
539539
the response. For example
540540
541541
```cpp
542-
void from_bulk(mystruct& obj, char const* p, std::size_t size, boost::system::error_code& ec)
542+
void boost_redis_from_bulk(mystruct& obj, char const* p, std::size_t size, boost::system::error_code& ec)
543543
{
544544
// Deserializes p into obj.
545545
}
@@ -600,7 +600,7 @@ from Redis with `HGETALL`, some of the options are
600600
* `std::vector<node<std::string>`: Works always.
601601
* `std::vector<std::string>`: Efficient and flat, all elements as string.
602602
* `std::map<std::string, std::string>`: Efficient if you need the data as a `std::map`.
603-
* `std::map<U, V>`: Efficient if you are storing serialized data. Avoids temporaries and requires `from_bulk` for `U` and `V`.
603+
* `std::map<U, V>`: Efficient if you are storing serialized data. Avoids temporaries and requires `boost_redis_from_bulk` for `U` and `V`.
604604

605605
In addition to the above users can also use unordered versions of the
606606
containers. The same reasoning applies to sets e.g. `SMEMBERS`
@@ -863,6 +863,12 @@ Acknowledgement to people that helped shape Boost.Redis
863863

864864
## Changelog
865865

866+
### master
867+
868+
* Renames the project to Boost.Redis and moves the code into namespace `boost::redis`.
869+
* As pointed out in the reviews `to_buld` and `from_buld` were too generic
870+
for ADL customization. They gained the prefix `boost_redis_`.
871+
866872
### v1.4.0-1
867873

868874
* Renames `retry_on_connection_lost` to `cancel_if_unresponded`. (v1.4.1)

examples/cpp20_serialization.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -76,12 +76,12 @@ auto tag_invoke(value_to_tag<user>, value const& jv)
7676
}
7777

7878
// Serialization
79-
void to_bulk(std::string& to, user const& u)
79+
void boost_redis_to_bulk(std::string& to, user const& u)
8080
{
81-
redis::resp3::to_bulk(to, serialize(value_from(u)));
81+
redis::resp3::boost_redis_to_bulk(to, serialize(value_from(u)));
8282
}
8383

84-
void from_bulk(user& u, std::string_view sv, boost::system::error_code&)
84+
void boost_redis_from_bulk(user& u, std::string_view sv, boost::system::error_code&)
8585
{
8686
value jv = parse(sv);
8787
u = value_to<user>(jv);

include/boost/redis/adapter/detail/adapters.hpp

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -33,21 +33,21 @@ namespace boost::redis::adapter::detail {
3333
// Serialization.
3434

3535
template <class T>
36-
auto from_bulk(T& i, std::string_view sv, system::error_code& ec) -> typename std::enable_if<std::is_integral<T>::value, void>::type
36+
auto boost_redis_from_bulk(T& i, std::string_view sv, system::error_code& ec) -> typename std::enable_if<std::is_integral<T>::value, void>::type
3737
{
3838
auto const res = std::from_chars(sv.data(), sv.data() + std::size(sv), i);
3939
if (res.ec != std::errc())
4040
ec = error::not_a_number;
4141
}
4242

4343
inline
44-
void from_bulk(bool& t, std::string_view sv, system::error_code&)
44+
void boost_redis_from_bulk(bool& t, std::string_view sv, system::error_code&)
4545
{
4646
t = *sv.data() == 't';
4747
}
4848

4949
inline
50-
void from_bulk(double& d, std::string_view sv, system::error_code& ec)
50+
void boost_redis_from_bulk(double& d, std::string_view sv, system::error_code& ec)
5151
{
5252
auto const res = std::from_chars(sv.data(), sv.data() + std::size(sv), d);
5353
if (res.ec != std::errc())
@@ -56,7 +56,7 @@ void from_bulk(double& d, std::string_view sv, system::error_code& ec)
5656

5757
template <class CharT, class Traits, class Allocator>
5858
void
59-
from_bulk(
59+
boost_redis_from_bulk(
6060
std::basic_string<CharT, Traits, Allocator>& s,
6161
std::string_view sv,
6262
system::error_code&)
@@ -128,7 +128,7 @@ class simple_impl {
128128
return;
129129
}
130130

131-
from_bulk(result, n.value, ec);
131+
boost_redis_from_bulk(result, n.value, ec);
132132
}
133133
};
134134

@@ -165,7 +165,7 @@ class set_impl {
165165
}
166166

167167
typename Result::key_type obj;
168-
from_bulk(obj, nd.value, ec);
168+
boost_redis_from_bulk(obj, nd.value, ec);
169169
hint_ = result.insert(hint_, std::move(obj));
170170
}
171171
};
@@ -205,11 +205,11 @@ class map_impl {
205205

206206
if (on_key_) {
207207
typename Result::key_type obj;
208-
from_bulk(obj, nd.value, ec);
208+
boost_redis_from_bulk(obj, nd.value, ec);
209209
current_ = result.insert(current_, {std::move(obj), {}});
210210
} else {
211211
typename Result::mapped_type obj;
212-
from_bulk(obj, nd.value, ec);
212+
boost_redis_from_bulk(obj, nd.value, ec);
213213
current_->second = std::move(obj);
214214
}
215215

@@ -237,7 +237,7 @@ class vector_impl {
237237
result.reserve(result.size() + m * nd.aggregate_size);
238238
} else {
239239
result.push_back({});
240-
from_bulk(result.back(), nd.value, ec);
240+
boost_redis_from_bulk(result.back(), nd.value, ec);
241241
}
242242
}
243243
};
@@ -277,7 +277,7 @@ class array_impl {
277277
}
278278

279279
BOOST_ASSERT(nd.aggregate_size == 1);
280-
from_bulk(result.at(i_), nd.value, ec);
280+
boost_redis_from_bulk(result.at(i_), nd.value, ec);
281281
}
282282

283283
++i_;
@@ -307,7 +307,7 @@ struct list_impl {
307307
}
308308

309309
result.push_back({});
310-
from_bulk(result.back(), nd.value, ec);
310+
boost_redis_from_bulk(result.back(), nd.value, ec);
311311
}
312312
}
313313
};

include/boost/redis/resp3/request.hpp

Lines changed: 10 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@
1919
// the value type is a pair.
2020

2121
namespace boost::redis::resp3 {
22-
2322
constexpr char const* separator = "\r\n";
2423

2524
/** @brief Adds a bulk to the request.
@@ -29,10 +28,10 @@ constexpr char const* separator = "\r\n";
2928
* structures in a request. For example
3029
*
3130
* @code
32-
* void to_bulk(std::string& to, mystruct const& obj)
31+
* void boost_redis_to_bulk(std::string& to, mystruct const& obj)
3332
* {
3433
* auto const str = // Convert obj to a string.
35-
* resp3::to_bulk(to, str);
34+
* boost_redis_to_bulk(to, str);
3635
* }
3736
* @endcode
3837
*
@@ -42,7 +41,7 @@ constexpr char const* separator = "\r\n";
4241
* See more in @ref serialization.
4342
*/
4443
template <class Request>
45-
void to_bulk(Request& to, std::string_view data)
44+
void boost_redis_to_bulk(Request& to, std::string_view data)
4645
{
4746
auto const str = std::to_string(data.size());
4847

@@ -54,10 +53,10 @@ void to_bulk(Request& to, std::string_view data)
5453
}
5554

5655
template <class Request, class T, typename = typename std::enable_if<std::is_integral<T>::value>::type>
57-
void to_bulk(Request& to, T n)
56+
void boost_redis_to_bulk(Request& to, T n)
5857
{
5958
auto const s = std::to_string(n);
60-
to_bulk(to, std::string_view{s});
59+
boost_redis_to_bulk(to, std::string_view{s});
6160
}
6261

6362
namespace detail {
@@ -70,7 +69,7 @@ struct add_bulk_impl {
7069
static void add(Request& to, T const& from)
7170
{
7271
using namespace boost::redis::resp3;
73-
to_bulk(to, from);
72+
boost_redis_to_bulk(to, from);
7473
}
7574
};
7675

@@ -82,7 +81,7 @@ struct add_bulk_impl<std::tuple<Ts...>> {
8281
auto f = [&](auto const&... vs)
8382
{
8483
using namespace boost::redis::resp3;
85-
(to_bulk(to, vs), ...);
84+
(boost_redis_to_bulk(to, vs), ...);
8685
};
8786

8887
std::apply(f, t);
@@ -95,8 +94,8 @@ struct add_bulk_impl<std::pair<U, V>> {
9594
static void add(Request& to, std::pair<U, V> const& from)
9695
{
9796
using namespace boost::redis::resp3;
98-
to_bulk(to, from.first);
99-
to_bulk(to, from.second);
97+
boost_redis_to_bulk(to, from.first);
98+
boost_redis_to_bulk(to, from.second);
10099
}
101100
};
102101

@@ -162,7 +161,7 @@ void add_separator(Request& to)
162161
* \remarks
163162
*
164163
* \li Non-string types will be converted to string by using \c
165-
* to_bulk, which must be made available over ADL.
164+
* boost_redis_to_bulk, which must be made available over ADL.
166165
* \li Uses a std::string for internal storage.
167166
*/
168167
class request {

0 commit comments

Comments
 (0)