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