26#include <boost/endian/conversion.hpp>
27#include <seastar/core/unaligned.hh>
28#include <seastar/util/modules.hh>
33SEASTAR_MODULE_EXPORT_BEGIN
36inline T cpu_to_le(T x)
noexcept {
37 return boost::endian::native_to_little(x);
40inline T le_to_cpu(T x)
noexcept {
41 return boost::endian::little_to_native(x);
45inline T cpu_to_be(T x)
noexcept {
46 return boost::endian::native_to_big(x);
49inline T be_to_cpu(T x)
noexcept {
50 return boost::endian::big_to_native(x);
54inline T cpu_to_le(
const unaligned<T>& v)
noexcept {
55 return cpu_to_le(T(v));
59inline T le_to_cpu(
const unaligned<T>& v)
noexcept {
60 return le_to_cpu(T(v));
66read_le(
const char* p)
noexcept {
68 std::copy_n(p,
sizeof(T),
reinterpret_cast<char*
>(&datum));
69 return le_to_cpu(datum);
75write_le(
char* p, T datum)
noexcept {
76 datum = cpu_to_le(datum);
77 std::copy_n(
reinterpret_cast<const char*
>(&datum),
sizeof(T), p);
83read_be(
const char* p)
noexcept {
85 std::copy_n(p,
sizeof(T),
reinterpret_cast<char*
>(&datum));
86 return be_to_cpu(datum);
92write_be(
char* p, T datum)
noexcept {
93 datum = cpu_to_be(datum);
94 std::copy_n(
reinterpret_cast<const char*
>(&datum),
sizeof(T), p);
100consume_be(
const char*& p)
noexcept {
101 auto ret = read_be<T>(p);
109produce_be(
char*& p, T datum)
noexcept {
110 write_be<T>(p, datum);
114SEASTAR_MODULE_EXPORT_END
Seastar API namespace.
Definition: abort_on_ebadf.hh:26