nwd1-quic

Crates.ionwd1-quic
lib.rsnwd1-quic
version0.1.0
created_at2025-10-28 05:20:56.603046+00
updated_at2025-10-28 05:20:56.603046+00
descriptionQUIC transport for nwd1 binary frames.
homepage
repositoryhttps://github.com/iadev09/nwd1-quic
max_upload_size
id1904197
size36,290
(iadev09)

documentation

README

nwd1-quic

QUIC transport for nwd1 binary frames.

nwd1-quic provides async helpers to send and receive nwd1 frames over QUIC streams, using the quinn library. It integrates seamlessly with netid64 identifiers and uses Tokio runtime.


🧱 Frame Layout

Each frame follows the nwd1 binary format:

MAGIC (4B) | LEN (4B) | ID (8B) | KIND (1B) | VER (8B) | PAYLOAD (variable)
  • MAGIC: constant b"NWD1" header
  • LEN: total byte length following header (u32, BE)
  • ID: 64-bit network ID (netid64)
  • KIND: frame type discriminator
  • VER: protocol version
  • PAYLOAD: binary application data

⚙️ Example

use nwd1_quic::{send_frame, recv_frame};
use nwd1::Frame;
use netid64::NetId64;
use bytes::Bytes;
use quinn::{RecvStream, SendStream};

async fn example(mut send: SendStream, mut recv: RecvStream) -> anyhow::Result<()> {
    let frame = Frame {
        id: NetId64::make(1, 7, 42),
        kind: 1,
        ver: 1,
        payload: Bytes::from_static(b"hello"),
    };

    // Send frame
    send_frame(&mut send, &frame).await?;

    // Receive frame
    if let Some(received) = recv_frame(&mut recv).await? {
        assert_eq!(received.id.raw(), frame.id.raw());
    }
    Ok(())
}

🧩 Design

  • Fully async, tokio + quinn
  • Uses read_exact_opt() helper for compact error handling
  • Checks frame MAGIC early to avoid wasteful allocations
  • Enforces maximum frame length (MAX_FRAME_LEN = 8 MiB) for safety

📦 License

Licensed under either of:

at your option.

Commit count: 0

cargo fmt