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        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 = 86;
19pub const MIN_VERSION: i16 = 0;
20pub const MAX_VERSION: i16 = 0;
21pub const LATEST_STABLE_VERSION: i16 = 0;
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 DeleteShareGroupStateRequest {
30    pub group_id: String,
31    pub topics: Vec<DeleteStateData>,
32    pub unknown_tagged_fields: UnknownTaggedFields,
33}
34impl Encode for DeleteShareGroupStateRequest {
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 DeleteShareGroupStateRequest {
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(DeleteStateData::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 DeleteShareGroupStateRequest {
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![DeleteStateData::populated(version)];
131        }
132        m
133    }
134}
135#[derive(Debug, Clone, PartialEq, Eq, Default)]
136pub struct DeleteStateData {
137    pub topic_id: Uuid,
138    pub partitions: Vec<PartitionData>,
139    pub unknown_tagged_fields: UnknownTaggedFields,
140}
141impl Encode for DeleteStateData {
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 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 = 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 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 = 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_owned(),
283        ::serde_json::Value::String(String::new()),
284    );
285    obj.insert("topics".to_owned(), ::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}