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