crabka_protocol/opt/rustwide/workdir/generated/
ShareGroupHeartbeatRequest.owned.rs1use bytes::{Buf, BufMut};
4
5use crate::primitives::fixed::{get_i32, 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, string_len,
10};
11use crate::tagged_fields::{WriteTaggedFields, read_tagged_fields, tagged_fields_len};
12use crate::{Decode, Encode, ProtocolError, UnknownTaggedFields};
13
14pub const API_KEY: i16 = 76;
15pub const MIN_VERSION: i16 = 1;
16pub const MAX_VERSION: i16 = 1;
17pub const FLEXIBLE_MIN: i16 = 0;
18
19#[inline]
20fn is_flexible(version: i16) -> bool {
21 version >= FLEXIBLE_MIN
22}
23
24#[derive(Debug, Clone, PartialEq, Eq, Default)]
25pub struct ShareGroupHeartbeatRequest {
26 pub group_id: String,
27 pub member_id: String,
28 pub member_epoch: i32,
29 pub rack_id: Option<String>,
30 pub subscribed_topic_names: Option<Vec<String>>,
31 pub unknown_tagged_fields: UnknownTaggedFields,
32}
33impl Encode for ShareGroupHeartbeatRequest {
34 fn encode<B: BufMut>(&self, buf: &mut B, version: i16) -> Result<(), ProtocolError> {
35 if !(MIN_VERSION..=MAX_VERSION).contains(&version) {
36 return Err(ProtocolError::UnsupportedVersion {
37 api_key: API_KEY,
38 version,
39 });
40 }
41 let flex = is_flexible(version);
42 if version >= 0 {
43 if flex {
44 put_compact_string(buf, &self.group_id);
45 } else {
46 put_string(buf, &self.group_id);
47 }
48 }
49 if version >= 0 {
50 if flex {
51 put_compact_string(buf, &self.member_id);
52 } else {
53 put_string(buf, &self.member_id);
54 }
55 }
56 if version >= 0 {
57 put_i32(buf, self.member_epoch);
58 }
59 if version >= 0 {
60 if flex {
61 put_compact_nullable_string(buf, self.rack_id.as_deref());
62 } else {
63 put_nullable_string(buf, self.rack_id.as_deref());
64 }
65 }
66 if version >= 0 {
67 {
68 let len = (self.subscribed_topic_names).as_ref().map(Vec::len);
69 crate::primitives::array::put_nullable_array_len(buf, len, flex);
70 if let Some(v) = &self.subscribed_topic_names {
71 for it in v {
72 if flex {
73 put_compact_string(buf, it);
74 } else {
75 put_string(buf, it);
76 }
77 }
78 }
79 }
80 }
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 {
91 n += if flex {
92 compact_string_len(&self.group_id)
93 } else {
94 string_len(&self.group_id)
95 };
96 }
97 if version >= 0 {
98 n += if flex {
99 compact_string_len(&self.member_id)
100 } else {
101 string_len(&self.member_id)
102 };
103 }
104 if version >= 0 {
105 n += 4;
106 }
107 if version >= 0 {
108 n += if flex {
109 compact_nullable_string_len(self.rack_id.as_deref())
110 } else {
111 nullable_string_len(self.rack_id.as_deref())
112 };
113 }
114 if version >= 0 {
115 n += {
116 let opt: Option<&Vec<_>> = (self.subscribed_topic_names).as_ref();
117 let prefix = crate::primitives::array::nullable_array_len_prefix_len(
118 opt.map(std::vec::Vec::len),
119 flex,
120 );
121 let body: usize = opt.map_or(0, |v| {
122 v.iter()
123 .map(|it| {
124 if flex {
125 compact_string_len(it)
126 } else {
127 string_len(it)
128 }
129 })
130 .sum()
131 });
132 prefix + body
133 };
134 }
135 if flex {
136 let known_pairs: Vec<(u32, usize)> = Vec::new();
137 n += tagged_fields_len(&known_pairs, &self.unknown_tagged_fields);
138 }
139 n
140 }
141}
142impl Decode<'_> for ShareGroupHeartbeatRequest {
143 fn decode<B: Buf>(buf: &mut B, version: i16) -> Result<Self, ProtocolError> {
144 if !(MIN_VERSION..=MAX_VERSION).contains(&version) {
145 return Err(ProtocolError::UnsupportedVersion {
146 api_key: API_KEY,
147 version,
148 });
149 }
150 let flex = is_flexible(version);
151 let mut out = Self::default();
152 if version >= 0 {
153 out.group_id = if flex {
154 get_compact_string_owned(buf)?
155 } else {
156 get_string_owned(buf)?
157 };
158 }
159 if version >= 0 {
160 out.member_id = if flex {
161 get_compact_string_owned(buf)?
162 } else {
163 get_string_owned(buf)?
164 };
165 }
166 if version >= 0 {
167 out.member_epoch = get_i32(buf)?;
168 }
169 if version >= 0 {
170 out.rack_id = if flex {
171 get_compact_nullable_string_owned(buf)?
172 } else {
173 get_nullable_string_owned(buf)?
174 };
175 }
176 if version >= 0 {
177 out.subscribed_topic_names = {
178 let opt = crate::primitives::array::get_nullable_array_len(buf, flex)?;
179 match opt {
180 None => None,
181 Some(n) => {
182 let mut v = Vec::with_capacity(n);
183 for _ in 0..n {
184 v.push(if flex {
185 get_compact_string_owned(buf)?
186 } else {
187 get_string_owned(buf)?
188 });
189 }
190 Some(v)
191 }
192 }
193 };
194 }
195 if flex {
196 out.unknown_tagged_fields = read_tagged_fields(buf, |_tag, _payload| Ok(false))?;
197 }
198 Ok(out)
199 }
200}
201#[cfg(test)]
202impl ShareGroupHeartbeatRequest {
203 #[must_use]
204 pub fn populated(version: i16) -> Self {
205 let mut m = Self::default();
206 if version >= 0 {
207 m.group_id = "x".to_string();
208 }
209 if version >= 0 {
210 m.member_id = "x".to_string();
211 }
212 if version >= 0 {
213 m.member_epoch = 1i32;
214 }
215 if version >= 0 {
216 m.rack_id = Some("x".to_string());
217 }
218 if version >= 0 {
219 m.subscribed_topic_names = Some(vec!["x".to_string()]);
220 }
221 m
222 }
223}
224
225#[must_use]
228#[allow(unused_comparisons)]
229pub fn default_json(version: i16) -> ::serde_json::Value {
230 let mut obj = ::serde_json::Map::new();
231 obj.insert(
232 "groupId".to_string(),
233 ::serde_json::Value::String(String::new()),
234 );
235 obj.insert(
236 "memberId".to_string(),
237 ::serde_json::Value::String(String::new()),
238 );
239 obj.insert("memberEpoch".to_string(), ::serde_json::json!(0));
240 obj.insert("rackId".to_string(), ::serde_json::Value::Null);
241 obj.insert(
242 "subscribedTopicNames".to_string(),
243 ::serde_json::Value::Null,
244 );
245 ::serde_json::Value::Object(obj)
246}
247
248impl crate::ProtocolRequest for ShareGroupHeartbeatRequest {
249 const API_KEY: i16 = API_KEY;
250 const MIN_VERSION: i16 = MIN_VERSION;
251 const MAX_VERSION: i16 = MAX_VERSION;
252 const FLEXIBLE_MIN: i16 = FLEXIBLE_MIN;
253 type Response = super::share_group_heartbeat_response::ShareGroupHeartbeatResponse;
254}