2
0
mirror of https://github.com/telegramdesktop/tdesktop synced 2025-08-31 14:38:15 +00:00

Move all gsl::byte helpers to base/bytes module.

This commit is contained in:
John Preston
2018-03-27 16:16:00 +04:00
parent b2014f403e
commit 1392e05ab1
33 changed files with 360 additions and 390 deletions

View File

@@ -92,31 +92,6 @@ using set_of_unique_ptr = std::set<std::unique_ptr<T>, base::pointer_comparator<
template <typename T>
using set_of_shared_ptr = std::set<std::shared_ptr<T>, base::pointer_comparator<T>>;
using byte_span = gsl::span<gsl::byte>;
using const_byte_span = gsl::span<const gsl::byte>;
using byte_vector = std::vector<gsl::byte>;
template <size_t N>
using byte_array = std::array<gsl::byte, N>;
inline void copy_bytes(byte_span destination, const_byte_span source) {
Expects(destination.size() >= source.size());
memcpy(destination.data(), source.data(), source.size());
}
inline void move_bytes(byte_span destination, const_byte_span source) {
Expects(destination.size() >= source.size());
memmove(destination.data(), source.data(), source.size());
}
inline void set_bytes(byte_span destination, gsl::byte value) {
memset(destination.data(), gsl::to_integer<unsigned char>(value), destination.size());
}
inline int compare_bytes(const_byte_span a, const_byte_span b) {
auto aSize = a.size(), bSize = b.size();
return (aSize > bSize) ? 1 : (aSize < bSize) ? -1 : memcmp(a.data(), b.data(), aSize);
}
// Thanks https://stackoverflow.com/a/28139075
template <typename Container>