CppCommon  1.0.4.1
C++ Common Library
endian.h
Go to the documentation of this file.
1 
9 #ifndef CPPCOMMON_UTILITY_ENDIAN_H
10 #define CPPCOMMON_UTILITY_ENDIAN_H
11 
12 #include <cstdint>
13 #include <cstring>
14 
15 namespace CppCommon {
16 
18 
23 class Endian
24 {
25 public:
26  Endian() = delete;
27  Endian(const Endian&) = delete;
28  Endian(Endian&&) = delete;
29  ~Endian() = delete;
30 
31  Endian& operator=(const Endian&) = delete;
32  Endian& operator=(Endian&&) = delete;
33 
35  static bool IsBigEndian();
37  static bool IsLittleEndian();
38 
40 
45  static size_t ReadBigEndian(const void* buffer, int16_t& value);
47 
52  static size_t ReadBigEndian(const void* buffer, uint16_t& value);
54 
59  static size_t ReadBigEndian(const void* buffer, int32_t& value);
61 
66  static size_t ReadBigEndian(const void* buffer, uint32_t& value);
68 
73  static size_t ReadBigEndian(const void* buffer, int64_t& value);
75 
80  static size_t ReadBigEndian(const void* buffer, uint64_t& value);
81 
83 
88  static size_t ReadLittleEndian(const void* buffer, int16_t& value);
90 
95  static size_t ReadLittleEndian(const void* buffer, uint16_t& value);
97 
102  static size_t ReadLittleEndian(const void* buffer, int32_t& value);
104 
109  static size_t ReadLittleEndian(const void* buffer, uint32_t& value);
111 
116  static size_t ReadLittleEndian(const void* buffer, int64_t& value);
118 
123  static size_t ReadLittleEndian(const void* buffer, uint64_t& value);
124 
126 
131  static size_t WriteBigEndian(void* buffer, int16_t value);
133 
138  static size_t WriteBigEndian(void* buffer, uint16_t value);
140 
145  static size_t WriteBigEndian(void* buffer, int32_t value);
147 
152  static size_t WriteBigEndian(void* buffer, uint32_t value);
154 
159  static size_t WriteBigEndian(void* buffer, int64_t value);
161 
166  static size_t WriteBigEndian(void* buffer, uint64_t value);
167 
169 
174  static size_t WriteLittleEndian(void* buffer, int16_t value);
176 
181  static size_t WriteLittleEndian(void* buffer, uint16_t value);
183 
188  static size_t WriteLittleEndian(void* buffer, int32_t value);
190 
195  static size_t WriteLittleEndian(void* buffer, uint32_t value);
197 
202  static size_t WriteLittleEndian(void* buffer, int64_t value);
204 
209  static size_t WriteLittleEndian(void* buffer, uint64_t value);
210 };
211 
212 } // namespace CppCommon
213 
214 #include "endian.inl"
215 
216 #endif // CPPCOMMON_UTILITY_ENDIAN_H
Big/Little-endian utilities.
Definition: endian.h:24
static size_t ReadLittleEndian(const void *buffer, int16_t &value)
Read little-endian signed 16-bit integer value from the given buffer.
Definition: endian.inl:149
static size_t WriteBigEndian(void *buffer, int16_t value)
Write big-endian signed 16-bit integer value into the given buffer.
Definition: endian.inl:277
static bool IsLittleEndian()
Is little-endian system?
Definition: endian.inl:16
static size_t ReadBigEndian(const void *buffer, int16_t &value)
Read big-endian signed 16-bit integer value from the given buffer.
Definition: endian.inl:21
Endian & operator=(Endian &&)=delete
static size_t WriteLittleEndian(void *buffer, int16_t value)
Write little-endian signed 16-bit integer value into the given buffer.
Definition: endian.inl:405
static bool IsBigEndian()
Is big-endian system?
Definition: endian.inl:11
Endian(Endian &&)=delete
Endian & operator=(const Endian &)=delete
Endian(const Endian &)=delete
Big/Little-endian utilities inline implementation.
C++ Common project definitions.
Definition: token_bucket.h:15