Skip to main content

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

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