krabka_protocol/opt/rustwide/workdir/generated/
HeartbeatRequest.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 = 12;
21pub const MIN_VERSION: i16 = 0;
22pub const MAX_VERSION: i16 = 4;
23pub const LATEST_STABLE_VERSION: i16 = 4;
24pub const FLEXIBLE_MIN: i16 = 4;
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 HeartbeatRequest<'a> {
32 pub group_id: &'a str,
33 pub generation_id: i32,
34 pub member_id: &'a str,
35 pub group_instance_id: Option<&'a str>,
36 pub unknown_tagged_fields: UnknownTaggedFields,
37}
38impl HeartbeatRequest<'_> {
39 #[must_use]
43 pub fn to_owned(&self) -> crate::owned::heartbeat_request::HeartbeatRequest {
44 crate::owned::heartbeat_request::HeartbeatRequest {
45 group_id: (self.group_id).to_string(),
46 generation_id: (self.generation_id),
47 member_id: (self.member_id).to_string(),
48 group_instance_id: (self.group_instance_id).map(std::string::ToString::to_string),
49 unknown_tagged_fields: self.unknown_tagged_fields.clone(),
50 }
51 }
52}
53impl Encode for HeartbeatRequest<'_> {
54 fn encode<B: BufMut>(&self, buf: &mut B, version: i16) -> Result<(), ProtocolError> {
55 if !(MIN_VERSION..=MAX_VERSION).contains(&version) {
56 return Err(ProtocolError::UnsupportedVersion {
57 api_key: API_KEY,
58 version,
59 });
60 }
61 let flex = is_flexible(version);
62 if version >= 0 {
63 if flex {
64 let () = put_compact_string(buf, self.group_id);
65 } else {
66 let () = put_string(buf, self.group_id);
67 }
68 }
69 if version >= 0 {
70 put_i32(buf, self.generation_id);
71 }
72 if version >= 0 {
73 if flex {
74 let () = put_compact_string(buf, self.member_id);
75 } else {
76 let () = put_string(buf, self.member_id);
77 }
78 }
79 if version >= 3 {
80 if flex {
81 let () = put_compact_nullable_string(buf, self.group_instance_id);
82 } else {
83 let () = put_nullable_string(buf, self.group_instance_id);
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 += 4;
104 }
105 if version >= 0 {
106 n += if flex {
107 compact_string_len(self.member_id)
108 } else {
109 string_len(self.member_id)
110 };
111 }
112 if version >= 3 {
113 n += if flex {
114 compact_nullable_string_len(self.group_instance_id)
115 } else {
116 nullable_string_len(self.group_instance_id)
117 };
118 }
119 if flex {
120 let known_pairs: Vec<(u32, usize)> = Vec::new();
121 n += tagged_fields_len(&known_pairs, &self.unknown_tagged_fields);
122 }
123 n
124 }
125}
126impl<'de> DecodeBorrow<'de> for HeartbeatRequest<'de> {
127 fn decode_borrow(buf: &mut &'de [u8], version: i16) -> Result<Self, ProtocolError> {
128 if !(MIN_VERSION..=MAX_VERSION).contains(&version) {
129 return Err(ProtocolError::UnsupportedVersion {
130 api_key: API_KEY,
131 version,
132 });
133 }
134 let flex = is_flexible(version);
135 let mut out = Self::default();
136 if version >= 0 {
137 out.group_id = if flex {
138 get_compact_string_borrowed(buf)?
139 } else {
140 get_string_borrowed(buf)?
141 };
142 }
143 if version >= 0 {
144 out.generation_id = get_i32(buf)?;
145 }
146 if version >= 0 {
147 out.member_id = if flex {
148 get_compact_string_borrowed(buf)?
149 } else {
150 get_string_borrowed(buf)?
151 };
152 }
153 if version >= 3 {
154 out.group_instance_id = if flex {
155 get_compact_nullable_string_borrowed(buf)?
156 } else {
157 get_nullable_string_borrowed(buf)?
158 };
159 }
160 if flex {
161 out.unknown_tagged_fields = read_tagged_fields(buf, |_tag, _payload| Ok(false))?;
162 }
163 Ok(out)
164 }
165}
166#[cfg(test)]
167impl HeartbeatRequest<'_> {
168 #[must_use]
169 pub fn populated(version: i16) -> Self {
170 let mut m = Self::default();
171 if version >= 0 {
172 m.group_id = "x";
173 }
174 if version >= 0 {
175 m.generation_id = 1i32;
176 }
177 if version >= 0 {
178 m.member_id = "x";
179 }
180 if version >= 3 {
181 m.group_instance_id = Some("x");
182 }
183 m
184 }
185}