crabka_protocol/opt/rustwide/workdir/generated/
ReadShareGroupStateSummaryRequest.borrowed.rs1use 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 = 87;
14pub const MIN_VERSION: i16 = 0;
15pub const MAX_VERSION: i16 = 1;
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 ReadShareGroupStateSummaryRequest<'a> {
25 pub group_id: &'a str,
26 pub topics: Vec<ReadStateSummaryData>,
27 pub unknown_tagged_fields: UnknownTaggedFields,
28}
29impl ReadShareGroupStateSummaryRequest<'_> {
30 pub fn to_owned(
31 &self,
32 ) -> crate::owned::read_share_group_state_summary_request::ReadShareGroupStateSummaryRequest
33 {
34 crate::owned::read_share_group_state_summary_request::ReadShareGroupStateSummaryRequest {
35 group_id: (self.group_id).to_string(),
36 topics: (self.topics)
37 .iter()
38 .map(ReadStateSummaryData::to_owned)
39 .collect(),
40 unknown_tagged_fields: self.unknown_tagged_fields.clone(),
41 }
42 }
43}
44impl Encode for ReadShareGroupStateSummaryRequest<'_> {
45 fn encode<B: BufMut>(&self, buf: &mut B, version: i16) -> Result<(), ProtocolError> {
46 if !(MIN_VERSION..=MAX_VERSION).contains(&version) {
47 return Err(ProtocolError::UnsupportedVersion {
48 api_key: API_KEY,
49 version,
50 });
51 }
52 let flex = is_flexible(version);
53 if version >= 0 {
54 if flex {
55 put_compact_string(buf, self.group_id);
56 } else {
57 put_string(buf, self.group_id);
58 }
59 }
60 if version >= 0 {
61 {
62 crate::primitives::array::put_array_len(buf, (self.topics).len(), flex);
63 for it in &self.topics {
64 it.encode(buf, version)?;
65 }
66 }
67 }
68 if flex {
69 let tagged = WriteTaggedFields::new();
70 tagged.write(buf, &self.unknown_tagged_fields);
71 }
72 Ok(())
73 }
74 fn encoded_len(&self, version: i16) -> usize {
75 let flex = is_flexible(version);
76 let mut n: usize = 0;
77 if version >= 0 {
78 n += if flex {
79 compact_string_len(self.group_id)
80 } else {
81 string_len(self.group_id)
82 };
83 }
84 if version >= 0 {
85 n += {
86 let prefix =
87 crate::primitives::array::array_len_prefix_len((self.topics).len(), flex);
88 let body: usize = (self.topics).iter().map(|it| it.encoded_len(version)).sum();
89 prefix + body
90 };
91 }
92 if flex {
93 let known_pairs: Vec<(u32, usize)> = Vec::new();
94 n += tagged_fields_len(&known_pairs, &self.unknown_tagged_fields);
95 }
96 n
97 }
98}
99impl<'de> DecodeBorrow<'de> for ReadShareGroupStateSummaryRequest<'de> {
100 fn decode_borrow(buf: &mut &'de [u8], version: i16) -> Result<Self, ProtocolError> {
101 if !(MIN_VERSION..=MAX_VERSION).contains(&version) {
102 return Err(ProtocolError::UnsupportedVersion {
103 api_key: API_KEY,
104 version,
105 });
106 }
107 let flex = is_flexible(version);
108 let mut out = Self::default();
109 if version >= 0 {
110 out.group_id = if flex {
111 get_compact_string_borrowed(buf)?
112 } else {
113 get_string_borrowed(buf)?
114 };
115 }
116 if version >= 0 {
117 out.topics = {
118 let n = crate::primitives::array::get_array_len(buf, flex)?;
119 let mut v = Vec::with_capacity(n);
120 for _ in 0..n {
121 v.push(ReadStateSummaryData::decode_borrow(buf, version)?);
122 }
123 v
124 };
125 }
126 if flex {
127 out.unknown_tagged_fields = read_tagged_fields(buf, |_tag, _payload| Ok(false))?;
128 }
129 Ok(out)
130 }
131}
132#[cfg(test)]
133impl ReadShareGroupStateSummaryRequest<'_> {
134 #[must_use]
135 pub fn populated(version: i16) -> Self {
136 let mut m = Self::default();
137 if version >= 0 {
138 m.group_id = "x";
139 }
140 if version >= 0 {
141 m.topics = vec![ReadStateSummaryData::populated(version)];
142 }
143 m
144 }
145}
146#[derive(Debug, Clone, PartialEq, Eq, Default)]
147pub struct ReadStateSummaryData {
148 pub topic_id: crate::primitives::uuid::Uuid,
149 pub partitions: Vec<PartitionData>,
150 pub unknown_tagged_fields: UnknownTaggedFields,
151}
152impl ReadStateSummaryData {
153 pub fn to_owned(
154 &self,
155 ) -> crate::owned::read_share_group_state_summary_request::ReadStateSummaryData {
156 crate::owned::read_share_group_state_summary_request::ReadStateSummaryData {
157 topic_id: (self.topic_id),
158 partitions: (self.partitions)
159 .iter()
160 .map(PartitionData::to_owned)
161 .collect(),
162 unknown_tagged_fields: self.unknown_tagged_fields.clone(),
163 }
164 }
165}
166impl Encode for ReadStateSummaryData {
167 fn encode<B: BufMut>(&self, buf: &mut B, version: i16) -> Result<(), ProtocolError> {
168 let flex = version >= 0;
169 if version >= 0 {
170 crate::primitives::uuid::put_uuid(buf, self.topic_id);
171 }
172 if version >= 0 {
173 {
174 crate::primitives::array::put_array_len(buf, (self.partitions).len(), flex);
175 for it in &self.partitions {
176 it.encode(buf, version)?;
177 }
178 }
179 }
180 if flex {
181 let tagged = WriteTaggedFields::new();
182 tagged.write(buf, &self.unknown_tagged_fields);
183 }
184 Ok(())
185 }
186 fn encoded_len(&self, version: i16) -> usize {
187 let flex = version >= 0;
188 let mut n: usize = 0;
189 if version >= 0 {
190 n += 16;
191 }
192 if version >= 0 {
193 n += {
194 let prefix =
195 crate::primitives::array::array_len_prefix_len((self.partitions).len(), flex);
196 let body: usize = (self.partitions)
197 .iter()
198 .map(|it| it.encoded_len(version))
199 .sum();
200 prefix + body
201 };
202 }
203 if flex {
204 let known_pairs: Vec<(u32, usize)> = Vec::new();
205 n += tagged_fields_len(&known_pairs, &self.unknown_tagged_fields);
206 }
207 n
208 }
209}
210impl<'de> DecodeBorrow<'de> for ReadStateSummaryData {
211 fn decode_borrow(buf: &mut &'de [u8], version: i16) -> Result<Self, ProtocolError> {
212 let flex = version >= 0;
213 let mut out = Self::default();
214 if version >= 0 {
215 out.topic_id = crate::primitives::uuid::get_uuid(buf)?;
216 }
217 if version >= 0 {
218 out.partitions = {
219 let n = crate::primitives::array::get_array_len(buf, flex)?;
220 let mut v = Vec::with_capacity(n);
221 for _ in 0..n {
222 v.push(PartitionData::decode_borrow(buf, version)?);
223 }
224 v
225 };
226 }
227 if flex {
228 out.unknown_tagged_fields = read_tagged_fields(buf, |_tag, _payload| Ok(false))?;
229 }
230 Ok(out)
231 }
232}
233#[cfg(test)]
234impl ReadStateSummaryData {
235 #[must_use]
236 pub fn populated(version: i16) -> Self {
237 let mut m = Self::default();
238 if version >= 0 {
239 m.topic_id = crate::primitives::uuid::Uuid([1u8; 16]);
240 }
241 if version >= 0 {
242 m.partitions = vec![PartitionData::populated(version)];
243 }
244 m
245 }
246}
247#[derive(Debug, Clone, PartialEq, Eq, Default)]
248pub struct PartitionData {
249 pub partition: i32,
250 pub leader_epoch: i32,
251 pub unknown_tagged_fields: UnknownTaggedFields,
252}
253impl PartitionData {
254 pub fn to_owned(&self) -> crate::owned::read_share_group_state_summary_request::PartitionData {
255 crate::owned::read_share_group_state_summary_request::PartitionData {
256 partition: (self.partition),
257 leader_epoch: (self.leader_epoch),
258 unknown_tagged_fields: self.unknown_tagged_fields.clone(),
259 }
260 }
261}
262impl Encode for PartitionData {
263 fn encode<B: BufMut>(&self, buf: &mut B, version: i16) -> Result<(), ProtocolError> {
264 let flex = version >= 0;
265 if version >= 0 {
266 put_i32(buf, self.partition);
267 }
268 if version >= 0 {
269 put_i32(buf, self.leader_epoch);
270 }
271 if flex {
272 let tagged = WriteTaggedFields::new();
273 tagged.write(buf, &self.unknown_tagged_fields);
274 }
275 Ok(())
276 }
277 fn encoded_len(&self, version: i16) -> usize {
278 let flex = version >= 0;
279 let mut n: usize = 0;
280 if version >= 0 {
281 n += 4;
282 }
283 if version >= 0 {
284 n += 4;
285 }
286 if flex {
287 let known_pairs: Vec<(u32, usize)> = Vec::new();
288 n += tagged_fields_len(&known_pairs, &self.unknown_tagged_fields);
289 }
290 n
291 }
292}
293impl<'de> DecodeBorrow<'de> for PartitionData {
294 fn decode_borrow(buf: &mut &'de [u8], version: i16) -> Result<Self, ProtocolError> {
295 let flex = version >= 0;
296 let mut out = Self::default();
297 if version >= 0 {
298 out.partition = get_i32(buf)?;
299 }
300 if version >= 0 {
301 out.leader_epoch = get_i32(buf)?;
302 }
303 if flex {
304 out.unknown_tagged_fields = read_tagged_fields(buf, |_tag, _payload| Ok(false))?;
305 }
306 Ok(out)
307 }
308}
309#[cfg(test)]
310impl PartitionData {
311 #[must_use]
312 pub fn populated(version: i16) -> Self {
313 let mut m = Self::default();
314 if version >= 0 {
315 m.partition = 1i32;
316 }
317 if version >= 0 {
318 m.leader_epoch = 1i32;
319 }
320 m
321 }
322}