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, owned::api_versions_request::ApiVersionsRequest};
32//!
33//! let req = ApiVersionsRequest::default();
34//! let version = 4;
35//! let mut buf = BytesMut::with_capacity(req.encoded_len(version));
36//! req.encode(&mut buf, version).unwrap();
37//! assert_eq!(buf.len(), req.encoded_len(version));
38//! ```
39
40pub mod api_key;
41pub use api_key::ApiKey;
42mod arbitrary_impls;
43pub mod borrowed;
44mod codec;
45#[doc(hidden)]
46pub mod codegen_helpers;
47mod error;
48pub mod kafka_3_6_2;
49pub mod legacy_compat;
50pub mod owned;
51pub mod primitives;
52pub mod records;
53pub mod tagged_fields;
54
55pub use codec::{Decode, DecodeBorrow, Encode, ProtocolRequest};
56pub use error::ProtocolError;
57pub use records::remote_log_metadata::RemoteLogMetadataRecord;
58pub use tagged_fields::{UnknownTaggedField, UnknownTaggedFields};