crabka_protocol/opt/rustwide/workdir/generated/
GetTelemetrySubscriptionsResponse.owned.rs1use bytes::{Buf, BufMut};
4
5use crate::primitives::fixed::{
6 get_bool, get_i8, get_i16, get_i32, put_bool, put_i8, put_i16, put_i32,
7};
8use crate::primitives::string_bytes::{
9 compact_string_len, get_compact_string_owned, get_string_owned, put_compact_string, put_string,
10 string_len,
11};
12use crate::tagged_fields::{WriteTaggedFields, read_tagged_fields, tagged_fields_len};
13use crate::{Decode, Encode, ProtocolError, UnknownTaggedFields};
14
15pub const API_KEY: i16 = 71;
16pub const MIN_VERSION: i16 = 0;
17pub const MAX_VERSION: i16 = 0;
18pub const FLEXIBLE_MIN: i16 = 0;
19
20#[inline]
21fn is_flexible(version: i16) -> bool {
22 version >= FLEXIBLE_MIN
23}
24
25#[derive(Debug, Clone, PartialEq, Eq, Default)]
26pub struct GetTelemetrySubscriptionsResponse {
27 pub throttle_time_ms: i32,
28 pub error_code: i16,
29 pub client_instance_id: crate::primitives::uuid::Uuid,
30 pub subscription_id: i32,
31 pub accepted_compression_types: Vec<i8>,
32 pub push_interval_ms: i32,
33 pub telemetry_max_bytes: i32,
34 pub delta_temporality: bool,
35 pub requested_metrics: Vec<String>,
36 pub unknown_tagged_fields: UnknownTaggedFields,
37}
38impl Encode for GetTelemetrySubscriptionsResponse {
39 fn encode<B: BufMut>(&self, buf: &mut B, version: i16) -> Result<(), ProtocolError> {
40 if !(MIN_VERSION..=MAX_VERSION).contains(&version) {
41 return Err(ProtocolError::UnsupportedVersion {
42 api_key: API_KEY,
43 version,
44 });
45 }
46 let flex = is_flexible(version);
47 if version >= 0 {
48 put_i32(buf, self.throttle_time_ms);
49 }
50 if version >= 0 {
51 put_i16(buf, self.error_code);
52 }
53 if version >= 0 {
54 crate::primitives::uuid::put_uuid(buf, self.client_instance_id);
55 }
56 if version >= 0 {
57 put_i32(buf, self.subscription_id);
58 }
59 if version >= 0 {
60 {
61 crate::primitives::array::put_array_len(
62 buf,
63 (self.accepted_compression_types).len(),
64 flex,
65 );
66 for it in &self.accepted_compression_types {
67 put_i8(buf, *it);
68 }
69 }
70 }
71 if version >= 0 {
72 put_i32(buf, self.push_interval_ms);
73 }
74 if version >= 0 {
75 put_i32(buf, self.telemetry_max_bytes);
76 }
77 if version >= 0 {
78 put_bool(buf, self.delta_temporality);
79 }
80 if version >= 0 {
81 {
82 crate::primitives::array::put_array_len(buf, (self.requested_metrics).len(), flex);
83 for it in &self.requested_metrics {
84 if flex {
85 put_compact_string(buf, it);
86 } else {
87 put_string(buf, it);
88 }
89 }
90 }
91 }
92 if flex {
93 let tagged = WriteTaggedFields::new();
94 tagged.write(buf, &self.unknown_tagged_fields);
95 }
96 Ok(())
97 }
98 fn encoded_len(&self, version: i16) -> usize {
99 let flex = is_flexible(version);
100 let mut n: usize = 0;
101 if version >= 0 {
102 n += 4;
103 }
104 if version >= 0 {
105 n += 2;
106 }
107 if version >= 0 {
108 n += 16;
109 }
110 if version >= 0 {
111 n += 4;
112 }
113 if version >= 0 {
114 n += {
115 let prefix = crate::primitives::array::array_len_prefix_len(
116 (self.accepted_compression_types).len(),
117 flex,
118 );
119 let body: usize = (self.accepted_compression_types).iter().map(|_| 1).sum();
120 prefix + body
121 };
122 }
123 if version >= 0 {
124 n += 4;
125 }
126 if version >= 0 {
127 n += 4;
128 }
129 if version >= 0 {
130 n += 1;
131 }
132 if version >= 0 {
133 n += {
134 let prefix = crate::primitives::array::array_len_prefix_len(
135 (self.requested_metrics).len(),
136 flex,
137 );
138 let body: usize = (self.requested_metrics)
139 .iter()
140 .map(|it| {
141 if flex {
142 compact_string_len(it)
143 } else {
144 string_len(it)
145 }
146 })
147 .sum();
148 prefix + body
149 };
150 }
151 if flex {
152 let known_pairs: Vec<(u32, usize)> = Vec::new();
153 n += tagged_fields_len(&known_pairs, &self.unknown_tagged_fields);
154 }
155 n
156 }
157}
158impl Decode<'_> for GetTelemetrySubscriptionsResponse {
159 fn decode<B: Buf>(buf: &mut B, version: i16) -> Result<Self, ProtocolError> {
160 if !(MIN_VERSION..=MAX_VERSION).contains(&version) {
161 return Err(ProtocolError::UnsupportedVersion {
162 api_key: API_KEY,
163 version,
164 });
165 }
166 let flex = is_flexible(version);
167 let mut out = Self::default();
168 if version >= 0 {
169 out.throttle_time_ms = get_i32(buf)?;
170 }
171 if version >= 0 {
172 out.error_code = get_i16(buf)?;
173 }
174 if version >= 0 {
175 out.client_instance_id = crate::primitives::uuid::get_uuid(buf)?;
176 }
177 if version >= 0 {
178 out.subscription_id = get_i32(buf)?;
179 }
180 if version >= 0 {
181 out.accepted_compression_types = {
182 let n = crate::primitives::array::get_array_len(buf, flex)?;
183 let mut v = Vec::with_capacity(n);
184 for _ in 0..n {
185 v.push(get_i8(buf)?);
186 }
187 v
188 };
189 }
190 if version >= 0 {
191 out.push_interval_ms = get_i32(buf)?;
192 }
193 if version >= 0 {
194 out.telemetry_max_bytes = get_i32(buf)?;
195 }
196 if version >= 0 {
197 out.delta_temporality = get_bool(buf)?;
198 }
199 if version >= 0 {
200 out.requested_metrics = {
201 let n = crate::primitives::array::get_array_len(buf, flex)?;
202 let mut v = Vec::with_capacity(n);
203 for _ in 0..n {
204 v.push(if flex {
205 get_compact_string_owned(buf)?
206 } else {
207 get_string_owned(buf)?
208 });
209 }
210 v
211 };
212 }
213 if flex {
214 out.unknown_tagged_fields = read_tagged_fields(buf, |_tag, _payload| Ok(false))?;
215 }
216 Ok(out)
217 }
218}
219#[cfg(test)]
220impl GetTelemetrySubscriptionsResponse {
221 #[must_use]
222 pub fn populated(version: i16) -> Self {
223 let mut m = Self::default();
224 if version >= 0 {
225 m.throttle_time_ms = 1i32;
226 }
227 if version >= 0 {
228 m.error_code = 1i16;
229 }
230 if version >= 0 {
231 m.client_instance_id = crate::primitives::uuid::Uuid([1u8; 16]);
232 }
233 if version >= 0 {
234 m.subscription_id = 1i32;
235 }
236 if version >= 0 {
237 m.accepted_compression_types = vec![1i8];
238 }
239 if version >= 0 {
240 m.push_interval_ms = 1i32;
241 }
242 if version >= 0 {
243 m.telemetry_max_bytes = 1i32;
244 }
245 if version >= 0 {
246 m.delta_temporality = true;
247 }
248 if version >= 0 {
249 m.requested_metrics = vec!["x".to_string()];
250 }
251 m
252 }
253}
254
255#[must_use]
258#[allow(unused_comparisons)]
259pub fn default_json(version: i16) -> ::serde_json::Value {
260 let mut obj = ::serde_json::Map::new();
261 obj.insert("throttleTimeMs".to_string(), ::serde_json::json!(0));
262 obj.insert("errorCode".to_string(), ::serde_json::json!(0));
263 obj.insert(
264 "clientInstanceId".to_string(),
265 ::serde_json::Value::String("AAAAAAAAAAAAAAAAAAAAAA".to_string()),
266 );
267 obj.insert("subscriptionId".to_string(), ::serde_json::json!(0));
268 obj.insert(
269 "acceptedCompressionTypes".to_string(),
270 ::serde_json::Value::Array(vec![]),
271 );
272 obj.insert("pushIntervalMs".to_string(), ::serde_json::json!(0));
273 obj.insert("telemetryMaxBytes".to_string(), ::serde_json::json!(0));
274 obj.insert(
275 "deltaTemporality".to_string(),
276 ::serde_json::Value::Bool(false),
277 );
278 obj.insert(
279 "requestedMetrics".to_string(),
280 ::serde_json::Value::Array(vec![]),
281 );
282 ::serde_json::Value::Object(obj)
283}