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