Skip to main content

krabka_protocol/opt/rustwide/workdir/generated/
DeleteGroupsResponse.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_nullable_string_len, compact_string_len, get_compact_nullable_string_owned,
11            get_compact_string_owned, get_nullable_string_owned, get_string_owned,
12            nullable_string_len, put_compact_nullable_string, put_compact_string,
13            put_nullable_string, put_string, string_len,
14        },
15    },
16    tagged_fields::{WriteTaggedFields, read_tagged_fields, tagged_fields_len},
17};
18pub const API_KEY: i16 = 42;
19pub const MIN_VERSION: i16 = 0;
20pub const MAX_VERSION: i16 = 3;
21pub const FLEXIBLE_MIN: i16 = 2;
22#[inline]
23#[must_use]
24pub fn is_flexible(version: i16) -> bool {
25    version >= FLEXIBLE_MIN
26}
27#[derive(Debug, Clone, PartialEq, Eq, Default)]
28pub struct DeleteGroupsResponse {
29    pub throttle_time_ms: i32,
30    pub results: Vec<DeletableGroupResult>,
31    pub unknown_tagged_fields: UnknownTaggedFields,
32}
33impl Encode for DeleteGroupsResponse {
34    fn encode<B: BufMut>(&self, buf: &mut B, version: i16) -> Result<(), ProtocolError> {
35        if !(MIN_VERSION..=MAX_VERSION).contains(&version) {
36            return Err(ProtocolError::UnsupportedVersion {
37                api_key: API_KEY,
38                version,
39            });
40        }
41        let flex = is_flexible(version);
42        if version >= 0 {
43            put_i32(buf, self.throttle_time_ms);
44        }
45        if version >= 0 {
46            {
47                crate::primitives::array::put_array_len(buf, (self.results).len(), flex);
48                for it in &self.results {
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 += 4;
64        }
65        if version >= 0 {
66            n += {
67                let prefix =
68                    crate::primitives::array::array_len_prefix_len((self.results).len(), flex);
69                let body: usize = (self.results)
70                    .iter()
71                    .map(|it| it.encoded_len(version))
72                    .sum();
73                prefix + body
74            };
75        }
76        if flex {
77            let known_pairs: Vec<(u32, usize)> = Vec::new();
78            n += tagged_fields_len(&known_pairs, &self.unknown_tagged_fields);
79        }
80        n
81    }
82}
83impl Decode<'_> for DeleteGroupsResponse {
84    fn decode<B: Buf>(buf: &mut B, version: i16) -> Result<Self, ProtocolError> {
85        if !(MIN_VERSION..=MAX_VERSION).contains(&version) {
86            return Err(ProtocolError::UnsupportedVersion {
87                api_key: API_KEY,
88                version,
89            });
90        }
91        let flex = is_flexible(version);
92        let mut out = Self::default();
93        if version >= 0 {
94            out.throttle_time_ms = get_i32(buf)?;
95        }
96        if version >= 0 {
97            out.results = {
98                let n = crate::primitives::array::get_array_len(buf, flex)?;
99                let mut v = Vec::with_capacity(n);
100                for _ in 0..n {
101                    v.push(DeletableGroupResult::decode(buf, version)?);
102                }
103                v
104            };
105        }
106        if flex {
107            out.unknown_tagged_fields = read_tagged_fields(buf, |_tag, _payload| Ok(false))?;
108        }
109        Ok(out)
110    }
111}
112#[cfg(test)]
113impl DeleteGroupsResponse {
114    #[must_use]
115    pub fn populated(version: i16) -> Self {
116        let mut m = Self::default();
117        if version >= 0 {
118            m.throttle_time_ms = 1i32;
119        }
120        if version >= 0 {
121            m.results = vec![DeletableGroupResult::populated(version)];
122        }
123        m
124    }
125}
126#[derive(Debug, Clone, PartialEq, Eq, Default)]
127pub struct DeletableGroupResult {
128    pub group_id: String,
129    pub error_code: i16,
130    pub error_message: Option<String>,
131    pub unknown_tagged_fields: UnknownTaggedFields,
132}
133impl Encode for DeletableGroupResult {
134    fn encode<B: BufMut>(&self, buf: &mut B, version: i16) -> Result<(), ProtocolError> {
135        let flex = version >= 2;
136        if version >= 0 {
137            if flex {
138                let () = put_compact_string(buf, &self.group_id);
139            } else {
140                let () = put_string(buf, &self.group_id);
141            }
142        }
143        if version >= 0 {
144            put_i16(buf, self.error_code);
145        }
146        if version >= 3 {
147            if flex {
148                let () = put_compact_nullable_string(buf, self.error_message.as_deref());
149            } else {
150                let () = put_nullable_string(buf, self.error_message.as_deref());
151            }
152        }
153        if flex {
154            let tagged = WriteTaggedFields::new();
155            tagged.write(buf, &self.unknown_tagged_fields);
156        }
157        Ok(())
158    }
159    fn encoded_len(&self, version: i16) -> usize {
160        let flex = version >= 2;
161        let mut n: usize = 0;
162        if version >= 0 {
163            n += if flex {
164                compact_string_len(&self.group_id)
165            } else {
166                string_len(&self.group_id)
167            };
168        }
169        if version >= 0 {
170            n += 2;
171        }
172        if version >= 3 {
173            n += if flex {
174                compact_nullable_string_len(self.error_message.as_deref())
175            } else {
176                nullable_string_len(self.error_message.as_deref())
177            };
178        }
179        if flex {
180            let known_pairs: Vec<(u32, usize)> = Vec::new();
181            n += tagged_fields_len(&known_pairs, &self.unknown_tagged_fields);
182        }
183        n
184    }
185}
186impl Decode<'_> for DeletableGroupResult {
187    fn decode<B: Buf>(buf: &mut B, version: i16) -> Result<Self, ProtocolError> {
188        let flex = version >= 2;
189        let mut out = Self::default();
190        if version >= 0 {
191            out.group_id = if flex {
192                get_compact_string_owned(buf)?
193            } else {
194                get_string_owned(buf)?
195            };
196        }
197        if version >= 0 {
198            out.error_code = get_i16(buf)?;
199        }
200        if version >= 3 {
201            out.error_message = if flex {
202                get_compact_nullable_string_owned(buf)?
203            } else {
204                get_nullable_string_owned(buf)?
205            };
206        }
207        if flex {
208            out.unknown_tagged_fields = read_tagged_fields(buf, |_tag, _payload| Ok(false))?;
209        }
210        Ok(out)
211    }
212}
213#[cfg(test)]
214impl DeletableGroupResult {
215    #[must_use]
216    pub fn populated(version: i16) -> Self {
217        let mut m = Self::default();
218        if version >= 0 {
219            m.group_id = "x".to_string();
220        }
221        if version >= 0 {
222            m.error_code = 1i16;
223        }
224        if version >= 3 {
225            m.error_message = Some("x".to_string());
226        }
227        m
228    }
229}
230/// Default JSON payload matching `Self::default()` for JVM oracle differential testing.
231/// Only includes fields valid for the given version.
232#[must_use]
233#[allow(unused_comparisons)]
234pub fn default_json(_version: i16) -> ::serde_json::Value {
235    let mut obj = ::serde_json::Map::new();
236    obj.insert("throttleTimeMs".to_string(), ::serde_json::json!(0));
237    obj.insert("results".to_string(), ::serde_json::Value::Array(vec![]));
238    ::serde_json::Value::Object(obj)
239}