| Crates.io | endbyte |
| lib.rs | endbyte |
| version | 0.1.0 |
| created_at | 2025-09-10 10:33:58.171112+00 |
| updated_at | 2025-09-10 10:33:58.171112+00 |
| description | A no_std compatible rust library for handling byte order conversions between different endianness formats. |
| homepage | |
| repository | https://github.com/Iskra-Initiative/endbyte |
| max_upload_size | |
| id | 1832362 |
| size | 25,466 |
a no_std compatible rust library for handling byte order conversions between different endianness formats.
swap_bytes() methods for optimal performanceadd this to your Cargo.toml:
[dependencies]
endbyte = "0.1.0"
use endbyte::Endianness;
let value = 0x1234u16;
// convert to specific endianness
let big_endian = value.host_to_big_endian();
let little_endian = value.host_to_little_endian();
// convert from specific endianness back to host
let from_big = big_endian.big_endian_to_host();
let from_little = little_endian.little_endian_to_host();
assert_eq!(from_big, value);
assert_eq!(from_little, value);
this library is designed to work in no_std environments:
#![no_std]
use endbyte::Endianness;
fn process_network_data(data: u32) -> u32 {
// convert from network byte order (big endian) to host
let host_value = data.big_endian_to_host();
// process the value...
let result = host_value * 2;
// convert back to network byte order
result.host_to_big_endian()
}
the Endianness trait is implemented for all standard integer types:
u8, u16, u32, u64, u128i8, i16, i32, i64, i128note: single-byte types (u8, i8) have zero-cost implementations since byte swapping is not needed.
host_to_big_endian(): convert from host byte order to big endianhost_to_little_endian(): convert from host byte order to little endianbig_endian_to_host(): convert from big endian to host byte orderlittle_endian_to_host(): convert from little endian to host byte orderthis library is designed for maximum performance:
swap_bytes() methods which compile to optimal assembly#[inline] for optimal inliningthe library includes comprehensive tests that work on both big and little endian systems:
cargo test
for embedded targets:
cargo build --target thumbv7em-none-eabihf
cargo build --target thumbv6m-none-eabi
this project is licensed under the mit license - see the license file for details.