Skip to main content

crabka_protocol/opt/rustwide/workdir/generated/
BeginQuorumEpochRequest.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_u16, put_i32, put_u16};
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 = 53;
16pub const MIN_VERSION: i16 = 0;
17pub const MAX_VERSION: i16 = 1;
18pub const FLEXIBLE_MIN: i16 = 1;
19
20#[inline]
21fn is_flexible(version: i16) -> bool { version >= FLEXIBLE_MIN }
22
23#[derive(Debug, Clone, PartialEq, Eq)]
24pub struct BeginQuorumEpochRequest {
25    pub cluster_id: Option<String>,
26    pub voter_id: i32,
27    pub topics: Vec<TopicData>,
28    pub leader_endpoints: Vec<LeaderEndpoint>,
29    pub unknown_tagged_fields: UnknownTaggedFields,
30}
31
32impl Default for BeginQuorumEpochRequest {
33    fn default() -> Self {
34        Self {
35            cluster_id: None,
36            voter_id: -1i32,
37            topics: Vec::new(),
38            leader_endpoints: Vec::new(),
39            unknown_tagged_fields: Default::default(),
40        }
41    }
42}
43
44impl Encode for BeginQuorumEpochRequest {
45    fn encode<B: BufMut>(&self, buf: &mut B, version: i16) -> Result<(), ProtocolError> {
46        if !(MIN_VERSION..=MAX_VERSION).contains(&version) {
47            return Err(ProtocolError::UnsupportedVersion { api_key: API_KEY, version });
48        }
49        let flex = is_flexible(version);
50        if version >= 0 { if flex { put_compact_nullable_string(buf, self.cluster_id.as_deref()) } else { put_nullable_string(buf, self.cluster_id.as_deref()) } }
51        if version >= 1 { put_i32(buf, self.voter_id) }
52        if version >= 0 { { crate::primitives::array::put_array_len(buf, (self.topics).len(), flex); for it in &self.topics { it.encode(buf, version)?; } } }
53        if version >= 1 { { crate::primitives::array::put_array_len(buf, (self.leader_endpoints).len(), flex); for it in &self.leader_endpoints { 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 += if flex { compact_nullable_string_len(self.cluster_id.as_deref()) } else { nullable_string_len(self.cluster_id.as_deref()) }; }
64        if version >= 1 { n += 4; }
65        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 }; }
66        if version >= 1 { n += { let prefix = crate::primitives::array::array_len_prefix_len((self.leader_endpoints).len(), flex); let body: usize = (self.leader_endpoints).iter().map(|it| it.encoded_len(version)).sum(); prefix + body }; }
67        if flex {
68            let known_pairs: Vec<(u32, usize)> = Vec::new();
69            n += tagged_fields_len(&known_pairs, &self.unknown_tagged_fields);
70        }
71        n
72    }
73}
74
75impl<'de> Decode<'de> for BeginQuorumEpochRequest {
76    fn decode<B: Buf>(buf: &mut B, version: i16) -> Result<Self, ProtocolError> {
77        if !(MIN_VERSION..=MAX_VERSION).contains(&version) {
78            return Err(ProtocolError::UnsupportedVersion { api_key: API_KEY, version });
79        }
80        let flex = is_flexible(version);
81        let mut out = Self::default();
82        if version >= 0 { out.cluster_id = if flex { get_compact_nullable_string_owned(buf)? } else { get_nullable_string_owned(buf)? }; }
83        if version >= 1 { out.voter_id = get_i32(buf)?; }
84        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(buf, version)?); } v }; }
85        if version >= 1 { out.leader_endpoints = { let n = crate::primitives::array::get_array_len(buf, flex)?; let mut v = Vec::with_capacity(n); for _ in 0..n { v.push(LeaderEndpoint::decode(buf, version)?); } v }; }
86        if flex {
87            out.unknown_tagged_fields = read_tagged_fields(buf, |_tag, _payload| {
88                Ok(false)
89            })?;
90        }
91        Ok(out)
92    }
93}
94
95#[derive(Debug, Clone, PartialEq, Eq, Default)]
96pub struct TopicData {
97    pub topic_name: String,
98    pub partitions: Vec<PartitionData>,
99    pub unknown_tagged_fields: UnknownTaggedFields,
100}
101
102impl Encode for TopicData {
103    fn encode<B: BufMut>(&self, buf: &mut B, version: i16) -> Result<(), ProtocolError> {
104        let flex = version >= 1;
105        if version >= 0 { if flex { put_compact_string(buf, &self.topic_name) } else { put_string(buf, &self.topic_name) } }
106        if version >= 0 { { crate::primitives::array::put_array_len(buf, (self.partitions).len(), flex); for it in &self.partitions { it.encode(buf, version)?; } } }
107        if flex {
108            let tagged = WriteTaggedFields::new();
109            tagged.write(buf, &self.unknown_tagged_fields);
110        }
111        Ok(())
112    }
113    fn encoded_len(&self, version: i16) -> usize {
114        let flex = version >= 1;
115        let mut n: usize = 0;
116        if version >= 0 { n += if flex { compact_string_len(&self.topic_name) } else { string_len(&self.topic_name) }; }
117        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 }; }
118        if flex {
119            let known_pairs: Vec<(u32, usize)> = Vec::new();
120            n += tagged_fields_len(&known_pairs, &self.unknown_tagged_fields);
121        }
122        n
123    }
124}
125
126impl<'de> Decode<'de> for TopicData {
127    fn decode<B: Buf>(buf: &mut B, version: i16) -> Result<Self, ProtocolError> {
128        let flex = version >= 1;
129        let mut out = Self::default();
130        if version >= 0 { out.topic_name = if flex { get_compact_string_owned(buf)? } else { get_string_owned(buf)? }; }
131        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(buf, version)?); } v }; }
132        if flex {
133            out.unknown_tagged_fields = read_tagged_fields(buf, |_tag, _payload| {
134                Ok(false)
135            })?;
136        }
137        Ok(out)
138    }
139}
140
141#[derive(Debug, Clone, PartialEq, Eq, Default)]
142pub struct PartitionData {
143    pub partition_index: i32,
144    pub voter_directory_id: crate::primitives::uuid::Uuid,
145    pub leader_id: i32,
146    pub leader_epoch: i32,
147    pub unknown_tagged_fields: UnknownTaggedFields,
148}
149
150impl Encode for PartitionData {
151    fn encode<B: BufMut>(&self, buf: &mut B, version: i16) -> Result<(), ProtocolError> {
152        let flex = version >= 1;
153        if version >= 0 { put_i32(buf, self.partition_index) }
154        if version >= 1 { crate::primitives::uuid::put_uuid(buf, self.voter_directory_id) }
155        if version >= 0 { put_i32(buf, self.leader_id) }
156        if version >= 0 { put_i32(buf, self.leader_epoch) }
157        if flex {
158            let tagged = WriteTaggedFields::new();
159            tagged.write(buf, &self.unknown_tagged_fields);
160        }
161        Ok(())
162    }
163    fn encoded_len(&self, version: i16) -> usize {
164        let flex = version >= 1;
165        let mut n: usize = 0;
166        if version >= 0 { n += 4; }
167        if version >= 1 { n += 16; }
168        if version >= 0 { n += 4; }
169        if version >= 0 { n += 4; }
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> Decode<'de> for PartitionData {
179    fn decode<B: Buf>(buf: &mut B, version: i16) -> Result<Self, ProtocolError> {
180        let flex = version >= 1;
181        let mut out = Self::default();
182        if version >= 0 { out.partition_index = get_i32(buf)?; }
183        if version >= 1 { out.voter_directory_id = crate::primitives::uuid::get_uuid(buf)?; }
184        if version >= 0 { out.leader_id = get_i32(buf)?; }
185        if version >= 0 { out.leader_epoch = get_i32(buf)?; }
186        if flex {
187            out.unknown_tagged_fields = read_tagged_fields(buf, |_tag, _payload| {
188                Ok(false)
189            })?;
190        }
191        Ok(out)
192    }
193}
194
195#[derive(Debug, Clone, PartialEq, Eq, Default)]
196pub struct LeaderEndpoint {
197    pub name: String,
198    pub host: String,
199    pub port: u16,
200    pub unknown_tagged_fields: UnknownTaggedFields,
201}
202
203impl Encode for LeaderEndpoint {
204    fn encode<B: BufMut>(&self, buf: &mut B, version: i16) -> Result<(), ProtocolError> {
205        let flex = version >= 1;
206        if version >= 1 { if flex { put_compact_string(buf, &self.name) } else { put_string(buf, &self.name) } }
207        if version >= 1 { if flex { put_compact_string(buf, &self.host) } else { put_string(buf, &self.host) } }
208        if version >= 1 { put_u16(buf, self.port) }
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 >= 1;
217        let mut n: usize = 0;
218        if version >= 1 { n += if flex { compact_string_len(&self.name) } else { string_len(&self.name) }; }
219        if version >= 1 { n += if flex { compact_string_len(&self.host) } else { string_len(&self.host) }; }
220        if version >= 1 { n += 2; }
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> Decode<'de> for LeaderEndpoint {
230    fn decode<B: Buf>(buf: &mut B, version: i16) -> Result<Self, ProtocolError> {
231        let flex = version >= 1;
232        let mut out = Self::default();
233        if version >= 1 { out.name = if flex { get_compact_string_owned(buf)? } else { get_string_owned(buf)? }; }
234        if version >= 1 { out.host = if flex { get_compact_string_owned(buf)? } else { get_string_owned(buf)? }; }
235        if version >= 1 { out.port = get_u16(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}
244
245/// Default JSON payload matching `Self::default()` for JVM oracle differential testing.
246/// Only includes fields valid for the given version.
247#[must_use]
248#[allow(unused_comparisons)]
249pub fn default_json(version: i16) -> ::serde_json::Value {
250    let mut obj = ::serde_json::Map::new();
251    obj.insert("clusterId".to_string(), ::serde_json::Value::Null);
252    if version >= 1 {
253        obj.insert("voterId".to_string(), ::serde_json::json!(-1));
254    }
255    obj.insert("topics".to_string(), ::serde_json::Value::Array(vec![]));
256    if version >= 1 {
257        obj.insert("leaderEndpoints".to_string(), ::serde_json::Value::Array(vec![]));
258    }
259    ::serde_json::Value::Object(obj)
260}
261
262impl crate::ProtocolRequest for BeginQuorumEpochRequest {
263    const API_KEY: i16 = API_KEY;
264    const MIN_VERSION: i16 = MIN_VERSION;
265    const MAX_VERSION: i16 = MAX_VERSION;
266    const FLEXIBLE_MIN: i16 = FLEXIBLE_MIN;
267    type Response = super::begin_quorum_epoch_response::BeginQuorumEpochResponse;
268}