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