use std::io;
use bytes::Buf;
use crate::{codec::*, err_decode_message_null};
#[derive(Debug, Default)]
pub struct CreateTopicsRequest {
pub topics: Vec<CreatableTopic>,
pub timeout_ms: i32,
pub validate_only: bool,
pub unknown_tagged_fields: Vec<RawTaggedField>,
}
impl Decodable for CreateTopicsRequest {
fn decode<B: Buf>(buf: &mut B, version: i16) -> io::Result<Self> {
let mut res = CreateTopicsRequest {
topics: NullableArray(Struct(version), version >= 5)
.decode(buf)?
.ok_or_else(|| err_decode_message_null("name"))?,
timeout_ms: Int32.decode(buf)?,
..Default::default()
};
if version >= 1 {
res.validate_only = Bool.decode(buf)?;
}
if version >= 5 {
res.unknown_tagged_fields = RawTaggedFieldList.decode(buf)?;
}
Ok(res)
}
}
#[derive(Debug, Default)]
pub struct CreatableTopic {
pub name: String,
pub num_partitions: i32,
pub replication_factor: i16,
pub assignments: Vec<CreatableReplicaAssignment>,
pub configs: Vec<CreatableTopicConfig>,
pub unknown_tagged_fields: Vec<RawTaggedField>,
}
impl Decodable for CreatableTopic {
fn decode<B: Buf>(buf: &mut B, version: i16) -> io::Result<Self> {
let mut res = CreatableTopic {
name: NullableString(version >= 5)
.decode(buf)?
.ok_or_else(|| err_decode_message_null("name"))?,
num_partitions: Int32.decode(buf)?,
replication_factor: Int16.decode(buf)?,
assignments: NullableArray(Struct(version), version >= 5)
.decode(buf)?
.ok_or_else(|| err_decode_message_null("assignments"))?,
configs: NullableArray(Struct(version), version >= 5)
.decode(buf)?
.ok_or_else(|| err_decode_message_null("assignments"))?,
..Default::default()
};
if version >= 5 {
res.unknown_tagged_fields = RawTaggedFieldList.decode(buf)?;
}
Ok(res)
}
}
#[derive(Debug, Default)]
pub struct CreatableTopicConfig {
pub name: String,
pub value: Option<String>,
pub unknown_tagged_fields: Vec<RawTaggedField>,
}
impl Decodable for CreatableTopicConfig {
fn decode<B: Buf>(buf: &mut B, version: i16) -> io::Result<Self> {
let mut res = CreatableTopicConfig {
name: NullableString(version >= 5)
.decode(buf)?
.ok_or_else(|| err_decode_message_null("name"))?,
value: NullableString(version >= 5).decode(buf)?,
..Default::default()
};
if version >= 5 {
res.unknown_tagged_fields = RawTaggedFieldList.decode(buf)?;
}
Ok(res)
}
}
#[derive(Debug, Default)]
pub struct CreatableReplicaAssignment {
pub partition_index: i32,
pub broker_ids: Vec<i32>,
pub unknown_tagged_fields: Vec<RawTaggedField>,
}
impl Decodable for CreatableReplicaAssignment {
fn decode<B: Buf>(buf: &mut B, version: i16) -> io::Result<Self> {
let mut res = CreatableReplicaAssignment {
partition_index: Int32.decode(buf)?,
..Default::default()
};
res.broker_ids = NullableArray(Int32, version >= 5)
.decode(buf)?
.ok_or_else(|| err_decode_message_null("broker_ids"))?;
if version >= 5 {
res.unknown_tagged_fields = RawTaggedFieldList.decode(buf)?;
}
Ok(res)
}
}