Skip to main content

crabka_protocol/opt/rustwide/workdir/generated/
GetReplicaLogInfoResponse.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, get_i64, put_i16, put_i32, put_i64};
6use crate::primitives::string_bytes::{
7    compact_nullable_string_len, compact_string_len, nullable_string_len,
8    put_compact_nullable_string, put_compact_string, put_nullable_string, put_string,
9    string_len,
10};
11use crate::primitives::string_bytes_borrowed::{
12    get_compact_nullable_string_borrowed, get_compact_string_borrowed,
13    get_nullable_string_borrowed, get_string_borrowed,
14};
15use crate::tagged_fields::{read_tagged_fields, tagged_fields_len, WriteTaggedFields};
16use crate::{DecodeBorrow, Encode, ProtocolError, UnknownTaggedFields};
17
18pub const API_KEY: i16 = 93;
19pub const MIN_VERSION: i16 = 0;
20pub const MAX_VERSION: i16 = 0;
21pub const FLEXIBLE_MIN: i16 = 0;
22
23#[inline]
24fn is_flexible(version: i16) -> bool { version >= FLEXIBLE_MIN }
25
26#[derive(Debug, Clone, PartialEq, Eq)]
27pub struct GetReplicaLogInfoResponse<'a> {
28    pub broker_epoch: i64,
29    pub topic_partition_log_info_list: Vec<TopicPartitionLogInfo<'a>>,
30    pub unknown_tagged_fields: UnknownTaggedFields,
31}
32
33impl<'a> Default for GetReplicaLogInfoResponse<'a> {
34    fn default() -> Self {
35        Self {
36            broker_epoch: 0i64,
37            topic_partition_log_info_list: Vec::new(),
38            unknown_tagged_fields: Default::default(),
39        }
40    }
41}
42
43impl<'a> GetReplicaLogInfoResponse<'a> {
44    pub fn to_owned(&self) -> crate::owned::get_replica_log_info_response::GetReplicaLogInfoResponse {
45        crate::owned::get_replica_log_info_response::GetReplicaLogInfoResponse {
46            broker_epoch: (self.broker_epoch),
47            topic_partition_log_info_list: (self.topic_partition_log_info_list).iter().map(|it| it.to_owned()).collect(),
48            unknown_tagged_fields: self.unknown_tagged_fields.clone(),
49        }
50    }
51}
52
53impl<'a> Encode for GetReplicaLogInfoResponse<'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 { put_i64(buf, self.broker_epoch) }
60        if version >= 0 { { crate::primitives::array::put_array_len(buf, (self.topic_partition_log_info_list).len(), flex); for it in &self.topic_partition_log_info_list { it.encode(buf, version)?; } } }
61        if flex {
62            let tagged = WriteTaggedFields::new();
63            tagged.write(buf, &self.unknown_tagged_fields);
64        }
65        Ok(())
66    }
67    fn encoded_len(&self, version: i16) -> usize {
68        let flex = is_flexible(version);
69        let mut n: usize = 0;
70        if version >= 0 { n += 8; }
71        if version >= 0 { n += { let prefix = crate::primitives::array::array_len_prefix_len((self.topic_partition_log_info_list).len(), flex); let body: usize = (self.topic_partition_log_info_list).iter().map(|it| it.encoded_len(version)).sum(); prefix + body }; }
72        if flex {
73            let known_pairs: Vec<(u32, usize)> = Vec::new();
74            n += tagged_fields_len(&known_pairs, &self.unknown_tagged_fields);
75        }
76        n
77    }
78}
79
80impl<'de> DecodeBorrow<'de> for GetReplicaLogInfoResponse<'de> {
81    fn decode_borrow(buf: &mut &'de [u8], version: i16) -> Result<Self, ProtocolError> {
82        if !(MIN_VERSION..=MAX_VERSION).contains(&version) {
83            return Err(ProtocolError::UnsupportedVersion { api_key: API_KEY, version });
84        }
85        let flex = is_flexible(version);
86        let mut out = Self::default();
87        if version >= 0 { out.broker_epoch = get_i64(buf)?; }
88        if version >= 0 { out.topic_partition_log_info_list = { let n = crate::primitives::array::get_array_len(buf, flex)?; let mut v = Vec::with_capacity(n); for _ in 0..n { v.push(TopicPartitionLogInfo::decode_borrow(buf, version)?); } v }; }
89        if flex {
90            out.unknown_tagged_fields = read_tagged_fields(buf, |_tag, _payload| {
91                Ok(false)
92            })?;
93        }
94        Ok(out)
95    }
96}
97
98#[derive(Debug, Clone, PartialEq, Eq)]
99pub struct TopicPartitionLogInfo<'a> {
100    pub topic_id: crate::primitives::uuid::Uuid,
101    pub partition_log_info: Vec<PartitionLogInfo<'a>>,
102    pub unknown_tagged_fields: UnknownTaggedFields,
103}
104
105impl<'a> Default for TopicPartitionLogInfo<'a> {
106    fn default() -> Self {
107        Self {
108            topic_id: Default::default(),
109            partition_log_info: Vec::new(),
110            unknown_tagged_fields: Default::default(),
111        }
112    }
113}
114
115impl<'a> TopicPartitionLogInfo<'a> {
116    pub fn to_owned(&self) -> crate::owned::get_replica_log_info_response::TopicPartitionLogInfo {
117        crate::owned::get_replica_log_info_response::TopicPartitionLogInfo {
118            topic_id: (self.topic_id),
119            partition_log_info: (self.partition_log_info).iter().map(|it| it.to_owned()).collect(),
120            unknown_tagged_fields: self.unknown_tagged_fields.clone(),
121        }
122    }
123}
124
125impl<'a> Encode for TopicPartitionLogInfo<'a> {
126    fn encode<B: BufMut>(&self, buf: &mut B, version: i16) -> Result<(), ProtocolError> {
127        let flex = version >= 0;
128        if version >= 0 { crate::primitives::uuid::put_uuid(buf, self.topic_id) }
129        if version >= 0 { { crate::primitives::array::put_array_len(buf, (self.partition_log_info).len(), flex); for it in &self.partition_log_info { it.encode(buf, version)?; } } }
130        if flex {
131            let tagged = WriteTaggedFields::new();
132            tagged.write(buf, &self.unknown_tagged_fields);
133        }
134        Ok(())
135    }
136    fn encoded_len(&self, version: i16) -> usize {
137        let flex = version >= 0;
138        let mut n: usize = 0;
139        if version >= 0 { n += 16; }
140        if version >= 0 { n += { let prefix = crate::primitives::array::array_len_prefix_len((self.partition_log_info).len(), flex); let body: usize = (self.partition_log_info).iter().map(|it| it.encoded_len(version)).sum(); prefix + body }; }
141        if flex {
142            let known_pairs: Vec<(u32, usize)> = Vec::new();
143            n += tagged_fields_len(&known_pairs, &self.unknown_tagged_fields);
144        }
145        n
146    }
147}
148
149impl<'de> DecodeBorrow<'de> for TopicPartitionLogInfo<'de> {
150    fn decode_borrow(buf: &mut &'de [u8], version: i16) -> Result<Self, ProtocolError> {
151        let flex = version >= 0;
152        let mut out = Self::default();
153        if version >= 0 { out.topic_id = crate::primitives::uuid::get_uuid(buf)?; }
154        if version >= 0 { out.partition_log_info = { let n = crate::primitives::array::get_array_len(buf, flex)?; let mut v = Vec::with_capacity(n); for _ in 0..n { v.push(PartitionLogInfo::decode_borrow(buf, version)?); } v }; }
155        if flex {
156            out.unknown_tagged_fields = read_tagged_fields(buf, |_tag, _payload| {
157                Ok(false)
158            })?;
159        }
160        Ok(out)
161    }
162}
163
164#[derive(Debug, Clone, PartialEq, Eq)]
165pub struct PartitionLogInfo<'a> {
166    pub partition: i32,
167    pub last_written_leader_epoch: i32,
168    pub current_leader_epoch: i32,
169    pub log_end_offset: i64,
170    pub error_code: i16,
171    pub error_message: Option<&'a str>,
172    pub unknown_tagged_fields: UnknownTaggedFields,
173}
174
175impl<'a> Default for PartitionLogInfo<'a> {
176    fn default() -> Self {
177        Self {
178            partition: 0i32,
179            last_written_leader_epoch: 0i32,
180            current_leader_epoch: 0i32,
181            log_end_offset: 0i64,
182            error_code: 0i16,
183            error_message: None,
184            unknown_tagged_fields: Default::default(),
185        }
186    }
187}
188
189impl<'a> PartitionLogInfo<'a> {
190    pub fn to_owned(&self) -> crate::owned::get_replica_log_info_response::PartitionLogInfo {
191        crate::owned::get_replica_log_info_response::PartitionLogInfo {
192            partition: (self.partition),
193            last_written_leader_epoch: (self.last_written_leader_epoch),
194            current_leader_epoch: (self.current_leader_epoch),
195            log_end_offset: (self.log_end_offset),
196            error_code: (self.error_code),
197            error_message: (self.error_message).map(|s| s.to_string()),
198            unknown_tagged_fields: self.unknown_tagged_fields.clone(),
199        }
200    }
201}
202
203impl<'a> Encode for PartitionLogInfo<'a> {
204    fn encode<B: BufMut>(&self, buf: &mut B, version: i16) -> Result<(), ProtocolError> {
205        let flex = version >= 0;
206        if version >= 0 { put_i32(buf, self.partition) }
207        if version >= 0 { put_i32(buf, self.last_written_leader_epoch) }
208        if version >= 0 { put_i32(buf, self.current_leader_epoch) }
209        if version >= 0 { put_i64(buf, self.log_end_offset) }
210        if version >= 0 { put_i16(buf, self.error_code) }
211        if version >= 0 { if flex { put_compact_nullable_string(buf, self.error_message) } else { put_nullable_string(buf, self.error_message) } }
212        if flex {
213            let tagged = WriteTaggedFields::new();
214            tagged.write(buf, &self.unknown_tagged_fields);
215        }
216        Ok(())
217    }
218    fn encoded_len(&self, version: i16) -> usize {
219        let flex = version >= 0;
220        let mut n: usize = 0;
221        if version >= 0 { n += 4; }
222        if version >= 0 { n += 4; }
223        if version >= 0 { n += 4; }
224        if version >= 0 { n += 8; }
225        if version >= 0 { n += 2; }
226        if version >= 0 { n += if flex { compact_nullable_string_len(self.error_message) } else { nullable_string_len(self.error_message) }; }
227        if flex {
228            let known_pairs: Vec<(u32, usize)> = Vec::new();
229            n += tagged_fields_len(&known_pairs, &self.unknown_tagged_fields);
230        }
231        n
232    }
233}
234
235impl<'de> DecodeBorrow<'de> for PartitionLogInfo<'de> {
236    fn decode_borrow(buf: &mut &'de [u8], version: i16) -> Result<Self, ProtocolError> {
237        let flex = version >= 0;
238        let mut out = Self::default();
239        if version >= 0 { out.partition = get_i32(buf)?; }
240        if version >= 0 { out.last_written_leader_epoch = get_i32(buf)?; }
241        if version >= 0 { out.current_leader_epoch = get_i32(buf)?; }
242        if version >= 0 { out.log_end_offset = get_i64(buf)?; }
243        if version >= 0 { out.error_code = get_i16(buf)?; }
244        if version >= 0 { out.error_message = if flex { get_compact_nullable_string_borrowed(buf)? } else { get_nullable_string_borrowed(buf)? }; }
245        if flex {
246            out.unknown_tagged_fields = read_tagged_fields(buf, |_tag, _payload| {
247                Ok(false)
248            })?;
249        }
250        Ok(out)
251    }
252}