wire_codec/lib.rs
1//! # wire-codec
2//!
3//! Binary frame codec and protocol codec toolkit. Length-prefixed, delimiter-
4//! based, and custom framing strategies. Built-in varint, zigzag, and bitfield
5//! encoding. Runtime-agnostic foundation under network-protocol crates.
6//!
7//! # Module map
8//!
9//! - [`buf`] holds [`ReadBuf`] and [`WriteBuf`], the zero-copy byte cursors
10//! every other module is built on.
11//! - [`traits`] defines [`Encode`] and [`Decode`], the codec trait pair.
12//! - [`varint`] and [`zigzag`] provide variable-length integer primitives.
13//! - [`bitfield`] provides packed-bit read and write cursors.
14//! - [`framing`] supplies a [`Framer`][`framing::Framer`] trait plus
15//! [`LengthPrefixed`][`framing::LengthPrefixed`] and
16//! [`Delimited`][`framing::Delimited`] strategies.
17//!
18//! # Example
19//!
20//! Length-prefix a payload, then read it back:
21//!
22//! ```
23//! use wire_codec::WriteBuf;
24//! use wire_codec::framing::{Endian, Framer, LengthPrefixed, LengthWidth};
25//!
26//! let framer = LengthPrefixed::new(LengthWidth::U16, Endian::Big);
27//!
28//! let mut out = [0u8; 32];
29//! let mut buf = WriteBuf::new(&mut out);
30//! framer.write_frame(b"ping", &mut buf).unwrap();
31//! let n = buf.position();
32//!
33//! let frame = framer.next_frame(&out[..n]).unwrap().unwrap();
34//! assert_eq!(frame.payload(), b"ping");
35//! ```
36//!
37//! # Status
38//!
39//! Pre-1.0 foundation. Public API surface defined in this release; further
40//! milestones expand implementations and lock semantics in.
41//!
42//! # License
43//!
44//! Dual-licensed under Apache-2.0 OR MIT.
45
46#![doc(html_root_url = "https://docs.rs/wire-codec")]
47#![cfg_attr(docsrs, feature(doc_cfg))]
48#![cfg_attr(not(feature = "std"), no_std)]
49// REPS-mandated lint set. Keep aligned with REPS.md "Compiler & Lint Configuration".
50#![deny(warnings)]
51#![deny(missing_docs)]
52#![deny(unsafe_op_in_unsafe_fn)]
53#![deny(unused_must_use)]
54#![deny(unused_results)]
55#![deny(clippy::unwrap_used)]
56#![deny(clippy::expect_used)]
57#![deny(clippy::todo)]
58#![deny(clippy::unimplemented)]
59#![deny(clippy::unreachable)]
60#![deny(clippy::print_stdout)]
61#![deny(clippy::print_stderr)]
62#![deny(clippy::dbg_macro)]
63#![deny(clippy::undocumented_unsafe_blocks)]
64#![deny(clippy::missing_safety_doc)]
65
66pub mod bitfield;
67pub mod buf;
68pub mod error;
69pub mod framing;
70pub mod traits;
71pub mod varint;
72pub mod zigzag;
73
74pub use bitfield::{BitReader, BitWriter};
75pub use buf::{ReadBuf, WriteBuf};
76pub use error::{Error, Result};
77pub use traits::{Decode, Encode};
78
79/// Crate version string, populated by Cargo at build time.
80pub const VERSION: &str = env!("CARGO_PKG_VERSION");