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