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