Skip to main content

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