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