Skip to main content

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

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