Skip to main content

krabka_protocol/opt/rustwide/workdir/generated/
GetTelemetrySubscriptionsResponse.borrowed.rs

1// AUTO-GENERATED by krabka-protocol-codegen against a9ce3221537b8653448750697915607dc7936cf3. Do not edit.
2use bytes::BufMut;
3
4use crate::{
5    DecodeBorrow, Encode, ProtocolError, UnknownTaggedFields,
6    primitives::{
7        fixed::{get_bool, get_i8, get_i16, get_i32, put_bool, put_i8, put_i16, put_i32},
8        string_bytes::{compact_string_len, put_compact_string, put_string, string_len},
9        string_bytes_borrowed::{get_compact_string_borrowed, get_string_borrowed},
10    },
11    tagged_fields::{WriteTaggedFields, read_tagged_fields, tagged_fields_len},
12};
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]
18#[must_use]
19pub fn is_flexible(version: i16) -> bool {
20    version >= FLEXIBLE_MIN
21}
22#[derive(Debug, Clone, PartialEq, Eq, Default)]
23pub struct GetTelemetrySubscriptionsResponse<'a> {
24    pub throttle_time_ms: i32,
25    pub error_code: i16,
26    pub client_instance_id: crate::primitives::uuid::Uuid,
27    pub subscription_id: i32,
28    pub accepted_compression_types: Vec<i8>,
29    pub push_interval_ms: i32,
30    pub telemetry_max_bytes: i32,
31    pub delta_temporality: bool,
32    pub requested_metrics: Vec<&'a str>,
33    pub unknown_tagged_fields: UnknownTaggedFields,
34}
35impl<'a> GetTelemetrySubscriptionsResponse<'a> {
36    /// # Panics
37    ///
38    /// Panics if a records field contains an invalid encoded record batch.
39    #[must_use]
40    pub fn to_owned(
41        &self,
42    ) -> crate::owned::get_telemetry_subscriptions_response::GetTelemetrySubscriptionsResponse {
43        crate::owned::get_telemetry_subscriptions_response::GetTelemetrySubscriptionsResponse {
44            throttle_time_ms: (self.throttle_time_ms),
45            error_code: (self.error_code),
46            client_instance_id: (self.client_instance_id),
47            subscription_id: (self.subscription_id),
48            accepted_compression_types: (self.accepted_compression_types).clone(),
49            push_interval_ms: (self.push_interval_ms),
50            telemetry_max_bytes: (self.telemetry_max_bytes),
51            delta_temporality: (self.delta_temporality),
52            requested_metrics: (self.requested_metrics)
53                .iter()
54                .map(std::string::ToString::to_string)
55                .collect(),
56            unknown_tagged_fields: self.unknown_tagged_fields.clone(),
57        }
58    }
59    fn encode_field_0<B: BufMut>(&self, buf: &mut B, version: i16, _flex: bool) {
60        if version >= 0 {
61            put_i32(buf, self.throttle_time_ms);
62        }
63    }
64    fn encode_field_1<B: BufMut>(&self, buf: &mut B, version: i16, _flex: bool) {
65        if version >= 0 {
66            put_i16(buf, self.error_code);
67        }
68    }
69    fn encode_field_2<B: BufMut>(&self, buf: &mut B, version: i16, _flex: bool) {
70        if version >= 0 {
71            crate::primitives::uuid::put_uuid(buf, self.client_instance_id);
72        }
73    }
74    fn encode_field_3<B: BufMut>(&self, buf: &mut B, version: i16, _flex: bool) {
75        if version >= 0 {
76            put_i32(buf, self.subscription_id);
77        }
78    }
79    fn encode_field_4<B: BufMut>(&self, buf: &mut B, version: i16, flex: bool) {
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    }
93    fn encode_field_5<B: BufMut>(&self, buf: &mut B, version: i16, _flex: bool) {
94        if version >= 0 {
95            put_i32(buf, self.push_interval_ms);
96        }
97    }
98    fn encode_field_6<B: BufMut>(&self, buf: &mut B, version: i16, _flex: bool) {
99        if version >= 0 {
100            put_i32(buf, self.telemetry_max_bytes);
101        }
102    }
103    fn encode_field_7<B: BufMut>(&self, buf: &mut B, version: i16, _flex: bool) {
104        if version >= 0 {
105            put_bool(buf, self.delta_temporality);
106        }
107    }
108    fn encode_field_8<B: BufMut>(&self, buf: &mut B, version: i16, flex: bool) {
109        if version >= 0 {
110            {
111                crate::primitives::array::put_array_len(buf, (self.requested_metrics).len(), flex);
112                for it in &self.requested_metrics {
113                    if flex {
114                        let () = put_compact_string(buf, it);
115                    } else {
116                        let () = put_string(buf, it);
117                    }
118                }
119            };
120        }
121    }
122    fn encode_tagged_fields<B: BufMut>(&self, buf: &mut B, _version: i16, flex: bool) {
123        if flex {
124            let tagged = WriteTaggedFields::new();
125            tagged.write(buf, &self.unknown_tagged_fields);
126        }
127    }
128    fn decode_field_0(
129        out: &mut Self,
130        buf: &mut &'a [u8],
131        version: i16,
132        _flex: bool,
133    ) -> Result<(), ProtocolError> {
134        if version >= 0 {
135            out.throttle_time_ms = get_i32(buf)?;
136        }
137        Ok(())
138    }
139    fn decode_field_1(
140        out: &mut Self,
141        buf: &mut &'a [u8],
142        version: i16,
143        _flex: bool,
144    ) -> Result<(), ProtocolError> {
145        if version >= 0 {
146            out.error_code = get_i16(buf)?;
147        }
148        Ok(())
149    }
150    fn decode_field_2(
151        out: &mut Self,
152        buf: &mut &'a [u8],
153        version: i16,
154        _flex: bool,
155    ) -> Result<(), ProtocolError> {
156        if version >= 0 {
157            out.client_instance_id = crate::primitives::uuid::get_uuid(buf)?;
158        }
159        Ok(())
160    }
161    fn decode_field_3(
162        out: &mut Self,
163        buf: &mut &'a [u8],
164        version: i16,
165        _flex: bool,
166    ) -> Result<(), ProtocolError> {
167        if version >= 0 {
168            out.subscription_id = get_i32(buf)?;
169        }
170        Ok(())
171    }
172    fn decode_field_4(
173        out: &mut Self,
174        buf: &mut &'a [u8],
175        version: i16,
176        flex: bool,
177    ) -> Result<(), ProtocolError> {
178        if version >= 0 {
179            out.accepted_compression_types = {
180                let n = crate::primitives::array::get_array_len(buf, flex)?;
181                let mut v = Vec::with_capacity(n);
182                for _ in 0..n {
183                    v.push(get_i8(buf)?);
184                }
185                v
186            };
187        }
188        Ok(())
189    }
190    fn decode_field_5(
191        out: &mut Self,
192        buf: &mut &'a [u8],
193        version: i16,
194        _flex: bool,
195    ) -> Result<(), ProtocolError> {
196        if version >= 0 {
197            out.push_interval_ms = get_i32(buf)?;
198        }
199        Ok(())
200    }
201    fn decode_field_6(
202        out: &mut Self,
203        buf: &mut &'a [u8],
204        version: i16,
205        _flex: bool,
206    ) -> Result<(), ProtocolError> {
207        if version >= 0 {
208            out.telemetry_max_bytes = get_i32(buf)?;
209        }
210        Ok(())
211    }
212    fn decode_field_7(
213        out: &mut Self,
214        buf: &mut &'a [u8],
215        version: i16,
216        _flex: bool,
217    ) -> Result<(), ProtocolError> {
218        if version >= 0 {
219            out.delta_temporality = get_bool(buf)?;
220        }
221        Ok(())
222    }
223    fn decode_field_8(
224        out: &mut Self,
225        buf: &mut &'a [u8],
226        version: i16,
227        flex: bool,
228    ) -> Result<(), ProtocolError> {
229        if version >= 0 {
230            out.requested_metrics = {
231                let n = crate::primitives::array::get_array_len(buf, flex)?;
232                let mut v = Vec::with_capacity(n);
233                for _ in 0..n {
234                    v.push(if flex {
235                        get_compact_string_borrowed(buf)?
236                    } else {
237                        get_string_borrowed(buf)?
238                    });
239                }
240                v
241            };
242        }
243        Ok(())
244    }
245    fn decode_tagged_fields(
246        out: &mut Self,
247        buf: &mut &'a [u8],
248        _version: i16,
249        flex: bool,
250    ) -> Result<(), ProtocolError> {
251        if flex {
252            out.unknown_tagged_fields = read_tagged_fields(buf, |_tag, _payload| Ok(false))?;
253        }
254        Ok(())
255    }
256}
257impl Encode for GetTelemetrySubscriptionsResponse<'_> {
258    fn encode<B: BufMut>(&self, buf: &mut B, version: i16) -> Result<(), ProtocolError> {
259        if !(MIN_VERSION..=MAX_VERSION).contains(&version) {
260            return Err(ProtocolError::UnsupportedVersion {
261                api_key: API_KEY,
262                version,
263            });
264        }
265        let flex = is_flexible(version);
266        self.encode_field_0(buf, version, flex);
267        self.encode_field_1(buf, version, flex);
268        self.encode_field_2(buf, version, flex);
269        self.encode_field_3(buf, version, flex);
270        self.encode_field_4(buf, version, flex);
271        self.encode_field_5(buf, version, flex);
272        self.encode_field_6(buf, version, flex);
273        self.encode_field_7(buf, version, flex);
274        self.encode_field_8(buf, version, flex);
275        self.encode_tagged_fields(buf, version, flex);
276        Ok(())
277    }
278    fn encoded_len(&self, version: i16) -> usize {
279        let flex = is_flexible(version);
280        let mut n: usize = 0;
281        if version >= 0 {
282            n += 4;
283        }
284        if version >= 0 {
285            n += 2;
286        }
287        if version >= 0 {
288            n += 16;
289        }
290        if version >= 0 {
291            n += 4;
292        }
293        if version >= 0 {
294            n += {
295                let prefix = crate::primitives::array::array_len_prefix_len(
296                    (self.accepted_compression_types).len(),
297                    flex,
298                );
299                let body: usize = (self.accepted_compression_types).iter().map(|_| 1).sum();
300                prefix + body
301            };
302        }
303        if version >= 0 {
304            n += 4;
305        }
306        if version >= 0 {
307            n += 4;
308        }
309        if version >= 0 {
310            n += 1;
311        }
312        if version >= 0 {
313            n += {
314                let prefix = crate::primitives::array::array_len_prefix_len(
315                    (self.requested_metrics).len(),
316                    flex,
317                );
318                let body: usize = (self.requested_metrics)
319                    .iter()
320                    .map(|it| {
321                        if flex {
322                            compact_string_len(it)
323                        } else {
324                            string_len(it)
325                        }
326                    })
327                    .sum();
328                prefix + body
329            };
330        }
331        if flex {
332            let known_pairs: Vec<(u32, usize)> = Vec::new();
333            n += tagged_fields_len(&known_pairs, &self.unknown_tagged_fields);
334        }
335        n
336    }
337}
338impl<'de> DecodeBorrow<'de> for GetTelemetrySubscriptionsResponse<'de> {
339    fn decode_borrow(buf: &mut &'de [u8], version: i16) -> Result<Self, ProtocolError> {
340        if !(MIN_VERSION..=MAX_VERSION).contains(&version) {
341            return Err(ProtocolError::UnsupportedVersion {
342                api_key: API_KEY,
343                version,
344            });
345        }
346        let flex = is_flexible(version);
347        let mut out = Self::default();
348        Self::decode_field_0(&mut out, buf, version, flex)?;
349        Self::decode_field_1(&mut out, buf, version, flex)?;
350        Self::decode_field_2(&mut out, buf, version, flex)?;
351        Self::decode_field_3(&mut out, buf, version, flex)?;
352        Self::decode_field_4(&mut out, buf, version, flex)?;
353        Self::decode_field_5(&mut out, buf, version, flex)?;
354        Self::decode_field_6(&mut out, buf, version, flex)?;
355        Self::decode_field_7(&mut out, buf, version, flex)?;
356        Self::decode_field_8(&mut out, buf, version, flex)?;
357        Self::decode_tagged_fields(&mut out, buf, version, flex)?;
358        Ok(out)
359    }
360}
361#[cfg(test)]
362impl GetTelemetrySubscriptionsResponse<'_> {
363    #[must_use]
364    pub fn populated(version: i16) -> Self {
365        let mut m = Self::default();
366        if version >= 0 {
367            m.throttle_time_ms = 1i32;
368        }
369        if version >= 0 {
370            m.error_code = 1i16;
371        }
372        if version >= 0 {
373            m.client_instance_id = crate::primitives::uuid::Uuid([1u8; 16]);
374        }
375        if version >= 0 {
376            m.subscription_id = 1i32;
377        }
378        if version >= 0 {
379            m.accepted_compression_types = vec![1i8];
380        }
381        if version >= 0 {
382            m.push_interval_ms = 1i32;
383        }
384        if version >= 0 {
385            m.telemetry_max_bytes = 1i32;
386        }
387        if version >= 0 {
388            m.delta_temporality = true;
389        }
390        if version >= 0 {
391            m.requested_metrics = vec!["x"];
392        }
393        m
394    }
395}