crabka_protocol/opt/rustwide/workdir/generated/
DescribeQuorumRequest.borrowed.rs1use bytes::BufMut;
4
5use crate::primitives::fixed::{get_i32, 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 = 55;
16pub const MIN_VERSION: i16 = 0;
17pub const MAX_VERSION: i16 = 2;
18pub const FLEXIBLE_MIN: i16 = 0;
19
20#[inline]
21fn is_flexible(version: i16) -> bool { version >= FLEXIBLE_MIN }
22
23#[derive(Debug, Clone, PartialEq, Eq)]
24pub struct DescribeQuorumRequest<'a> {
25 pub topics: Vec<TopicData<'a>>,
26 pub unknown_tagged_fields: UnknownTaggedFields,
27}
28
29impl<'a> Default for DescribeQuorumRequest<'a> {
30 fn default() -> Self {
31 Self {
32 topics: Vec::new(),
33 unknown_tagged_fields: Default::default(),
34 }
35 }
36}
37
38impl<'a> DescribeQuorumRequest<'a> {
39 pub fn to_owned(&self) -> crate::owned::describe_quorum_request::DescribeQuorumRequest {
40 crate::owned::describe_quorum_request::DescribeQuorumRequest {
41 topics: (self.topics).iter().map(|it| it.to_owned()).collect(),
42 unknown_tagged_fields: self.unknown_tagged_fields.clone(),
43 }
44 }
45}
46
47impl<'a> Encode for DescribeQuorumRequest<'a> {
48 fn encode<B: BufMut>(&self, buf: &mut B, version: i16) -> Result<(), ProtocolError> {
49 if !(MIN_VERSION..=MAX_VERSION).contains(&version) {
50 return Err(ProtocolError::UnsupportedVersion { api_key: API_KEY, version });
51 }
52 let flex = is_flexible(version);
53 if version >= 0 { { crate::primitives::array::put_array_len(buf, (self.topics).len(), flex); for it in &self.topics { it.encode(buf, version)?; } } }
54 if flex {
55 let tagged = WriteTaggedFields::new();
56 tagged.write(buf, &self.unknown_tagged_fields);
57 }
58 Ok(())
59 }
60 fn encoded_len(&self, version: i16) -> usize {
61 let flex = is_flexible(version);
62 let mut n: usize = 0;
63 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 }; }
64 if flex {
65 let known_pairs: Vec<(u32, usize)> = Vec::new();
66 n += tagged_fields_len(&known_pairs, &self.unknown_tagged_fields);
67 }
68 n
69 }
70}
71
72impl<'de> DecodeBorrow<'de> for DescribeQuorumRequest<'de> {
73 fn decode_borrow(buf: &mut &'de [u8], version: i16) -> Result<Self, ProtocolError> {
74 if !(MIN_VERSION..=MAX_VERSION).contains(&version) {
75 return Err(ProtocolError::UnsupportedVersion { api_key: API_KEY, version });
76 }
77 let flex = is_flexible(version);
78 let mut out = Self::default();
79 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(TopicData::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 TopicData<'a> {
91 pub topic_name: &'a str,
92 pub partitions: Vec<PartitionData>,
93 pub unknown_tagged_fields: UnknownTaggedFields,
94}
95
96impl<'a> Default for TopicData<'a> {
97 fn default() -> Self {
98 Self {
99 topic_name: "",
100 partitions: Vec::new(),
101 unknown_tagged_fields: Default::default(),
102 }
103 }
104}
105
106impl<'a> TopicData<'a> {
107 pub fn to_owned(&self) -> crate::owned::describe_quorum_request::TopicData {
108 crate::owned::describe_quorum_request::TopicData {
109 topic_name: (self.topic_name).to_string(),
110 partitions: (self.partitions).iter().map(|it| it.to_owned()).collect(),
111 unknown_tagged_fields: self.unknown_tagged_fields.clone(),
112 }
113 }
114}
115
116impl<'a> Encode for TopicData<'a> {
117 fn encode<B: BufMut>(&self, buf: &mut B, version: i16) -> Result<(), ProtocolError> {
118 let flex = version >= 0;
119 if version >= 0 { if flex { put_compact_string(buf, self.topic_name) } else { put_string(buf, self.topic_name) } }
120 if version >= 0 { { crate::primitives::array::put_array_len(buf, (self.partitions).len(), flex); for it in &self.partitions { it.encode(buf, version)?; } } }
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 += if flex { compact_string_len(self.topic_name) } else { string_len(self.topic_name) }; }
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(|it| it.encoded_len(version)).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 TopicData<'de> {
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_name = if flex { get_compact_string_borrowed(buf)? } else { get_string_borrowed(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(PartitionData::decode_borrow(buf, version)?); } 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}
154
155#[derive(Debug, Clone, PartialEq, Eq)]
156pub struct PartitionData {
157 pub partition_index: i32,
158 pub unknown_tagged_fields: UnknownTaggedFields,
159}
160
161impl Default for PartitionData {
162 fn default() -> Self {
163 Self {
164 partition_index: 0i32,
165 unknown_tagged_fields: Default::default(),
166 }
167 }
168}
169
170impl PartitionData {
171 pub fn to_owned(&self) -> crate::owned::describe_quorum_request::PartitionData {
172 crate::owned::describe_quorum_request::PartitionData {
173 partition_index: (self.partition_index),
174 unknown_tagged_fields: self.unknown_tagged_fields.clone(),
175 }
176 }
177}
178
179impl Encode for PartitionData {
180 fn encode<B: BufMut>(&self, buf: &mut B, version: i16) -> Result<(), ProtocolError> {
181 let flex = version >= 0;
182 if version >= 0 { put_i32(buf, self.partition_index) }
183 if flex {
184 let tagged = WriteTaggedFields::new();
185 tagged.write(buf, &self.unknown_tagged_fields);
186 }
187 Ok(())
188 }
189 fn encoded_len(&self, version: i16) -> usize {
190 let flex = version >= 0;
191 let mut n: usize = 0;
192 if version >= 0 { n += 4; }
193 if flex {
194 let known_pairs: Vec<(u32, usize)> = Vec::new();
195 n += tagged_fields_len(&known_pairs, &self.unknown_tagged_fields);
196 }
197 n
198 }
199}
200
201impl<'de> DecodeBorrow<'de> for PartitionData {
202 fn decode_borrow(buf: &mut &'de [u8], version: i16) -> Result<Self, ProtocolError> {
203 let flex = version >= 0;
204 let mut out = Self::default();
205 if version >= 0 { out.partition_index = get_i32(buf)?; }
206 if flex {
207 out.unknown_tagged_fields = read_tagged_fields(buf, |_tag, _payload| {
208 Ok(false)
209 })?;
210 }
211 Ok(out)
212 }
213}