Skip to main content

krabka_protocol/opt/rustwide/workdir/generated/
ListConfigResourcesRequest.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    owned::list_config_resources_request,
7    primitives::{
8        array::{array_len_prefix_len, get_array_len, put_array_len},
9        fixed::{get_i8, put_i8},
10    },
11    tagged_fields::{WriteTaggedFields, read_tagged_fields, tagged_fields_len},
12};
13pub const API_KEY: i16 = 74;
14pub const MIN_VERSION: i16 = 0;
15pub const MAX_VERSION: i16 = 1;
16pub const LATEST_STABLE_VERSION: i16 = 1;
17pub const FLEXIBLE_MIN: i16 = 0;
18#[inline]
19#[must_use]
20pub fn is_flexible(version: i16) -> bool {
21    version >= FLEXIBLE_MIN
22}
23#[derive(Debug, Clone, PartialEq, Eq, Default)]
24pub struct ListConfigResourcesRequest {
25    pub resource_types: Vec<i8>,
26    pub unknown_tagged_fields: UnknownTaggedFields,
27}
28impl ListConfigResourcesRequest {
29    #[must_use]
30    pub fn to_owned(&self) -> list_config_resources_request::ListConfigResourcesRequest {
31        list_config_resources_request::ListConfigResourcesRequest {
32            resource_types: (self.resource_types).clone(),
33            unknown_tagged_fields: self.unknown_tagged_fields.clone(),
34        }
35    }
36}
37impl Encode for ListConfigResourcesRequest {
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 >= 1 {
47            {
48                put_array_len(buf, (self.resource_types).len(), flex)?;
49                for it in &self.resource_types {
50                    put_i8(buf, *it);
51                }
52            }
53        }
54        if flex {
55            let tagged = WriteTaggedFields::new();
56            tagged.write(buf, &self.unknown_tagged_fields)?;
57        }
58        Ok(())
59    }
60    fn encoded_len(&self, version: i16) -> usize {
61        let flex = is_flexible(version);
62        let mut n: usize = 0;
63        if version >= 1 {
64            n += {
65                let prefix = array_len_prefix_len((self.resource_types).len(), flex);
66                let body: usize = (self.resource_types).iter().map(|_| 1).sum();
67                prefix + body
68            };
69        }
70        if flex {
71            let known_pairs: Vec<(u32, usize)> = Vec::new();
72            n += tagged_fields_len(&known_pairs, &self.unknown_tagged_fields);
73        }
74        n
75    }
76}
77impl<'de> DecodeBorrow<'de> for ListConfigResourcesRequest {
78    fn decode_borrow(buf: &mut &'de [u8], version: i16) -> Result<Self, ProtocolError> {
79        if !(MIN_VERSION..=MAX_VERSION).contains(&version) {
80            return Err(ProtocolError::UnsupportedVersion {
81                api_key: API_KEY,
82                version,
83            });
84        }
85        let flex = is_flexible(version);
86        let mut out = Self::default();
87        if version >= 1 {
88            out.resource_types = {
89                let n = get_array_len(buf, flex)?;
90                let mut v = Vec::with_capacity(n);
91                for _ in 0..n {
92                    v.push(get_i8(buf)?);
93                }
94                v
95            };
96        }
97        if flex {
98            out.unknown_tagged_fields = read_tagged_fields(buf, |_tag, _payload| Ok(false))?;
99        }
100        Ok(out)
101    }
102}
103#[cfg(test)]
104impl ListConfigResourcesRequest {
105    #[must_use]
106    pub fn populated(version: i16) -> Self {
107        let mut m = Self::default();
108        if version >= 1 {
109            m.resource_types = vec![1i8];
110        }
111        m
112    }
113}