Skip to main content

Crate futures_byteorder

Crate futures_byteorder 

Source
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

Structs§

AsyncReadBytes
Wraps a type that implements AsyncReadExt to extend its functionality with methods for reading numbers (for futures_lite::io).
AsyncWriteBytes
Wraps a type that implements AsyncWriteExt to extend its functionality with methods for writing numbers (for futures_lite::io).
BigEndian
Defines big-endian serialization.
LittleEndian
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 with NetworkEndian!
NativeEndian
Defines system native-endian serialization. On this platform, this is an alias for LittleEndian.
NetworkEndian
Defines network byte order serialization. (type alias for BigEndian)