crabka_protocol/opt/rustwide/workdir/generated/
HeartbeatRequest.owned.rs1use bytes::{Buf, BufMut};
4
5use crate::primitives::fixed::{get_i32, put_i32};
6use crate::primitives::string_bytes::{
7 compact_nullable_string_len, compact_string_len, get_compact_nullable_string_owned,
8 get_compact_string_owned, get_nullable_string_owned, get_string_owned, nullable_string_len,
9 put_compact_nullable_string, put_compact_string, put_nullable_string, put_string, string_len,
10};
11use crate::tagged_fields::{WriteTaggedFields, read_tagged_fields, tagged_fields_len};
12use crate::{Decode, Encode, ProtocolError, UnknownTaggedFields};
13
14pub const API_KEY: i16 = 12;
15pub const MIN_VERSION: i16 = 0;
16pub const MAX_VERSION: i16 = 4;
17pub const FLEXIBLE_MIN: i16 = 4;
18
19#[inline]
20fn is_flexible(version: i16) -> bool {
21 version >= FLEXIBLE_MIN
22}
23
24#[derive(Debug, Clone, PartialEq, Eq, Default)]
25pub struct HeartbeatRequest {
26 pub group_id: String,
27 pub generation_id: i32,
28 pub member_id: String,
29 pub group_instance_id: Option<String>,
30 pub unknown_tagged_fields: UnknownTaggedFields,
31}
32impl Encode for HeartbeatRequest {
33 fn encode<B: BufMut>(&self, buf: &mut B, version: i16) -> Result<(), ProtocolError> {
34 if !(MIN_VERSION..=MAX_VERSION).contains(&version) {
35 return Err(ProtocolError::UnsupportedVersion {
36 api_key: API_KEY,
37 version,
38 });
39 }
40 let flex = is_flexible(version);
41 if version >= 0 {
42 if flex {
43 put_compact_string(buf, &self.group_id);
44 } else {
45 put_string(buf, &self.group_id);
46 }
47 }
48 if version >= 0 {
49 put_i32(buf, self.generation_id);
50 }
51 if version >= 0 {
52 if flex {
53 put_compact_string(buf, &self.member_id);
54 } else {
55 put_string(buf, &self.member_id);
56 }
57 }
58 if version >= 3 {
59 if flex {
60 put_compact_nullable_string(buf, self.group_instance_id.as_deref());
61 } else {
62 put_nullable_string(buf, self.group_instance_id.as_deref());
63 }
64 }
65 if flex {
66 let tagged = WriteTaggedFields::new();
67 tagged.write(buf, &self.unknown_tagged_fields);
68 }
69 Ok(())
70 }
71 fn encoded_len(&self, version: i16) -> usize {
72 let flex = is_flexible(version);
73 let mut n: usize = 0;
74 if version >= 0 {
75 n += if flex {
76 compact_string_len(&self.group_id)
77 } else {
78 string_len(&self.group_id)
79 };
80 }
81 if version >= 0 {
82 n += 4;
83 }
84 if version >= 0 {
85 n += if flex {
86 compact_string_len(&self.member_id)
87 } else {
88 string_len(&self.member_id)
89 };
90 }
91 if version >= 3 {
92 n += if flex {
93 compact_nullable_string_len(self.group_instance_id.as_deref())
94 } else {
95 nullable_string_len(self.group_instance_id.as_deref())
96 };
97 }
98 if flex {
99 let known_pairs: Vec<(u32, usize)> = Vec::new();
100 n += tagged_fields_len(&known_pairs, &self.unknown_tagged_fields);
101 }
102 n
103 }
104}
105impl Decode<'_> for HeartbeatRequest {
106 fn decode<B: Buf>(buf: &mut B, version: i16) -> Result<Self, ProtocolError> {
107 if !(MIN_VERSION..=MAX_VERSION).contains(&version) {
108 return Err(ProtocolError::UnsupportedVersion {
109 api_key: API_KEY,
110 version,
111 });
112 }
113 let flex = is_flexible(version);
114 let mut out = Self::default();
115 if version >= 0 {
116 out.group_id = if flex {
117 get_compact_string_owned(buf)?
118 } else {
119 get_string_owned(buf)?
120 };
121 }
122 if version >= 0 {
123 out.generation_id = get_i32(buf)?;
124 }
125 if version >= 0 {
126 out.member_id = if flex {
127 get_compact_string_owned(buf)?
128 } else {
129 get_string_owned(buf)?
130 };
131 }
132 if version >= 3 {
133 out.group_instance_id = if flex {
134 get_compact_nullable_string_owned(buf)?
135 } else {
136 get_nullable_string_owned(buf)?
137 };
138 }
139 if flex {
140 out.unknown_tagged_fields = read_tagged_fields(buf, |_tag, _payload| Ok(false))?;
141 }
142 Ok(out)
143 }
144}
145#[cfg(test)]
146impl HeartbeatRequest {
147 #[must_use]
148 pub fn populated(version: i16) -> Self {
149 let mut m = Self::default();
150 if version >= 0 {
151 m.group_id = "x".to_string();
152 }
153 if version >= 0 {
154 m.generation_id = 1i32;
155 }
156 if version >= 0 {
157 m.member_id = "x".to_string();
158 }
159 if version >= 3 {
160 m.group_instance_id = Some("x".to_string());
161 }
162 m
163 }
164}
165
166#[must_use]
169#[allow(unused_comparisons)]
170pub fn default_json(version: i16) -> ::serde_json::Value {
171 let mut obj = ::serde_json::Map::new();
172 obj.insert(
173 "groupId".to_string(),
174 ::serde_json::Value::String(String::new()),
175 );
176 obj.insert("generationId".to_string(), ::serde_json::json!(0));
177 obj.insert(
178 "memberId".to_string(),
179 ::serde_json::Value::String(String::new()),
180 );
181 if version >= 3 {
182 obj.insert("groupInstanceId".to_string(), ::serde_json::Value::Null);
183 }
184 ::serde_json::Value::Object(obj)
185}
186
187impl crate::ProtocolRequest for HeartbeatRequest {
188 const API_KEY: i16 = API_KEY;
189 const MIN_VERSION: i16 = MIN_VERSION;
190 const MAX_VERSION: i16 = MAX_VERSION;
191 const FLEXIBLE_MIN: i16 = FLEXIBLE_MIN;
192 type Response = super::heartbeat_response::HeartbeatResponse;
193}