Skip to main content

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