Skip to main content

odradek_protocol/messages/
list_groups_request.rs

1//! `ListGroupsRequest` — generated from `schemas/ListGroupsRequest.json`.
2//!
3//! @generated by `cargo xtask codegen`. Do not edit by hand.
4
5#![allow(
6    clippy::field_reassign_with_default,
7    clippy::nonminimal_bool,
8    clippy::derivable_impls,
9    clippy::borrow_deref_ref,
10    clippy::double_parens,
11    unused_parens
12)]
13
14use bytes::{Buf, BufMut};
15
16use crate::budget::{Budget, Limits};
17#[allow(unused_imports)]
18use crate::error::{DecodeError, EncodeError};
19use crate::wire::{self, RawTaggedField};
20
21/// Whether `version` of this message uses the flexible (compact) encoding.
22pub fn is_flexible(version: i16) -> bool {
23    let _ = version;
24    version >= 3
25}
26
27/// `ListGroupsRequest`, versions 0-5.
28#[derive(Debug, Clone, PartialEq)]
29#[non_exhaustive]
30pub struct ListGroupsRequest {
31    /// The states of the groups we want to list. If empty, all groups are returned with their state.
32    pub states_filter: Vec<String>,
33    /// The types of the groups we want to list. If empty, all groups are returned with their type.
34    pub types_filter: Vec<String>,
35    /// Tagged fields not (yet) known to this crate, kept raw.
36    pub unknown_tagged_fields: Vec<RawTaggedField>,
37}
38
39impl Default for ListGroupsRequest {
40    fn default() -> Self {
41        Self {
42            states_filter: Vec::new(),
43            types_filter: Vec::new(),
44            unknown_tagged_fields: Vec::new(),
45        }
46    }
47}
48
49impl ListGroupsRequest {
50    /// This message's api key in Kafka's registry.
51    pub const API_KEY: i16 = 16;
52    /// The lowest schema version this snapshot can speak.
53    pub const MIN_VERSION: i16 = 0;
54    /// The highest schema version this snapshot can speak.
55    pub const MAX_VERSION: i16 = 5;
56
57    /// Encode this `ListGroupsRequest` at `version`.
58    pub fn encode(&self, buf: &mut impl BufMut, version: i16) -> Result<(), EncodeError> {
59        if version >= 4 {
60            if is_flexible(version) {
61                wire::put_compact_array_len(buf, Some(self.states_filter.len()));
62            } else {
63                wire::put_array_len(buf, Some(self.states_filter.len()))?;
64            }
65            for item in &self.states_filter {
66                if is_flexible(version) {
67                    wire::put_compact_string(buf, item);
68                } else {
69                    wire::put_string(buf, item)?;
70                }
71            }
72        }
73        if version >= 5 {
74            if is_flexible(version) {
75                wire::put_compact_array_len(buf, Some(self.types_filter.len()));
76            } else {
77                wire::put_array_len(buf, Some(self.types_filter.len()))?;
78            }
79            for item in &self.types_filter {
80                if is_flexible(version) {
81                    wire::put_compact_string(buf, item);
82                } else {
83                    wire::put_string(buf, item)?;
84                }
85            }
86        }
87        if is_flexible(version) {
88            wire::put_tagged_fields(buf, &self.unknown_tagged_fields);
89        }
90        Ok(())
91    }
92
93    /// Decode one `ListGroupsRequest`, bounding allocation by the default
94    /// [`Limits`] derived from `buf`'s remaining length.
95    pub fn decode(buf: &mut impl Buf, version: i16) -> Result<Self, DecodeError> {
96        Self::decode_with_limits(buf, version, Limits::default())
97    }
98
99    /// Decode one `ListGroupsRequest` under `limits`.
100    pub fn decode_with_limits(
101        buf: &mut impl Buf,
102        version: i16,
103        limits: Limits,
104    ) -> Result<Self, DecodeError> {
105        let mut budget = limits.budget(buf.remaining());
106        Self::decode_with_budget(buf, version, &mut budget)
107    }
108
109    /// Decode one `ListGroupsRequest` against an existing `budget`.
110    pub fn decode_with_budget(
111        buf: &mut impl Buf,
112        version: i16,
113        budget: &mut Budget,
114    ) -> Result<Self, DecodeError> {
115        let mut this = Self::default();
116        if version >= 4 {
117            this.states_filter = {
118                let len = if is_flexible(version) {
119                    wire::get_compact_array_len(buf)?
120                } else {
121                    wire::get_array_len(buf)?
122                };
123                match len {
124                    None => return Err(DecodeError::InvalidLength(-1)),
125                    Some(n) => {
126                        let mut items = Vec::new();
127                        for _ in 0..n {
128                            budget.push(
129                                &mut items,
130                                if is_flexible(version) {
131                                    wire::get_compact_string(buf)?
132                                } else {
133                                    wire::get_string(buf)?
134                                },
135                            )?;
136                        }
137                        items
138                    }
139                }
140            };
141        }
142        if version >= 5 {
143            this.types_filter = {
144                let len = if is_flexible(version) {
145                    wire::get_compact_array_len(buf)?
146                } else {
147                    wire::get_array_len(buf)?
148                };
149                match len {
150                    None => return Err(DecodeError::InvalidLength(-1)),
151                    Some(n) => {
152                        let mut items = Vec::new();
153                        for _ in 0..n {
154                            budget.push(
155                                &mut items,
156                                if is_flexible(version) {
157                                    wire::get_compact_string(buf)?
158                                } else {
159                                    wire::get_string(buf)?
160                                },
161                            )?;
162                        }
163                        items
164                    }
165                }
166            };
167        }
168        if is_flexible(version) {
169            this.unknown_tagged_fields = wire::get_tagged_fields_with_budget(buf, budget)?;
170        }
171        Ok(this)
172    }
173}
174
175impl crate::Message for ListGroupsRequest {
176    const API_KEY: i16 = 16;
177    const MIN_VERSION: i16 = 0;
178    const MAX_VERSION: i16 = 5;
179
180    fn encode(&self, buf: &mut impl BufMut, version: i16) -> Result<(), EncodeError> {
181        ListGroupsRequest::encode(self, buf, version)
182    }
183    fn decode(buf: &mut impl Buf, version: i16) -> Result<Self, DecodeError> {
184        ListGroupsRequest::decode(buf, version)
185    }
186    fn decode_with_limits(
187        buf: &mut impl Buf,
188        version: i16,
189        limits: Limits,
190    ) -> Result<Self, DecodeError> {
191        ListGroupsRequest::decode_with_limits(buf, version, limits)
192    }
193}