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