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