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