Skip to main content

crabka_protocol/opt/rustwide/workdir/generated/
ReadShareGroupStateSummaryRequest.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 = 87;
12pub const MIN_VERSION: i16 = 0;
13pub const MAX_VERSION: i16 = 1;
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 ReadShareGroupStateSummaryRequest {
21    pub group_id: String,
22    pub topics: Vec<ReadStateSummaryData>,
23    pub unknown_tagged_fields: UnknownTaggedFields,
24}
25impl Encode for ReadShareGroupStateSummaryRequest {
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 ReadShareGroupStateSummaryRequest {
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(ReadStateSummaryData::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 ReadShareGroupStateSummaryRequest {
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![ReadStateSummaryData::populated(version)];
123        }
124        m
125    }
126}
127#[derive(Debug, Clone, PartialEq, Eq, Default)]
128pub struct ReadStateSummaryData {
129    pub topic_id: crate::primitives::uuid::Uuid,
130    pub partitions: Vec<PartitionData>,
131    pub unknown_tagged_fields: UnknownTaggedFields,
132}
133impl Encode for ReadStateSummaryData {
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 ReadStateSummaryData {
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 ReadStateSummaryData {
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 leader_epoch: i32,
218    pub unknown_tagged_fields: UnknownTaggedFields,
219}
220impl Encode for PartitionData {
221    fn encode<B: BufMut>(&self, buf: &mut B, version: i16) -> Result<(), ProtocolError> {
222        let flex = version >= 0;
223        if version >= 0 {
224            put_i32(buf, self.partition);
225        }
226        if version >= 0 {
227            put_i32(buf, self.leader_epoch);
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 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 version >= 0 {
259            out.leader_epoch = get_i32(buf)?;
260        }
261        if flex {
262            out.unknown_tagged_fields = read_tagged_fields(buf, |_tag, _payload| Ok(false))?;
263        }
264        Ok(out)
265    }
266}
267#[cfg(test)]
268impl PartitionData {
269    #[must_use]
270    pub fn populated(version: i16) -> Self {
271        let mut m = Self::default();
272        if version >= 0 {
273            m.partition = 1i32;
274        }
275        if version >= 0 {
276            m.leader_epoch = 1i32;
277        }
278        m
279    }
280}
281/// Default JSON payload matching `Self::default()` for JVM oracle differential testing.
282/// Only includes fields valid for the given version.
283#[must_use]
284#[allow(unused_comparisons)]
285pub fn default_json(version: i16) -> ::serde_json::Value {
286    let mut obj = ::serde_json::Map::new();
287    obj.insert(
288        "groupId".to_string(),
289        ::serde_json::Value::String(String::new()),
290    );
291    obj.insert("topics".to_string(), ::serde_json::Value::Array(vec![]));
292    ::serde_json::Value::Object(obj)
293}
294impl crate::ProtocolRequest for ReadShareGroupStateSummaryRequest {
295    const API_KEY: i16 = API_KEY;
296    const MIN_VERSION: i16 = MIN_VERSION;
297    const MAX_VERSION: i16 = MAX_VERSION;
298    const FLEXIBLE_MIN: i16 = FLEXIBLE_MIN;
299    type Response =
300        super::read_share_group_state_summary_response::ReadShareGroupStateSummaryResponse;
301}