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