qb
2.0.0.0
C++17 Actor Framework
|
Endianness detection and byte swapping utilities. More...
#include <cstdint>
#include <cstring>
#include <type_traits>
Go to the source code of this file.
Enumerations | |
enum class | qb::endian::order { little , big , unknown } |
Enumeration of byte order types. More... |
Functions | |
constexpr order | qb::endian::native_order () |
Determines the system's native byte order at runtime. | |
constexpr bool | qb::endian::is_little_endian () |
Checks if the system is little-endian at compile time when possible. | |
constexpr bool | qb::endian::is_big_endian () |
Checks if the system is big-endian. | |
template<typename T> | |
T | qb::endian::byteswap (T value) |
Swaps the byte order of a value. | |
template<typename T> | |
T | qb::endian::to_big_endian (T value) |
Converts a value from native endianness to big-endian. | |
template<typename T> | |
T | qb::endian::from_big_endian (T value) |
Converts a value from big-endian to native endianness. | |
template<typename T> | |
T | qb::endian::to_little_endian (T value) |
Converts a value from native endianness to little-endian. | |
template<typename T> | |
T | qb::endian::from_little_endian (T value) |
Converts a value from little-endian to native endianness. |
Endianness detection and byte swapping utilities.
This file provides utilities for detecting the system's native endianness and converting values between different byte orders (little endian and big endian). It includes functions for runtime and compile-time endianness detection, as well as safe byte-swapping operations that work with arithmetic and enum types.
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.
|
strong |
|
constexpr |
Determines the system's native byte order at runtime.
Uses compiler macros for detection when available, with a fallback to runtime detection using a union.
|
constexpr |
Checks if the system is little-endian at compile time when possible.
Uses compiler macros for detection when available, with a fallback to runtime detection.
|
constexpr |
Checks if the system is big-endian.
|
inline |
Swaps the byte order of a value.
Reverses the bytes of any trivially copyable type. This function is safe to use with any arithmetic or enum type.
T | The type of value to byte-swap (must be arithmetic or enum and trivially copyable) |
value | The value to byte-swap |
|
inline |
Converts a value from native endianness to big-endian.
T | The type of value to convert |
value | The value to convert |
|
inline |
Converts a value from big-endian to native endianness.
T | The type of value to convert |
value | The big-endian value to convert |
|
inline |
Converts a value from native endianness to little-endian.
T | The type of value to convert |
value | The value to convert |
|
inline |
Converts a value from little-endian to native endianness.
T | The type of value to convert |
value | The little-endian value to convert |