crabka_protocol/opt/rustwide/workdir/generated/
DeleteTopicsRequest.borrowed.rs1use bytes::BufMut;
4
5use crate::primitives::fixed::{get_i32, put_i32};
6use crate::primitives::string_bytes::{
7 compact_nullable_string_len, compact_string_len, nullable_string_len,
8 put_compact_nullable_string, put_compact_string, put_nullable_string, put_string,
9 string_len,
10};
11use crate::primitives::string_bytes_borrowed::{
12 get_compact_nullable_string_borrowed, get_compact_string_borrowed,
13 get_nullable_string_borrowed, get_string_borrowed,
14};
15use crate::tagged_fields::{read_tagged_fields, tagged_fields_len, WriteTaggedFields};
16use crate::{DecodeBorrow, Encode, ProtocolError, UnknownTaggedFields};
17
18pub const API_KEY: i16 = 20;
19pub const MIN_VERSION: i16 = 1;
20pub const MAX_VERSION: i16 = 6;
21pub const FLEXIBLE_MIN: i16 = 4;
22
23#[inline]
24fn is_flexible(version: i16) -> bool { version >= FLEXIBLE_MIN }
25
26#[derive(Debug, Clone, PartialEq, Eq)]
27pub struct DeleteTopicsRequest<'a> {
28 pub topics: Vec<DeleteTopicState<'a>>,
29 pub topic_names: Vec<&'a str>,
30 pub timeout_ms: i32,
31 pub unknown_tagged_fields: UnknownTaggedFields,
32}
33
34impl<'a> Default for DeleteTopicsRequest<'a> {
35 fn default() -> Self {
36 Self {
37 topics: Vec::new(),
38 topic_names: Vec::new(),
39 timeout_ms: 0i32,
40 unknown_tagged_fields: Default::default(),
41 }
42 }
43}
44
45impl<'a> DeleteTopicsRequest<'a> {
46 pub fn to_owned(&self) -> crate::owned::delete_topics_request::DeleteTopicsRequest {
47 crate::owned::delete_topics_request::DeleteTopicsRequest {
48 topics: (self.topics).iter().map(|it| it.to_owned()).collect(),
49 topic_names: (self.topic_names).iter().map(|s| s.to_string()).collect(),
50 timeout_ms: (self.timeout_ms),
51 unknown_tagged_fields: self.unknown_tagged_fields.clone(),
52 }
53 }
54}
55
56impl<'a> Encode for DeleteTopicsRequest<'a> {
57 fn encode<B: BufMut>(&self, buf: &mut B, version: i16) -> Result<(), ProtocolError> {
58 if !(MIN_VERSION..=MAX_VERSION).contains(&version) {
59 return Err(ProtocolError::UnsupportedVersion { api_key: API_KEY, version });
60 }
61 let flex = is_flexible(version);
62 if version >= 6 { { crate::primitives::array::put_array_len(buf, (self.topics).len(), flex); for it in &self.topics { it.encode(buf, version)?; } } }
63 if version >= 0 && version <= 5 { { crate::primitives::array::put_array_len(buf, (self.topic_names).len(), flex); for it in &self.topic_names { if flex { put_compact_string(buf, *it) } else { put_string(buf, *it) }; } } }
64 if version >= 0 { put_i32(buf, self.timeout_ms) }
65 if flex {
66 let tagged = WriteTaggedFields::new();
67 tagged.write(buf, &self.unknown_tagged_fields);
68 }
69 Ok(())
70 }
71 fn encoded_len(&self, version: i16) -> usize {
72 let flex = is_flexible(version);
73 let mut n: usize = 0;
74 if version >= 6 { n += { let prefix = crate::primitives::array::array_len_prefix_len((self.topics).len(), flex); let body: usize = (self.topics).iter().map(|it| it.encoded_len(version)).sum(); prefix + body }; }
75 if version >= 0 && version <= 5 { n += { let prefix = crate::primitives::array::array_len_prefix_len((self.topic_names).len(), flex); let body: usize = (self.topic_names).iter().map(|it| if flex { compact_string_len(*it) } else { string_len(*it) }).sum(); prefix + body }; }
76 if version >= 0 { n += 4; }
77 if flex {
78 let known_pairs: Vec<(u32, usize)> = Vec::new();
79 n += tagged_fields_len(&known_pairs, &self.unknown_tagged_fields);
80 }
81 n
82 }
83}
84
85impl<'de> DecodeBorrow<'de> for DeleteTopicsRequest<'de> {
86 fn decode_borrow(buf: &mut &'de [u8], version: i16) -> Result<Self, ProtocolError> {
87 if !(MIN_VERSION..=MAX_VERSION).contains(&version) {
88 return Err(ProtocolError::UnsupportedVersion { api_key: API_KEY, version });
89 }
90 let flex = is_flexible(version);
91 let mut out = Self::default();
92 if version >= 6 { out.topics = { let n = crate::primitives::array::get_array_len(buf, flex)?; let mut v = Vec::with_capacity(n); for _ in 0..n { v.push(DeleteTopicState::decode_borrow(buf, version)?); } v }; }
93 if version >= 0 && version <= 5 { out.topic_names = { let n = crate::primitives::array::get_array_len(buf, flex)?; let mut v = Vec::with_capacity(n); for _ in 0..n { v.push(if flex { get_compact_string_borrowed(buf)? } else { get_string_borrowed(buf)? }); } v }; }
94 if version >= 0 { out.timeout_ms = get_i32(buf)?; }
95 if flex {
96 out.unknown_tagged_fields = read_tagged_fields(buf, |_tag, _payload| {
97 Ok(false)
98 })?;
99 }
100 Ok(out)
101 }
102}
103
104#[derive(Debug, Clone, PartialEq, Eq)]
105pub struct DeleteTopicState<'a> {
106 pub name: Option<&'a str>,
107 pub topic_id: crate::primitives::uuid::Uuid,
108 pub unknown_tagged_fields: UnknownTaggedFields,
109}
110
111impl<'a> Default for DeleteTopicState<'a> {
112 fn default() -> Self {
113 Self {
114 name: None,
115 topic_id: Default::default(),
116 unknown_tagged_fields: Default::default(),
117 }
118 }
119}
120
121impl<'a> DeleteTopicState<'a> {
122 pub fn to_owned(&self) -> crate::owned::delete_topics_request::DeleteTopicState {
123 crate::owned::delete_topics_request::DeleteTopicState {
124 name: (self.name).map(|s| s.to_string()),
125 topic_id: (self.topic_id),
126 unknown_tagged_fields: self.unknown_tagged_fields.clone(),
127 }
128 }
129}
130
131impl<'a> Encode for DeleteTopicState<'a> {
132 fn encode<B: BufMut>(&self, buf: &mut B, version: i16) -> Result<(), ProtocolError> {
133 let flex = version >= 4;
134 if version >= 6 { if flex { put_compact_nullable_string(buf, self.name) } else { put_nullable_string(buf, self.name) } }
135 if version >= 6 { crate::primitives::uuid::put_uuid(buf, self.topic_id) }
136 if flex {
137 let tagged = WriteTaggedFields::new();
138 tagged.write(buf, &self.unknown_tagged_fields);
139 }
140 Ok(())
141 }
142 fn encoded_len(&self, version: i16) -> usize {
143 let flex = version >= 4;
144 let mut n: usize = 0;
145 if version >= 6 { n += if flex { compact_nullable_string_len(self.name) } else { nullable_string_len(self.name) }; }
146 if version >= 6 { n += 16; }
147 if flex {
148 let known_pairs: Vec<(u32, usize)> = Vec::new();
149 n += tagged_fields_len(&known_pairs, &self.unknown_tagged_fields);
150 }
151 n
152 }
153}
154
155impl<'de> DecodeBorrow<'de> for DeleteTopicState<'de> {
156 fn decode_borrow(buf: &mut &'de [u8], version: i16) -> Result<Self, ProtocolError> {
157 let flex = version >= 4;
158 let mut out = Self::default();
159 if version >= 6 { out.name = if flex { get_compact_nullable_string_borrowed(buf)? } else { get_nullable_string_borrowed(buf)? }; }
160 if version >= 6 { out.topic_id = crate::primitives::uuid::get_uuid(buf)?; }
161 if flex {
162 out.unknown_tagged_fields = read_tagged_fields(buf, |_tag, _payload| {
163 Ok(false)
164 })?;
165 }
166 Ok(out)
167 }
168}