8 #ifndef NETWORK_INTERFACE_NETWORK_UTILS_H 9 #define NETWORK_INTERFACE_NETWORK_UTILS_H 33 } big_int = {0x12345678};
35 return big_int.c[0] == 1;
42 const uint32_t& offset,
44 const uint32_t& valueOffset)
48 for (uint32_t i = size; i > 0; i--)
53 rcvData |= bufArray[(offset - 1) + i];
57 std::memcpy(&retVal, (
system_is_big_endian()) ? &rcvData +
sizeof(uint64_t) -
sizeof(T) : &rcvData,
sizeof(T));
59 retVal += valueOffset;
66 const unsigned int& size,
67 const unsigned int& offset)
69 return read_le<T>(bufArray, size, offset, 1.0, 0);
75 std::vector<uint8_t> ret_val;
80 if (
typeid(source) ==
typeid(
float) ||
typeid(source) ==
typeid(
double) ||
typeid(source) ==
typeid(
long double))
85 while ((*source & mask) > 0)
87 ret_val.push_back(uint8_t(*source & mask));
97 const unsigned int& size,
98 const unsigned int& offset,
100 const unsigned int& valueOffset)
102 uint64_t rcvData = 0;
104 for (
unsigned int i = 0; i < size; i++)
107 rcvData |= bufArray[(offset) + i];
111 std::memcpy(&retVal, (
system_is_big_endian()) ? &rcvData +
sizeof(uint64_t) -
sizeof(T) : &rcvData,
sizeof(T));
112 retVal *= (T) factor;
113 retVal += valueOffset;
120 const unsigned int& size,
121 const unsigned int& offset)
123 return read_be<T>(bufArray, size, offset, 1.0, 0);
129 std::vector<uint8_t> ret_val;
131 if (
typeid(source) ==
typeid(
float) ||
typeid(source) ==
typeid(
double) ||
typeid(source) ==
typeid(
long double))
138 int shift = 8 * (
sizeof(T) - 1);
144 ret_val.push_back(uint8_t(((*source) & mask) >> shift));
154 bool packet_found =
false;
157 const uint32_t chunk_bytes = 4;
159 while (!packet_found && buf_size >= chunk_bytes)
161 chunk = read_be<uint32_t>(in, chunk_bytes, i);
163 if (chunk == magic_word)
179 #endif // NETWORK_INTERFACE_NETWORK_UTILS_H T read_le(uint8_t *bufArray, const uint32_t &size, const uint32_t &offset, const float &factor, const uint32_t &valueOffset)
std::vector< uint8_t > write_be(T *source)
bool system_is_big_endian()
std::vector< uint8_t > write_le(T *source)
T read_be(unsigned char *bufArray, const unsigned int &size, const unsigned int &offset, const float &factor, const unsigned int &valueOffset)
int32_t find_magic_word(uint8_t *in, uint32_t buf_size, size_t magic_word)