commonlib
bytehelper.h
Go to the documentation of this file.
1 
11 #pragma once
12 #include "datatypes.h"
13 #include <cstdint>
14 #include <cstddef>
15 
16 BEGIN_NAMESPACE_DATATYPES
17 
22 {
23 public:
24  template <typename T>
25  static T byteSwap(T&& value);
26 
27  static bool isLittleEndian();
28 
29 private:
30  template <size_t size>
31  static void sizedByteSwap(uint8_t* data);
32 };
33 
34 template <typename T>
35 T ByteHelper::byteSwap(T&& value)
36 {
37  sizedByteSwap<sizeof(T)>(reinterpret_cast<uint8_t*>(&value));
38  return value;
39 }
40 
41 END_NAMESPACE_DATATYPES
The class ByteHelper implements functions for handling bytes.
Definition: bytehelper.h:21