protozero
Minimalistic protocol buffer decoder and encoder in C++.
byteswap.hpp
1 #ifndef PROTOZERO_BYTESWAP_HPP
2 #define PROTOZERO_BYTESWAP_HPP
3 
4 /*****************************************************************************
5 
6 protozero - Minimalistic protocol buffer decoder and encoder in C++.
7 
8 This file is from https://github.com/mapbox/protozero where you can find more
9 documentation.
10 
11 *****************************************************************************/
12 
13 #include <cassert>
14 
15 namespace protozero {
16 
17 template <int N>
18 inline void byteswap(const char* /*data*/, char* /*result*/) {
19  assert(false);
20 }
21 
22 template <>
23 inline void byteswap<1>(const char* data, char* result) {
24  result[0] = data[0];
25 }
26 
27 template <>
28 inline void byteswap<4>(const char* data, char* result) {
29  result[3] = data[0];
30  result[2] = data[1];
31  result[1] = data[2];
32  result[0] = data[3];
33 }
34 
35 template <>
36 inline void byteswap<8>(const char* data, char* result) {
37  result[7] = data[0];
38  result[6] = data[1];
39  result[5] = data[2];
40  result[4] = data[3];
41  result[3] = data[4];
42  result[2] = data[5];
43  result[1] = data[6];
44  result[0] = data[7];
45 }
46 
47 } // end namespace protozero
48 
49 #endif // PROTOZERO_BYTESWAP_HPP
All parts of the protozero header-only library are in this namespace.
Definition: byteswap.hpp:15