Skip to main content

odradek_protocol/messages/
sync_group_response.rs

1//! `SyncGroupResponse` — generated from `schemas/SyncGroupResponse.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 >= 4
25}
26
27/// `SyncGroupResponse`, versions 0-5.
28#[derive(Debug, Clone, PartialEq)]
29#[non_exhaustive]
30pub struct SyncGroupResponse {
31    /// The duration in milliseconds for which the request was throttled due to a quota violation, or zero if the request did not violate any quota.
32    pub throttle_time_ms: i32,
33    /// The error code, or 0 if there was no error.
34    pub error_code: i16,
35    /// The group protocol type.
36    pub protocol_type: Option<String>,
37    /// The group protocol name.
38    pub protocol_name: Option<String>,
39    /// The member assignment.
40    pub assignment: bytes::Bytes,
41    /// Tagged fields not (yet) known to this crate, kept raw.
42    pub unknown_tagged_fields: Vec<RawTaggedField>,
43}
44
45impl Default for SyncGroupResponse {
46    fn default() -> Self {
47        Self {
48            throttle_time_ms: 0,
49            error_code: 0,
50            protocol_type: None,
51            protocol_name: None,
52            assignment: bytes::Bytes::new(),
53            unknown_tagged_fields: Vec::new(),
54        }
55    }
56}
57
58impl SyncGroupResponse {
59    /// This message's api key in Kafka's registry.
60    pub const API_KEY: i16 = 14;
61    /// The lowest schema version this snapshot can speak.
62    pub const MIN_VERSION: i16 = 0;
63    /// The highest schema version this snapshot can speak.
64    pub const MAX_VERSION: i16 = 5;
65
66    /// Encode this `SyncGroupResponse` at `version`.
67    pub fn encode(&self, buf: &mut impl BufMut, version: i16) -> Result<(), EncodeError> {
68        if version >= 1 {
69            buf.put_i32(self.throttle_time_ms);
70        }
71        buf.put_i16(self.error_code);
72        if version >= 5 {
73            if is_flexible(version) {
74                wire::put_compact_nullable_string(buf, self.protocol_type.as_deref());
75            } else {
76                wire::put_nullable_string(buf, self.protocol_type.as_deref())?;
77            }
78        }
79        if version >= 5 {
80            if is_flexible(version) {
81                wire::put_compact_nullable_string(buf, self.protocol_name.as_deref());
82            } else {
83                wire::put_nullable_string(buf, self.protocol_name.as_deref())?;
84            }
85        }
86        if is_flexible(version) {
87            wire::put_compact_bytes(buf, &self.assignment);
88        } else {
89            wire::put_bytes(buf, &self.assignment)?;
90        }
91        if is_flexible(version) {
92            wire::put_tagged_fields(buf, &self.unknown_tagged_fields);
93        }
94        Ok(())
95    }
96
97    /// Decode one `SyncGroupResponse`, bounding allocation by the default
98    /// [`Limits`] derived from `buf`'s remaining length.
99    pub fn decode(buf: &mut impl Buf, version: i16) -> Result<Self, DecodeError> {
100        Self::decode_with_limits(buf, version, Limits::default())
101    }
102
103    /// Decode one `SyncGroupResponse` under `limits`.
104    pub fn decode_with_limits(
105        buf: &mut impl Buf,
106        version: i16,
107        limits: Limits,
108    ) -> Result<Self, DecodeError> {
109        let mut budget = limits.budget(buf.remaining());
110        Self::decode_with_budget(buf, version, &mut budget)
111    }
112
113    /// Decode one `SyncGroupResponse` against an existing `budget`.
114    pub fn decode_with_budget(
115        buf: &mut impl Buf,
116        version: i16,
117        budget: &mut Budget,
118    ) -> Result<Self, DecodeError> {
119        let mut this = Self::default();
120        if version >= 1 {
121            this.throttle_time_ms = wire::get_i32(buf)?;
122        }
123        this.error_code = wire::get_i16(buf)?;
124        if version >= 5 {
125            this.protocol_type = if is_flexible(version) {
126                wire::get_compact_nullable_string(buf)?
127            } else {
128                wire::get_nullable_string(buf)?
129            };
130        }
131        if version >= 5 {
132            this.protocol_name = if is_flexible(version) {
133                wire::get_compact_nullable_string(buf)?
134            } else {
135                wire::get_nullable_string(buf)?
136            };
137        }
138        this.assignment = {
139            let raw = if is_flexible(version) {
140                wire::get_compact_nullable_bytes(buf)?
141            } else {
142                wire::get_nullable_bytes(buf)?
143            };
144            match raw {
145                Some(v) => v,
146                None => return Err(DecodeError::InvalidLength(-1)),
147            }
148        };
149        if is_flexible(version) {
150            this.unknown_tagged_fields = wire::get_tagged_fields_with_budget(buf, budget)?;
151        }
152        Ok(this)
153    }
154}
155
156impl crate::Message for SyncGroupResponse {
157    const API_KEY: i16 = 14;
158    const MIN_VERSION: i16 = 0;
159    const MAX_VERSION: i16 = 5;
160
161    fn encode(&self, buf: &mut impl BufMut, version: i16) -> Result<(), EncodeError> {
162        SyncGroupResponse::encode(self, buf, version)
163    }
164    fn decode(buf: &mut impl Buf, version: i16) -> Result<Self, DecodeError> {
165        SyncGroupResponse::decode(buf, version)
166    }
167    fn decode_with_limits(
168        buf: &mut impl Buf,
169        version: i16,
170        limits: Limits,
171    ) -> Result<Self, DecodeError> {
172        SyncGroupResponse::decode_with_limits(buf, version, limits)
173    }
174    fn throttle_time_ms(&self) -> Option<i32> {
175        Some(self.throttle_time_ms)
176    }
177}