crabka_protocol/opt/rustwide/workdir/generated/
ConsumerGroupHeartbeatResponse.borrowed.rs1use bytes::BufMut;
4
5use crate::primitives::fixed::{get_i16, get_i32, get_i8, put_i16, put_i32};
6use crate::primitives::string_bytes::{
7 compact_nullable_string_len, compact_string_len, nullable_string_len,
8 put_compact_nullable_string, put_compact_string, put_nullable_string, put_string,
9 string_len,
10};
11use crate::primitives::string_bytes_borrowed::{
12 get_compact_nullable_string_borrowed, get_compact_string_borrowed,
13 get_nullable_string_borrowed, get_string_borrowed,
14};
15use crate::tagged_fields::{read_tagged_fields, tagged_fields_len, WriteTaggedFields};
16use crate::{DecodeBorrow, Encode, ProtocolError, UnknownTaggedFields};
17
18pub const API_KEY: i16 = 68;
19pub const MIN_VERSION: i16 = 0;
20pub const MAX_VERSION: i16 = 1;
21pub const FLEXIBLE_MIN: i16 = 0;
22
23#[inline]
24fn is_flexible(version: i16) -> bool { version >= FLEXIBLE_MIN }
25
26#[derive(Debug, Clone, PartialEq, Eq)]
27pub struct ConsumerGroupHeartbeatResponse<'a> {
28 pub throttle_time_ms: i32,
29 pub error_code: i16,
30 pub error_message: Option<&'a str>,
31 pub member_id: Option<&'a str>,
32 pub member_epoch: i32,
33 pub heartbeat_interval_ms: i32,
34 pub assignment: Option<Assignment>,
35 pub unknown_tagged_fields: UnknownTaggedFields,
36}
37
38impl<'a> Default for ConsumerGroupHeartbeatResponse<'a> {
39 fn default() -> Self {
40 Self {
41 throttle_time_ms: 0i32,
42 error_code: 0i16,
43 error_message: None,
44 member_id: None,
45 member_epoch: 0i32,
46 heartbeat_interval_ms: 0i32,
47 assignment: None,
48 unknown_tagged_fields: Default::default(),
49 }
50 }
51}
52
53impl<'a> ConsumerGroupHeartbeatResponse<'a> {
54 pub fn to_owned(&self) -> crate::owned::consumer_group_heartbeat_response::ConsumerGroupHeartbeatResponse {
55 crate::owned::consumer_group_heartbeat_response::ConsumerGroupHeartbeatResponse {
56 throttle_time_ms: (self.throttle_time_ms),
57 error_code: (self.error_code),
58 error_message: (self.error_message).map(|s| s.to_string()),
59 member_id: (self.member_id).map(|s| s.to_string()),
60 member_epoch: (self.member_epoch),
61 heartbeat_interval_ms: (self.heartbeat_interval_ms),
62 assignment: (self.assignment).as_ref().map(|v| v.to_owned()),
63 unknown_tagged_fields: self.unknown_tagged_fields.clone(),
64 }
65 }
66}
67
68impl<'a> Encode for ConsumerGroupHeartbeatResponse<'a> {
69 fn encode<B: BufMut>(&self, buf: &mut B, version: i16) -> Result<(), ProtocolError> {
70 if !(MIN_VERSION..=MAX_VERSION).contains(&version) {
71 return Err(ProtocolError::UnsupportedVersion { api_key: API_KEY, version });
72 }
73 let flex = is_flexible(version);
74 if version >= 0 { put_i32(buf, self.throttle_time_ms) }
75 if version >= 0 { put_i16(buf, self.error_code) }
76 if version >= 0 { if flex { put_compact_nullable_string(buf, self.error_message) } else { put_nullable_string(buf, self.error_message) } }
77 if version >= 0 { if flex { put_compact_nullable_string(buf, self.member_id) } else { put_nullable_string(buf, self.member_id) } }
78 if version >= 0 { put_i32(buf, self.member_epoch) }
79 if version >= 0 { put_i32(buf, self.heartbeat_interval_ms) }
80 if version >= 0 { match &self.assignment { None => { buf.put_i8(-1); }, Some(v) => { buf.put_i8(1); v.encode(buf, version)?; } } }
81 if flex {
82 let tagged = WriteTaggedFields::new();
83 tagged.write(buf, &self.unknown_tagged_fields);
84 }
85 Ok(())
86 }
87 fn encoded_len(&self, version: i16) -> usize {
88 let flex = is_flexible(version);
89 let mut n: usize = 0;
90 if version >= 0 { n += 4; }
91 if version >= 0 { n += 2; }
92 if version >= 0 { n += if flex { compact_nullable_string_len(self.error_message) } else { nullable_string_len(self.error_message) }; }
93 if version >= 0 { n += if flex { compact_nullable_string_len(self.member_id) } else { nullable_string_len(self.member_id) }; }
94 if version >= 0 { n += 4; }
95 if version >= 0 { n += 4; }
96 if version >= 0 { n += 1 + self.assignment.as_ref().map_or(0, |v| v.encoded_len(version)); }
97 if flex {
98 let known_pairs: Vec<(u32, usize)> = Vec::new();
99 n += tagged_fields_len(&known_pairs, &self.unknown_tagged_fields);
100 }
101 n
102 }
103}
104
105impl<'de> DecodeBorrow<'de> for ConsumerGroupHeartbeatResponse<'de> {
106 fn decode_borrow(buf: &mut &'de [u8], version: i16) -> Result<Self, ProtocolError> {
107 if !(MIN_VERSION..=MAX_VERSION).contains(&version) {
108 return Err(ProtocolError::UnsupportedVersion { api_key: API_KEY, version });
109 }
110 let flex = is_flexible(version);
111 let mut out = Self::default();
112 if version >= 0 { out.throttle_time_ms = get_i32(buf)?; }
113 if version >= 0 { out.error_code = get_i16(buf)?; }
114 if version >= 0 { out.error_message = if flex { get_compact_nullable_string_borrowed(buf)? } else { get_nullable_string_borrowed(buf)? }; }
115 if version >= 0 { out.member_id = if flex { get_compact_nullable_string_borrowed(buf)? } else { get_nullable_string_borrowed(buf)? }; }
116 if version >= 0 { out.member_epoch = get_i32(buf)?; }
117 if version >= 0 { out.heartbeat_interval_ms = get_i32(buf)?; }
118 if version >= 0 { out.assignment = if get_i8(buf)? < 0 { None } else { Some(Assignment::decode_borrow(buf, version)?) }; }
119 if flex {
120 out.unknown_tagged_fields = read_tagged_fields(buf, |_tag, _payload| {
121 Ok(false)
122 })?;
123 }
124 Ok(out)
125 }
126}
127
128#[derive(Debug, Clone, PartialEq, Eq)]
129pub struct Assignment {
130 pub topic_partitions: Vec<super::common::topic_partitions::TopicPartitions>,
131 pub unknown_tagged_fields: UnknownTaggedFields,
132}
133
134impl Default for Assignment {
135 fn default() -> Self {
136 Self {
137 topic_partitions: Vec::new(),
138 unknown_tagged_fields: Default::default(),
139 }
140 }
141}
142
143impl Assignment {
144 pub fn to_owned(&self) -> crate::owned::consumer_group_heartbeat_response::Assignment {
145 crate::owned::consumer_group_heartbeat_response::Assignment {
146 topic_partitions: (self.topic_partitions).iter().map(|it| it.to_owned()).collect(),
147 unknown_tagged_fields: self.unknown_tagged_fields.clone(),
148 }
149 }
150}
151
152impl Encode for Assignment {
153 fn encode<B: BufMut>(&self, buf: &mut B, version: i16) -> Result<(), ProtocolError> {
154 let flex = version >= 0;
155 if version >= 0 { { crate::primitives::array::put_array_len(buf, (self.topic_partitions).len(), flex); for it in &self.topic_partitions { it.encode(buf, version)?; } } }
156 if flex {
157 let tagged = WriteTaggedFields::new();
158 tagged.write(buf, &self.unknown_tagged_fields);
159 }
160 Ok(())
161 }
162 fn encoded_len(&self, version: i16) -> usize {
163 let flex = version >= 0;
164 let mut n: usize = 0;
165 if version >= 0 { n += { let prefix = crate::primitives::array::array_len_prefix_len((self.topic_partitions).len(), flex); let body: usize = (self.topic_partitions).iter().map(|it| it.encoded_len(version)).sum(); prefix + body }; }
166 if flex {
167 let known_pairs: Vec<(u32, usize)> = Vec::new();
168 n += tagged_fields_len(&known_pairs, &self.unknown_tagged_fields);
169 }
170 n
171 }
172}
173
174impl<'de> DecodeBorrow<'de> for Assignment {
175 fn decode_borrow(buf: &mut &'de [u8], version: i16) -> Result<Self, ProtocolError> {
176 let flex = version >= 0;
177 let mut out = Self::default();
178 if version >= 0 { out.topic_partitions = { let n = crate::primitives::array::get_array_len(buf, flex)?; let mut v = Vec::with_capacity(n); for _ in 0..n { v.push(super::common::topic_partitions::TopicPartitions::decode_borrow(buf, version)?); } v }; }
179 if flex {
180 out.unknown_tagged_fields = read_tagged_fields(buf, |_tag, _payload| {
181 Ok(false)
182 })?;
183 }
184 Ok(out)
185 }
186}