Skip to main content

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

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