Skip to main content

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