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    owned::describe_producers_request,
7    primitives::{
8        array::{array_len_prefix_len, get_array_len, put_array_len},
9        fixed::{get_i32, put_i32},
10        string_bytes::{compact_string_len, put_compact_string, put_string, string_len},
11        string_bytes_borrowed::{get_compact_string_borrowed, get_string_borrowed},
12    },
13    tagged_fields::{WriteTaggedFields, read_tagged_fields, tagged_fields_len},
14};
15pub const API_KEY: i16 = 61;
16pub const MIN_VERSION: i16 = 0;
17pub const MAX_VERSION: i16 = 0;
18pub const LATEST_STABLE_VERSION: i16 = 0;
19pub const FLEXIBLE_MIN: i16 = 0;
20#[inline]
21#[must_use]
22pub fn is_flexible(version: i16) -> bool {
23    version >= FLEXIBLE_MIN
24}
25#[derive(Debug, Clone, PartialEq, Eq, Default)]
26pub struct DescribeProducersRequest<'a> {
27    pub topics: Vec<TopicRequest<'a>>,
28    pub unknown_tagged_fields: UnknownTaggedFields,
29}
30impl DescribeProducersRequest<'_> {
31    #[must_use]
32    pub fn to_owned(&self) -> describe_producers_request::DescribeProducersRequest {
33        describe_producers_request::DescribeProducersRequest {
34            topics: (self.topics).iter().map(TopicRequest::to_owned).collect(),
35            unknown_tagged_fields: self.unknown_tagged_fields.clone(),
36        }
37    }
38}
39impl Encode for DescribeProducersRequest<'_> {
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            {
50                put_array_len(buf, (self.topics).len(), flex)?;
51                for it in &self.topics {
52                    it.encode(buf, version)?;
53                }
54            }
55        }
56        if flex {
57            let tagged = WriteTaggedFields::new();
58            tagged.write(buf, &self.unknown_tagged_fields)?;
59        }
60        Ok(())
61    }
62    fn encoded_len(&self, version: i16) -> usize {
63        let flex = is_flexible(version);
64        let mut n: usize = 0;
65        if version >= 0 {
66            n += {
67                let prefix = array_len_prefix_len((self.topics).len(), flex);
68                let body: usize = (self.topics).iter().map(|it| it.encoded_len(version)).sum();
69                prefix + body
70            };
71        }
72        if flex {
73            let known_pairs: Vec<(u32, usize)> = Vec::new();
74            n += tagged_fields_len(&known_pairs, &self.unknown_tagged_fields);
75        }
76        n
77    }
78}
79impl<'de> DecodeBorrow<'de> for DescribeProducersRequest<'de> {
80    fn decode_borrow(buf: &mut &'de [u8], version: i16) -> Result<Self, ProtocolError> {
81        if !(MIN_VERSION..=MAX_VERSION).contains(&version) {
82            return Err(ProtocolError::UnsupportedVersion {
83                api_key: API_KEY,
84                version,
85            });
86        }
87        let flex = is_flexible(version);
88        let mut out = Self::default();
89        if version >= 0 {
90            out.topics = {
91                let n = get_array_len(buf, flex)?;
92                let mut v = Vec::with_capacity(n);
93                for _ in 0..n {
94                    v.push(TopicRequest::decode_borrow(buf, version)?);
95                }
96                v
97            };
98        }
99        if flex {
100            out.unknown_tagged_fields = read_tagged_fields(buf, |_tag, _payload| Ok(false))?;
101        }
102        Ok(out)
103    }
104}
105#[cfg(test)]
106impl DescribeProducersRequest<'_> {
107    #[must_use]
108    pub fn populated(version: i16) -> Self {
109        let mut m = Self::default();
110        if version >= 0 {
111            m.topics = vec![TopicRequest::populated(version)];
112        }
113        m
114    }
115}
116#[derive(Debug, Clone, PartialEq, Eq, Default)]
117pub struct TopicRequest<'a> {
118    pub name: &'a str,
119    pub partition_indexes: Vec<i32>,
120    pub unknown_tagged_fields: UnknownTaggedFields,
121}
122impl TopicRequest<'_> {
123    #[must_use]
124    pub fn to_owned(&self) -> describe_producers_request::TopicRequest {
125        describe_producers_request::TopicRequest {
126            name: (self.name).to_owned(),
127            partition_indexes: (self.partition_indexes).clone(),
128            unknown_tagged_fields: self.unknown_tagged_fields.clone(),
129        }
130    }
131}
132impl Encode for TopicRequest<'_> {
133    fn encode<B: BufMut>(&self, buf: &mut B, version: i16) -> Result<(), ProtocolError> {
134        let flex = version >= 0;
135        if version >= 0 {
136            if flex {
137                put_compact_string(buf, self.name)?;
138            } else {
139                put_string(buf, self.name)?;
140            }
141        }
142        if version >= 0 {
143            {
144                put_array_len(buf, (self.partition_indexes).len(), flex)?;
145                for it in &self.partition_indexes {
146                    put_i32(buf, *it);
147                }
148            }
149        }
150        if flex {
151            let tagged = WriteTaggedFields::new();
152            tagged.write(buf, &self.unknown_tagged_fields)?;
153        }
154        Ok(())
155    }
156    fn encoded_len(&self, version: i16) -> usize {
157        let flex = version >= 0;
158        let mut n: usize = 0;
159        if version >= 0 {
160            n += if flex {
161                compact_string_len(self.name)
162            } else {
163                string_len(self.name)
164            };
165        }
166        if version >= 0 {
167            n += {
168                let prefix = array_len_prefix_len((self.partition_indexes).len(), flex);
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 = 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}