kafka_protocol/messages/
write_share_group_state_response.rs

1//! WriteShareGroupStateResponse
2//!
3//! See the schema for this message [here](https://github.com/apache/kafka/blob/trunk/clients/src/main/resources/common/message/WriteShareGroupStateResponse.json).
4// WARNING: the items of this module are generated and should not be edited directly
5#![allow(unused)]
6
7use std::borrow::Borrow;
8use std::collections::BTreeMap;
9
10use anyhow::{bail, Result};
11use bytes::Bytes;
12use uuid::Uuid;
13
14use crate::protocol::{
15    buf::{ByteBuf, ByteBufMut},
16    compute_unknown_tagged_fields_size, types, write_unknown_tagged_fields, Decodable, Decoder,
17    Encodable, Encoder, HeaderVersion, Message, StrBytes, VersionRange,
18};
19
20/// Valid versions: 0
21#[non_exhaustive]
22#[derive(Debug, Clone, PartialEq)]
23pub struct PartitionResult {
24    /// The partition index.
25    ///
26    /// Supported API versions: 0
27    pub partition: i32,
28
29    /// The error code, or 0 if there was no error.
30    ///
31    /// Supported API versions: 0
32    pub error_code: i16,
33
34    /// The error message, or null if there was no error.
35    ///
36    /// Supported API versions: 0
37    pub error_message: Option<StrBytes>,
38
39    /// Other tagged fields
40    pub unknown_tagged_fields: BTreeMap<i32, Bytes>,
41}
42
43impl PartitionResult {
44    /// Sets `partition` to the passed value.
45    ///
46    /// The partition index.
47    ///
48    /// Supported API versions: 0
49    pub fn with_partition(mut self, value: i32) -> Self {
50        self.partition = value;
51        self
52    }
53    /// Sets `error_code` to the passed value.
54    ///
55    /// The error code, or 0 if there was no error.
56    ///
57    /// Supported API versions: 0
58    pub fn with_error_code(mut self, value: i16) -> Self {
59        self.error_code = value;
60        self
61    }
62    /// Sets `error_message` to the passed value.
63    ///
64    /// The error message, or null if there was no error.
65    ///
66    /// Supported API versions: 0
67    pub fn with_error_message(mut self, value: Option<StrBytes>) -> Self {
68        self.error_message = value;
69        self
70    }
71    /// Sets unknown_tagged_fields to the passed value.
72    pub fn with_unknown_tagged_fields(mut self, value: BTreeMap<i32, Bytes>) -> Self {
73        self.unknown_tagged_fields = value;
74        self
75    }
76    /// Inserts an entry into unknown_tagged_fields.
77    pub fn with_unknown_tagged_field(mut self, key: i32, value: Bytes) -> Self {
78        self.unknown_tagged_fields.insert(key, value);
79        self
80    }
81}
82
83#[cfg(feature = "broker")]
84impl Encodable for PartitionResult {
85    fn encode<B: ByteBufMut>(&self, buf: &mut B, version: i16) -> Result<()> {
86        if version != 0 {
87            bail!("specified version not supported by this message type");
88        }
89        types::Int32.encode(buf, &self.partition)?;
90        types::Int16.encode(buf, &self.error_code)?;
91        types::CompactString.encode(buf, &self.error_message)?;
92        let num_tagged_fields = self.unknown_tagged_fields.len();
93        if num_tagged_fields > std::u32::MAX as usize {
94            bail!(
95                "Too many tagged fields to encode ({} fields)",
96                num_tagged_fields
97            );
98        }
99        types::UnsignedVarInt.encode(buf, num_tagged_fields as u32)?;
100
101        write_unknown_tagged_fields(buf, 0.., &self.unknown_tagged_fields)?;
102        Ok(())
103    }
104    fn compute_size(&self, version: i16) -> Result<usize> {
105        let mut total_size = 0;
106        total_size += types::Int32.compute_size(&self.partition)?;
107        total_size += types::Int16.compute_size(&self.error_code)?;
108        total_size += types::CompactString.compute_size(&self.error_message)?;
109        let num_tagged_fields = self.unknown_tagged_fields.len();
110        if num_tagged_fields > std::u32::MAX as usize {
111            bail!(
112                "Too many tagged fields to encode ({} fields)",
113                num_tagged_fields
114            );
115        }
116        total_size += types::UnsignedVarInt.compute_size(num_tagged_fields as u32)?;
117
118        total_size += compute_unknown_tagged_fields_size(&self.unknown_tagged_fields)?;
119        Ok(total_size)
120    }
121}
122
123#[cfg(feature = "client")]
124impl Decodable for PartitionResult {
125    fn decode<B: ByteBuf>(buf: &mut B, version: i16) -> Result<Self> {
126        if version != 0 {
127            bail!("specified version not supported by this message type");
128        }
129        let partition = types::Int32.decode(buf)?;
130        let error_code = types::Int16.decode(buf)?;
131        let error_message = types::CompactString.decode(buf)?;
132        let mut unknown_tagged_fields = BTreeMap::new();
133        let num_tagged_fields = types::UnsignedVarInt.decode(buf)?;
134        for _ in 0..num_tagged_fields {
135            let tag: u32 = types::UnsignedVarInt.decode(buf)?;
136            let size: u32 = types::UnsignedVarInt.decode(buf)?;
137            let unknown_value = buf.try_get_bytes(size as usize)?;
138            unknown_tagged_fields.insert(tag as i32, unknown_value);
139        }
140        Ok(Self {
141            partition,
142            error_code,
143            error_message,
144            unknown_tagged_fields,
145        })
146    }
147}
148
149impl Default for PartitionResult {
150    fn default() -> Self {
151        Self {
152            partition: 0,
153            error_code: 0,
154            error_message: None,
155            unknown_tagged_fields: BTreeMap::new(),
156        }
157    }
158}
159
160impl Message for PartitionResult {
161    const VERSIONS: VersionRange = VersionRange { min: 0, max: 0 };
162    const DEPRECATED_VERSIONS: Option<VersionRange> = None;
163}
164
165/// Valid versions: 0
166#[non_exhaustive]
167#[derive(Debug, Clone, PartialEq)]
168pub struct WriteShareGroupStateResponse {
169    /// The write results.
170    ///
171    /// Supported API versions: 0
172    pub results: Vec<WriteStateResult>,
173
174    /// Other tagged fields
175    pub unknown_tagged_fields: BTreeMap<i32, Bytes>,
176}
177
178impl WriteShareGroupStateResponse {
179    /// Sets `results` to the passed value.
180    ///
181    /// The write results.
182    ///
183    /// Supported API versions: 0
184    pub fn with_results(mut self, value: Vec<WriteStateResult>) -> Self {
185        self.results = value;
186        self
187    }
188    /// Sets unknown_tagged_fields to the passed value.
189    pub fn with_unknown_tagged_fields(mut self, value: BTreeMap<i32, Bytes>) -> Self {
190        self.unknown_tagged_fields = value;
191        self
192    }
193    /// Inserts an entry into unknown_tagged_fields.
194    pub fn with_unknown_tagged_field(mut self, key: i32, value: Bytes) -> Self {
195        self.unknown_tagged_fields.insert(key, value);
196        self
197    }
198}
199
200#[cfg(feature = "broker")]
201impl Encodable for WriteShareGroupStateResponse {
202    fn encode<B: ByteBufMut>(&self, buf: &mut B, version: i16) -> Result<()> {
203        if version != 0 {
204            bail!("specified version not supported by this message type");
205        }
206        types::CompactArray(types::Struct { version }).encode(buf, &self.results)?;
207        let num_tagged_fields = self.unknown_tagged_fields.len();
208        if num_tagged_fields > std::u32::MAX as usize {
209            bail!(
210                "Too many tagged fields to encode ({} fields)",
211                num_tagged_fields
212            );
213        }
214        types::UnsignedVarInt.encode(buf, num_tagged_fields as u32)?;
215
216        write_unknown_tagged_fields(buf, 0.., &self.unknown_tagged_fields)?;
217        Ok(())
218    }
219    fn compute_size(&self, version: i16) -> Result<usize> {
220        let mut total_size = 0;
221        total_size += types::CompactArray(types::Struct { version }).compute_size(&self.results)?;
222        let num_tagged_fields = self.unknown_tagged_fields.len();
223        if num_tagged_fields > std::u32::MAX as usize {
224            bail!(
225                "Too many tagged fields to encode ({} fields)",
226                num_tagged_fields
227            );
228        }
229        total_size += types::UnsignedVarInt.compute_size(num_tagged_fields as u32)?;
230
231        total_size += compute_unknown_tagged_fields_size(&self.unknown_tagged_fields)?;
232        Ok(total_size)
233    }
234}
235
236#[cfg(feature = "client")]
237impl Decodable for WriteShareGroupStateResponse {
238    fn decode<B: ByteBuf>(buf: &mut B, version: i16) -> Result<Self> {
239        if version != 0 {
240            bail!("specified version not supported by this message type");
241        }
242        let results = types::CompactArray(types::Struct { version }).decode(buf)?;
243        let mut unknown_tagged_fields = BTreeMap::new();
244        let num_tagged_fields = types::UnsignedVarInt.decode(buf)?;
245        for _ in 0..num_tagged_fields {
246            let tag: u32 = types::UnsignedVarInt.decode(buf)?;
247            let size: u32 = types::UnsignedVarInt.decode(buf)?;
248            let unknown_value = buf.try_get_bytes(size as usize)?;
249            unknown_tagged_fields.insert(tag as i32, unknown_value);
250        }
251        Ok(Self {
252            results,
253            unknown_tagged_fields,
254        })
255    }
256}
257
258impl Default for WriteShareGroupStateResponse {
259    fn default() -> Self {
260        Self {
261            results: Default::default(),
262            unknown_tagged_fields: BTreeMap::new(),
263        }
264    }
265}
266
267impl Message for WriteShareGroupStateResponse {
268    const VERSIONS: VersionRange = VersionRange { min: 0, max: 0 };
269    const DEPRECATED_VERSIONS: Option<VersionRange> = None;
270}
271
272/// Valid versions: 0
273#[non_exhaustive]
274#[derive(Debug, Clone, PartialEq)]
275pub struct WriteStateResult {
276    /// The topic identifier.
277    ///
278    /// Supported API versions: 0
279    pub topic_id: Uuid,
280
281    /// The results for the partitions.
282    ///
283    /// Supported API versions: 0
284    pub partitions: Vec<PartitionResult>,
285
286    /// Other tagged fields
287    pub unknown_tagged_fields: BTreeMap<i32, Bytes>,
288}
289
290impl WriteStateResult {
291    /// Sets `topic_id` to the passed value.
292    ///
293    /// The topic identifier.
294    ///
295    /// Supported API versions: 0
296    pub fn with_topic_id(mut self, value: Uuid) -> Self {
297        self.topic_id = value;
298        self
299    }
300    /// Sets `partitions` to the passed value.
301    ///
302    /// The results for the partitions.
303    ///
304    /// Supported API versions: 0
305    pub fn with_partitions(mut self, value: Vec<PartitionResult>) -> Self {
306        self.partitions = value;
307        self
308    }
309    /// Sets unknown_tagged_fields to the passed value.
310    pub fn with_unknown_tagged_fields(mut self, value: BTreeMap<i32, Bytes>) -> Self {
311        self.unknown_tagged_fields = value;
312        self
313    }
314    /// Inserts an entry into unknown_tagged_fields.
315    pub fn with_unknown_tagged_field(mut self, key: i32, value: Bytes) -> Self {
316        self.unknown_tagged_fields.insert(key, value);
317        self
318    }
319}
320
321#[cfg(feature = "broker")]
322impl Encodable for WriteStateResult {
323    fn encode<B: ByteBufMut>(&self, buf: &mut B, version: i16) -> Result<()> {
324        if version != 0 {
325            bail!("specified version not supported by this message type");
326        }
327        types::Uuid.encode(buf, &self.topic_id)?;
328        types::CompactArray(types::Struct { version }).encode(buf, &self.partitions)?;
329        let num_tagged_fields = self.unknown_tagged_fields.len();
330        if num_tagged_fields > std::u32::MAX as usize {
331            bail!(
332                "Too many tagged fields to encode ({} fields)",
333                num_tagged_fields
334            );
335        }
336        types::UnsignedVarInt.encode(buf, num_tagged_fields as u32)?;
337
338        write_unknown_tagged_fields(buf, 0.., &self.unknown_tagged_fields)?;
339        Ok(())
340    }
341    fn compute_size(&self, version: i16) -> Result<usize> {
342        let mut total_size = 0;
343        total_size += types::Uuid.compute_size(&self.topic_id)?;
344        total_size +=
345            types::CompactArray(types::Struct { version }).compute_size(&self.partitions)?;
346        let num_tagged_fields = self.unknown_tagged_fields.len();
347        if num_tagged_fields > std::u32::MAX as usize {
348            bail!(
349                "Too many tagged fields to encode ({} fields)",
350                num_tagged_fields
351            );
352        }
353        total_size += types::UnsignedVarInt.compute_size(num_tagged_fields as u32)?;
354
355        total_size += compute_unknown_tagged_fields_size(&self.unknown_tagged_fields)?;
356        Ok(total_size)
357    }
358}
359
360#[cfg(feature = "client")]
361impl Decodable for WriteStateResult {
362    fn decode<B: ByteBuf>(buf: &mut B, version: i16) -> Result<Self> {
363        if version != 0 {
364            bail!("specified version not supported by this message type");
365        }
366        let topic_id = types::Uuid.decode(buf)?;
367        let partitions = types::CompactArray(types::Struct { version }).decode(buf)?;
368        let mut unknown_tagged_fields = BTreeMap::new();
369        let num_tagged_fields = types::UnsignedVarInt.decode(buf)?;
370        for _ in 0..num_tagged_fields {
371            let tag: u32 = types::UnsignedVarInt.decode(buf)?;
372            let size: u32 = types::UnsignedVarInt.decode(buf)?;
373            let unknown_value = buf.try_get_bytes(size as usize)?;
374            unknown_tagged_fields.insert(tag as i32, unknown_value);
375        }
376        Ok(Self {
377            topic_id,
378            partitions,
379            unknown_tagged_fields,
380        })
381    }
382}
383
384impl Default for WriteStateResult {
385    fn default() -> Self {
386        Self {
387            topic_id: Uuid::nil(),
388            partitions: Default::default(),
389            unknown_tagged_fields: BTreeMap::new(),
390        }
391    }
392}
393
394impl Message for WriteStateResult {
395    const VERSIONS: VersionRange = VersionRange { min: 0, max: 0 };
396    const DEPRECATED_VERSIONS: Option<VersionRange> = None;
397}
398
399impl HeaderVersion for WriteShareGroupStateResponse {
400    fn header_version(version: i16) -> i16 {
401        1
402    }
403}