crabka_protocol/opt/rustwide/workdir/generated/
ElectLeadersResponse.owned.rs1use bytes::{Buf, BufMut};
4
5use crate::primitives::fixed::{get_i16, get_i32, put_i16, put_i32};
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 = 43;
16pub const MIN_VERSION: i16 = 0;
17pub const MAX_VERSION: i16 = 2;
18pub const FLEXIBLE_MIN: i16 = 2;
19
20#[inline]
21fn is_flexible(version: i16) -> bool { version >= FLEXIBLE_MIN }
22
23#[derive(Debug, Clone, PartialEq, Eq, Default)]
24pub struct ElectLeadersResponse {
25 pub throttle_time_ms: i32,
26 pub error_code: i16,
27 pub replica_election_results: Vec<ReplicaElectionResult>,
28 pub unknown_tagged_fields: UnknownTaggedFields,
29}
30
31impl Encode for ElectLeadersResponse {
32 fn encode<B: BufMut>(&self, buf: &mut B, version: i16) -> Result<(), ProtocolError> {
33 if !(MIN_VERSION..=MAX_VERSION).contains(&version) {
34 return Err(ProtocolError::UnsupportedVersion { api_key: API_KEY, version });
35 }
36 let flex = is_flexible(version);
37 if version >= 0 { put_i32(buf, self.throttle_time_ms) }
38 if version >= 1 { put_i16(buf, self.error_code) }
39 if version >= 0 { { crate::primitives::array::put_array_len(buf, (self.replica_election_results).len(), flex); for it in &self.replica_election_results { it.encode(buf, version)?; } } }
40 if flex {
41 let tagged = WriteTaggedFields::new();
42 tagged.write(buf, &self.unknown_tagged_fields);
43 }
44 Ok(())
45 }
46 fn encoded_len(&self, version: i16) -> usize {
47 let flex = is_flexible(version);
48 let mut n: usize = 0;
49 if version >= 0 { n += 4; }
50 if version >= 1 { n += 2; }
51 if version >= 0 { n += { let prefix = crate::primitives::array::array_len_prefix_len((self.replica_election_results).len(), flex); let body: usize = (self.replica_election_results).iter().map(|it| it.encoded_len(version)).sum(); prefix + body }; }
52 if flex {
53 let known_pairs: Vec<(u32, usize)> = Vec::new();
54 n += tagged_fields_len(&known_pairs, &self.unknown_tagged_fields);
55 }
56 n
57 }
58}
59
60impl<'de> Decode<'de> for ElectLeadersResponse {
61 fn decode<B: Buf>(buf: &mut B, version: i16) -> Result<Self, ProtocolError> {
62 if !(MIN_VERSION..=MAX_VERSION).contains(&version) {
63 return Err(ProtocolError::UnsupportedVersion { api_key: API_KEY, version });
64 }
65 let flex = is_flexible(version);
66 let mut out = Self::default();
67 if version >= 0 { out.throttle_time_ms = get_i32(buf)?; }
68 if version >= 1 { out.error_code = get_i16(buf)?; }
69 if version >= 0 { out.replica_election_results = { let n = crate::primitives::array::get_array_len(buf, flex)?; let mut v = Vec::with_capacity(n); for _ in 0..n { v.push(ReplicaElectionResult::decode(buf, version)?); } v }; }
70 if flex {
71 out.unknown_tagged_fields = read_tagged_fields(buf, |_tag, _payload| {
72 Ok(false)
73 })?;
74 }
75 Ok(out)
76 }
77}
78
79#[derive(Debug, Clone, PartialEq, Eq, Default)]
80pub struct ReplicaElectionResult {
81 pub topic: String,
82 pub partition_result: Vec<PartitionResult>,
83 pub unknown_tagged_fields: UnknownTaggedFields,
84}
85
86impl Encode for ReplicaElectionResult {
87 fn encode<B: BufMut>(&self, buf: &mut B, version: i16) -> Result<(), ProtocolError> {
88 let flex = version >= 2;
89 if version >= 0 { if flex { put_compact_string(buf, &self.topic) } else { put_string(buf, &self.topic) } }
90 if version >= 0 { { crate::primitives::array::put_array_len(buf, (self.partition_result).len(), flex); for it in &self.partition_result { it.encode(buf, version)?; } } }
91 if flex {
92 let tagged = WriteTaggedFields::new();
93 tagged.write(buf, &self.unknown_tagged_fields);
94 }
95 Ok(())
96 }
97 fn encoded_len(&self, version: i16) -> usize {
98 let flex = version >= 2;
99 let mut n: usize = 0;
100 if version >= 0 { n += if flex { compact_string_len(&self.topic) } else { string_len(&self.topic) }; }
101 if version >= 0 { n += { let prefix = crate::primitives::array::array_len_prefix_len((self.partition_result).len(), flex); let body: usize = (self.partition_result).iter().map(|it| it.encoded_len(version)).sum(); prefix + body }; }
102 if flex {
103 let known_pairs: Vec<(u32, usize)> = Vec::new();
104 n += tagged_fields_len(&known_pairs, &self.unknown_tagged_fields);
105 }
106 n
107 }
108}
109
110impl<'de> Decode<'de> for ReplicaElectionResult {
111 fn decode<B: Buf>(buf: &mut B, version: i16) -> Result<Self, ProtocolError> {
112 let flex = version >= 2;
113 let mut out = Self::default();
114 if version >= 0 { out.topic = if flex { get_compact_string_owned(buf)? } else { get_string_owned(buf)? }; }
115 if version >= 0 { out.partition_result = { let n = crate::primitives::array::get_array_len(buf, flex)?; let mut v = Vec::with_capacity(n); for _ in 0..n { v.push(PartitionResult::decode(buf, version)?); } v }; }
116 if flex {
117 out.unknown_tagged_fields = read_tagged_fields(buf, |_tag, _payload| {
118 Ok(false)
119 })?;
120 }
121 Ok(out)
122 }
123}
124
125#[derive(Debug, Clone, PartialEq, Eq, Default)]
126pub struct PartitionResult {
127 pub partition_id: i32,
128 pub error_code: i16,
129 pub error_message: Option<String>,
130 pub unknown_tagged_fields: UnknownTaggedFields,
131}
132
133impl Encode for PartitionResult {
134 fn encode<B: BufMut>(&self, buf: &mut B, version: i16) -> Result<(), ProtocolError> {
135 let flex = version >= 2;
136 if version >= 0 { put_i32(buf, self.partition_id) }
137 if version >= 0 { put_i16(buf, self.error_code) }
138 if version >= 0 { if flex { put_compact_nullable_string(buf, self.error_message.as_deref()) } else { put_nullable_string(buf, self.error_message.as_deref()) } }
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 >= 2;
147 let mut n: usize = 0;
148 if version >= 0 { n += 4; }
149 if version >= 0 { n += 2; }
150 if version >= 0 { n += if flex { compact_nullable_string_len(self.error_message.as_deref()) } else { nullable_string_len(self.error_message.as_deref()) }; }
151 if flex {
152 let known_pairs: Vec<(u32, usize)> = Vec::new();
153 n += tagged_fields_len(&known_pairs, &self.unknown_tagged_fields);
154 }
155 n
156 }
157}
158
159impl<'de> Decode<'de> for PartitionResult {
160 fn decode<B: Buf>(buf: &mut B, version: i16) -> Result<Self, ProtocolError> {
161 let flex = version >= 2;
162 let mut out = Self::default();
163 if version >= 0 { out.partition_id = get_i32(buf)?; }
164 if version >= 0 { out.error_code = get_i16(buf)?; }
165 if version >= 0 { out.error_message = if flex { get_compact_nullable_string_owned(buf)? } else { get_nullable_string_owned(buf)? }; }
166 if flex {
167 out.unknown_tagged_fields = read_tagged_fields(buf, |_tag, _payload| {
168 Ok(false)
169 })?;
170 }
171 Ok(out)
172 }
173}
174
175#[must_use]
178#[allow(unused_comparisons)]
179pub fn default_json(version: i16) -> ::serde_json::Value {
180 let mut obj = ::serde_json::Map::new();
181 obj.insert("throttleTimeMs".to_string(), ::serde_json::json!(0));
182 if version >= 1 {
183 obj.insert("errorCode".to_string(), ::serde_json::json!(0));
184 }
185 obj.insert("replicaElectionResults".to_string(), ::serde_json::Value::Array(vec![]));
186 ::serde_json::Value::Object(obj)
187}