Skip to main content

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

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