Some methods of managed_bytes contain the logic needed to read/write the
contents of managed_bytes, even though this logic is already present in
managed_bytes_{,mutable}_view.
Reimplementing those methods by using the views as intermediates allows us to
remove some code and makes the responsibilities cleaner -- after the change,
managed_bytes contains the logic of allocating and freeing the storage,
while views provide read/write access to the storage.
This change will simplify the next patch which changes the internals of
managed_bytes.
44 lines
797 B
C++
44 lines
797 B
C++
|
|
/*
|
|
* Copyright 2015-present ScyllaDB
|
|
*/
|
|
|
|
/*
|
|
* SPDX-License-Identifier: AGPL-3.0-or-later
|
|
*/
|
|
|
|
|
|
#include "managed_bytes.hh"
|
|
|
|
bytes_opt
|
|
to_bytes_opt(const managed_bytes_opt& mbo) {
|
|
if (!mbo) {
|
|
return std::nullopt;
|
|
}
|
|
return mbo->with_linearized([] (bytes_view bv) {
|
|
return bytes_opt(bv);
|
|
});
|
|
}
|
|
|
|
managed_bytes_opt to_managed_bytes_opt(const bytes_opt& bo) {
|
|
if (!bo) {
|
|
return std::nullopt;
|
|
}
|
|
return managed_bytes(*bo);
|
|
}
|
|
|
|
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";
|
|
}
|