Skip to main content

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

1// AUTO-GENERATED by crabka-protocol-codegen against a9ce3221537b8653448750697915607dc7936cf3. Do not edit.
2
3use 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 = 84;
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 ReadShareGroupStateRequest {
25    pub group_id: String,
26    pub topics: Vec<ReadStateData>,
27    pub unknown_tagged_fields: UnknownTaggedFields,
28}
29impl Encode for ReadShareGroupStateRequest {
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 ReadShareGroupStateRequest {
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(ReadStateData::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 ReadShareGroupStateRequest {
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![ReadStateData::populated(version)];
127        }
128        m
129    }
130}
131#[derive(Debug, Clone, PartialEq, Eq, Default)]
132pub struct ReadStateData {
133    pub topic_id: crate::primitives::uuid::Uuid,
134    pub partitions: Vec<PartitionData>,
135    pub unknown_tagged_fields: UnknownTaggedFields,
136}
137impl Encode for ReadStateData {
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 ReadStateData {
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 ReadStateData {
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 leader_epoch: i32,
222    pub unknown_tagged_fields: UnknownTaggedFields,
223}
224impl Encode for PartitionData {
225    fn encode<B: BufMut>(&self, buf: &mut B, version: i16) -> Result<(), ProtocolError> {
226        let flex = version >= 0;
227        if version >= 0 {
228            put_i32(buf, self.partition);
229        }
230        if version >= 0 {
231            put_i32(buf, self.leader_epoch);
232        }
233        if flex {
234            let tagged = WriteTaggedFields::new();
235            tagged.write(buf, &self.unknown_tagged_fields);
236        }
237        Ok(())
238    }
239    fn encoded_len(&self, version: i16) -> usize {
240        let flex = version >= 0;
241        let mut n: usize = 0;
242        if version >= 0 {
243            n += 4;
244        }
245        if version >= 0 {
246            n += 4;
247        }
248        if flex {
249            let known_pairs: Vec<(u32, usize)> = Vec::new();
250            n += tagged_fields_len(&known_pairs, &self.unknown_tagged_fields);
251        }
252        n
253    }
254}
255impl Decode<'_> for PartitionData {
256    fn decode<B: Buf>(buf: &mut B, version: i16) -> Result<Self, ProtocolError> {
257        let flex = version >= 0;
258        let mut out = Self::default();
259        if version >= 0 {
260            out.partition = get_i32(buf)?;
261        }
262        if version >= 0 {
263            out.leader_epoch = get_i32(buf)?;
264        }
265        if flex {
266            out.unknown_tagged_fields = read_tagged_fields(buf, |_tag, _payload| Ok(false))?;
267        }
268        Ok(out)
269    }
270}
271#[cfg(test)]
272impl PartitionData {
273    #[must_use]
274    pub fn populated(version: i16) -> Self {
275        let mut m = Self::default();
276        if version >= 0 {
277            m.partition = 1i32;
278        }
279        if version >= 0 {
280            m.leader_epoch = 1i32;
281        }
282        m
283    }
284}
285
286/// Default JSON payload matching `Self::default()` for JVM oracle differential testing.
287/// Only includes fields valid for the given version.
288#[must_use]
289#[allow(unused_comparisons)]
290pub fn default_json(version: i16) -> ::serde_json::Value {
291    let mut obj = ::serde_json::Map::new();
292    obj.insert(
293        "groupId".to_string(),
294        ::serde_json::Value::String(String::new()),
295    );
296    obj.insert("topics".to_string(), ::serde_json::Value::Array(vec![]));
297    ::serde_json::Value::Object(obj)
298}
299
300impl crate::ProtocolRequest for ReadShareGroupStateRequest {
301    const API_KEY: i16 = API_KEY;
302    const MIN_VERSION: i16 = MIN_VERSION;
303    const MAX_VERSION: i16 = MAX_VERSION;
304    const FLEXIBLE_MIN: i16 = FLEXIBLE_MIN;
305    type Response = super::read_share_group_state_response::ReadShareGroupStateResponse;
306}