Skip to main content

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