Skip to main content

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

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