Skip to main content

krabka_protocol/opt/rustwide/workdir/generated/
DescribeProducersRequest.borrowed.rs

1// AUTO-GENERATED by krabka-protocol-codegen against a9ce3221537b8653448750697915607dc7936cf3. Do not edit.
2use bytes::BufMut;
3
4use crate::{
5    DecodeBorrow, Encode, ProtocolError, UnknownTaggedFields,
6    primitives::{
7        fixed::{get_i32, put_i32},
8        string_bytes::{compact_string_len, put_compact_string, put_string, string_len},
9        string_bytes_borrowed::{get_compact_string_borrowed, get_string_borrowed},
10    },
11    tagged_fields::{WriteTaggedFields, read_tagged_fields, tagged_fields_len},
12};
13pub const API_KEY: i16 = 61;
14pub const MIN_VERSION: i16 = 0;
15pub const MAX_VERSION: i16 = 0;
16pub const LATEST_STABLE_VERSION: i16 = 0;
17pub const FLEXIBLE_MIN: i16 = 0;
18#[inline]
19#[must_use]
20pub fn is_flexible(version: i16) -> bool {
21    version >= FLEXIBLE_MIN
22}
23#[derive(Debug, Clone, PartialEq, Eq, Default)]
24pub struct DescribeProducersRequest<'a> {
25    pub topics: Vec<TopicRequest<'a>>,
26    pub unknown_tagged_fields: UnknownTaggedFields,
27}
28impl DescribeProducersRequest<'_> {
29    /// # Panics
30    ///
31    /// Panics if a records field contains an invalid encoded record batch.
32    #[must_use]
33    pub fn to_owned(&self) -> crate::owned::describe_producers_request::DescribeProducersRequest {
34        crate::owned::describe_producers_request::DescribeProducersRequest {
35            topics: (self.topics).iter().map(TopicRequest::to_owned).collect(),
36            unknown_tagged_fields: self.unknown_tagged_fields.clone(),
37        }
38    }
39}
40impl Encode for DescribeProducersRequest<'_> {
41    fn encode<B: BufMut>(&self, buf: &mut B, version: i16) -> Result<(), ProtocolError> {
42        if !(MIN_VERSION..=MAX_VERSION).contains(&version) {
43            return Err(ProtocolError::UnsupportedVersion {
44                api_key: API_KEY,
45                version,
46            });
47        }
48        let flex = is_flexible(version);
49        if version >= 0 {
50            {
51                crate::primitives::array::put_array_len(buf, (self.topics).len(), flex);
52                for it in &self.topics {
53                    it.encode(buf, version)?;
54                }
55            };
56        }
57        if flex {
58            let tagged = WriteTaggedFields::new();
59            tagged.write(buf, &self.unknown_tagged_fields);
60        }
61        Ok(())
62    }
63    fn encoded_len(&self, version: i16) -> usize {
64        let flex = is_flexible(version);
65        let mut n: usize = 0;
66        if version >= 0 {
67            n += {
68                let prefix =
69                    crate::primitives::array::array_len_prefix_len((self.topics).len(), flex);
70                let body: usize = (self.topics).iter().map(|it| it.encoded_len(version)).sum();
71                prefix + body
72            };
73        }
74        if flex {
75            let known_pairs: Vec<(u32, usize)> = Vec::new();
76            n += tagged_fields_len(&known_pairs, &self.unknown_tagged_fields);
77        }
78        n
79    }
80}
81impl<'de> DecodeBorrow<'de> for DescribeProducersRequest<'de> {
82    fn decode_borrow(buf: &mut &'de [u8], version: i16) -> Result<Self, ProtocolError> {
83        if !(MIN_VERSION..=MAX_VERSION).contains(&version) {
84            return Err(ProtocolError::UnsupportedVersion {
85                api_key: API_KEY,
86                version,
87            });
88        }
89        let flex = is_flexible(version);
90        let mut out = Self::default();
91        if version >= 0 {
92            out.topics = {
93                let n = crate::primitives::array::get_array_len(buf, flex)?;
94                let mut v = Vec::with_capacity(n);
95                for _ in 0..n {
96                    v.push(TopicRequest::decode_borrow(buf, version)?);
97                }
98                v
99            };
100        }
101        if flex {
102            out.unknown_tagged_fields = read_tagged_fields(buf, |_tag, _payload| Ok(false))?;
103        }
104        Ok(out)
105    }
106}
107#[cfg(test)]
108impl DescribeProducersRequest<'_> {
109    #[must_use]
110    pub fn populated(version: i16) -> Self {
111        let mut m = Self::default();
112        if version >= 0 {
113            m.topics = vec![TopicRequest::populated(version)];
114        }
115        m
116    }
117}
118#[derive(Debug, Clone, PartialEq, Eq, Default)]
119pub struct TopicRequest<'a> {
120    pub name: &'a str,
121    pub partition_indexes: Vec<i32>,
122    pub unknown_tagged_fields: UnknownTaggedFields,
123}
124impl TopicRequest<'_> {
125    /// # Panics
126    ///
127    /// Panics if a records field contains an invalid encoded record batch.
128    #[must_use]
129    pub fn to_owned(&self) -> crate::owned::describe_producers_request::TopicRequest {
130        crate::owned::describe_producers_request::TopicRequest {
131            name: (self.name).to_string(),
132            partition_indexes: (self.partition_indexes).clone(),
133            unknown_tagged_fields: self.unknown_tagged_fields.clone(),
134        }
135    }
136}
137impl Encode for TopicRequest<'_> {
138    fn encode<B: BufMut>(&self, buf: &mut B, version: i16) -> Result<(), ProtocolError> {
139        let flex = version >= 0;
140        if version >= 0 {
141            if flex {
142                let () = put_compact_string(buf, self.name);
143            } else {
144                let () = put_string(buf, self.name);
145            }
146        }
147        if version >= 0 {
148            {
149                crate::primitives::array::put_array_len(buf, (self.partition_indexes).len(), flex);
150                for it in &self.partition_indexes {
151                    put_i32(buf, *it);
152                }
153            };
154        }
155        if flex {
156            let tagged = WriteTaggedFields::new();
157            tagged.write(buf, &self.unknown_tagged_fields);
158        }
159        Ok(())
160    }
161    fn encoded_len(&self, version: i16) -> usize {
162        let flex = version >= 0;
163        let mut n: usize = 0;
164        if version >= 0 {
165            n += if flex {
166                compact_string_len(self.name)
167            } else {
168                string_len(self.name)
169            };
170        }
171        if version >= 0 {
172            n += {
173                let prefix = crate::primitives::array::array_len_prefix_len(
174                    (self.partition_indexes).len(),
175                    flex,
176                );
177                let body: usize = (self.partition_indexes).iter().map(|_| 4).sum();
178                prefix + body
179            };
180        }
181        if flex {
182            let known_pairs: Vec<(u32, usize)> = Vec::new();
183            n += tagged_fields_len(&known_pairs, &self.unknown_tagged_fields);
184        }
185        n
186    }
187}
188impl<'de> DecodeBorrow<'de> for TopicRequest<'de> {
189    fn decode_borrow(buf: &mut &'de [u8], version: i16) -> Result<Self, ProtocolError> {
190        let flex = version >= 0;
191        let mut out = Self::default();
192        if version >= 0 {
193            out.name = if flex {
194                get_compact_string_borrowed(buf)?
195            } else {
196                get_string_borrowed(buf)?
197            };
198        }
199        if version >= 0 {
200            out.partition_indexes = {
201                let n = crate::primitives::array::get_array_len(buf, flex)?;
202                let mut v = Vec::with_capacity(n);
203                for _ in 0..n {
204                    v.push(get_i32(buf)?);
205                }
206                v
207            };
208        }
209        if flex {
210            out.unknown_tagged_fields = read_tagged_fields(buf, |_tag, _payload| Ok(false))?;
211        }
212        Ok(out)
213    }
214}
215#[cfg(test)]
216impl TopicRequest<'_> {
217    #[must_use]
218    pub fn populated(version: i16) -> Self {
219        let mut m = Self::default();
220        if version >= 0 {
221            m.name = "x";
222        }
223        if version >= 0 {
224            m.partition_indexes = vec![1i32];
225        }
226        m
227    }
228}