Skip to main content

crabka_protocol/opt/rustwide/workdir/generated/
ShareGroupDescribeResponse.borrowed.rs

1// AUTO-GENERATED by crabka-protocol-codegen against a9ce3221537b8653448750697915607dc7936cf3. Do not edit.
2use crate::primitives::fixed::{get_i16, get_i32, put_i16, put_i32};
3use crate::primitives::string_bytes::{
4    compact_nullable_string_len, compact_string_len, nullable_string_len,
5    put_compact_nullable_string, put_compact_string, put_nullable_string, put_string, string_len,
6};
7use crate::primitives::string_bytes_borrowed::{
8    get_compact_nullable_string_borrowed, get_compact_string_borrowed,
9    get_nullable_string_borrowed, get_string_borrowed,
10};
11use crate::tagged_fields::{WriteTaggedFields, read_tagged_fields, tagged_fields_len};
12use crate::{DecodeBorrow, Encode, ProtocolError, UnknownTaggedFields};
13use bytes::BufMut;
14pub const API_KEY: i16 = 77;
15pub const MIN_VERSION: i16 = 1;
16pub const MAX_VERSION: i16 = 1;
17pub const FLEXIBLE_MIN: i16 = 0;
18#[inline]
19fn is_flexible(version: i16) -> bool {
20    version >= FLEXIBLE_MIN
21}
22#[derive(Debug, Clone, PartialEq, Eq, Default)]
23pub struct ShareGroupDescribeResponse<'a> {
24    pub throttle_time_ms: i32,
25    pub groups: Vec<DescribedGroup<'a>>,
26    pub unknown_tagged_fields: UnknownTaggedFields,
27}
28impl ShareGroupDescribeResponse<'_> {
29    pub fn to_owned(
30        &self,
31    ) -> crate::owned::share_group_describe_response::ShareGroupDescribeResponse {
32        crate::owned::share_group_describe_response::ShareGroupDescribeResponse {
33            throttle_time_ms: (self.throttle_time_ms),
34            groups: (self.groups).iter().map(DescribedGroup::to_owned).collect(),
35            unknown_tagged_fields: self.unknown_tagged_fields.clone(),
36        }
37    }
38}
39impl Encode for ShareGroupDescribeResponse<'_> {
40    fn encode<B: BufMut>(&self, buf: &mut B, version: i16) -> Result<(), ProtocolError> {
41        if !(MIN_VERSION..=MAX_VERSION).contains(&version) {
42            return Err(ProtocolError::UnsupportedVersion {
43                api_key: API_KEY,
44                version,
45            });
46        }
47        let flex = is_flexible(version);
48        if version >= 0 {
49            put_i32(buf, self.throttle_time_ms);
50        }
51        if version >= 0 {
52            {
53                crate::primitives::array::put_array_len(buf, (self.groups).len(), flex);
54                for it in &self.groups {
55                    it.encode(buf, version)?;
56                }
57            }
58        }
59        if flex {
60            let tagged = WriteTaggedFields::new();
61            tagged.write(buf, &self.unknown_tagged_fields);
62        }
63        Ok(())
64    }
65    fn encoded_len(&self, version: i16) -> usize {
66        let flex = is_flexible(version);
67        let mut n: usize = 0;
68        if version >= 0 {
69            n += 4;
70        }
71        if version >= 0 {
72            n += {
73                let prefix =
74                    crate::primitives::array::array_len_prefix_len((self.groups).len(), flex);
75                let body: usize = (self.groups).iter().map(|it| it.encoded_len(version)).sum();
76                prefix + body
77            };
78        }
79        if flex {
80            let known_pairs: Vec<(u32, usize)> = Vec::new();
81            n += tagged_fields_len(&known_pairs, &self.unknown_tagged_fields);
82        }
83        n
84    }
85}
86impl<'de> DecodeBorrow<'de> for ShareGroupDescribeResponse<'de> {
87    fn decode_borrow(buf: &mut &'de [u8], version: i16) -> Result<Self, ProtocolError> {
88        if !(MIN_VERSION..=MAX_VERSION).contains(&version) {
89            return Err(ProtocolError::UnsupportedVersion {
90                api_key: API_KEY,
91                version,
92            });
93        }
94        let flex = is_flexible(version);
95        let mut out = Self::default();
96        if version >= 0 {
97            out.throttle_time_ms = get_i32(buf)?;
98        }
99        if version >= 0 {
100            out.groups = {
101                let n = crate::primitives::array::get_array_len(buf, flex)?;
102                let mut v = Vec::with_capacity(n);
103                for _ in 0..n {
104                    v.push(DescribedGroup::decode_borrow(buf, version)?);
105                }
106                v
107            };
108        }
109        if flex {
110            out.unknown_tagged_fields = read_tagged_fields(buf, |_tag, _payload| Ok(false))?;
111        }
112        Ok(out)
113    }
114}
115#[cfg(test)]
116impl ShareGroupDescribeResponse<'_> {
117    #[must_use]
118    pub fn populated(version: i16) -> Self {
119        let mut m = Self::default();
120        if version >= 0 {
121            m.throttle_time_ms = 1i32;
122        }
123        if version >= 0 {
124            m.groups = vec![DescribedGroup::populated(version)];
125        }
126        m
127    }
128}
129#[derive(Debug, Clone, PartialEq, Eq)]
130pub struct DescribedGroup<'a> {
131    pub error_code: i16,
132    pub error_message: Option<&'a str>,
133    pub group_id: &'a str,
134    pub group_state: &'a str,
135    pub group_epoch: i32,
136    pub assignment_epoch: i32,
137    pub assignor_name: &'a str,
138    pub members: Vec<Member<'a>>,
139    pub authorized_operations: i32,
140    pub unknown_tagged_fields: UnknownTaggedFields,
141}
142impl Default for DescribedGroup<'_> {
143    fn default() -> Self {
144        Self {
145            error_code: 0i16,
146            error_message: None,
147            group_id: "",
148            group_state: "",
149            group_epoch: 0i32,
150            assignment_epoch: 0i32,
151            assignor_name: "",
152            members: Vec::new(),
153            authorized_operations: -2_147_483_648i32,
154            unknown_tagged_fields: Default::default(),
155        }
156    }
157}
158impl DescribedGroup<'_> {
159    pub fn to_owned(&self) -> crate::owned::share_group_describe_response::DescribedGroup {
160        crate::owned::share_group_describe_response::DescribedGroup {
161            error_code: (self.error_code),
162            error_message: (self.error_message).map(std::string::ToString::to_string),
163            group_id: (self.group_id).to_string(),
164            group_state: (self.group_state).to_string(),
165            group_epoch: (self.group_epoch),
166            assignment_epoch: (self.assignment_epoch),
167            assignor_name: (self.assignor_name).to_string(),
168            members: (self.members).iter().map(Member::to_owned).collect(),
169            authorized_operations: (self.authorized_operations),
170            unknown_tagged_fields: self.unknown_tagged_fields.clone(),
171        }
172    }
173}
174impl Encode for DescribedGroup<'_> {
175    fn encode<B: BufMut>(&self, buf: &mut B, version: i16) -> Result<(), ProtocolError> {
176        let flex = version >= 0;
177        if version >= 0 {
178            put_i16(buf, self.error_code);
179        }
180        if version >= 0 {
181            if flex {
182                put_compact_nullable_string(buf, self.error_message);
183            } else {
184                put_nullable_string(buf, self.error_message);
185            }
186        }
187        if version >= 0 {
188            if flex {
189                put_compact_string(buf, self.group_id);
190            } else {
191                put_string(buf, self.group_id);
192            }
193        }
194        if version >= 0 {
195            if flex {
196                put_compact_string(buf, self.group_state);
197            } else {
198                put_string(buf, self.group_state);
199            }
200        }
201        if version >= 0 {
202            put_i32(buf, self.group_epoch);
203        }
204        if version >= 0 {
205            put_i32(buf, self.assignment_epoch);
206        }
207        if version >= 0 {
208            if flex {
209                put_compact_string(buf, self.assignor_name);
210            } else {
211                put_string(buf, self.assignor_name);
212            }
213        }
214        if version >= 0 {
215            {
216                crate::primitives::array::put_array_len(buf, (self.members).len(), flex);
217                for it in &self.members {
218                    it.encode(buf, version)?;
219                }
220            }
221        }
222        if version >= 0 {
223            put_i32(buf, self.authorized_operations);
224        }
225        if flex {
226            let tagged = WriteTaggedFields::new();
227            tagged.write(buf, &self.unknown_tagged_fields);
228        }
229        Ok(())
230    }
231    fn encoded_len(&self, version: i16) -> usize {
232        let flex = version >= 0;
233        let mut n: usize = 0;
234        if version >= 0 {
235            n += 2;
236        }
237        if version >= 0 {
238            n += if flex {
239                compact_nullable_string_len(self.error_message)
240            } else {
241                nullable_string_len(self.error_message)
242            };
243        }
244        if version >= 0 {
245            n += if flex {
246                compact_string_len(self.group_id)
247            } else {
248                string_len(self.group_id)
249            };
250        }
251        if version >= 0 {
252            n += if flex {
253                compact_string_len(self.group_state)
254            } else {
255                string_len(self.group_state)
256            };
257        }
258        if version >= 0 {
259            n += 4;
260        }
261        if version >= 0 {
262            n += 4;
263        }
264        if version >= 0 {
265            n += if flex {
266                compact_string_len(self.assignor_name)
267            } else {
268                string_len(self.assignor_name)
269            };
270        }
271        if version >= 0 {
272            n += {
273                let prefix =
274                    crate::primitives::array::array_len_prefix_len((self.members).len(), flex);
275                let body: usize = (self.members)
276                    .iter()
277                    .map(|it| it.encoded_len(version))
278                    .sum();
279                prefix + body
280            };
281        }
282        if version >= 0 {
283            n += 4;
284        }
285        if flex {
286            let known_pairs: Vec<(u32, usize)> = Vec::new();
287            n += tagged_fields_len(&known_pairs, &self.unknown_tagged_fields);
288        }
289        n
290    }
291}
292impl<'de> DecodeBorrow<'de> for DescribedGroup<'de> {
293    fn decode_borrow(buf: &mut &'de [u8], version: i16) -> Result<Self, ProtocolError> {
294        let flex = version >= 0;
295        let mut out = Self::default();
296        if version >= 0 {
297            out.error_code = get_i16(buf)?;
298        }
299        if version >= 0 {
300            out.error_message = if flex {
301                get_compact_nullable_string_borrowed(buf)?
302            } else {
303                get_nullable_string_borrowed(buf)?
304            };
305        }
306        if version >= 0 {
307            out.group_id = if flex {
308                get_compact_string_borrowed(buf)?
309            } else {
310                get_string_borrowed(buf)?
311            };
312        }
313        if version >= 0 {
314            out.group_state = if flex {
315                get_compact_string_borrowed(buf)?
316            } else {
317                get_string_borrowed(buf)?
318            };
319        }
320        if version >= 0 {
321            out.group_epoch = get_i32(buf)?;
322        }
323        if version >= 0 {
324            out.assignment_epoch = get_i32(buf)?;
325        }
326        if version >= 0 {
327            out.assignor_name = if flex {
328                get_compact_string_borrowed(buf)?
329            } else {
330                get_string_borrowed(buf)?
331            };
332        }
333        if version >= 0 {
334            out.members = {
335                let n = crate::primitives::array::get_array_len(buf, flex)?;
336                let mut v = Vec::with_capacity(n);
337                for _ in 0..n {
338                    v.push(Member::decode_borrow(buf, version)?);
339                }
340                v
341            };
342        }
343        if version >= 0 {
344            out.authorized_operations = get_i32(buf)?;
345        }
346        if flex {
347            out.unknown_tagged_fields = read_tagged_fields(buf, |_tag, _payload| Ok(false))?;
348        }
349        Ok(out)
350    }
351}
352#[cfg(test)]
353impl DescribedGroup<'_> {
354    #[must_use]
355    pub fn populated(version: i16) -> Self {
356        let mut m = Self::default();
357        if version >= 0 {
358            m.error_code = 1i16;
359        }
360        if version >= 0 {
361            m.error_message = Some("x");
362        }
363        if version >= 0 {
364            m.group_id = "x";
365        }
366        if version >= 0 {
367            m.group_state = "x";
368        }
369        if version >= 0 {
370            m.group_epoch = 1i32;
371        }
372        if version >= 0 {
373            m.assignment_epoch = 1i32;
374        }
375        if version >= 0 {
376            m.assignor_name = "x";
377        }
378        if version >= 0 {
379            m.members = vec![Member::populated(version)];
380        }
381        if version >= 0 {
382            m.authorized_operations = 1i32;
383        }
384        m
385    }
386}
387#[derive(Debug, Clone, PartialEq, Eq, Default)]
388pub struct Member<'a> {
389    pub member_id: &'a str,
390    pub rack_id: Option<&'a str>,
391    pub member_epoch: i32,
392    pub client_id: &'a str,
393    pub client_host: &'a str,
394    pub subscribed_topic_names: Vec<&'a str>,
395    pub assignment: super::common::share_group_describe_response::assignment::Assignment<'a>,
396    pub unknown_tagged_fields: UnknownTaggedFields,
397}
398impl Member<'_> {
399    pub fn to_owned(&self) -> crate::owned::share_group_describe_response::Member {
400        crate::owned::share_group_describe_response::Member {
401            member_id: (self.member_id).to_string(),
402            rack_id: (self.rack_id).map(std::string::ToString::to_string),
403            member_epoch: (self.member_epoch),
404            client_id: (self.client_id).to_string(),
405            client_host: (self.client_host).to_string(),
406            subscribed_topic_names: (self.subscribed_topic_names)
407                .iter()
408                .map(std::string::ToString::to_string)
409                .collect(),
410            assignment: (self.assignment).to_owned(),
411            unknown_tagged_fields: self.unknown_tagged_fields.clone(),
412        }
413    }
414}
415impl Encode for Member<'_> {
416    fn encode<B: BufMut>(&self, buf: &mut B, version: i16) -> Result<(), ProtocolError> {
417        let flex = version >= 0;
418        if version >= 0 {
419            if flex {
420                put_compact_string(buf, self.member_id);
421            } else {
422                put_string(buf, self.member_id);
423            }
424        }
425        if version >= 0 {
426            if flex {
427                put_compact_nullable_string(buf, self.rack_id);
428            } else {
429                put_nullable_string(buf, self.rack_id);
430            }
431        }
432        if version >= 0 {
433            put_i32(buf, self.member_epoch);
434        }
435        if version >= 0 {
436            if flex {
437                put_compact_string(buf, self.client_id);
438            } else {
439                put_string(buf, self.client_id);
440            }
441        }
442        if version >= 0 {
443            if flex {
444                put_compact_string(buf, self.client_host);
445            } else {
446                put_string(buf, self.client_host);
447            }
448        }
449        if version >= 0 {
450            {
451                crate::primitives::array::put_array_len(
452                    buf,
453                    (self.subscribed_topic_names).len(),
454                    flex,
455                );
456                for it in &self.subscribed_topic_names {
457                    if flex {
458                        put_compact_string(buf, it);
459                    } else {
460                        put_string(buf, it);
461                    }
462                }
463            }
464        }
465        if version >= 0 {
466            self.assignment.encode(buf, version)?;
467        }
468        if flex {
469            let tagged = WriteTaggedFields::new();
470            tagged.write(buf, &self.unknown_tagged_fields);
471        }
472        Ok(())
473    }
474    fn encoded_len(&self, version: i16) -> usize {
475        let flex = version >= 0;
476        let mut n: usize = 0;
477        if version >= 0 {
478            n += if flex {
479                compact_string_len(self.member_id)
480            } else {
481                string_len(self.member_id)
482            };
483        }
484        if version >= 0 {
485            n += if flex {
486                compact_nullable_string_len(self.rack_id)
487            } else {
488                nullable_string_len(self.rack_id)
489            };
490        }
491        if version >= 0 {
492            n += 4;
493        }
494        if version >= 0 {
495            n += if flex {
496                compact_string_len(self.client_id)
497            } else {
498                string_len(self.client_id)
499            };
500        }
501        if version >= 0 {
502            n += if flex {
503                compact_string_len(self.client_host)
504            } else {
505                string_len(self.client_host)
506            };
507        }
508        if version >= 0 {
509            n += {
510                let prefix = crate::primitives::array::array_len_prefix_len(
511                    (self.subscribed_topic_names).len(),
512                    flex,
513                );
514                let body: usize = (self.subscribed_topic_names)
515                    .iter()
516                    .map(|it| {
517                        if flex {
518                            compact_string_len(it)
519                        } else {
520                            string_len(it)
521                        }
522                    })
523                    .sum();
524                prefix + body
525            };
526        }
527        if version >= 0 {
528            n += self.assignment.encoded_len(version);
529        }
530        if flex {
531            let known_pairs: Vec<(u32, usize)> = Vec::new();
532            n += tagged_fields_len(&known_pairs, &self.unknown_tagged_fields);
533        }
534        n
535    }
536}
537impl<'de> DecodeBorrow<'de> for Member<'de> {
538    fn decode_borrow(buf: &mut &'de [u8], version: i16) -> Result<Self, ProtocolError> {
539        let flex = version >= 0;
540        let mut out = Self::default();
541        if version >= 0 {
542            out.member_id = if flex {
543                get_compact_string_borrowed(buf)?
544            } else {
545                get_string_borrowed(buf)?
546            };
547        }
548        if version >= 0 {
549            out.rack_id = if flex {
550                get_compact_nullable_string_borrowed(buf)?
551            } else {
552                get_nullable_string_borrowed(buf)?
553            };
554        }
555        if version >= 0 {
556            out.member_epoch = get_i32(buf)?;
557        }
558        if version >= 0 {
559            out.client_id = if flex {
560                get_compact_string_borrowed(buf)?
561            } else {
562                get_string_borrowed(buf)?
563            };
564        }
565        if version >= 0 {
566            out.client_host = if flex {
567                get_compact_string_borrowed(buf)?
568            } else {
569                get_string_borrowed(buf)?
570            };
571        }
572        if version >= 0 {
573            out.subscribed_topic_names = {
574                let n = crate::primitives::array::get_array_len(buf, flex)?;
575                let mut v = Vec::with_capacity(n);
576                for _ in 0..n {
577                    v.push(if flex {
578                        get_compact_string_borrowed(buf)?
579                    } else {
580                        get_string_borrowed(buf)?
581                    });
582                }
583                v
584            };
585        }
586        if version >= 0 {
587            out.assignment = super::common::share_group_describe_response::assignment::Assignment::decode_borrow(
588                buf,
589                version,
590            )?;
591        }
592        if flex {
593            out.unknown_tagged_fields = read_tagged_fields(buf, |_tag, _payload| Ok(false))?;
594        }
595        Ok(out)
596    }
597}
598#[cfg(test)]
599impl Member<'_> {
600    #[must_use]
601    pub fn populated(version: i16) -> Self {
602        let mut m = Self::default();
603        if version >= 0 {
604            m.member_id = "x";
605        }
606        if version >= 0 {
607            m.rack_id = Some("x");
608        }
609        if version >= 0 {
610            m.member_epoch = 1i32;
611        }
612        if version >= 0 {
613            m.client_id = "x";
614        }
615        if version >= 0 {
616            m.client_host = "x";
617        }
618        if version >= 0 {
619            m.subscribed_topic_names = vec!["x"];
620        }
621        if version >= 0 {
622            m.assignment =
623                super::common::share_group_describe_response::assignment::Assignment::populated(
624                    version,
625                );
626        }
627        m
628    }
629}