krabka_protocol/opt/rustwide/workdir/generated/
ListGroupsRequest.owned.rs1use bytes::{Buf, BufMut};
4
5use crate::{
6 Decode, Encode, ProtocolError, UnknownTaggedFields,
7 primitives::{
8 array::{array_len_prefix_len, get_array_len, put_array_len},
9 string_bytes::{
10 compact_string_len, get_compact_string_owned, get_string_owned, put_compact_string,
11 put_string, string_len,
12 },
13 },
14 tagged_fields::{WriteTaggedFields, read_tagged_fields, tagged_fields_len},
15};
16pub const API_KEY: i16 = 16;
17pub const MIN_VERSION: i16 = 0;
18pub const MAX_VERSION: i16 = 5;
19pub const LATEST_STABLE_VERSION: i16 = 5;
20pub const FLEXIBLE_MIN: i16 = 3;
21#[inline]
22#[must_use]
23pub fn is_flexible(version: i16) -> bool {
24 version >= FLEXIBLE_MIN
25}
26#[derive(Debug, Clone, PartialEq, Eq, Default)]
27pub struct ListGroupsRequest {
28 pub states_filter: Vec<String>,
29 pub types_filter: Vec<String>,
30 pub unknown_tagged_fields: UnknownTaggedFields,
31}
32impl Encode for ListGroupsRequest {
33 fn encode<B: BufMut>(&self, buf: &mut B, version: i16) -> Result<(), ProtocolError> {
34 if !(MIN_VERSION..=MAX_VERSION).contains(&version) {
35 return Err(ProtocolError::UnsupportedVersion {
36 api_key: API_KEY,
37 version,
38 });
39 }
40 let flex = is_flexible(version);
41 if version >= 4 {
42 {
43 put_array_len(buf, (self.states_filter).len(), flex)?;
44 for it in &self.states_filter {
45 if flex {
46 put_compact_string(buf, it)?;
47 } else {
48 put_string(buf, it)?;
49 }
50 }
51 }
52 }
53 if version >= 5 {
54 {
55 put_array_len(buf, (self.types_filter).len(), flex)?;
56 for it in &self.types_filter {
57 if flex {
58 put_compact_string(buf, it)?;
59 } else {
60 put_string(buf, it)?;
61 }
62 }
63 }
64 }
65 if flex {
66 let tagged = WriteTaggedFields::new();
67 tagged.write(buf, &self.unknown_tagged_fields)?;
68 }
69 Ok(())
70 }
71 fn encoded_len(&self, version: i16) -> usize {
72 let flex = is_flexible(version);
73 let mut n: usize = 0;
74 if version >= 4 {
75 n += {
76 let prefix = array_len_prefix_len((self.states_filter).len(), flex);
77 let body: usize = (self.states_filter)
78 .iter()
79 .map(|it| {
80 if flex {
81 compact_string_len(it)
82 } else {
83 string_len(it)
84 }
85 })
86 .sum();
87 prefix + body
88 };
89 }
90 if version >= 5 {
91 n += {
92 let prefix = array_len_prefix_len((self.types_filter).len(), flex);
93 let body: usize = (self.types_filter)
94 .iter()
95 .map(|it| {
96 if flex {
97 compact_string_len(it)
98 } else {
99 string_len(it)
100 }
101 })
102 .sum();
103 prefix + body
104 };
105 }
106 if flex {
107 let known_pairs: Vec<(u32, usize)> = Vec::new();
108 n += tagged_fields_len(&known_pairs, &self.unknown_tagged_fields);
109 }
110 n
111 }
112}
113impl Decode<'_> for ListGroupsRequest {
114 fn decode<B: Buf>(buf: &mut B, version: i16) -> Result<Self, ProtocolError> {
115 if !(MIN_VERSION..=MAX_VERSION).contains(&version) {
116 return Err(ProtocolError::UnsupportedVersion {
117 api_key: API_KEY,
118 version,
119 });
120 }
121 let flex = is_flexible(version);
122 let mut out = Self::default();
123 if version >= 4 {
124 out.states_filter = {
125 let n = get_array_len(buf, flex)?;
126 let mut v = Vec::with_capacity(n);
127 for _ in 0..n {
128 v.push(if flex {
129 get_compact_string_owned(buf)?
130 } else {
131 get_string_owned(buf)?
132 });
133 }
134 v
135 };
136 }
137 if version >= 5 {
138 out.types_filter = {
139 let n = get_array_len(buf, flex)?;
140 let mut v = Vec::with_capacity(n);
141 for _ in 0..n {
142 v.push(if flex {
143 get_compact_string_owned(buf)?
144 } else {
145 get_string_owned(buf)?
146 });
147 }
148 v
149 };
150 }
151 if flex {
152 out.unknown_tagged_fields = read_tagged_fields(buf, |_tag, _payload| Ok(false))?;
153 }
154 Ok(out)
155 }
156}
157#[cfg(test)]
158impl ListGroupsRequest {
159 #[must_use]
160 pub fn populated(version: i16) -> Self {
161 let mut m = Self::default();
162 if version >= 4 {
163 m.states_filter = vec!["x".to_owned()];
164 }
165 if version >= 5 {
166 m.types_filter = vec!["x".to_owned()];
167 }
168 m
169 }
170}
171#[must_use]
174#[allow(unused_comparisons)]
175pub fn default_json(version: i16) -> ::serde_json::Value {
176 let mut obj = ::serde_json::Map::new();
177 if version >= 4 {
178 obj.insert(
179 "statesFilter".to_owned(),
180 ::serde_json::Value::Array(vec![]),
181 );
182 }
183 if version >= 5 {
184 obj.insert("typesFilter".to_owned(), ::serde_json::Value::Array(vec![]));
185 }
186 ::serde_json::Value::Object(obj)
187}
188impl crate::ProtocolRequest for ListGroupsRequest {
189 const API_KEY: i16 = API_KEY;
190 const MIN_VERSION: i16 = MIN_VERSION;
191 const MAX_VERSION: i16 = MAX_VERSION;
192 const LATEST_STABLE_VERSION: i16 = LATEST_STABLE_VERSION;
193 const FLEXIBLE_MIN: i16 = FLEXIBLE_MIN;
194 type Response = super::list_groups_response::ListGroupsResponse;
195}