crabka-protocol
Apache Kafka wire-protocol codec for Rust.
Part of Crabka, a Rust implementation of Apache Kafka-compatible infrastructure and clients.
Overview
crabka-protocol is the generated Kafka request/response and record-batch
codec used by Crabka clients, broker code, and protocol tests. It contains no
networking and no async runtime assumptions: callers provide bytes, choose the
Kafka API version, and use typed encode/decode traits.
The generated schemas are pinned to Apache Kafka 4.3.0. Both owned message types and borrowed zero-copy decode types are generated for Kafka APIs.
Capabilities
Encode,Decode, andDecodeBorrowtraits for Kafka wire structs.ProtocolRequestimplementations that carry each request's response type and API key.- Generated
owned::*request/response modules for owned data. - Generated
borrowed::*modules for zero-copy decode from contiguous buffers. ApiKeyregistry for Kafka APIs through Kafka 4.3.0.- Typed v2
RecordBatch,Record, and record-header support. - Produce/read framing helpers for record-batch byte streams.
- Optional compression forwarding through
crabka-compression.
Kafka Scope
This crate is wire-protocol and record-codec infrastructure only. It does not
open sockets, maintain connections, implement broker state, or provide producer
or consumer behavior. Use crabka-client-core for typed RPC transport and the
higher-level client crates for application APIs.
Legacy v0/v1 MessageSet conversion lives in the private crabka-records-legacy
workspace crate; this published crate focuses on generated Kafka APIs and modern
v2 record batches.
Install
For workspace development, use the path dependency from this repository.
Usage
Encode and decode an ApiVersionsRequest for a specific Kafka API version:
use BytesMut;
use ApiVersionsRequest;
use ;
let request = default;
let version = 4;
let mut buf = with_capacity;
request.encode?;
let mut input = &buf;
let decoded = decode?;
assert_eq!;
# Ok::
Cargo Features
Default features enable arbitrary generation support and all four compression codecs. Disable defaults to opt into a smaller codec set:
= { = "0.3.8", = false, = ["snappy", "zstd"] }
arbitrary- enablesarbitraryimplementations for generated/test data.gzip,snappy,lz4,zstd- forward tocrabka-compressioncodecs.
Documentation
License
Apache-2.0. Derivative work of Apache Kafka; see NOTICE.