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