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