Skip to main content

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