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