crabka_protocol/opt/rustwide/workdir/generated/
ListConfigResourcesRequest.borrowed.rs1use bytes::BufMut;
4
5use crate::primitives::fixed::{get_i8, put_i8};
6use crate::tagged_fields::{WriteTaggedFields, read_tagged_fields, tagged_fields_len};
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 {
16 version >= FLEXIBLE_MIN
17}
18
19#[derive(Debug, Clone, PartialEq, Eq, Default)]
20pub struct ListConfigResourcesRequest {
21 pub resource_types: Vec<i8>,
22 pub unknown_tagged_fields: UnknownTaggedFields,
23}
24impl ListConfigResourcesRequest {
25 pub fn to_owned(
26 &self,
27 ) -> crate::owned::list_config_resources_request::ListConfigResourcesRequest {
28 crate::owned::list_config_resources_request::ListConfigResourcesRequest {
29 resource_types: (self.resource_types).clone(),
30 unknown_tagged_fields: self.unknown_tagged_fields.clone(),
31 }
32 }
33}
34impl Encode for ListConfigResourcesRequest {
35 fn encode<B: BufMut>(&self, buf: &mut B, version: i16) -> Result<(), ProtocolError> {
36 if !(MIN_VERSION..=MAX_VERSION).contains(&version) {
37 return Err(ProtocolError::UnsupportedVersion {
38 api_key: API_KEY,
39 version,
40 });
41 }
42 let flex = is_flexible(version);
43 if version >= 1 {
44 {
45 crate::primitives::array::put_array_len(buf, (self.resource_types).len(), flex);
46 for it in &self.resource_types {
47 put_i8(buf, *it);
48 }
49 }
50 }
51 if flex {
52 let tagged = WriteTaggedFields::new();
53 tagged.write(buf, &self.unknown_tagged_fields);
54 }
55 Ok(())
56 }
57 fn encoded_len(&self, version: i16) -> usize {
58 let flex = is_flexible(version);
59 let mut n: usize = 0;
60 if version >= 1 {
61 n += {
62 let prefix = crate::primitives::array::array_len_prefix_len(
63 (self.resource_types).len(),
64 flex,
65 );
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 = crate::primitives::array::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}