Skip to main content

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

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