Expand description
Kafka wire-protocol codec.
krabka-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 does no I/O and makes no async assumptions. The
broker, client, and tooling crates in the Krabka project use it.
§Two flavors
Every message has two generated types:
owned::FooRequestowns its data asString,Bytes, andVec<T>. It is easy to move acrossawaitpoints.borrowed::FooRequest<'a>references slices of the input buffer as&'a strand&'a [u8]. It decodes with zero copies.
Both implement Encode. The owned flavor implements Decode and the
borrowed flavor implements DecodeBorrow.
§Krabka-private messages
krabka holds the hand-written messages that Apache Kafka does not define.
Their api keys sit at 1000 and above, so a later Kafka assignment cannot
collide with them.
§Versioning
krabka-protocol is pre-1.0. Breaking API changes are allowed per minor
version. See CHANGELOG.md. crates/protocol/schemas/VERSION records the
wire-protocol pin.
§Encoding a generated request
use bytes::BytesMut;
use krabka_protocol::{Encode, 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 records::remote_log_metadata::RemoteLogMetadataRecord;pub use tagged_fields::UnknownTaggedField;pub use tagged_fields::UnknownTaggedFields;
Modules§
- api_key
- borrowed
- Borrowed-flavor generated message types.
- kafka_
3_ 6_ 2 - krabka
- Krabka-private wire messages that Apache Kafka does not define.
- legacy_
compat - Adapters between the canonical Produce and Fetch types and the
kafka_3_6_2-namespaced flavors. - 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 the borrowed, zero-copy flavors. - Encode
- Encode a Kafka wire-protocol value into a buffer at the given protocol version.
- Protocol
Request - Implemented by every generated Request struct in
krabka-protocol.