crabka_protocol/opt/rustwide/workdir/generated/
ListConfigResourcesRequest.owned.rs1use bytes::{Buf, BufMut};
4
5use crate::primitives::fixed::{get_i8, put_i8};
6use crate::tagged_fields::{WriteTaggedFields, read_tagged_fields, tagged_fields_len};
7use crate::{Decode, 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 Encode for ListConfigResourcesRequest {
25 fn encode<B: BufMut>(&self, buf: &mut B, version: i16) -> Result<(), ProtocolError> {
26 if !(MIN_VERSION..=MAX_VERSION).contains(&version) {
27 return Err(ProtocolError::UnsupportedVersion {
28 api_key: API_KEY,
29 version,
30 });
31 }
32 let flex = is_flexible(version);
33 if version >= 1 {
34 {
35 crate::primitives::array::put_array_len(buf, (self.resource_types).len(), flex);
36 for it in &self.resource_types {
37 put_i8(buf, *it);
38 }
39 }
40 }
41 if flex {
42 let tagged = WriteTaggedFields::new();
43 tagged.write(buf, &self.unknown_tagged_fields);
44 }
45 Ok(())
46 }
47 fn encoded_len(&self, version: i16) -> usize {
48 let flex = is_flexible(version);
49 let mut n: usize = 0;
50 if version >= 1 {
51 n += {
52 let prefix = crate::primitives::array::array_len_prefix_len(
53 (self.resource_types).len(),
54 flex,
55 );
56 let body: usize = (self.resource_types).iter().map(|_| 1).sum();
57 prefix + body
58 };
59 }
60 if flex {
61 let known_pairs: Vec<(u32, usize)> = Vec::new();
62 n += tagged_fields_len(&known_pairs, &self.unknown_tagged_fields);
63 }
64 n
65 }
66}
67impl Decode<'_> for ListConfigResourcesRequest {
68 fn decode<B: Buf>(buf: &mut B, version: i16) -> Result<Self, ProtocolError> {
69 if !(MIN_VERSION..=MAX_VERSION).contains(&version) {
70 return Err(ProtocolError::UnsupportedVersion {
71 api_key: API_KEY,
72 version,
73 });
74 }
75 let flex = is_flexible(version);
76 let mut out = Self::default();
77 if version >= 1 {
78 out.resource_types = {
79 let n = crate::primitives::array::get_array_len(buf, flex)?;
80 let mut v = Vec::with_capacity(n);
81 for _ in 0..n {
82 v.push(get_i8(buf)?);
83 }
84 v
85 };
86 }
87 if flex {
88 out.unknown_tagged_fields = read_tagged_fields(buf, |_tag, _payload| Ok(false))?;
89 }
90 Ok(out)
91 }
92}
93#[cfg(test)]
94impl ListConfigResourcesRequest {
95 #[must_use]
96 pub fn populated(version: i16) -> Self {
97 let mut m = Self::default();
98 if version >= 1 {
99 m.resource_types = vec![1i8];
100 }
101 m
102 }
103}
104
105#[must_use]
108#[allow(unused_comparisons)]
109pub fn default_json(version: i16) -> ::serde_json::Value {
110 let mut obj = ::serde_json::Map::new();
111 if version >= 1 {
112 obj.insert(
113 "resourceTypes".to_string(),
114 ::serde_json::Value::Array(vec![]),
115 );
116 }
117 ::serde_json::Value::Object(obj)
118}
119
120impl crate::ProtocolRequest for ListConfigResourcesRequest {
121 const API_KEY: i16 = API_KEY;
122 const MIN_VERSION: i16 = MIN_VERSION;
123 const MAX_VERSION: i16 = MAX_VERSION;
124 const FLEXIBLE_MIN: i16 = FLEXIBLE_MIN;
125 type Response = super::list_config_resources_response::ListConfigResourcesResponse;
126}