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