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.
2
3use bytes::BufMut;
4
5use crate::primitives::fixed::{get_i32, put_i32};
6use crate::tagged_fields::{read_tagged_fields, tagged_fields_len, WriteTaggedFields};
7use crate::{DecodeBorrow, Encode, ProtocolError, UnknownTaggedFields};
8
9pub const API_KEY: i16 = 93;
10pub const MIN_VERSION: i16 = 0;
11pub const MAX_VERSION: i16 = 0;
12pub const FLEXIBLE_MIN: i16 = 0;
13
14#[inline]
15fn is_flexible(version: i16) -> bool { version >= FLEXIBLE_MIN }
16
17#[derive(Debug, Clone, PartialEq, Eq)]
18pub struct GetReplicaLogInfoRequest {
19    pub broker_id: i32,
20    pub topic_partitions: Vec<TopicPartitions>,
21    pub unknown_tagged_fields: UnknownTaggedFields,
22}
23
24impl Default for GetReplicaLogInfoRequest {
25    fn default() -> Self {
26        Self {
27            broker_id: 0i32,
28            topic_partitions: Vec::new(),
29            unknown_tagged_fields: Default::default(),
30        }
31    }
32}
33
34impl GetReplicaLogInfoRequest {
35    pub fn to_owned(&self) -> crate::owned::get_replica_log_info_request::GetReplicaLogInfoRequest {
36        crate::owned::get_replica_log_info_request::GetReplicaLogInfoRequest {
37            broker_id: (self.broker_id),
38            topic_partitions: (self.topic_partitions).iter().map(|it| it.to_owned()).collect(),
39            unknown_tagged_fields: self.unknown_tagged_fields.clone(),
40        }
41    }
42}
43
44impl Encode for GetReplicaLogInfoRequest {
45    fn encode<B: BufMut>(&self, buf: &mut B, version: i16) -> Result<(), ProtocolError> {
46        if !(MIN_VERSION..=MAX_VERSION).contains(&version) {
47            return Err(ProtocolError::UnsupportedVersion { api_key: API_KEY, version });
48        }
49        let flex = is_flexible(version);
50        if version >= 0 { put_i32(buf, self.broker_id) }
51        if version >= 0 { { crate::primitives::array::put_array_len(buf, (self.topic_partitions).len(), flex); for it in &self.topic_partitions { it.encode(buf, version)?; } } }
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 { n += 4; }
62        if version >= 0 { n += { let prefix = crate::primitives::array::array_len_prefix_len((self.topic_partitions).len(), flex); let body: usize = (self.topic_partitions).iter().map(|it| it.encoded_len(version)).sum(); prefix + body }; }
63        if flex {
64            let known_pairs: Vec<(u32, usize)> = Vec::new();
65            n += tagged_fields_len(&known_pairs, &self.unknown_tagged_fields);
66        }
67        n
68    }
69}
70
71impl<'de> DecodeBorrow<'de> for GetReplicaLogInfoRequest {
72    fn decode_borrow(buf: &mut &'de [u8], version: i16) -> Result<Self, ProtocolError> {
73        if !(MIN_VERSION..=MAX_VERSION).contains(&version) {
74            return Err(ProtocolError::UnsupportedVersion { api_key: API_KEY, version });
75        }
76        let flex = is_flexible(version);
77        let mut out = Self::default();
78        if version >= 0 { out.broker_id = get_i32(buf)?; }
79        if version >= 0 { out.topic_partitions = { let n = crate::primitives::array::get_array_len(buf, flex)?; let mut v = Vec::with_capacity(n); for _ in 0..n { v.push(TopicPartitions::decode_borrow(buf, version)?); } v }; }
80        if flex {
81            out.unknown_tagged_fields = read_tagged_fields(buf, |_tag, _payload| {
82                Ok(false)
83            })?;
84        }
85        Ok(out)
86    }
87}
88
89#[derive(Debug, Clone, PartialEq, Eq)]
90pub struct TopicPartitions {
91    pub topic_id: crate::primitives::uuid::Uuid,
92    pub partitions: Vec<i32>,
93    pub unknown_tagged_fields: UnknownTaggedFields,
94}
95
96impl Default for TopicPartitions {
97    fn default() -> Self {
98        Self {
99            topic_id: Default::default(),
100            partitions: Vec::new(),
101            unknown_tagged_fields: Default::default(),
102        }
103    }
104}
105
106impl TopicPartitions {
107    pub fn to_owned(&self) -> crate::owned::get_replica_log_info_request::TopicPartitions {
108        crate::owned::get_replica_log_info_request::TopicPartitions {
109            topic_id: (self.topic_id),
110            partitions: (self.partitions).clone(),
111            unknown_tagged_fields: self.unknown_tagged_fields.clone(),
112        }
113    }
114}
115
116impl Encode for TopicPartitions {
117    fn encode<B: BufMut>(&self, buf: &mut B, version: i16) -> Result<(), ProtocolError> {
118        let flex = version >= 0;
119        if version >= 0 { crate::primitives::uuid::put_uuid(buf, self.topic_id) }
120        if version >= 0 { { crate::primitives::array::put_array_len(buf, (self.partitions).len(), flex); for it in &self.partitions { put_i32(buf, *it); } } }
121        if flex {
122            let tagged = WriteTaggedFields::new();
123            tagged.write(buf, &self.unknown_tagged_fields);
124        }
125        Ok(())
126    }
127    fn encoded_len(&self, version: i16) -> usize {
128        let flex = version >= 0;
129        let mut n: usize = 0;
130        if version >= 0 { n += 16; }
131        if version >= 0 { n += { let prefix = crate::primitives::array::array_len_prefix_len((self.partitions).len(), flex); let body: usize = (self.partitions).iter().map(|_| 4).sum(); prefix + body }; }
132        if flex {
133            let known_pairs: Vec<(u32, usize)> = Vec::new();
134            n += tagged_fields_len(&known_pairs, &self.unknown_tagged_fields);
135        }
136        n
137    }
138}
139
140impl<'de> DecodeBorrow<'de> for TopicPartitions {
141    fn decode_borrow(buf: &mut &'de [u8], version: i16) -> Result<Self, ProtocolError> {
142        let flex = version >= 0;
143        let mut out = Self::default();
144        if version >= 0 { out.topic_id = crate::primitives::uuid::get_uuid(buf)?; }
145        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(get_i32(buf)?); } v }; }
146        if flex {
147            out.unknown_tagged_fields = read_tagged_fields(buf, |_tag, _payload| {
148                Ok(false)
149            })?;
150        }
151        Ok(out)
152    }
153}