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