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