| Crates.io | kafka-serde |
| lib.rs | kafka-serde |
| version | 0.1.0 |
| created_at | 2021-02-12 12:44:26.117755+00 |
| updated_at | 2021-02-12 12:44:26.117755+00 |
| description | serialization and deserialization for the Kafka protocol |
| homepage | https://github.com/DataDog/kafka-serde |
| repository | https://github.com/DataDog/kafka-serde |
| max_upload_size | |
| id | 354176 |
| size | 54,730 |
Rust's serde implementation for the Kafka protocol.
This allows you to serialize and deserialize kafka payloads. It can be used as a building block for a native-rust kafka client.
Serializing the kafka request header:
use serde::Serialize;
use std::io::{Write, Cursor};
#[derive(Serialize, Debug)]
struct RequestHeader {
api_key: i16,
api_version: i16,
correlation_id: i32,
client_id: &'static str,
}
let req = RequestHeader {
api_key: 0,
api_version: 0,
correlation_id: 1,
client_id: ""
};
let mut x = Cursor::new(Vec::<u8>::new());
kafka_serde::to_writer(x, &req).unwrap();
Deserializing the kafka response header:
use serde::Serialize;
#[derive(Deserialize, Default, Debug, Clone)]
struct ResponseHeader {
pub correlation: i32,
}
let data : Vec<u8> = [0x0, 0x0, 0x0, 0x1];
let resp: ResponseHeader = kafka_serde::from_bytes(&data).unwrap();
All Kafka protocol types are listed here
int8 -> i8, etc).String and &str, and similarly
for bytesVARLONG and COMPACT_STRING are not
supported (yet)