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