Skip to main content

crabka_protocol/opt/rustwide/workdir/generated/
DeleteRecordsResponse.owned.rs

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