Expand description
§kafrust-protocol
Kafka wire protocol primitives for kafrust.
kafrust-protocol is the runtime-free protocol crate used by the high-level
kafrust client. It owns Kafka request and response
encoding, response decoding, request/response headers, frame handling, and
focused wire-format tests.
This crate is not a Kafka client by itself. Applications should normally depend
on kafrust; this crate is public so protocol behavior can be inspected,
tested, and reused where low-level Kafka messages are needed.
§Design Goals
- Keep Kafka API/version details explicit in type names.
- Keep wire-format code small and easy to audit.
- Avoid async runtime assumptions.
- Avoid
unsafe. - Add Kafka protocol surface only when encoding, decoding, and client behavior need it.
§Implemented Areas
The 0.2.x protocol surface includes support used by the current high-level
client paths:
- primitive Kafka wire types
- nullable and compact strings/bytes/arrays
- tagged fields
- request and response headers
- frame encoding and decoding
ApiVersions v0Metadata v1Metadata v12with topic UUIDs (KIP-848 assignment support)CreateTopics v2DeleteTopics v3DescribeConfigs v1DescribeGroups v1ListGroups v1DeleteGroups v1IncrementalAlterConfigs v0FindCoordinator v1Produce v2MessageSet andProduce v3RecordBatch pathsFetch v2,Fetch v4, and non-flexibleFetch v11request/response decoding for MessageSet and RecordBatch records, including rack IDs and preferred read replicas in v11JoinGroup v2andJoinGroup v5SyncGroup v2andSyncGroup v3Heartbeat v2andHeartbeat v3ConsumerGroupHeartbeat v0(KIP-848 flexible protocol foundation)LeaveGroup v3OffsetFetch v2OffsetCommit v2andOffsetCommit v7SaslHandshake v1SaslAuthenticate v0InitProducerId v0,AddPartitionsToTxn v0,AddOffsetsToTxn v0,TxnOffsetCommit v0, andEndTxn v0- classic consumer protocol subscription and assignment payloads
§Encoding Example
use kafrust_protocol::api::api_versions::ApiVersionsRequestV0;
let request = ApiVersionsRequestV0 {
correlation_id: 42,
client_id: Some("kafrust".to_owned()),
};
let bytes = request.encode()?;
assert!(!bytes.is_empty());§Decoding Example
use kafrust_protocol::api::api_versions::ApiVersionsResponseV0;
use kafrust_protocol::codec::Decoder;
let response_body = [
0, 0, // error_code
0, 0, 0, 1, // api_keys length
0, 18, // ApiVersions api key
0, 0, // min version
0, 4, // max version
];
let mut decoder = Decoder::new(&response_body);
let response = ApiVersionsResponseV0::decode_body(&mut decoder)?;
assert_eq!(response.error_code, 0);
assert_eq!(response.api_keys.len(), 1);§Compatibility
Protocol types can exist before a high-level client path is verified against a real broker. kafrust compatibility claims are made from the high-level client crate and repository docs, not from the presence of protocol structs alone.
The current 0.2.x client compatibility claim is Apache Kafka 3.7.2,
3.8.1, 3.9.1, and 4.3.1 single-node KRaft over PLAINTEXT, with the
secured and three-broker client profiles verified against Kafka 3.7.2.
§Current Limits
- This crate does not implement a broker.
- This crate does not perform network I/O.
- Protocol coverage is intentionally incomplete.
- SASL protocol structs do not perform authentication by themselves.
- This crate provides wire-format primitives, not the high-level routing,
retry, coordinator, or lifecycle behavior documented by
kafrust. - Compression codecs, transaction and idempotent-producer protocol paths, and implemented admin API schemas still require high-level client verification before they support a new compatibility claim.
- Public APIs are pre-
1.0and can change between minor versions.
§Project Docs
- Repository: https://github.com/TaeeunKil/kafrust
- kafrust client crate: https://docs.rs/kafrust
- Roadmap: https://github.com/TaeeunKil/kafrust/blob/main/docs/roadmap.md
- Compatibility: https://github.com/TaeeunKil/kafrust/blob/main/docs/compatibility.md
Re-exports§
Modules§
Functions§
- version
- Returns the protocol crate version compiled into this build.