krabka_protocol/opt/rustwide/workdir/generated/
ReadShareGroupStateRequest.borrowed.rs1use 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 = 84;
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 ReadShareGroupStateRequest<'a> {
25 pub group_id: &'a str,
26 pub topics: Vec<ReadStateData>,
27 pub unknown_tagged_fields: UnknownTaggedFields,
28}
29impl ReadShareGroupStateRequest<'_> {
30 #[must_use]
34 pub fn to_owned(
35 &self,
36 ) -> crate::owned::read_share_group_state_request::ReadShareGroupStateRequest {
37 crate::owned::read_share_group_state_request::ReadShareGroupStateRequest {
38 group_id: (self.group_id).to_string(),
39 topics: (self.topics).iter().map(ReadStateData::to_owned).collect(),
40 unknown_tagged_fields: self.unknown_tagged_fields.clone(),
41 }
42 }
43}
44impl Encode for ReadShareGroupStateRequest<'_> {
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 let () = put_compact_string(buf, self.group_id);
56 } else {
57 let () = 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 ReadShareGroupStateRequest<'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(ReadStateData::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 ReadShareGroupStateRequest<'_> {
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![ReadStateData::populated(version)];
142 }
143 m
144 }
145}
146#[derive(Debug, Clone, PartialEq, Eq, Default)]
147pub struct ReadStateData {
148 pub topic_id: crate::primitives::uuid::Uuid,
149 pub partitions: Vec<PartitionData>,
150 pub unknown_tagged_fields: UnknownTaggedFields,
151}
152impl ReadStateData {
153 #[must_use]
157 pub fn to_owned(&self) -> crate::owned::read_share_group_state_request::ReadStateData {
158 crate::owned::read_share_group_state_request::ReadStateData {
159 topic_id: (self.topic_id),
160 partitions: (self.partitions)
161 .iter()
162 .map(PartitionData::to_owned)
163 .collect(),
164 unknown_tagged_fields: self.unknown_tagged_fields.clone(),
165 }
166 }
167}
168impl Encode for ReadStateData {
169 fn encode<B: BufMut>(&self, buf: &mut B, version: i16) -> Result<(), ProtocolError> {
170 let flex = version >= 0;
171 if version >= 0 {
172 crate::primitives::uuid::put_uuid(buf, self.topic_id);
173 }
174 if version >= 0 {
175 {
176 crate::primitives::array::put_array_len(buf, (self.partitions).len(), flex);
177 for it in &self.partitions {
178 it.encode(buf, version)?;
179 }
180 };
181 }
182 if flex {
183 let tagged = WriteTaggedFields::new();
184 tagged.write(buf, &self.unknown_tagged_fields);
185 }
186 Ok(())
187 }
188 fn encoded_len(&self, version: i16) -> usize {
189 let flex = version >= 0;
190 let mut n: usize = 0;
191 if version >= 0 {
192 n += 16;
193 }
194 if version >= 0 {
195 n += {
196 let prefix =
197 crate::primitives::array::array_len_prefix_len((self.partitions).len(), flex);
198 let body: usize = (self.partitions)
199 .iter()
200 .map(|it| it.encoded_len(version))
201 .sum();
202 prefix + body
203 };
204 }
205 if flex {
206 let known_pairs: Vec<(u32, usize)> = Vec::new();
207 n += tagged_fields_len(&known_pairs, &self.unknown_tagged_fields);
208 }
209 n
210 }
211}
212impl<'de> DecodeBorrow<'de> for ReadStateData {
213 fn decode_borrow(buf: &mut &'de [u8], version: i16) -> Result<Self, ProtocolError> {
214 let flex = version >= 0;
215 let mut out = Self::default();
216 if version >= 0 {
217 out.topic_id = crate::primitives::uuid::get_uuid(buf)?;
218 }
219 if version >= 0 {
220 out.partitions = {
221 let n = crate::primitives::array::get_array_len(buf, flex)?;
222 let mut v = Vec::with_capacity(n);
223 for _ in 0..n {
224 v.push(PartitionData::decode_borrow(buf, version)?);
225 }
226 v
227 };
228 }
229 if flex {
230 out.unknown_tagged_fields = read_tagged_fields(buf, |_tag, _payload| Ok(false))?;
231 }
232 Ok(out)
233 }
234}
235#[cfg(test)]
236impl ReadStateData {
237 #[must_use]
238 pub fn populated(version: i16) -> Self {
239 let mut m = Self::default();
240 if version >= 0 {
241 m.topic_id = crate::primitives::uuid::Uuid([1u8; 16]);
242 }
243 if version >= 0 {
244 m.partitions = vec![PartitionData::populated(version)];
245 }
246 m
247 }
248}
249#[derive(Debug, Clone, PartialEq, Eq, Default)]
250pub struct PartitionData {
251 pub partition: i32,
252 pub leader_epoch: i32,
253 pub unknown_tagged_fields: UnknownTaggedFields,
254}
255impl PartitionData {
256 #[must_use]
260 pub fn to_owned(&self) -> crate::owned::read_share_group_state_request::PartitionData {
261 crate::owned::read_share_group_state_request::PartitionData {
262 partition: (self.partition),
263 leader_epoch: (self.leader_epoch),
264 unknown_tagged_fields: self.unknown_tagged_fields.clone(),
265 }
266 }
267}
268impl Encode for PartitionData {
269 fn encode<B: BufMut>(&self, buf: &mut B, version: i16) -> Result<(), ProtocolError> {
270 let flex = version >= 0;
271 if version >= 0 {
272 put_i32(buf, self.partition);
273 }
274 if version >= 0 {
275 put_i32(buf, self.leader_epoch);
276 }
277 if flex {
278 let tagged = WriteTaggedFields::new();
279 tagged.write(buf, &self.unknown_tagged_fields);
280 }
281 Ok(())
282 }
283 fn encoded_len(&self, version: i16) -> usize {
284 let flex = version >= 0;
285 let mut n: usize = 0;
286 if version >= 0 {
287 n += 4;
288 }
289 if version >= 0 {
290 n += 4;
291 }
292 if flex {
293 let known_pairs: Vec<(u32, usize)> = Vec::new();
294 n += tagged_fields_len(&known_pairs, &self.unknown_tagged_fields);
295 }
296 n
297 }
298}
299impl<'de> DecodeBorrow<'de> for PartitionData {
300 fn decode_borrow(buf: &mut &'de [u8], version: i16) -> Result<Self, ProtocolError> {
301 let flex = version >= 0;
302 let mut out = Self::default();
303 if version >= 0 {
304 out.partition = get_i32(buf)?;
305 }
306 if version >= 0 {
307 out.leader_epoch = get_i32(buf)?;
308 }
309 if flex {
310 out.unknown_tagged_fields = read_tagged_fields(buf, |_tag, _payload| Ok(false))?;
311 }
312 Ok(out)
313 }
314}
315#[cfg(test)]
316impl PartitionData {
317 #[must_use]
318 pub fn populated(version: i16) -> Self {
319 let mut m = Self::default();
320 if version >= 0 {
321 m.partition = 1i32;
322 }
323 if version >= 0 {
324 m.leader_epoch = 1i32;
325 }
326 m
327 }
328}