Skip to main content

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

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