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