crabka_protocol/opt/rustwide/workdir/generated/
InitializeShareGroupStateResponse.owned.rs1use bytes::{Buf, BufMut};
4
5use crate::primitives::fixed::{get_i16, get_i32, put_i16, put_i32};
6use crate::primitives::string_bytes::{
7 compact_nullable_string_len, get_compact_nullable_string_owned, get_nullable_string_owned,
8 nullable_string_len, put_compact_nullable_string, put_nullable_string,
9};
10use crate::tagged_fields::{WriteTaggedFields, read_tagged_fields, tagged_fields_len};
11use crate::{Decode, Encode, ProtocolError, UnknownTaggedFields};
12
13pub const API_KEY: i16 = 83;
14pub const MIN_VERSION: i16 = 0;
15pub const MAX_VERSION: i16 = 0;
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 InitializeShareGroupStateResponse {
25 pub results: Vec<InitializeStateResult>,
26 pub unknown_tagged_fields: UnknownTaggedFields,
27}
28impl Encode for InitializeShareGroupStateResponse {
29 fn encode<B: BufMut>(&self, buf: &mut B, version: i16) -> Result<(), ProtocolError> {
30 if !(MIN_VERSION..=MAX_VERSION).contains(&version) {
31 return Err(ProtocolError::UnsupportedVersion {
32 api_key: API_KEY,
33 version,
34 });
35 }
36 let flex = is_flexible(version);
37 if version >= 0 {
38 {
39 crate::primitives::array::put_array_len(buf, (self.results).len(), flex);
40 for it in &self.results {
41 it.encode(buf, version)?;
42 }
43 }
44 }
45 if flex {
46 let tagged = WriteTaggedFields::new();
47 tagged.write(buf, &self.unknown_tagged_fields);
48 }
49 Ok(())
50 }
51 fn encoded_len(&self, version: i16) -> usize {
52 let flex = is_flexible(version);
53 let mut n: usize = 0;
54 if version >= 0 {
55 n += {
56 let prefix =
57 crate::primitives::array::array_len_prefix_len((self.results).len(), flex);
58 let body: usize = (self.results)
59 .iter()
60 .map(|it| it.encoded_len(version))
61 .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 Decode<'_> for InitializeShareGroupStateResponse {
73 fn decode<B: Buf>(buf: &mut B, 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.results = {
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(InitializeStateResult::decode(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 InitializeShareGroupStateResponse {
100 #[must_use]
101 pub fn populated(version: i16) -> Self {
102 let mut m = Self::default();
103 if version >= 0 {
104 m.results = vec![InitializeStateResult::populated(version)];
105 }
106 m
107 }
108}
109#[derive(Debug, Clone, PartialEq, Eq, Default)]
110pub struct InitializeStateResult {
111 pub topic_id: crate::primitives::uuid::Uuid,
112 pub partitions: Vec<PartitionResult>,
113 pub unknown_tagged_fields: UnknownTaggedFields,
114}
115impl Encode for InitializeStateResult {
116 fn encode<B: BufMut>(&self, buf: &mut B, version: i16) -> Result<(), ProtocolError> {
117 let flex = version >= 0;
118 if version >= 0 {
119 crate::primitives::uuid::put_uuid(buf, self.topic_id);
120 }
121 if version >= 0 {
122 {
123 crate::primitives::array::put_array_len(buf, (self.partitions).len(), flex);
124 for it in &self.partitions {
125 it.encode(buf, version)?;
126 }
127 }
128 }
129 if flex {
130 let tagged = WriteTaggedFields::new();
131 tagged.write(buf, &self.unknown_tagged_fields);
132 }
133 Ok(())
134 }
135 fn encoded_len(&self, version: i16) -> usize {
136 let flex = version >= 0;
137 let mut n: usize = 0;
138 if version >= 0 {
139 n += 16;
140 }
141 if version >= 0 {
142 n += {
143 let prefix =
144 crate::primitives::array::array_len_prefix_len((self.partitions).len(), flex);
145 let body: usize = (self.partitions)
146 .iter()
147 .map(|it| it.encoded_len(version))
148 .sum();
149 prefix + body
150 };
151 }
152 if flex {
153 let known_pairs: Vec<(u32, usize)> = Vec::new();
154 n += tagged_fields_len(&known_pairs, &self.unknown_tagged_fields);
155 }
156 n
157 }
158}
159impl Decode<'_> for InitializeStateResult {
160 fn decode<B: Buf>(buf: &mut B, version: i16) -> Result<Self, ProtocolError> {
161 let flex = version >= 0;
162 let mut out = Self::default();
163 if version >= 0 {
164 out.topic_id = crate::primitives::uuid::get_uuid(buf)?;
165 }
166 if version >= 0 {
167 out.partitions = {
168 let n = crate::primitives::array::get_array_len(buf, flex)?;
169 let mut v = Vec::with_capacity(n);
170 for _ in 0..n {
171 v.push(PartitionResult::decode(buf, version)?);
172 }
173 v
174 };
175 }
176 if flex {
177 out.unknown_tagged_fields = read_tagged_fields(buf, |_tag, _payload| Ok(false))?;
178 }
179 Ok(out)
180 }
181}
182#[cfg(test)]
183impl InitializeStateResult {
184 #[must_use]
185 pub fn populated(version: i16) -> Self {
186 let mut m = Self::default();
187 if version >= 0 {
188 m.topic_id = crate::primitives::uuid::Uuid([1u8; 16]);
189 }
190 if version >= 0 {
191 m.partitions = vec![PartitionResult::populated(version)];
192 }
193 m
194 }
195}
196#[derive(Debug, Clone, PartialEq, Eq, Default)]
197pub struct PartitionResult {
198 pub partition: i32,
199 pub error_code: i16,
200 pub error_message: Option<String>,
201 pub unknown_tagged_fields: UnknownTaggedFields,
202}
203impl Encode for PartitionResult {
204 fn encode<B: BufMut>(&self, buf: &mut B, version: i16) -> Result<(), ProtocolError> {
205 let flex = version >= 0;
206 if version >= 0 {
207 put_i32(buf, self.partition);
208 }
209 if version >= 0 {
210 put_i16(buf, self.error_code);
211 }
212 if version >= 0 {
213 if flex {
214 put_compact_nullable_string(buf, self.error_message.as_deref());
215 } else {
216 put_nullable_string(buf, self.error_message.as_deref());
217 }
218 }
219 if flex {
220 let tagged = WriteTaggedFields::new();
221 tagged.write(buf, &self.unknown_tagged_fields);
222 }
223 Ok(())
224 }
225 fn encoded_len(&self, version: i16) -> usize {
226 let flex = version >= 0;
227 let mut n: usize = 0;
228 if version >= 0 {
229 n += 4;
230 }
231 if version >= 0 {
232 n += 2;
233 }
234 if version >= 0 {
235 n += if flex {
236 compact_nullable_string_len(self.error_message.as_deref())
237 } else {
238 nullable_string_len(self.error_message.as_deref())
239 };
240 }
241 if flex {
242 let known_pairs: Vec<(u32, usize)> = Vec::new();
243 n += tagged_fields_len(&known_pairs, &self.unknown_tagged_fields);
244 }
245 n
246 }
247}
248impl Decode<'_> for PartitionResult {
249 fn decode<B: Buf>(buf: &mut B, version: i16) -> Result<Self, ProtocolError> {
250 let flex = version >= 0;
251 let mut out = Self::default();
252 if version >= 0 {
253 out.partition = get_i32(buf)?;
254 }
255 if version >= 0 {
256 out.error_code = get_i16(buf)?;
257 }
258 if version >= 0 {
259 out.error_message = if flex {
260 get_compact_nullable_string_owned(buf)?
261 } else {
262 get_nullable_string_owned(buf)?
263 };
264 }
265 if flex {
266 out.unknown_tagged_fields = read_tagged_fields(buf, |_tag, _payload| Ok(false))?;
267 }
268 Ok(out)
269 }
270}
271#[cfg(test)]
272impl PartitionResult {
273 #[must_use]
274 pub fn populated(version: i16) -> Self {
275 let mut m = Self::default();
276 if version >= 0 {
277 m.partition = 1i32;
278 }
279 if version >= 0 {
280 m.error_code = 1i16;
281 }
282 if version >= 0 {
283 m.error_message = Some("x".to_string());
284 }
285 m
286 }
287}
288
289#[must_use]
292#[allow(unused_comparisons)]
293pub fn default_json(version: i16) -> ::serde_json::Value {
294 let mut obj = ::serde_json::Map::new();
295 obj.insert("results".to_string(), ::serde_json::Value::Array(vec![]));
296 ::serde_json::Value::Object(obj)
297}