crabka_protocol/opt/rustwide/workdir/generated/
AlterReplicaLogDirsRequest.borrowed.rs1use bytes::BufMut;
4
5use crate::primitives::fixed::{get_i32, put_i32};
6use crate::primitives::string_bytes::{
7 compact_string_len, put_compact_string, put_string, string_len,
8};
9use crate::primitives::string_bytes_borrowed::{
10 get_compact_string_borrowed, get_string_borrowed,
11};
12use crate::tagged_fields::{read_tagged_fields, tagged_fields_len, WriteTaggedFields};
13use crate::{DecodeBorrow, Encode, ProtocolError, UnknownTaggedFields};
14
15pub const API_KEY: i16 = 34;
16pub const MIN_VERSION: i16 = 1;
17pub const MAX_VERSION: i16 = 2;
18pub const FLEXIBLE_MIN: i16 = 2;
19
20#[inline]
21fn is_flexible(version: i16) -> bool { version >= FLEXIBLE_MIN }
22
23#[derive(Debug, Clone, PartialEq, Eq)]
24pub struct AlterReplicaLogDirsRequest<'a> {
25 pub dirs: Vec<AlterReplicaLogDir<'a>>,
26 pub unknown_tagged_fields: UnknownTaggedFields,
27}
28
29impl<'a> Default for AlterReplicaLogDirsRequest<'a> {
30 fn default() -> Self {
31 Self {
32 dirs: Vec::new(),
33 unknown_tagged_fields: Default::default(),
34 }
35 }
36}
37
38impl<'a> AlterReplicaLogDirsRequest<'a> {
39 pub fn to_owned(&self) -> crate::owned::alter_replica_log_dirs_request::AlterReplicaLogDirsRequest {
40 crate::owned::alter_replica_log_dirs_request::AlterReplicaLogDirsRequest {
41 dirs: (self.dirs).iter().map(|it| it.to_owned()).collect(),
42 unknown_tagged_fields: self.unknown_tagged_fields.clone(),
43 }
44 }
45}
46
47impl<'a> Encode for AlterReplicaLogDirsRequest<'a> {
48 fn encode<B: BufMut>(&self, buf: &mut B, version: i16) -> Result<(), ProtocolError> {
49 if !(MIN_VERSION..=MAX_VERSION).contains(&version) {
50 return Err(ProtocolError::UnsupportedVersion { api_key: API_KEY, version });
51 }
52 let flex = is_flexible(version);
53 if version >= 0 { { crate::primitives::array::put_array_len(buf, (self.dirs).len(), flex); for it in &self.dirs { it.encode(buf, version)?; } } }
54 if flex {
55 let tagged = WriteTaggedFields::new();
56 tagged.write(buf, &self.unknown_tagged_fields);
57 }
58 Ok(())
59 }
60 fn encoded_len(&self, version: i16) -> usize {
61 let flex = is_flexible(version);
62 let mut n: usize = 0;
63 if version >= 0 { n += { let prefix = crate::primitives::array::array_len_prefix_len((self.dirs).len(), flex); let body: usize = (self.dirs).iter().map(|it| it.encoded_len(version)).sum(); prefix + body }; }
64 if flex {
65 let known_pairs: Vec<(u32, usize)> = Vec::new();
66 n += tagged_fields_len(&known_pairs, &self.unknown_tagged_fields);
67 }
68 n
69 }
70}
71
72impl<'de> DecodeBorrow<'de> for AlterReplicaLogDirsRequest<'de> {
73 fn decode_borrow(buf: &mut &'de [u8], version: i16) -> Result<Self, ProtocolError> {
74 if !(MIN_VERSION..=MAX_VERSION).contains(&version) {
75 return Err(ProtocolError::UnsupportedVersion { api_key: API_KEY, version });
76 }
77 let flex = is_flexible(version);
78 let mut out = Self::default();
79 if version >= 0 { out.dirs = { let n = crate::primitives::array::get_array_len(buf, flex)?; let mut v = Vec::with_capacity(n); for _ in 0..n { v.push(AlterReplicaLogDir::decode_borrow(buf, version)?); } v }; }
80 if flex {
81 out.unknown_tagged_fields = read_tagged_fields(buf, |_tag, _payload| {
82 Ok(false)
83 })?;
84 }
85 Ok(out)
86 }
87}
88
89#[derive(Debug, Clone, PartialEq, Eq)]
90pub struct AlterReplicaLogDir<'a> {
91 pub path: &'a str,
92 pub topics: Vec<AlterReplicaLogDirTopic<'a>>,
93 pub unknown_tagged_fields: UnknownTaggedFields,
94}
95
96impl<'a> Default for AlterReplicaLogDir<'a> {
97 fn default() -> Self {
98 Self {
99 path: "",
100 topics: Vec::new(),
101 unknown_tagged_fields: Default::default(),
102 }
103 }
104}
105
106impl<'a> AlterReplicaLogDir<'a> {
107 pub fn to_owned(&self) -> crate::owned::alter_replica_log_dirs_request::AlterReplicaLogDir {
108 crate::owned::alter_replica_log_dirs_request::AlterReplicaLogDir {
109 path: (self.path).to_string(),
110 topics: (self.topics).iter().map(|it| it.to_owned()).collect(),
111 unknown_tagged_fields: self.unknown_tagged_fields.clone(),
112 }
113 }
114}
115
116impl<'a> Encode for AlterReplicaLogDir<'a> {
117 fn encode<B: BufMut>(&self, buf: &mut B, version: i16) -> Result<(), ProtocolError> {
118 let flex = version >= 2;
119 if version >= 0 { if flex { put_compact_string(buf, self.path) } else { put_string(buf, self.path) } }
120 if version >= 0 { { crate::primitives::array::put_array_len(buf, (self.topics).len(), flex); for it in &self.topics { it.encode(buf, version)?; } } }
121 if flex {
122 let tagged = WriteTaggedFields::new();
123 tagged.write(buf, &self.unknown_tagged_fields);
124 }
125 Ok(())
126 }
127 fn encoded_len(&self, version: i16) -> usize {
128 let flex = version >= 2;
129 let mut n: usize = 0;
130 if version >= 0 { n += if flex { compact_string_len(self.path) } else { string_len(self.path) }; }
131 if version >= 0 { 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 }; }
132 if flex {
133 let known_pairs: Vec<(u32, usize)> = Vec::new();
134 n += tagged_fields_len(&known_pairs, &self.unknown_tagged_fields);
135 }
136 n
137 }
138}
139
140impl<'de> DecodeBorrow<'de> for AlterReplicaLogDir<'de> {
141 fn decode_borrow(buf: &mut &'de [u8], version: i16) -> Result<Self, ProtocolError> {
142 let flex = version >= 2;
143 let mut out = Self::default();
144 if version >= 0 { out.path = if flex { get_compact_string_borrowed(buf)? } else { get_string_borrowed(buf)? }; }
145 if version >= 0 { 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(AlterReplicaLogDirTopic::decode_borrow(buf, version)?); } v }; }
146 if flex {
147 out.unknown_tagged_fields = read_tagged_fields(buf, |_tag, _payload| {
148 Ok(false)
149 })?;
150 }
151 Ok(out)
152 }
153}
154
155#[derive(Debug, Clone, PartialEq, Eq)]
156pub struct AlterReplicaLogDirTopic<'a> {
157 pub name: &'a str,
158 pub partitions: Vec<i32>,
159 pub unknown_tagged_fields: UnknownTaggedFields,
160}
161
162impl<'a> Default for AlterReplicaLogDirTopic<'a> {
163 fn default() -> Self {
164 Self {
165 name: "",
166 partitions: Vec::new(),
167 unknown_tagged_fields: Default::default(),
168 }
169 }
170}
171
172impl<'a> AlterReplicaLogDirTopic<'a> {
173 pub fn to_owned(&self) -> crate::owned::alter_replica_log_dirs_request::AlterReplicaLogDirTopic {
174 crate::owned::alter_replica_log_dirs_request::AlterReplicaLogDirTopic {
175 name: (self.name).to_string(),
176 partitions: (self.partitions).clone(),
177 unknown_tagged_fields: self.unknown_tagged_fields.clone(),
178 }
179 }
180}
181
182impl<'a> Encode for AlterReplicaLogDirTopic<'a> {
183 fn encode<B: BufMut>(&self, buf: &mut B, version: i16) -> Result<(), ProtocolError> {
184 let flex = version >= 2;
185 if version >= 0 { if flex { put_compact_string(buf, self.name) } else { put_string(buf, self.name) } }
186 if version >= 0 { { crate::primitives::array::put_array_len(buf, (self.partitions).len(), flex); for it in &self.partitions { put_i32(buf, *it); } } }
187 if flex {
188 let tagged = WriteTaggedFields::new();
189 tagged.write(buf, &self.unknown_tagged_fields);
190 }
191 Ok(())
192 }
193 fn encoded_len(&self, version: i16) -> usize {
194 let flex = version >= 2;
195 let mut n: usize = 0;
196 if version >= 0 { n += if flex { compact_string_len(self.name) } else { string_len(self.name) }; }
197 if version >= 0 { n += { let prefix = crate::primitives::array::array_len_prefix_len((self.partitions).len(), flex); let body: usize = (self.partitions).iter().map(|_| 4).sum(); prefix + body }; }
198 if flex {
199 let known_pairs: Vec<(u32, usize)> = Vec::new();
200 n += tagged_fields_len(&known_pairs, &self.unknown_tagged_fields);
201 }
202 n
203 }
204}
205
206impl<'de> DecodeBorrow<'de> for AlterReplicaLogDirTopic<'de> {
207 fn decode_borrow(buf: &mut &'de [u8], version: i16) -> Result<Self, ProtocolError> {
208 let flex = version >= 2;
209 let mut out = Self::default();
210 if version >= 0 { out.name = if flex { get_compact_string_borrowed(buf)? } else { get_string_borrowed(buf)? }; }
211 if version >= 0 { out.partitions = { let n = crate::primitives::array::get_array_len(buf, flex)?; let mut v = Vec::with_capacity(n); for _ in 0..n { v.push(get_i32(buf)?); } v }; }
212 if flex {
213 out.unknown_tagged_fields = read_tagged_fields(buf, |_tag, _payload| {
214 Ok(false)
215 })?;
216 }
217 Ok(out)
218 }
219}