crabka_protocol/opt/rustwide/workdir/generated/
DeleteGroupsResponse.owned.rs1use bytes::{Buf, BufMut};
4
5use crate::primitives::fixed::{get_i16, get_i32, put_i16, put_i32};
6use crate::primitives::string_bytes::{
7 compact_string_len, get_compact_string_owned, get_string_owned, put_compact_string, put_string,
8 string_len,
9};
10use crate::tagged_fields::{WriteTaggedFields, read_tagged_fields, tagged_fields_len};
11use crate::{Decode, Encode, ProtocolError, UnknownTaggedFields};
12
13pub const API_KEY: i16 = 42;
14pub const MIN_VERSION: i16 = 0;
15pub const MAX_VERSION: i16 = 2;
16pub const FLEXIBLE_MIN: i16 = 2;
17
18#[inline]
19fn is_flexible(version: i16) -> bool {
20 version >= FLEXIBLE_MIN
21}
22
23#[derive(Debug, Clone, PartialEq, Eq, Default)]
24pub struct DeleteGroupsResponse {
25 pub throttle_time_ms: i32,
26 pub results: Vec<DeletableGroupResult>,
27 pub unknown_tagged_fields: UnknownTaggedFields,
28}
29impl Encode for DeleteGroupsResponse {
30 fn encode<B: BufMut>(&self, buf: &mut B, version: i16) -> Result<(), ProtocolError> {
31 if !(MIN_VERSION..=MAX_VERSION).contains(&version) {
32 return Err(ProtocolError::UnsupportedVersion {
33 api_key: API_KEY,
34 version,
35 });
36 }
37 let flex = is_flexible(version);
38 if version >= 0 {
39 put_i32(buf, self.throttle_time_ms);
40 }
41 if version >= 0 {
42 {
43 crate::primitives::array::put_array_len(buf, (self.results).len(), flex);
44 for it in &self.results {
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 += 4;
60 }
61 if version >= 0 {
62 n += {
63 let prefix =
64 crate::primitives::array::array_len_prefix_len((self.results).len(), flex);
65 let body: usize = (self.results)
66 .iter()
67 .map(|it| it.encoded_len(version))
68 .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 DeleteGroupsResponse {
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 >= 0 {
90 out.throttle_time_ms = get_i32(buf)?;
91 }
92 if version >= 0 {
93 out.results = {
94 let n = crate::primitives::array::get_array_len(buf, flex)?;
95 let mut v = Vec::with_capacity(n);
96 for _ in 0..n {
97 v.push(DeletableGroupResult::decode(buf, version)?);
98 }
99 v
100 };
101 }
102 if flex {
103 out.unknown_tagged_fields = read_tagged_fields(buf, |_tag, _payload| Ok(false))?;
104 }
105 Ok(out)
106 }
107}
108#[cfg(test)]
109impl DeleteGroupsResponse {
110 #[must_use]
111 pub fn populated(version: i16) -> Self {
112 let mut m = Self::default();
113 if version >= 0 {
114 m.throttle_time_ms = 1i32;
115 }
116 if version >= 0 {
117 m.results = vec![DeletableGroupResult::populated(version)];
118 }
119 m
120 }
121}
122#[derive(Debug, Clone, PartialEq, Eq, Default)]
123pub struct DeletableGroupResult {
124 pub group_id: String,
125 pub error_code: i16,
126 pub unknown_tagged_fields: UnknownTaggedFields,
127}
128impl Encode for DeletableGroupResult {
129 fn encode<B: BufMut>(&self, buf: &mut B, version: i16) -> Result<(), ProtocolError> {
130 let flex = version >= 2;
131 if version >= 0 {
132 if flex {
133 put_compact_string(buf, &self.group_id);
134 } else {
135 put_string(buf, &self.group_id);
136 }
137 }
138 if version >= 0 {
139 put_i16(buf, self.error_code);
140 }
141 if flex {
142 let tagged = WriteTaggedFields::new();
143 tagged.write(buf, &self.unknown_tagged_fields);
144 }
145 Ok(())
146 }
147 fn encoded_len(&self, version: i16) -> usize {
148 let flex = version >= 2;
149 let mut n: usize = 0;
150 if version >= 0 {
151 n += if flex {
152 compact_string_len(&self.group_id)
153 } else {
154 string_len(&self.group_id)
155 };
156 }
157 if version >= 0 {
158 n += 2;
159 }
160 if flex {
161 let known_pairs: Vec<(u32, usize)> = Vec::new();
162 n += tagged_fields_len(&known_pairs, &self.unknown_tagged_fields);
163 }
164 n
165 }
166}
167impl Decode<'_> for DeletableGroupResult {
168 fn decode<B: Buf>(buf: &mut B, version: i16) -> Result<Self, ProtocolError> {
169 let flex = version >= 2;
170 let mut out = Self::default();
171 if version >= 0 {
172 out.group_id = if flex {
173 get_compact_string_owned(buf)?
174 } else {
175 get_string_owned(buf)?
176 };
177 }
178 if version >= 0 {
179 out.error_code = get_i16(buf)?;
180 }
181 if flex {
182 out.unknown_tagged_fields = read_tagged_fields(buf, |_tag, _payload| Ok(false))?;
183 }
184 Ok(out)
185 }
186}
187#[cfg(test)]
188impl DeletableGroupResult {
189 #[must_use]
190 pub fn populated(version: i16) -> Self {
191 let mut m = Self::default();
192 if version >= 0 {
193 m.group_id = "x".to_string();
194 }
195 if version >= 0 {
196 m.error_code = 1i16;
197 }
198 m
199 }
200}
201
202#[must_use]
205#[allow(unused_comparisons)]
206pub fn default_json(version: i16) -> ::serde_json::Value {
207 let mut obj = ::serde_json::Map::new();
208 obj.insert("throttleTimeMs".to_string(), ::serde_json::json!(0));
209 obj.insert("results".to_string(), ::serde_json::Value::Array(vec![]));
210 ::serde_json::Value::Object(obj)
211}