Skip to main content

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

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