kafka_api/schemata/
create_topic_request.rs1use byteorder::ReadBytesExt;
16
17use crate::codec::*;
18use crate::IoResult;
19
20#[derive(Debug, Default, Clone)]
34pub struct CreateTopicsRequest {
35 pub topics: Vec<CreatableTopic>,
37 pub timeout_ms: i32,
39 pub validate_only: bool,
41 pub unknown_tagged_fields: Vec<RawTaggedField>,
43}
44
45impl Decodable for CreateTopicsRequest {
46 fn read<B: ReadBytesExt>(buf: &mut B, version: i16) -> IoResult<Self> {
47 let mut res = CreateTopicsRequest {
48 topics: NullableArray(Struct(version), version >= 5)
49 .decode(buf)?
50 .ok_or_else(|| err_decode_message_null("name"))?,
51 timeout_ms: Int32.decode(buf)?,
52 ..Default::default()
53 };
54 if version >= 1 {
55 res.validate_only = Bool.decode(buf)?;
56 }
57 if version >= 5 {
58 res.unknown_tagged_fields = RawTaggedFieldList.decode(buf)?;
59 }
60 Ok(res)
61 }
62}
63
64#[derive(Debug, Default, Clone)]
65pub struct CreatableTopic {
66 pub name: String,
68 pub num_partitions: i32,
71 pub replication_factor: i16,
74 pub assignments: Vec<CreatableReplicaAssignment>,
76 pub configs: Vec<CreatableTopicConfig>,
78 pub unknown_tagged_fields: Vec<RawTaggedField>,
80}
81
82impl Decodable for CreatableTopic {
83 fn read<B: ReadBytesExt>(buf: &mut B, version: i16) -> IoResult<Self> {
84 let mut res = CreatableTopic {
85 name: NullableString(version >= 5)
86 .decode(buf)?
87 .ok_or_else(|| err_decode_message_null("name"))?,
88 num_partitions: Int32.decode(buf)?,
89 replication_factor: Int16.decode(buf)?,
90 assignments: NullableArray(Struct(version), version >= 5)
91 .decode(buf)?
92 .ok_or_else(|| err_decode_message_null("assignments"))?,
93 configs: NullableArray(Struct(version), version >= 5)
94 .decode(buf)?
95 .ok_or_else(|| err_decode_message_null("assignments"))?,
96 ..Default::default()
97 };
98 if version >= 5 {
99 res.unknown_tagged_fields = RawTaggedFieldList.decode(buf)?;
100 }
101 Ok(res)
102 }
103}
104
105#[derive(Debug, Default, Clone)]
106pub struct CreatableTopicConfig {
107 pub name: String,
109 pub value: Option<String>,
111 pub unknown_tagged_fields: Vec<RawTaggedField>,
113}
114
115impl Decodable for CreatableTopicConfig {
116 fn read<B: ReadBytesExt>(buf: &mut B, version: i16) -> IoResult<Self> {
117 let mut res = CreatableTopicConfig {
118 name: NullableString(version >= 5)
119 .decode(buf)?
120 .ok_or_else(|| err_decode_message_null("name"))?,
121 value: NullableString(version >= 5).decode(buf)?,
122 ..Default::default()
123 };
124 if version >= 5 {
125 res.unknown_tagged_fields = RawTaggedFieldList.decode(buf)?;
126 }
127 Ok(res)
128 }
129}
130
131#[derive(Debug, Default, Clone)]
132pub struct CreatableReplicaAssignment {
133 pub partition_index: i32,
135 pub broker_ids: Vec<i32>,
137 pub unknown_tagged_fields: Vec<RawTaggedField>,
139}
140
141impl Decodable for CreatableReplicaAssignment {
142 fn read<B: ReadBytesExt>(buf: &mut B, version: i16) -> IoResult<Self> {
143 let mut res = CreatableReplicaAssignment {
144 partition_index: Int32.decode(buf)?,
145 ..Default::default()
146 };
147 res.broker_ids = NullableArray(Int32, version >= 5)
148 .decode(buf)?
149 .ok_or_else(|| err_decode_message_null("broker_ids"))?;
150 if version >= 5 {
151 res.unknown_tagged_fields = RawTaggedFieldList.decode(buf)?;
152 }
153 Ok(res)
154 }
155}