Expand description
Kafka wire-protocol codec.
crabka-protocol is a pure-Rust library that encodes and decodes every
Apache Kafka request and response message, byte-equivalent to the upstream
JVM implementation. It performs no I/O and makes no async assumptions; it
is intended to be consumed by broker, client, and tooling crates within
the Crabka project.
§Two flavors
Every message has two generated types:
owned::FooRequest— owns its data (String,Bytes,Vec<T>). Easy to move acrossawaitpoints.borrowed::FooRequest<'a>— references slices of the input buffer (&'a str,&'a [u8]). Zero-copy decoding.
Both implement Encode; the owned flavor implements Decode and the
borrowed flavor implements DecodeBorrow.
§Versioning
crabka-protocol is pre-1.0. Breaking API changes per minor version are
allowed; see CHANGELOG.md. The wire-protocol pin is recorded in
crates/protocol/schemas/VERSION.
§Encoding a generated request
use bytes::BytesMut;
use crabka_protocol::Encode;
use crabka_protocol::owned::api_versions_request::ApiVersionsRequest;
let req = ApiVersionsRequest::default();
let version = 4;
let mut buf = BytesMut::with_capacity(req.encoded_len(version));
req.encode(&mut buf, version).unwrap();
assert_eq!(buf.len(), req.encoded_len(version));Re-exports§
pub use api_key::ApiKey;pub use tagged_fields::UnknownTaggedField;pub use tagged_fields::UnknownTaggedFields;
Modules§
- api_key
- borrowed
- Borrowed-flavor generated message types.
- kafka_
3_ 6_ 2 - legacy_
compat - Adapters between the canonical Produce/Fetch types and the
kafka_3_6_2-namespaced flavors emitted from the vendored 3.6.2 schemas. Used by the wire-router branches for Produce v0–2 and Fetch v0–3. - owned
- Owned (heap-allocated) message types.
- primitives
- records
- Typed v2 record batch decoder/encoder.
- tagged_
fields - KIP-482 flexible-version tagged fields.
Enums§
- Protocol
Error - Errors that can occur during wire-protocol encoding or decoding.
Traits§
- Decode
- Decode a Kafka wire-protocol value from a buffer at the given protocol version.
- Decode
Borrow - Like
Decode, but for borrowed (zero-copy) flavors. Requires a contiguous buffer because borrowed values reference slices of it. - Encode
- Encode a Kafka wire-protocol value into a buffer at the given protocol version.
- Protocol
Request - Implemented by every generated Request struct in
crabka-protocol.