Files
scylladb/utils/managed_bytes.cc
Kefu Chai 59579d5876 utils: fragment_range: specialize fmt::formatter<FragmentedView>
this is a part of a series to migrating from `operator<<(ostream&, ..)`
based formatting to fmtlib based formatting. the goal here is to enable
fmtlib to print classes fulfill the requirement of `FragmentedView` concept
without the help of template function of `to_hex()`, this function is
dropped in this change, as all its callers are now using fmtlib
for formatting now. the helper of `fragment_to_hex()` is dropped
as well, its only caller is `to_hex()`.

Refs scylladb#13245

Signed-off-by: Kefu Chai <kefu.chai@scylladb.com>

Closes #13471
2023-04-11 16:09:38 +03:00

39 lines
792 B
C++

/*
* Copyright 2015-present ScyllaDB
*/
/*
* SPDX-License-Identifier: AGPL-3.0-or-later
*/
#include "managed_bytes.hh"
std::unique_ptr<bytes_view::value_type[]>
managed_bytes::do_linearize_pure() const {
auto b = _u.ptr;
auto data = std::unique_ptr<bytes_view::value_type[]>(new bytes_view::value_type[b->size]);
auto e = data.get();
while (b) {
e = std::copy_n(b->data, b->frag_size, e);
b = b->next;
}
return data;
}
sstring to_hex(const managed_bytes& b) {
return fmt::to_string(managed_bytes_view(b));
}
sstring to_hex(const managed_bytes_opt& b) {
return !b ? "null" : to_hex(*b);
}
std::ostream& operator<<(std::ostream& os, const managed_bytes_opt& b) {
if (b) {
return os << *b;
}
return os << "null";
}