Skip to main content

krabka_protocol/opt/rustwide/workdir/generated/
DeleteTopicsResponse.owned.rs

1// AUTO-GENERATED by krabka-protocol-codegen against a9ce3221537b8653448750697915607dc7936cf3. Do not edit.
2
3use bytes::{Buf, BufMut};
4
5use crate::{
6    Decode, Encode, ProtocolError, UnknownTaggedFields,
7    primitives::{
8        array::{array_len_prefix_len, get_array_len, put_array_len},
9        fixed::{get_i16, get_i32, put_i16, put_i32},
10        string_bytes::{
11            compact_nullable_string_len, compact_string_len, get_compact_nullable_string_owned,
12            get_compact_string_owned, get_nullable_string_owned, get_string_owned,
13            nullable_string_len, put_compact_nullable_string, put_compact_string,
14            put_nullable_string, put_string, string_len,
15        },
16        uuid::{Uuid, get_uuid, put_uuid},
17    },
18    tagged_fields::{WriteTaggedFields, read_tagged_fields, tagged_fields_len},
19};
20pub const API_KEY: i16 = 20;
21pub const MIN_VERSION: i16 = 1;
22pub const MAX_VERSION: i16 = 6;
23pub const FLEXIBLE_MIN: i16 = 4;
24#[inline]
25#[must_use]
26pub fn is_flexible(version: i16) -> bool {
27    version >= FLEXIBLE_MIN
28}
29#[derive(Debug, Clone, PartialEq, Eq, Default)]
30pub struct DeleteTopicsResponse {
31    pub throttle_time_ms: i32,
32    pub responses: Vec<DeletableTopicResult>,
33    pub unknown_tagged_fields: UnknownTaggedFields,
34}
35impl Encode for DeleteTopicsResponse {
36    fn encode<B: BufMut>(&self, buf: &mut B, version: i16) -> Result<(), ProtocolError> {
37        if !(MIN_VERSION..=MAX_VERSION).contains(&version) {
38            return Err(ProtocolError::UnsupportedVersion {
39                api_key: API_KEY,
40                version,
41            });
42        }
43        let flex = is_flexible(version);
44        if version >= 1 {
45            put_i32(buf, self.throttle_time_ms);
46        }
47        if version >= 0 {
48            {
49                put_array_len(buf, (self.responses).len(), flex)?;
50                for it in &self.responses {
51                    it.encode(buf, version)?;
52                }
53            }
54        }
55        if flex {
56            let tagged = WriteTaggedFields::new();
57            tagged.write(buf, &self.unknown_tagged_fields)?;
58        }
59        Ok(())
60    }
61    fn encoded_len(&self, version: i16) -> usize {
62        let flex = is_flexible(version);
63        let mut n: usize = 0;
64        if version >= 1 {
65            n += 4;
66        }
67        if version >= 0 {
68            n += {
69                let prefix = array_len_prefix_len((self.responses).len(), flex);
70                let body: usize = (self.responses)
71                    .iter()
72                    .map(|it| it.encoded_len(version))
73                    .sum();
74                prefix + body
75            };
76        }
77        if flex {
78            let known_pairs: Vec<(u32, usize)> = Vec::new();
79            n += tagged_fields_len(&known_pairs, &self.unknown_tagged_fields);
80        }
81        n
82    }
83}
84impl Decode<'_> for DeleteTopicsResponse {
85    fn decode<B: Buf>(buf: &mut B, version: i16) -> Result<Self, ProtocolError> {
86        if !(MIN_VERSION..=MAX_VERSION).contains(&version) {
87            return Err(ProtocolError::UnsupportedVersion {
88                api_key: API_KEY,
89                version,
90            });
91        }
92        let flex = is_flexible(version);
93        let mut out = Self::default();
94        if version >= 1 {
95            out.throttle_time_ms = get_i32(buf)?;
96        }
97        if version >= 0 {
98            out.responses = {
99                let n = get_array_len(buf, flex)?;
100                let mut v = Vec::with_capacity(n);
101                for _ in 0..n {
102                    v.push(DeletableTopicResult::decode(buf, version)?);
103                }
104                v
105            };
106        }
107        if flex {
108            out.unknown_tagged_fields = read_tagged_fields(buf, |_tag, _payload| Ok(false))?;
109        }
110        Ok(out)
111    }
112}
113#[cfg(test)]
114impl DeleteTopicsResponse {
115    #[must_use]
116    pub fn populated(version: i16) -> Self {
117        let mut m = Self::default();
118        if version >= 1 {
119            m.throttle_time_ms = 1i32;
120        }
121        if version >= 0 {
122            m.responses = vec![DeletableTopicResult::populated(version)];
123        }
124        m
125    }
126}
127#[derive(Debug, Clone, PartialEq, Eq)]
128pub struct DeletableTopicResult {
129    pub name: Option<String>,
130    pub topic_id: Uuid,
131    pub error_code: i16,
132    pub error_message: Option<String>,
133    pub unknown_tagged_fields: UnknownTaggedFields,
134}
135impl Default for DeletableTopicResult {
136    fn default() -> Self {
137        Self {
138            name: Some(String::new()),
139            topic_id: Uuid::default(),
140            error_code: 0i16,
141            error_message: None,
142            unknown_tagged_fields: UnknownTaggedFields::default(),
143        }
144    }
145}
146impl Encode for DeletableTopicResult {
147    fn encode<B: BufMut>(&self, buf: &mut B, version: i16) -> Result<(), ProtocolError> {
148        let flex = version >= 4;
149        if version >= 0 {
150            if version >= 6 {
151                if flex {
152                    put_compact_nullable_string(buf, self.name.as_deref())?;
153                } else {
154                    put_nullable_string(buf, self.name.as_deref())?;
155                }
156            } else {
157                if flex {
158                    put_compact_string(buf, (self.name).as_deref().unwrap_or(""))?;
159                } else {
160                    put_string(buf, (self.name).as_deref().unwrap_or(""))?;
161                }
162            }
163        }
164        if version >= 6 {
165            put_uuid(buf, self.topic_id);
166        }
167        if version >= 0 {
168            put_i16(buf, self.error_code);
169        }
170        if version >= 5 {
171            if flex {
172                put_compact_nullable_string(buf, self.error_message.as_deref())?;
173            } else {
174                put_nullable_string(buf, self.error_message.as_deref())?;
175            }
176        }
177        if flex {
178            let tagged = WriteTaggedFields::new();
179            tagged.write(buf, &self.unknown_tagged_fields)?;
180        }
181        Ok(())
182    }
183    fn encoded_len(&self, version: i16) -> usize {
184        let flex = version >= 4;
185        let mut n: usize = 0;
186        if version >= 0 {
187            n += if version >= 6 {
188                if flex {
189                    compact_nullable_string_len(self.name.as_deref())
190                } else {
191                    nullable_string_len(self.name.as_deref())
192                }
193            } else {
194                if flex {
195                    compact_string_len((self.name).as_deref().unwrap_or(""))
196                } else {
197                    string_len((self.name).as_deref().unwrap_or(""))
198                }
199            };
200        }
201        if version >= 6 {
202            n += 16;
203        }
204        if version >= 0 {
205            n += 2;
206        }
207        if version >= 5 {
208            n += if flex {
209                compact_nullable_string_len(self.error_message.as_deref())
210            } else {
211                nullable_string_len(self.error_message.as_deref())
212            };
213        }
214        if flex {
215            let known_pairs: Vec<(u32, usize)> = Vec::new();
216            n += tagged_fields_len(&known_pairs, &self.unknown_tagged_fields);
217        }
218        n
219    }
220}
221impl Decode<'_> for DeletableTopicResult {
222    fn decode<B: Buf>(buf: &mut B, version: i16) -> Result<Self, ProtocolError> {
223        let flex = version >= 4;
224        let mut out = Self::default();
225        if version >= 0 {
226            out.name = if version >= 6 {
227                if flex {
228                    get_compact_nullable_string_owned(buf)?
229                } else {
230                    get_nullable_string_owned(buf)?
231                }
232            } else {
233                Some(if flex {
234                    get_compact_string_owned(buf)?
235                } else {
236                    get_string_owned(buf)?
237                })
238            };
239        }
240        if version >= 6 {
241            out.topic_id = get_uuid(buf)?;
242        }
243        if version >= 0 {
244            out.error_code = get_i16(buf)?;
245        }
246        if version >= 5 {
247            out.error_message = if flex {
248                get_compact_nullable_string_owned(buf)?
249            } else {
250                get_nullable_string_owned(buf)?
251            };
252        }
253        if flex {
254            out.unknown_tagged_fields = read_tagged_fields(buf, |_tag, _payload| Ok(false))?;
255        }
256        Ok(out)
257    }
258}
259#[cfg(test)]
260impl DeletableTopicResult {
261    #[must_use]
262    pub fn populated(version: i16) -> Self {
263        let mut m = Self::default();
264        if version >= 0 {
265            m.name = Some("x".to_owned());
266        }
267        if version >= 6 {
268            m.topic_id = Uuid([1u8; 16]);
269        }
270        if version >= 0 {
271            m.error_code = 1i16;
272        }
273        if version >= 5 {
274            m.error_message = Some("x".to_owned());
275        }
276        m
277    }
278}
279/// Default JSON payload matching `Self::default()` for JVM oracle differential testing.
280/// Only includes fields valid for the given version.
281#[must_use]
282#[allow(unused_comparisons)]
283pub fn default_json(version: i16) -> ::serde_json::Value {
284    let mut obj = ::serde_json::Map::new();
285    if version >= 1 {
286        obj.insert("throttleTimeMs".to_owned(), ::serde_json::json!(0));
287    }
288    obj.insert("responses".to_owned(), ::serde_json::Value::Array(vec![]));
289    ::serde_json::Value::Object(obj)
290}