Skip to main content

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