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