Skip to main content

crabka_protocol/opt/rustwide/workdir/generated/
TxnOffsetCommitRequest.owned.rs

1// AUTO-GENERATED by crabka-protocol-codegen against a9ce3221537b8653448750697915607dc7936cf3. Do not edit.
2
3use bytes::{Buf, 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, get_compact_nullable_string_owned,
8    get_compact_string_owned, get_nullable_string_owned, get_string_owned, nullable_string_len,
9    put_compact_nullable_string, put_compact_string, put_nullable_string, put_string,
10    string_len,
11};
12use crate::tagged_fields::{read_tagged_fields, tagged_fields_len, WriteTaggedFields};
13use crate::{Decode, Encode, ProtocolError, UnknownTaggedFields};
14
15pub const API_KEY: i16 = 28;
16pub const MIN_VERSION: i16 = 0;
17pub const MAX_VERSION: i16 = 5;
18pub const FLEXIBLE_MIN: i16 = 3;
19
20#[inline]
21fn is_flexible(version: i16) -> bool { version >= FLEXIBLE_MIN }
22
23#[derive(Debug, Clone, PartialEq, Eq)]
24pub struct TxnOffsetCommitRequest {
25    pub transactional_id: String,
26    pub group_id: String,
27    pub producer_id: i64,
28    pub producer_epoch: i16,
29    pub generation_id: i32,
30    pub member_id: String,
31    pub group_instance_id: Option<String>,
32    pub topics: Vec<TxnOffsetCommitRequestTopic>,
33    pub unknown_tagged_fields: UnknownTaggedFields,
34}
35
36impl Default for TxnOffsetCommitRequest {
37    fn default() -> Self {
38        Self {
39            transactional_id: String::new(),
40            group_id: String::new(),
41            producer_id: 0i64,
42            producer_epoch: 0i16,
43            generation_id: -1i32,
44            member_id: "".to_string(),
45            group_instance_id: None,
46            topics: Vec::new(),
47            unknown_tagged_fields: Default::default(),
48        }
49    }
50}
51
52impl Encode for TxnOffsetCommitRequest {
53    fn encode<B: BufMut>(&self, buf: &mut B, version: i16) -> Result<(), ProtocolError> {
54        if !(MIN_VERSION..=MAX_VERSION).contains(&version) {
55            return Err(ProtocolError::UnsupportedVersion { api_key: API_KEY, version });
56        }
57        let flex = is_flexible(version);
58        if version >= 0 { if flex { put_compact_string(buf, &self.transactional_id) } else { put_string(buf, &self.transactional_id) } }
59        if version >= 0 { if flex { put_compact_string(buf, &self.group_id) } else { put_string(buf, &self.group_id) } }
60        if version >= 0 { put_i64(buf, self.producer_id) }
61        if version >= 0 { put_i16(buf, self.producer_epoch) }
62        if version >= 3 { put_i32(buf, self.generation_id) }
63        if version >= 3 { if flex { put_compact_string(buf, &self.member_id) } else { put_string(buf, &self.member_id) } }
64        if version >= 3 { if flex { put_compact_nullable_string(buf, self.group_instance_id.as_deref()) } else { put_nullable_string(buf, self.group_instance_id.as_deref()) } }
65        if version >= 0 { { crate::primitives::array::put_array_len(buf, (self.topics).len(), flex); for it in &self.topics { it.encode(buf, version)?; } } }
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 += if flex { compact_string_len(&self.transactional_id) } else { string_len(&self.transactional_id) }; }
76        if version >= 0 { n += if flex { compact_string_len(&self.group_id) } else { string_len(&self.group_id) }; }
77        if version >= 0 { n += 8; }
78        if version >= 0 { n += 2; }
79        if version >= 3 { n += 4; }
80        if version >= 3 { n += if flex { compact_string_len(&self.member_id) } else { string_len(&self.member_id) }; }
81        if version >= 3 { n += if flex { compact_nullable_string_len(self.group_instance_id.as_deref()) } else { nullable_string_len(self.group_instance_id.as_deref()) }; }
82        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 }; }
83        if flex {
84            let known_pairs: Vec<(u32, usize)> = Vec::new();
85            n += tagged_fields_len(&known_pairs, &self.unknown_tagged_fields);
86        }
87        n
88    }
89}
90
91impl<'de> Decode<'de> for TxnOffsetCommitRequest {
92    fn decode<B: Buf>(buf: &mut B, version: i16) -> Result<Self, ProtocolError> {
93        if !(MIN_VERSION..=MAX_VERSION).contains(&version) {
94            return Err(ProtocolError::UnsupportedVersion { api_key: API_KEY, version });
95        }
96        let flex = is_flexible(version);
97        let mut out = Self::default();
98        if version >= 0 { out.transactional_id = if flex { get_compact_string_owned(buf)? } else { get_string_owned(buf)? }; }
99        if version >= 0 { out.group_id = if flex { get_compact_string_owned(buf)? } else { get_string_owned(buf)? }; }
100        if version >= 0 { out.producer_id = get_i64(buf)?; }
101        if version >= 0 { out.producer_epoch = get_i16(buf)?; }
102        if version >= 3 { out.generation_id = get_i32(buf)?; }
103        if version >= 3 { out.member_id = if flex { get_compact_string_owned(buf)? } else { get_string_owned(buf)? }; }
104        if version >= 3 { out.group_instance_id = if flex { get_compact_nullable_string_owned(buf)? } else { get_nullable_string_owned(buf)? }; }
105        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(TxnOffsetCommitRequestTopic::decode(buf, version)?); } v }; }
106        if flex {
107            out.unknown_tagged_fields = read_tagged_fields(buf, |_tag, _payload| {
108                Ok(false)
109            })?;
110        }
111        Ok(out)
112    }
113}
114
115#[derive(Debug, Clone, PartialEq, Eq, Default)]
116pub struct TxnOffsetCommitRequestTopic {
117    pub name: String,
118    pub partitions: Vec<TxnOffsetCommitRequestPartition>,
119    pub unknown_tagged_fields: UnknownTaggedFields,
120}
121
122impl Encode for TxnOffsetCommitRequestTopic {
123    fn encode<B: BufMut>(&self, buf: &mut B, version: i16) -> Result<(), ProtocolError> {
124        let flex = version >= 3;
125        if version >= 0 { if flex { put_compact_string(buf, &self.name) } else { put_string(buf, &self.name) } }
126        if version >= 0 { { crate::primitives::array::put_array_len(buf, (self.partitions).len(), flex); for it in &self.partitions { it.encode(buf, version)?; } } }
127        if flex {
128            let tagged = WriteTaggedFields::new();
129            tagged.write(buf, &self.unknown_tagged_fields);
130        }
131        Ok(())
132    }
133    fn encoded_len(&self, version: i16) -> usize {
134        let flex = version >= 3;
135        let mut n: usize = 0;
136        if version >= 0 { n += if flex { compact_string_len(&self.name) } else { string_len(&self.name) }; }
137        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 }; }
138        if flex {
139            let known_pairs: Vec<(u32, usize)> = Vec::new();
140            n += tagged_fields_len(&known_pairs, &self.unknown_tagged_fields);
141        }
142        n
143    }
144}
145
146impl<'de> Decode<'de> for TxnOffsetCommitRequestTopic {
147    fn decode<B: Buf>(buf: &mut B, version: i16) -> Result<Self, ProtocolError> {
148        let flex = version >= 3;
149        let mut out = Self::default();
150        if version >= 0 { out.name = if flex { get_compact_string_owned(buf)? } else { get_string_owned(buf)? }; }
151        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(TxnOffsetCommitRequestPartition::decode(buf, version)?); } v }; }
152        if flex {
153            out.unknown_tagged_fields = read_tagged_fields(buf, |_tag, _payload| {
154                Ok(false)
155            })?;
156        }
157        Ok(out)
158    }
159}
160
161#[derive(Debug, Clone, PartialEq, Eq)]
162pub struct TxnOffsetCommitRequestPartition {
163    pub partition_index: i32,
164    pub committed_offset: i64,
165    pub committed_leader_epoch: i32,
166    pub committed_metadata: Option<String>,
167    pub unknown_tagged_fields: UnknownTaggedFields,
168}
169
170impl Default for TxnOffsetCommitRequestPartition {
171    fn default() -> Self {
172        Self {
173            partition_index: 0i32,
174            committed_offset: 0i64,
175            committed_leader_epoch: -1i32,
176            committed_metadata: None,
177            unknown_tagged_fields: Default::default(),
178        }
179    }
180}
181
182impl Encode for TxnOffsetCommitRequestPartition {
183    fn encode<B: BufMut>(&self, buf: &mut B, version: i16) -> Result<(), ProtocolError> {
184        let flex = version >= 3;
185        if version >= 0 { put_i32(buf, self.partition_index) }
186        if version >= 0 { put_i64(buf, self.committed_offset) }
187        if version >= 2 { put_i32(buf, self.committed_leader_epoch) }
188        if version >= 0 { if flex { put_compact_nullable_string(buf, self.committed_metadata.as_deref()) } else { put_nullable_string(buf, self.committed_metadata.as_deref()) } }
189        if flex {
190            let tagged = WriteTaggedFields::new();
191            tagged.write(buf, &self.unknown_tagged_fields);
192        }
193        Ok(())
194    }
195    fn encoded_len(&self, version: i16) -> usize {
196        let flex = version >= 3;
197        let mut n: usize = 0;
198        if version >= 0 { n += 4; }
199        if version >= 0 { n += 8; }
200        if version >= 2 { n += 4; }
201        if version >= 0 { n += if flex { compact_nullable_string_len(self.committed_metadata.as_deref()) } else { nullable_string_len(self.committed_metadata.as_deref()) }; }
202        if flex {
203            let known_pairs: Vec<(u32, usize)> = Vec::new();
204            n += tagged_fields_len(&known_pairs, &self.unknown_tagged_fields);
205        }
206        n
207    }
208}
209
210impl<'de> Decode<'de> for TxnOffsetCommitRequestPartition {
211    fn decode<B: Buf>(buf: &mut B, version: i16) -> Result<Self, ProtocolError> {
212        let flex = version >= 3;
213        let mut out = Self::default();
214        if version >= 0 { out.partition_index = get_i32(buf)?; }
215        if version >= 0 { out.committed_offset = get_i64(buf)?; }
216        if version >= 2 { out.committed_leader_epoch = get_i32(buf)?; }
217        if version >= 0 { out.committed_metadata = if flex { get_compact_nullable_string_owned(buf)? } else { get_nullable_string_owned(buf)? }; }
218        if flex {
219            out.unknown_tagged_fields = read_tagged_fields(buf, |_tag, _payload| {
220                Ok(false)
221            })?;
222        }
223        Ok(out)
224    }
225}
226
227/// Default JSON payload matching `Self::default()` for JVM oracle differential testing.
228/// Only includes fields valid for the given version.
229#[must_use]
230#[allow(unused_comparisons)]
231pub fn default_json(version: i16) -> ::serde_json::Value {
232    let mut obj = ::serde_json::Map::new();
233    obj.insert("transactionalId".to_string(), ::serde_json::Value::String(String::new()));
234    obj.insert("groupId".to_string(), ::serde_json::Value::String(String::new()));
235    obj.insert("producerId".to_string(), ::serde_json::json!(0));
236    obj.insert("producerEpoch".to_string(), ::serde_json::json!(0));
237    if version >= 3 {
238        obj.insert("generationId".to_string(), ::serde_json::json!(-1));
239    }
240    if version >= 3 {
241        obj.insert("memberId".to_string(), ::serde_json::Value::String("".to_string()));
242    }
243    if version >= 3 {
244        obj.insert("groupInstanceId".to_string(), ::serde_json::Value::Null);
245    }
246    obj.insert("topics".to_string(), ::serde_json::Value::Array(vec![]));
247    ::serde_json::Value::Object(obj)
248}
249
250impl crate::ProtocolRequest for TxnOffsetCommitRequest {
251    const API_KEY: i16 = API_KEY;
252    const MIN_VERSION: i16 = MIN_VERSION;
253    const MAX_VERSION: i16 = MAX_VERSION;
254    const FLEXIBLE_MIN: i16 = FLEXIBLE_MIN;
255    type Response = super::txn_offset_commit_response::TxnOffsetCommitResponse;
256}