Skip to main content

crabka_protocol/
lib.rs

1//! Kafka wire-protocol codec.
2//!
3//! `crabka-protocol` is a pure-Rust library that encodes and decodes every
4//! Apache Kafka request and response message, byte-equivalent to the upstream
5//! JVM implementation. It performs no I/O and makes no async assumptions; it
6//! is intended to be consumed by broker, client, and tooling crates within
7//! the Crabka project.
8//!
9//! ## Two flavors
10//!
11//! Every message has two generated types:
12//!
13//! - `owned::FooRequest` — owns its data (`String`, `Bytes`, `Vec<T>`).
14//!   Easy to move across `await` points.
15//! - `borrowed::FooRequest<'a>` — references slices of the input buffer
16//!   (`&'a str`, `&'a [u8]`). Zero-copy decoding.
17//!
18//! Both implement [`Encode`]; the owned flavor implements [`Decode`] and the
19//! borrowed flavor implements [`DecodeBorrow`].
20//!
21//! ## Versioning
22//!
23//! `crabka-protocol` is pre-1.0. Breaking API changes per minor version are
24//! allowed; see CHANGELOG.md. The wire-protocol pin is recorded in
25//! `crates/protocol/schemas/VERSION`.
26//!
27//! ## Encoding a generated request
28//!
29//! ```rust
30//! use bytes::BytesMut;
31//! use crabka_protocol::Encode;
32//! use crabka_protocol::owned::api_versions_request::ApiVersionsRequest;
33//!
34//! let req = ApiVersionsRequest::default();
35//! let version = 4;
36//! let mut buf = BytesMut::with_capacity(req.encoded_len(version));
37//! req.encode(&mut buf, version).unwrap();
38//! assert_eq!(buf.len(), req.encoded_len(version));
39//! ```
40
41pub mod api_key;
42pub use api_key::ApiKey;
43mod arbitrary_impls;
44pub mod borrowed;
45mod codec;
46#[doc(hidden)]
47pub mod codegen_helpers;
48mod error;
49pub mod kafka_3_6_2;
50pub mod legacy_compat;
51pub mod owned;
52pub mod primitives;
53pub mod records;
54pub mod tagged_fields;
55
56pub use codec::{Decode, DecodeBorrow, Encode, ProtocolRequest};
57pub use error::ProtocolError;
58pub use tagged_fields::{UnknownTaggedField, UnknownTaggedFields};