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