Skip to main content

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

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