Skip to main content

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