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