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