Skip to main content

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

1// AUTO-GENERATED by crabka-protocol-codegen against a9ce3221537b8653448750697915607dc7936cf3. Do not edit.
2
3use crate::tagged_fields::{WriteTaggedFields, read_tagged_fields, tagged_fields_len};
4use crate::{DecodeBorrow, Encode, ProtocolError, UnknownTaggedFields};
5use bytes::BufMut;
6
7pub const API_KEY: i16 = 71;
8pub const MIN_VERSION: i16 = 0;
9pub const MAX_VERSION: i16 = 0;
10pub const FLEXIBLE_MIN: i16 = 0;
11
12#[inline]
13fn is_flexible(version: i16) -> bool {
14    version >= FLEXIBLE_MIN
15}
16
17#[derive(Debug, Clone, PartialEq, Eq, Default)]
18pub struct GetTelemetrySubscriptionsRequest {
19    pub client_instance_id: crate::primitives::uuid::Uuid,
20    pub unknown_tagged_fields: UnknownTaggedFields,
21}
22impl GetTelemetrySubscriptionsRequest {
23    pub fn to_owned(
24        &self,
25    ) -> crate::owned::get_telemetry_subscriptions_request::GetTelemetrySubscriptionsRequest {
26        crate::owned::get_telemetry_subscriptions_request::GetTelemetrySubscriptionsRequest {
27            client_instance_id: (self.client_instance_id),
28            unknown_tagged_fields: self.unknown_tagged_fields.clone(),
29        }
30    }
31}
32impl Encode for GetTelemetrySubscriptionsRequest {
33    fn encode<B: BufMut>(&self, buf: &mut B, version: i16) -> Result<(), ProtocolError> {
34        if !(MIN_VERSION..=MAX_VERSION).contains(&version) {
35            return Err(ProtocolError::UnsupportedVersion {
36                api_key: API_KEY,
37                version,
38            });
39        }
40        let flex = is_flexible(version);
41        if version >= 0 {
42            crate::primitives::uuid::put_uuid(buf, self.client_instance_id);
43        }
44        if flex {
45            let tagged = WriteTaggedFields::new();
46            tagged.write(buf, &self.unknown_tagged_fields);
47        }
48        Ok(())
49    }
50    fn encoded_len(&self, version: i16) -> usize {
51        let flex = is_flexible(version);
52        let mut n: usize = 0;
53        if version >= 0 {
54            n += 16;
55        }
56        if flex {
57            let known_pairs: Vec<(u32, usize)> = Vec::new();
58            n += tagged_fields_len(&known_pairs, &self.unknown_tagged_fields);
59        }
60        n
61    }
62}
63impl<'de> DecodeBorrow<'de> for GetTelemetrySubscriptionsRequest {
64    fn decode_borrow(buf: &mut &'de [u8], version: i16) -> Result<Self, ProtocolError> {
65        if !(MIN_VERSION..=MAX_VERSION).contains(&version) {
66            return Err(ProtocolError::UnsupportedVersion {
67                api_key: API_KEY,
68                version,
69            });
70        }
71        let flex = is_flexible(version);
72        let mut out = Self::default();
73        if version >= 0 {
74            out.client_instance_id = crate::primitives::uuid::get_uuid(buf)?;
75        }
76        if flex {
77            out.unknown_tagged_fields = read_tagged_fields(buf, |_tag, _payload| Ok(false))?;
78        }
79        Ok(out)
80    }
81}
82#[cfg(test)]
83impl GetTelemetrySubscriptionsRequest {
84    #[must_use]
85    pub fn populated(version: i16) -> Self {
86        let mut m = Self::default();
87        if version >= 0 {
88            m.client_instance_id = crate::primitives::uuid::Uuid([1u8; 16]);
89        }
90        m
91    }
92}