Skip to main content

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