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