Skip to main content

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

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