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