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