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