Skip to main content

odradek_protocol/messages/
find_coordinator_request.rs

1//! `FindCoordinatorRequest` — generated from `schemas/FindCoordinatorRequest.json`.
2//!
3//! @generated by `cargo xtask codegen`. Do not edit by hand.
4
5#![allow(
6    clippy::field_reassign_with_default,
7    clippy::nonminimal_bool,
8    clippy::derivable_impls,
9    clippy::borrow_deref_ref,
10    clippy::double_parens,
11    unused_parens
12)]
13
14use bytes::{Buf, BufMut};
15
16use crate::budget::{Budget, Limits};
17#[allow(unused_imports)]
18use crate::error::{DecodeError, EncodeError};
19use crate::wire::{self, RawTaggedField};
20
21/// Whether `version` of this message uses the flexible (compact) encoding.
22pub fn is_flexible(version: i16) -> bool {
23    let _ = version;
24    version >= 3
25}
26
27/// `FindCoordinatorRequest`, versions 0-6.
28#[derive(Debug, Clone, PartialEq)]
29#[non_exhaustive]
30pub struct FindCoordinatorRequest {
31    /// The coordinator key.
32    pub key: String,
33    /// The coordinator key type. (group, transaction, share).
34    pub key_type: i8,
35    /// The coordinator keys.
36    pub coordinator_keys: Vec<String>,
37    /// Tagged fields not (yet) known to this crate, kept raw.
38    pub unknown_tagged_fields: Vec<RawTaggedField>,
39}
40
41impl Default for FindCoordinatorRequest {
42    fn default() -> Self {
43        Self {
44            key: String::new(),
45            key_type: 0,
46            coordinator_keys: Vec::new(),
47            unknown_tagged_fields: Vec::new(),
48        }
49    }
50}
51
52impl FindCoordinatorRequest {
53    /// This message's api key in Kafka's registry.
54    pub const API_KEY: i16 = 10;
55    /// The lowest schema version this snapshot can speak.
56    pub const MIN_VERSION: i16 = 0;
57    /// The highest schema version this snapshot can speak.
58    pub const MAX_VERSION: i16 = 6;
59
60    /// Encode this `FindCoordinatorRequest` at `version`.
61    pub fn encode(&self, buf: &mut impl BufMut, version: i16) -> Result<(), EncodeError> {
62        if version <= 3 {
63            if is_flexible(version) {
64                wire::put_compact_string(buf, &self.key);
65            } else {
66                wire::put_string(buf, &self.key)?;
67            }
68        }
69        if version >= 1 {
70            buf.put_i8(self.key_type);
71        }
72        if version >= 4 {
73            if is_flexible(version) {
74                wire::put_compact_array_len(buf, Some(self.coordinator_keys.len()));
75            } else {
76                wire::put_array_len(buf, Some(self.coordinator_keys.len()))?;
77            }
78            for item in &self.coordinator_keys {
79                if is_flexible(version) {
80                    wire::put_compact_string(buf, item);
81                } else {
82                    wire::put_string(buf, item)?;
83                }
84            }
85        }
86        if is_flexible(version) {
87            wire::put_tagged_fields(buf, &self.unknown_tagged_fields);
88        }
89        Ok(())
90    }
91
92    /// Decode one `FindCoordinatorRequest`, bounding allocation by the default
93    /// [`Limits`] derived from `buf`'s remaining length.
94    pub fn decode(buf: &mut impl Buf, version: i16) -> Result<Self, DecodeError> {
95        Self::decode_with_limits(buf, version, Limits::default())
96    }
97
98    /// Decode one `FindCoordinatorRequest` under `limits`.
99    pub fn decode_with_limits(
100        buf: &mut impl Buf,
101        version: i16,
102        limits: Limits,
103    ) -> Result<Self, DecodeError> {
104        let mut budget = limits.budget(buf.remaining());
105        Self::decode_with_budget(buf, version, &mut budget)
106    }
107
108    /// Decode one `FindCoordinatorRequest` against an existing `budget`.
109    pub fn decode_with_budget(
110        buf: &mut impl Buf,
111        version: i16,
112        budget: &mut Budget,
113    ) -> Result<Self, DecodeError> {
114        let mut this = Self::default();
115        if version <= 3 {
116            this.key = if is_flexible(version) {
117                wire::get_compact_string(buf)?
118            } else {
119                wire::get_string(buf)?
120            };
121        }
122        if version >= 1 {
123            this.key_type = wire::get_i8(buf)?;
124        }
125        if version >= 4 {
126            this.coordinator_keys = {
127                let len = if is_flexible(version) {
128                    wire::get_compact_array_len(buf)?
129                } else {
130                    wire::get_array_len(buf)?
131                };
132                match len {
133                    None => return Err(DecodeError::InvalidLength(-1)),
134                    Some(n) => {
135                        let mut items = Vec::new();
136                        for _ in 0..n {
137                            budget.push(
138                                &mut items,
139                                if is_flexible(version) {
140                                    wire::get_compact_string(buf)?
141                                } else {
142                                    wire::get_string(buf)?
143                                },
144                            )?;
145                        }
146                        items
147                    }
148                }
149            };
150        }
151        if is_flexible(version) {
152            this.unknown_tagged_fields = wire::get_tagged_fields_with_budget(buf, budget)?;
153        }
154        Ok(this)
155    }
156}
157
158impl crate::Message for FindCoordinatorRequest {
159    const API_KEY: i16 = 10;
160    const MIN_VERSION: i16 = 0;
161    const MAX_VERSION: i16 = 6;
162
163    fn encode(&self, buf: &mut impl BufMut, version: i16) -> Result<(), EncodeError> {
164        FindCoordinatorRequest::encode(self, buf, version)
165    }
166    fn decode(buf: &mut impl Buf, version: i16) -> Result<Self, DecodeError> {
167        FindCoordinatorRequest::decode(buf, version)
168    }
169    fn decode_with_limits(
170        buf: &mut impl Buf,
171        version: i16,
172        limits: Limits,
173    ) -> Result<Self, DecodeError> {
174        FindCoordinatorRequest::decode_with_limits(buf, version, limits)
175    }
176}