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