81 lines
2.0 KiB
Markdown
81 lines
2.0 KiB
Markdown
# Endianness Library
|
|
|
|
A modern C++ library for handling endianness conversions and byte order operations. This library provides a robust set of tools for working with different byte orders in a platform-independent manner.
|
|
|
|
## Features
|
|
|
|
- Platform-independent endianness detection
|
|
- Byte order conversion utilities
|
|
- Network byte order (big-endian) conversion functions
|
|
- Support for various data types:
|
|
- Integer types (8, 16, 32, 64-bit, signed and unsigned)
|
|
- Floating-point types (float, double)
|
|
- Modern C++20 implementation
|
|
- Cross-platform support (Windows and Unix-like systems)
|
|
|
|
## Requirements
|
|
|
|
- C++20 compatible compiler
|
|
- CMake 3.18 or higher
|
|
|
|
## Building the Project
|
|
|
|
```bash
|
|
# Create a build directory
|
|
mkdir build && cd build
|
|
|
|
# Configure with CMake
|
|
cmake ..
|
|
|
|
# Build the project
|
|
cmake --build .
|
|
```
|
|
|
|
## Usage
|
|
|
|
The library provides several key functions for endianness operations:
|
|
|
|
```cpp
|
|
#include <Endianness.hpp>
|
|
|
|
// Check system endianness
|
|
bool isLittleEndian = Endianness::IsLittleEndian();
|
|
bool isBigEndian = Endianness::IsBigEndian();
|
|
|
|
// Convert between host and network byte order
|
|
uint16_t networkValue = Endianness::HostToNetworkOrder(hostValue);
|
|
uint16_t hostValue = Endianness::NetworkToHostOrder(networkValue);
|
|
|
|
// Reverse byte order
|
|
uint32_t reversed = Endianness::ReverseByteOrder(originalValue);
|
|
|
|
// Conditional byte order reversal
|
|
uint64_t conditionalReversed = Endianness::ReverseByteOrderIfLittleEndian(value);
|
|
```
|
|
|
|
## Supported Types
|
|
|
|
The library supports the following types for byte order operations:
|
|
|
|
- Unsigned integers: `u8`, `u16`, `u32`, `u64`
|
|
- Signed integers: `s8`, `s16`, `s32`, `s64`
|
|
- Floating-point: `float`, `double`
|
|
|
|
## Project Structure
|
|
|
|
```
|
|
.
|
|
├── include/
|
|
│ └── Endianness.hpp # Main library header
|
|
├── src/ # Implementation files
|
|
├── main.cpp # Test program
|
|
└── CMakeLists.txt # Build configuration
|
|
```
|
|
|
|
## License
|
|
|
|
This project is released into the public domain under the Unlicense. See the [LICENSE](LICENSE) file for details.
|
|
|
|
## Contributing
|
|
|