Skip to main content

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

1// AUTO-GENERATED by crabka-protocol-codegen against a9ce3221537b8653448750697915607dc7936cf3. Do not edit.
2
3use bytes::BufMut;
4
5use crate::primitives::fixed::{get_i8, put_i8};
6use crate::tagged_fields::{read_tagged_fields, tagged_fields_len, WriteTaggedFields};
7use crate::{DecodeBorrow, Encode, ProtocolError, UnknownTaggedFields};
8
9pub const API_KEY: i16 = 74;
10pub const MIN_VERSION: i16 = 0;
11pub const MAX_VERSION: i16 = 1;
12pub const FLEXIBLE_MIN: i16 = 0;
13
14#[inline]
15fn is_flexible(version: i16) -> bool { version >= FLEXIBLE_MIN }
16
17#[derive(Debug, Clone, PartialEq, Eq)]
18pub struct ListConfigResourcesRequest {
19    pub resource_types: Vec<i8>,
20    pub unknown_tagged_fields: UnknownTaggedFields,
21}
22
23impl Default for ListConfigResourcesRequest {
24    fn default() -> Self {
25        Self {
26            resource_types: Vec::new(),
27            unknown_tagged_fields: Default::default(),
28        }
29    }
30}
31
32impl ListConfigResourcesRequest {
33    pub fn to_owned(&self) -> crate::owned::list_config_resources_request::ListConfigResourcesRequest {
34        crate::owned::list_config_resources_request::ListConfigResourcesRequest {
35            resource_types: (self.resource_types).clone(),
36            unknown_tagged_fields: self.unknown_tagged_fields.clone(),
37        }
38    }
39}
40
41impl Encode for ListConfigResourcesRequest {
42    fn encode<B: BufMut>(&self, buf: &mut B, version: i16) -> Result<(), ProtocolError> {
43        if !(MIN_VERSION..=MAX_VERSION).contains(&version) {
44            return Err(ProtocolError::UnsupportedVersion { api_key: API_KEY, version });
45        }
46        let flex = is_flexible(version);
47        if version >= 1 { { crate::primitives::array::put_array_len(buf, (self.resource_types).len(), flex); for it in &self.resource_types { put_i8(buf, *it); } } }
48        if flex {
49            let tagged = WriteTaggedFields::new();
50            tagged.write(buf, &self.unknown_tagged_fields);
51        }
52        Ok(())
53    }
54    fn encoded_len(&self, version: i16) -> usize {
55        let flex = is_flexible(version);
56        let mut n: usize = 0;
57        if version >= 1 { n += { let prefix = crate::primitives::array::array_len_prefix_len((self.resource_types).len(), flex); let body: usize = (self.resource_types).iter().map(|_| 1).sum(); prefix + body }; }
58        if flex {
59            let known_pairs: Vec<(u32, usize)> = Vec::new();
60            n += tagged_fields_len(&known_pairs, &self.unknown_tagged_fields);
61        }
62        n
63    }
64}
65
66impl<'de> DecodeBorrow<'de> for ListConfigResourcesRequest {
67    fn decode_borrow(buf: &mut &'de [u8], version: i16) -> Result<Self, ProtocolError> {
68        if !(MIN_VERSION..=MAX_VERSION).contains(&version) {
69            return Err(ProtocolError::UnsupportedVersion { api_key: API_KEY, version });
70        }
71        let flex = is_flexible(version);
72        let mut out = Self::default();
73        if version >= 1 { out.resource_types = { let n = crate::primitives::array::get_array_len(buf, flex)?; let mut v = Vec::with_capacity(n); for _ in 0..n { v.push(get_i8(buf)?); } v }; }
74        if flex {
75            out.unknown_tagged_fields = read_tagged_fields(buf, |_tag, _payload| {
76                Ok(false)
77            })?;
78        }
79        Ok(out)
80    }
81}