krabka_protocol/lib.rs
1//! Kafka wire-protocol codec.
2//!
3//! `krabka-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 does no I/O and makes no async assumptions. The
6//! broker, client, and tooling crates in the Krabka project use it.
7//!
8//! ## Two flavors
9//!
10//! Every message has two generated types:
11//!
12//! - `owned::FooRequest` owns its data as `String`, `Bytes`, and `Vec<T>`.
13//! It is easy to move across `await` points.
14//! - `borrowed::FooRequest<'a>` references slices of the input buffer as
15//! `&'a str` and `&'a [u8]`. It decodes with zero copies.
16//!
17//! Both implement [`Encode`]. The owned flavor implements [`Decode`] and the
18//! borrowed flavor implements [`DecodeBorrow`].
19//!
20//! ## Krabka-private messages
21//!
22//! [`krabka`] holds the hand-written messages that Apache Kafka does not define.
23//! Their api keys sit at 1000 and above, so a later Kafka assignment cannot
24//! collide with them.
25//!
26//! ## Versioning
27//!
28//! `krabka-protocol` is pre-1.0. Breaking API changes are allowed per minor
29//! version. See CHANGELOG.md. `crates/protocol/schemas/VERSION` records the
30//! wire-protocol pin.
31//!
32//! ## Encoding a generated request
33//!
34//! ```rust
35//! use bytes::BytesMut;
36//! use krabka_protocol::{Encode, owned::api_versions_request::ApiVersionsRequest};
37//!
38//! let req = ApiVersionsRequest::default();
39//! let version = 4;
40//! let mut buf = BytesMut::with_capacity(req.encoded_len(version));
41//! req.encode(&mut buf, version).unwrap();
42//! assert_eq!(buf.len(), req.encoded_len(version));
43//! ```
44
45pub mod api_key;
46pub use api_key::ApiKey;
47mod arbitrary_impls;
48pub mod borrowed;
49mod codec;
50#[doc(hidden)]
51pub mod codegen_helpers;
52mod error;
53pub mod kafka_3_6_2;
54pub mod krabka;
55pub mod legacy_compat;
56pub mod owned;
57pub mod primitives;
58pub mod records;
59pub mod tagged_fields;
60
61pub use codec::{Decode, DecodeBorrow, Encode, ProtocolRequest};
62pub use error::ProtocolError;
63pub use records::remote_log_metadata::RemoteLogMetadataRecord;
64pub use tagged_fields::{UnknownTaggedField, UnknownTaggedFields};