crabka_protocol/opt/rustwide/workdir/generated/
CreateTopicsResponse.owned.rs1use bytes::{Buf, BufMut};
4
5use crate::primitives::fixed::{get_bool, get_i16, get_i32, get_i8, put_bool, put_i16, put_i32, put_i8};
6use crate::primitives::string_bytes::{
7 compact_nullable_string_len, compact_string_len, get_compact_nullable_string_owned,
8 get_compact_string_owned, get_nullable_string_owned, get_string_owned, nullable_string_len,
9 put_compact_nullable_string, put_compact_string, put_nullable_string, put_string,
10 string_len,
11};
12use crate::tagged_fields::{encode_to_bytes, read_tagged_fields, tagged_fields_len, WriteTaggedFields};
13use crate::{Decode, Encode, ProtocolError, UnknownTaggedFields};
14
15pub const API_KEY: i16 = 19;
16pub const MIN_VERSION: i16 = 2;
17pub const MAX_VERSION: i16 = 7;
18pub const FLEXIBLE_MIN: i16 = 5;
19
20#[inline]
21fn is_flexible(version: i16) -> bool { version >= FLEXIBLE_MIN }
22
23#[derive(Debug, Clone, PartialEq, Eq, Default)]
24pub struct CreateTopicsResponse {
25 pub throttle_time_ms: i32,
26 pub topics: Vec<CreatableTopicResult>,
27 pub unknown_tagged_fields: UnknownTaggedFields,
28}
29
30impl Encode for CreateTopicsResponse {
31 fn encode<B: BufMut>(&self, buf: &mut B, version: i16) -> Result<(), ProtocolError> {
32 if !(MIN_VERSION..=MAX_VERSION).contains(&version) {
33 return Err(ProtocolError::UnsupportedVersion { api_key: API_KEY, version });
34 }
35 let flex = is_flexible(version);
36 if version >= 2 { put_i32(buf, self.throttle_time_ms) }
37 if version >= 0 { { crate::primitives::array::put_array_len(buf, (self.topics).len(), flex); for it in &self.topics { it.encode(buf, version)?; } } }
38 if flex {
39 let tagged = WriteTaggedFields::new();
40 tagged.write(buf, &self.unknown_tagged_fields);
41 }
42 Ok(())
43 }
44 fn encoded_len(&self, version: i16) -> usize {
45 let flex = is_flexible(version);
46 let mut n: usize = 0;
47 if version >= 2 { n += 4; }
48 if version >= 0 { n += { let prefix = crate::primitives::array::array_len_prefix_len((self.topics).len(), flex); let body: usize = (self.topics).iter().map(|it| it.encoded_len(version)).sum(); prefix + body }; }
49 if flex {
50 let known_pairs: Vec<(u32, usize)> = Vec::new();
51 n += tagged_fields_len(&known_pairs, &self.unknown_tagged_fields);
52 }
53 n
54 }
55}
56
57impl<'de> Decode<'de> for CreateTopicsResponse {
58 fn decode<B: Buf>(buf: &mut B, version: i16) -> Result<Self, ProtocolError> {
59 if !(MIN_VERSION..=MAX_VERSION).contains(&version) {
60 return Err(ProtocolError::UnsupportedVersion { api_key: API_KEY, version });
61 }
62 let flex = is_flexible(version);
63 let mut out = Self::default();
64 if version >= 2 { out.throttle_time_ms = get_i32(buf)?; }
65 if version >= 0 { out.topics = { let n = crate::primitives::array::get_array_len(buf, flex)?; let mut v = Vec::with_capacity(n); for _ in 0..n { v.push(CreatableTopicResult::decode(buf, version)?); } v }; }
66 if flex {
67 out.unknown_tagged_fields = read_tagged_fields(buf, |_tag, _payload| {
68 Ok(false)
69 })?;
70 }
71 Ok(out)
72 }
73}
74
75#[derive(Debug, Clone, PartialEq, Eq)]
76pub struct CreatableTopicResult {
77 pub name: String,
78 pub topic_id: crate::primitives::uuid::Uuid,
79 pub error_code: i16,
80 pub error_message: Option<String>,
81 pub num_partitions: i32,
82 pub replication_factor: i16,
83 pub configs: Option<Vec<CreatableTopicConfigs>>,
84 pub topic_config_error_code: i16,
85 pub unknown_tagged_fields: UnknownTaggedFields,
86}
87
88impl Default for CreatableTopicResult {
89 fn default() -> Self {
90 Self {
91 name: String::new(),
92 topic_id: Default::default(),
93 error_code: 0i16,
94 error_message: None,
95 num_partitions: -1i32,
96 replication_factor: -1i16,
97 configs: None,
98 topic_config_error_code: 0i16,
99 unknown_tagged_fields: Default::default(),
100 }
101 }
102}
103
104impl Encode for CreatableTopicResult {
105 fn encode<B: BufMut>(&self, buf: &mut B, version: i16) -> Result<(), ProtocolError> {
106 let flex = version >= 5;
107 if version >= 0 { if flex { put_compact_string(buf, &self.name) } else { put_string(buf, &self.name) } }
108 if version >= 7 { crate::primitives::uuid::put_uuid(buf, self.topic_id) }
109 if version >= 0 { put_i16(buf, self.error_code) }
110 if version >= 1 { if flex { put_compact_nullable_string(buf, self.error_message.as_deref()) } else { put_nullable_string(buf, self.error_message.as_deref()) } }
111 if version >= 5 { put_i32(buf, self.num_partitions) }
112 if version >= 5 { put_i16(buf, self.replication_factor) }
113 if version >= 5 { { let len = (self.configs).as_ref().map(Vec::len); crate::primitives::array::put_nullable_array_len(buf, len, flex); if let Some(v) = &self.configs { for it in v { it.encode(buf, version)?; } } } }
114 if flex {
115 let mut tagged = WriteTaggedFields::new();
116 if !(crate::codegen_helpers::is_default(&self.topic_config_error_code)) {
117 let payload = encode_to_bytes(2, |b| { put_i16(b, self.topic_config_error_code); Ok(()) });
118 tagged.add(0, payload);
119 }
120 tagged.write(buf, &self.unknown_tagged_fields);
121 }
122 Ok(())
123 }
124 fn encoded_len(&self, version: i16) -> usize {
125 let flex = version >= 5;
126 let mut n: usize = 0;
127 if version >= 0 { n += if flex { compact_string_len(&self.name) } else { string_len(&self.name) }; }
128 if version >= 7 { n += 16; }
129 if version >= 0 { n += 2; }
130 if version >= 1 { n += if flex { compact_nullable_string_len(self.error_message.as_deref()) } else { nullable_string_len(self.error_message.as_deref()) }; }
131 if version >= 5 { n += 4; }
132 if version >= 5 { n += 2; }
133 if version >= 5 { n += { let opt: Option<&Vec<_>> = (self.configs).as_ref(); let prefix = crate::primitives::array::nullable_array_len_prefix_len(opt.map(|v| v.len()), flex); let body: usize = opt.map_or(0, |v| v.iter().map(|it| it.encoded_len(version)).sum()); prefix + body }; }
134 if flex {
135 let mut known_pairs: Vec<(u32, usize)> = Vec::new();
136 if !(crate::codegen_helpers::is_default(&self.topic_config_error_code)) {
137 known_pairs.push((0, 2));
138 }
139 n += tagged_fields_len(&known_pairs, &self.unknown_tagged_fields);
140 }
141 n
142 }
143}
144
145impl<'de> Decode<'de> for CreatableTopicResult {
146 fn decode<B: Buf>(buf: &mut B, version: i16) -> Result<Self, ProtocolError> {
147 let flex = version >= 5;
148 let mut out = Self::default();
149 if version >= 0 { out.name = if flex { get_compact_string_owned(buf)? } else { get_string_owned(buf)? }; }
150 if version >= 7 { out.topic_id = crate::primitives::uuid::get_uuid(buf)?; }
151 if version >= 0 { out.error_code = get_i16(buf)?; }
152 if version >= 1 { out.error_message = if flex { get_compact_nullable_string_owned(buf)? } else { get_nullable_string_owned(buf)? }; }
153 if version >= 5 { out.num_partitions = get_i32(buf)?; }
154 if version >= 5 { out.replication_factor = get_i16(buf)?; }
155 if version >= 5 { out.configs = { let opt = crate::primitives::array::get_nullable_array_len(buf, flex)?; match opt { None => None, Some(n) => { let mut v = Vec::with_capacity(n); for _ in 0..n { v.push(CreatableTopicConfigs::decode(buf, version)?); } Some(v) } } }; }
156 if flex {
157 let mut tag_topic_config_error_code = None;
159 out.unknown_tagged_fields = read_tagged_fields(buf, |tag, payload| {
160 match tag {
161 0 => { tag_topic_config_error_code = Some({ let b: &mut &[u8] = payload; get_i16(b)? }); Ok(true) }
162 _ => Ok(false),
163 }
164 })?;
165 if let Some(v) = tag_topic_config_error_code { out.topic_config_error_code = v; }
166 }
167 Ok(out)
168 }
169}
170
171#[derive(Debug, Clone, PartialEq, Eq)]
172pub struct CreatableTopicConfigs {
173 pub name: String,
174 pub value: Option<String>,
175 pub read_only: bool,
176 pub config_source: i8,
177 pub is_sensitive: bool,
178 pub unknown_tagged_fields: UnknownTaggedFields,
179}
180
181impl Default for CreatableTopicConfigs {
182 fn default() -> Self {
183 Self {
184 name: String::new(),
185 value: None,
186 read_only: false,
187 config_source: -1i8,
188 is_sensitive: false,
189 unknown_tagged_fields: Default::default(),
190 }
191 }
192}
193
194impl Encode for CreatableTopicConfigs {
195 fn encode<B: BufMut>(&self, buf: &mut B, version: i16) -> Result<(), ProtocolError> {
196 let flex = version >= 5;
197 if version >= 5 { if flex { put_compact_string(buf, &self.name) } else { put_string(buf, &self.name) } }
198 if version >= 5 { if flex { put_compact_nullable_string(buf, self.value.as_deref()) } else { put_nullable_string(buf, self.value.as_deref()) } }
199 if version >= 5 { put_bool(buf, self.read_only) }
200 if version >= 5 { put_i8(buf, self.config_source) }
201 if version >= 5 { put_bool(buf, self.is_sensitive) }
202 if flex {
203 let tagged = WriteTaggedFields::new();
204 tagged.write(buf, &self.unknown_tagged_fields);
205 }
206 Ok(())
207 }
208 fn encoded_len(&self, version: i16) -> usize {
209 let flex = version >= 5;
210 let mut n: usize = 0;
211 if version >= 5 { n += if flex { compact_string_len(&self.name) } else { string_len(&self.name) }; }
212 if version >= 5 { n += if flex { compact_nullable_string_len(self.value.as_deref()) } else { nullable_string_len(self.value.as_deref()) }; }
213 if version >= 5 { n += 1; }
214 if version >= 5 { n += 1; }
215 if version >= 5 { n += 1; }
216 if flex {
217 let known_pairs: Vec<(u32, usize)> = Vec::new();
218 n += tagged_fields_len(&known_pairs, &self.unknown_tagged_fields);
219 }
220 n
221 }
222}
223
224impl<'de> Decode<'de> for CreatableTopicConfigs {
225 fn decode<B: Buf>(buf: &mut B, version: i16) -> Result<Self, ProtocolError> {
226 let flex = version >= 5;
227 let mut out = Self::default();
228 if version >= 5 { out.name = if flex { get_compact_string_owned(buf)? } else { get_string_owned(buf)? }; }
229 if version >= 5 { out.value = if flex { get_compact_nullable_string_owned(buf)? } else { get_nullable_string_owned(buf)? }; }
230 if version >= 5 { out.read_only = get_bool(buf)?; }
231 if version >= 5 { out.config_source = get_i8(buf)?; }
232 if version >= 5 { out.is_sensitive = get_bool(buf)?; }
233 if flex {
234 out.unknown_tagged_fields = read_tagged_fields(buf, |_tag, _payload| {
235 Ok(false)
236 })?;
237 }
238 Ok(out)
239 }
240}
241
242#[must_use]
245#[allow(unused_comparisons)]
246pub fn default_json(version: i16) -> ::serde_json::Value {
247 let mut obj = ::serde_json::Map::new();
248 if version >= 2 {
249 obj.insert("throttleTimeMs".to_string(), ::serde_json::json!(0));
250 }
251 obj.insert("topics".to_string(), ::serde_json::Value::Array(vec![]));
252 ::serde_json::Value::Object(obj)
253}