28 static bool isNetworkOrder() {
30 return (1 != *(uint8_t*)&test);
34 static inline T byteSwap(
const T& v) {
37 uint8_t *dest =
reinterpret_cast<uint8_t *
>(&ret);
38 uint8_t *src =
const_cast<uint8_t*
>(
reinterpret_cast<const uint8_t*
>(&v));
39 for (
int i = 0; i < size; ++i) {
40 dest[i] = src[size - i - 1];
46 static inline T hton(
const T& v)
48 return isNetworkOrder() ? v : byteSwap(v);
52 static inline T ntoh(
const T& v)
57 static inline int appendInteger(
char* buf) {
return 0;}
58 static inline int readInteger(
char* buf) {
return 0;}
60 template<
typename Type,
typename... Types>
61 static int appendInteger(
char* buf, Type value, Types... values) {
62 *(Type*)buf = hton(value);
63 return sizeof(Type) + appendInteger(buf +
sizeof(Type), values...);
66 template<
typename Type,
typename... Types>
67 static int readInteger(
char* buf, Type& value, Types&... values) {
68 value = ntoh(*(Type*)buf);
69 return sizeof(Type) + readInteger(buf +
sizeof(Type), values...);
Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements...
Definition: common.h:48