Skip to main content

krabka_protocol/opt/rustwide/workdir/generated/
DeleteShareGroupStateRequest.owned.rs

1// AUTO-GENERATED by krabka-protocol-codegen against a9ce3221537b8653448750697915607dc7936cf3. Do not edit.
2
3use bytes::{Buf, BufMut};
4
5use crate::{
6    Decode, Encode, ProtocolError, UnknownTaggedFields,
7    primitives::{
8        fixed::{get_i32, put_i32},
9        string_bytes::{
10            compact_string_len, get_compact_string_owned, get_string_owned, put_compact_string,
11            put_string, string_len,
12        },
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 {
28    pub group_id: String,
29    pub topics: Vec<DeleteStateData>,
30    pub unknown_tagged_fields: UnknownTaggedFields,
31}
32impl Encode for DeleteShareGroupStateRequest {
33    fn encode<B: BufMut>(&self, buf: &mut B, version: i16) -> Result<(), ProtocolError> {
34        if !(MIN_VERSION..=MAX_VERSION).contains(&version) {
35            return Err(ProtocolError::UnsupportedVersion {
36                api_key: API_KEY,
37                version,
38            });
39        }
40        let flex = is_flexible(version);
41        if version >= 0 {
42            if flex {
43                let () = put_compact_string(buf, &self.group_id);
44            } else {
45                let () = put_string(buf, &self.group_id);
46            }
47        }
48        if version >= 0 {
49            {
50                crate::primitives::array::put_array_len(buf, (self.topics).len(), flex);
51                for it in &self.topics {
52                    it.encode(buf, version)?;
53                }
54            };
55        }
56        if flex {
57            let tagged = WriteTaggedFields::new();
58            tagged.write(buf, &self.unknown_tagged_fields);
59        }
60        Ok(())
61    }
62    fn encoded_len(&self, version: i16) -> usize {
63        let flex = is_flexible(version);
64        let mut n: usize = 0;
65        if version >= 0 {
66            n += if flex {
67                compact_string_len(&self.group_id)
68            } else {
69                string_len(&self.group_id)
70            };
71        }
72        if version >= 0 {
73            n += {
74                let prefix =
75                    crate::primitives::array::array_len_prefix_len((self.topics).len(), flex);
76                let body: usize = (self.topics).iter().map(|it| it.encoded_len(version)).sum();
77                prefix + body
78            };
79        }
80        if flex {
81            let known_pairs: Vec<(u32, usize)> = Vec::new();
82            n += tagged_fields_len(&known_pairs, &self.unknown_tagged_fields);
83        }
84        n
85    }
86}
87impl Decode<'_> for DeleteShareGroupStateRequest {
88    fn decode<B: Buf>(buf: &mut B, version: i16) -> Result<Self, ProtocolError> {
89        if !(MIN_VERSION..=MAX_VERSION).contains(&version) {
90            return Err(ProtocolError::UnsupportedVersion {
91                api_key: API_KEY,
92                version,
93            });
94        }
95        let flex = is_flexible(version);
96        let mut out = Self::default();
97        if version >= 0 {
98            out.group_id = if flex {
99                get_compact_string_owned(buf)?
100            } else {
101                get_string_owned(buf)?
102            };
103        }
104        if version >= 0 {
105            out.topics = {
106                let n = crate::primitives::array::get_array_len(buf, flex)?;
107                let mut v = Vec::with_capacity(n);
108                for _ in 0..n {
109                    v.push(DeleteStateData::decode(buf, version)?);
110                }
111                v
112            };
113        }
114        if flex {
115            out.unknown_tagged_fields = read_tagged_fields(buf, |_tag, _payload| Ok(false))?;
116        }
117        Ok(out)
118    }
119}
120#[cfg(test)]
121impl DeleteShareGroupStateRequest {
122    #[must_use]
123    pub fn populated(version: i16) -> Self {
124        let mut m = Self::default();
125        if version >= 0 {
126            m.group_id = "x".to_string();
127        }
128        if version >= 0 {
129            m.topics = vec![DeleteStateData::populated(version)];
130        }
131        m
132    }
133}
134#[derive(Debug, Clone, PartialEq, Eq, Default)]
135pub struct DeleteStateData {
136    pub topic_id: crate::primitives::uuid::Uuid,
137    pub partitions: Vec<PartitionData>,
138    pub unknown_tagged_fields: UnknownTaggedFields,
139}
140impl Encode for DeleteStateData {
141    fn encode<B: BufMut>(&self, buf: &mut B, version: i16) -> Result<(), ProtocolError> {
142        let flex = version >= 0;
143        if version >= 0 {
144            crate::primitives::uuid::put_uuid(buf, self.topic_id);
145        }
146        if version >= 0 {
147            {
148                crate::primitives::array::put_array_len(buf, (self.partitions).len(), flex);
149                for it in &self.partitions {
150                    it.encode(buf, version)?;
151                }
152            };
153        }
154        if flex {
155            let tagged = WriteTaggedFields::new();
156            tagged.write(buf, &self.unknown_tagged_fields);
157        }
158        Ok(())
159    }
160    fn encoded_len(&self, version: i16) -> usize {
161        let flex = version >= 0;
162        let mut n: usize = 0;
163        if version >= 0 {
164            n += 16;
165        }
166        if version >= 0 {
167            n += {
168                let prefix =
169                    crate::primitives::array::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 DeleteStateData {
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 = crate::primitives::uuid::get_uuid(buf)?;
190        }
191        if version >= 0 {
192            out.partitions = {
193                let n = crate::primitives::array::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 DeleteStateData {
209    #[must_use]
210    pub fn populated(version: i16) -> Self {
211        let mut m = Self::default();
212        if version >= 0 {
213            m.topic_id = crate::primitives::uuid::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 unknown_tagged_fields: UnknownTaggedFields,
225}
226impl Encode for PartitionData {
227    fn encode<B: BufMut>(&self, buf: &mut B, version: i16) -> Result<(), ProtocolError> {
228        let flex = version >= 0;
229        if version >= 0 {
230            put_i32(buf, self.partition);
231        }
232        if flex {
233            let tagged = WriteTaggedFields::new();
234            tagged.write(buf, &self.unknown_tagged_fields);
235        }
236        Ok(())
237    }
238    fn encoded_len(&self, version: i16) -> usize {
239        let flex = version >= 0;
240        let mut n: usize = 0;
241        if version >= 0 {
242            n += 4;
243        }
244        if flex {
245            let known_pairs: Vec<(u32, usize)> = Vec::new();
246            n += tagged_fields_len(&known_pairs, &self.unknown_tagged_fields);
247        }
248        n
249    }
250}
251impl Decode<'_> for PartitionData {
252    fn decode<B: Buf>(buf: &mut B, version: i16) -> Result<Self, ProtocolError> {
253        let flex = version >= 0;
254        let mut out = Self::default();
255        if version >= 0 {
256            out.partition = get_i32(buf)?;
257        }
258        if flex {
259            out.unknown_tagged_fields = read_tagged_fields(buf, |_tag, _payload| Ok(false))?;
260        }
261        Ok(out)
262    }
263}
264#[cfg(test)]
265impl PartitionData {
266    #[must_use]
267    pub fn populated(version: i16) -> Self {
268        let mut m = Self::default();
269        if version >= 0 {
270            m.partition = 1i32;
271        }
272        m
273    }
274}
275/// Default JSON payload matching `Self::default()` for JVM oracle differential testing.
276/// Only includes fields valid for the given version.
277#[must_use]
278#[allow(unused_comparisons)]
279pub fn default_json(_version: i16) -> ::serde_json::Value {
280    let mut obj = ::serde_json::Map::new();
281    obj.insert(
282        "groupId".to_string(),
283        ::serde_json::Value::String(String::new()),
284    );
285    obj.insert("topics".to_string(), ::serde_json::Value::Array(vec![]));
286    ::serde_json::Value::Object(obj)
287}
288impl crate::ProtocolRequest for DeleteShareGroupStateRequest {
289    const API_KEY: i16 = API_KEY;
290    const MIN_VERSION: i16 = MIN_VERSION;
291    const MAX_VERSION: i16 = MAX_VERSION;
292    const LATEST_STABLE_VERSION: i16 = LATEST_STABLE_VERSION;
293    const FLEXIBLE_MIN: i16 = FLEXIBLE_MIN;
294    type Response = super::delete_share_group_state_response::DeleteShareGroupStateResponse;
295}