30#include <seastar/core/unaligned.hh>
31#include <seastar/util/modules.hh>
35inline uint64_t ntohq(uint64_t v) {
36#if defined(__BYTE_ORDER__) && defined(__ORDER_BIG_ENDIAN__) && __BYTE_ORDER__ == __ORDER_BIG_ENDIAN__
41 return __builtin_bswap64(v);
44inline uint64_t htonq(uint64_t v) {
54inline uint8_t ntoh(uint8_t x) {
return x; }
55inline uint8_t hton(uint8_t x) {
return x; }
56inline uint16_t ntoh(uint16_t x) {
return ntohs(x); }
57inline uint16_t hton(uint16_t x) {
return htons(x); }
58inline uint32_t ntoh(uint32_t x) {
return ntohl(x); }
59inline uint32_t hton(uint32_t x) {
return htonl(x); }
60inline uint64_t ntoh(uint64_t x) {
return ntohq(x); }
61inline uint64_t hton(uint64_t x) {
return htonq(x); }
63inline int8_t ntoh(int8_t x) {
return x; }
64inline int8_t hton(int8_t x) {
return x; }
65inline int16_t ntoh(int16_t x) {
return ntohs(x); }
66inline int16_t hton(int16_t x) {
return htons(x); }
67inline int32_t ntoh(int32_t x) {
return ntohl(x); }
68inline int32_t hton(int32_t x) {
return htonl(x); }
69inline int64_t ntoh(int64_t x) {
return ntohq(x); }
70inline int64_t hton(int64_t x) {
return htonq(x); }
74template <
typename T>
using packed = unaligned<T>;
77inline T ntoh(
const packed<T>& x) {
83inline T hton(
const packed<T>& x) {
89inline std::ostream& operator<<(std::ostream& os,
const packed<T>& v) {
97void hton_inplace() {};
99template <
typename First,
typename... Rest>
101void ntoh_inplace(First& first, Rest&... rest) {
103 ntoh_inplace(std::forward<Rest&>(rest)...);
106template <
typename First,
typename... Rest>
108void hton_inplace(First& first, Rest&... rest) {
110 hton_inplace(std::forward<Rest&>(rest)...);
117 tmp.adjust_endianness([] (
auto&&... what) { ntoh_inplace(std::forward<
decltype(what)&>(what)...); });
125 tmp.adjust_endianness([] (
auto&&... what) { hton_inplace(std::forward<
decltype(what)&>(what)...); });
Seastar API namespace.
Definition: abort_on_ebadf.hh:26