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