Skip to main content

crabka_protocol/opt/rustwide/workdir/generated/
DeleteTopicsRequest.borrowed.rs

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