Expand description
A modern async byteorder library for the smol/futures-lite ecosystem.
This crate provides utilities for reading and writing numbers in big-endian and
little-endian byte order for async I/O streams. It’s designed as a modern alternative
to the byteorder crate, with first-class async support using futures-lite.
§Features
- Async-first API using
futures-lite - Support for all integer types (
u8-u128,i8-i128) and floats (f32,f64) - Big-endian, little-endian, and native-endian support
- Zero-cost abstractions with const generics
- No unsafe code
§Examples
§Reading
use futures_byteorder::{AsyncReadBytes, BE};
use futures_lite::io::Cursor;
let data = vec![0x12, 0x34, 0x56, 0x78];
let mut reader = Cursor::new(data);
let mut reader = AsyncReadBytes::new(&mut reader);
// Read a big-endian u16
let value = reader.read_u16::<BE>().await?;
assert_eq!(value, 0x1234);
// Read using native endianness
let value = reader.read_u16_ne().await?;§Writing
use futures_byteorder::{AsyncWriteBytes, LE};
use futures_lite::io::Cursor;
let mut buffer = Vec::new();
let mut writer = Cursor::new(&mut buffer);
let mut writer = AsyncWriteBytes::new(&mut writer);
// Write a little-endian u32
writer.write_u32::<LE>(0x12345678).await?;
// Write using native endianness
writer.write_u16_ne(0xABCD).await?;§Endianness Types
BigEndian(aliasBE) - Big-endian byte orderLittleEndian(aliasLE) - Little-endian byte orderNativeEndian(aliasNE) - Platform’s native byte orderNetworkEndian- Network byte order (same asBE)
Structs§
- Async
Read Bytes - Wraps a type that implements
AsyncReadExtto extend its functionality with methods for reading numbers (forfutures_lite::io). - Async
Write Bytes - Wraps a type that implements
AsyncWriteExtto extend its functionality with methods for writing numbers (forfutures_lite::io). - BigEndian
- Defines big-endian serialization.
- Little
Endian - Defines little-endian serialization.
Traits§
- Endianness
- A trait defining byte order conversion behavior.
- Representable
- A trait for types that can be represented as a fixed-size byte array.
Type Aliases§
- BE
- Type alias for
BigEndian. - LE
- Type alias for
LittleEndian. - NE
- Type alias for
NativeEndian. Note: Not to be confused withNetworkEndian! - Native
Endian - Defines system native-endian serialization.
On this platform, this is an alias for
LittleEndian. - Network
Endian - Defines network byte order serialization. (type alias for
BigEndian)