crabka_protocol/opt/rustwide/workdir/generated/
ListGroupsRequest.borrowed.rs1use crate::primitives::string_bytes::{
3 compact_string_len, put_compact_string, put_string, string_len,
4};
5use crate::primitives::string_bytes_borrowed::{get_compact_string_borrowed, get_string_borrowed};
6use crate::tagged_fields::{WriteTaggedFields, read_tagged_fields, tagged_fields_len};
7use crate::{DecodeBorrow, Encode, ProtocolError, UnknownTaggedFields};
8use bytes::BufMut;
9pub const API_KEY: i16 = 16;
10pub const MIN_VERSION: i16 = 0;
11pub const MAX_VERSION: i16 = 5;
12pub const FLEXIBLE_MIN: i16 = 3;
13#[inline]
14fn is_flexible(version: i16) -> bool {
15 version >= FLEXIBLE_MIN
16}
17#[derive(Debug, Clone, PartialEq, Eq, Default)]
18pub struct ListGroupsRequest<'a> {
19 pub states_filter: Vec<&'a str>,
20 pub types_filter: Vec<&'a str>,
21 pub unknown_tagged_fields: UnknownTaggedFields,
22}
23impl ListGroupsRequest<'_> {
24 pub fn to_owned(&self) -> crate::owned::list_groups_request::ListGroupsRequest {
25 crate::owned::list_groups_request::ListGroupsRequest {
26 states_filter: (self.states_filter)
27 .iter()
28 .map(std::string::ToString::to_string)
29 .collect(),
30 types_filter: (self.types_filter)
31 .iter()
32 .map(std::string::ToString::to_string)
33 .collect(),
34 unknown_tagged_fields: self.unknown_tagged_fields.clone(),
35 }
36 }
37}
38impl Encode for ListGroupsRequest<'_> {
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 >= 4 {
48 {
49 crate::primitives::array::put_array_len(buf, (self.states_filter).len(), flex);
50 for it in &self.states_filter {
51 if flex {
52 put_compact_string(buf, it);
53 } else {
54 put_string(buf, it);
55 }
56 }
57 }
58 }
59 if version >= 5 {
60 {
61 crate::primitives::array::put_array_len(buf, (self.types_filter).len(), flex);
62 for it in &self.types_filter {
63 if flex {
64 put_compact_string(buf, it);
65 } else {
66 put_string(buf, it);
67 }
68 }
69 }
70 }
71 if flex {
72 let tagged = WriteTaggedFields::new();
73 tagged.write(buf, &self.unknown_tagged_fields);
74 }
75 Ok(())
76 }
77 fn encoded_len(&self, version: i16) -> usize {
78 let flex = is_flexible(version);
79 let mut n: usize = 0;
80 if version >= 4 {
81 n += {
82 let prefix = crate::primitives::array::array_len_prefix_len(
83 (self.states_filter).len(),
84 flex,
85 );
86 let body: usize = (self.states_filter)
87 .iter()
88 .map(|it| {
89 if flex {
90 compact_string_len(it)
91 } else {
92 string_len(it)
93 }
94 })
95 .sum();
96 prefix + body
97 };
98 }
99 if version >= 5 {
100 n += {
101 let prefix =
102 crate::primitives::array::array_len_prefix_len((self.types_filter).len(), flex);
103 let body: usize = (self.types_filter)
104 .iter()
105 .map(|it| {
106 if flex {
107 compact_string_len(it)
108 } else {
109 string_len(it)
110 }
111 })
112 .sum();
113 prefix + body
114 };
115 }
116 if flex {
117 let known_pairs: Vec<(u32, usize)> = Vec::new();
118 n += tagged_fields_len(&known_pairs, &self.unknown_tagged_fields);
119 }
120 n
121 }
122}
123impl<'de> DecodeBorrow<'de> for ListGroupsRequest<'de> {
124 fn decode_borrow(buf: &mut &'de [u8], version: i16) -> Result<Self, ProtocolError> {
125 if !(MIN_VERSION..=MAX_VERSION).contains(&version) {
126 return Err(ProtocolError::UnsupportedVersion {
127 api_key: API_KEY,
128 version,
129 });
130 }
131 let flex = is_flexible(version);
132 let mut out = Self::default();
133 if version >= 4 {
134 out.states_filter = {
135 let n = crate::primitives::array::get_array_len(buf, flex)?;
136 let mut v = Vec::with_capacity(n);
137 for _ in 0..n {
138 v.push(if flex {
139 get_compact_string_borrowed(buf)?
140 } else {
141 get_string_borrowed(buf)?
142 });
143 }
144 v
145 };
146 }
147 if version >= 5 {
148 out.types_filter = {
149 let n = crate::primitives::array::get_array_len(buf, flex)?;
150 let mut v = Vec::with_capacity(n);
151 for _ in 0..n {
152 v.push(if flex {
153 get_compact_string_borrowed(buf)?
154 } else {
155 get_string_borrowed(buf)?
156 });
157 }
158 v
159 };
160 }
161 if flex {
162 out.unknown_tagged_fields = read_tagged_fields(buf, |_tag, _payload| Ok(false))?;
163 }
164 Ok(out)
165 }
166}
167#[cfg(test)]
168impl ListGroupsRequest<'_> {
169 #[must_use]
170 pub fn populated(version: i16) -> Self {
171 let mut m = Self::default();
172 if version >= 4 {
173 m.states_filter = vec!["x"];
174 }
175 if version >= 5 {
176 m.types_filter = vec!["x"];
177 }
178 m
179 }
180}