decode_request is a great candidate for being codegen'd
aovestdipaperino opened this issue · 3 comments
aovestdipaperino commented
I am currently implementing this method myself, but it would be wonderful if it's part of the codegen when the message_enum
flag is enabled:
fn decode_request(
buf: &mut BytesMut,
api_key: ApiKey,
request_api_version: i16,
) -> Result<RequestKind, std::io::Error> {
let req = match api_key {
ApiKey::ApiVersionsKey => RequestKind::ApiVersions(
ApiVersionsRequest::decode(buf, request_api_version).unwrap(),
),
ApiKey::CreateTopicsKey => RequestKind::CreateTopics(
CreateTopicsRequest::decode(buf, request_api_version).unwrap(),
),
ApiKey::InitProducerIdKey => RequestKind::InitProducerId(
InitProducerIdRequest::decode(buf, request_api_version).unwrap(),
),
ApiKey::FindCoordinatorKey => RequestKind::FindCoordinator(
FindCoordinatorRequest::decode(buf, request_api_version).unwrap(),
),
ApiKey::MetadataKey => {
RequestKind::Metadata(MetadataRequest::decode(buf, request_api_version).unwrap())
}
ApiKey::ProduceKey => {
RequestKind::Produce(ProduceRequest::decode(buf, request_api_version).unwrap())
}
ApiKey::FetchKey => {
RequestKind::Fetch(FetchRequest::decode(buf, request_api_version).unwrap())
}
ApiKey::ListOffsetsKey => {
RequestKind::ListOffsets(ListOffsetsRequest::decode(buf, request_api_version).unwrap())
}
_ => Err(std::io::Error::new(
std::io::ErrorKind::InvalidData,
"Invalid API key",
))?,
};
Ok(req)
}
tychedelia commented
Yeah, have done something similar here before, would def accept a pr!
rukai commented
I believe that already exists as https://docs.rs/kafka-protocol/latest/kafka_protocol/messages/enum.RequestKind.html#method.decode ?
aovestdipaperino commented
Thanks, I was misled by the generated code example!