odradek_protocol/messages/
describe_groups_request.rs1#![allow(
6 clippy::field_reassign_with_default,
7 clippy::nonminimal_bool,
8 clippy::derivable_impls,
9 clippy::borrow_deref_ref,
10 clippy::double_parens,
11 unused_parens
12)]
13
14use bytes::{Buf, BufMut};
15
16use crate::budget::{Budget, Limits};
17#[allow(unused_imports)]
18use crate::error::{DecodeError, EncodeError};
19use crate::wire::{self, RawTaggedField};
20
21pub fn is_flexible(version: i16) -> bool {
23 let _ = version;
24 version >= 5
25}
26
27#[derive(Debug, Clone, PartialEq)]
29#[non_exhaustive]
30pub struct DescribeGroupsRequest {
31 pub groups: Vec<String>,
33 pub include_authorized_operations: bool,
35 pub unknown_tagged_fields: Vec<RawTaggedField>,
37}
38
39impl Default for DescribeGroupsRequest {
40 fn default() -> Self {
41 Self {
42 groups: Vec::new(),
43 include_authorized_operations: false,
44 unknown_tagged_fields: Vec::new(),
45 }
46 }
47}
48
49impl DescribeGroupsRequest {
50 pub const API_KEY: i16 = 15;
52 pub const MIN_VERSION: i16 = 0;
54 pub const MAX_VERSION: i16 = 6;
56
57 pub fn encode(&self, buf: &mut impl BufMut, version: i16) -> Result<(), EncodeError> {
59 if is_flexible(version) {
60 wire::put_compact_array_len(buf, Some(self.groups.len()));
61 } else {
62 wire::put_array_len(buf, Some(self.groups.len()))?;
63 }
64 for item in &self.groups {
65 if is_flexible(version) {
66 wire::put_compact_string(buf, item);
67 } else {
68 wire::put_string(buf, item)?;
69 }
70 }
71 if version >= 3 {
72 buf.put_u8(u8::from(self.include_authorized_operations));
73 }
74 if is_flexible(version) {
75 wire::put_tagged_fields(buf, &self.unknown_tagged_fields);
76 }
77 Ok(())
78 }
79
80 pub fn decode(buf: &mut impl Buf, version: i16) -> Result<Self, DecodeError> {
83 Self::decode_with_limits(buf, version, Limits::default())
84 }
85
86 pub fn decode_with_limits(
88 buf: &mut impl Buf,
89 version: i16,
90 limits: Limits,
91 ) -> Result<Self, DecodeError> {
92 let mut budget = limits.budget(buf.remaining());
93 Self::decode_with_budget(buf, version, &mut budget)
94 }
95
96 pub fn decode_with_budget(
98 buf: &mut impl Buf,
99 version: i16,
100 budget: &mut Budget,
101 ) -> Result<Self, DecodeError> {
102 let mut this = Self::default();
103 this.groups = {
104 let len = if is_flexible(version) {
105 wire::get_compact_array_len(buf)?
106 } else {
107 wire::get_array_len(buf)?
108 };
109 match len {
110 None => return Err(DecodeError::InvalidLength(-1)),
111 Some(n) => {
112 let mut items = Vec::new();
113 for _ in 0..n {
114 budget.push(
115 &mut items,
116 if is_flexible(version) {
117 wire::get_compact_string(buf)?
118 } else {
119 wire::get_string(buf)?
120 },
121 )?;
122 }
123 items
124 }
125 }
126 };
127 if version >= 3 {
128 this.include_authorized_operations = wire::get_bool(buf)?;
129 }
130 if is_flexible(version) {
131 this.unknown_tagged_fields = wire::get_tagged_fields_with_budget(buf, budget)?;
132 }
133 Ok(this)
134 }
135}
136
137impl crate::Message for DescribeGroupsRequest {
138 const API_KEY: i16 = 15;
139 const MIN_VERSION: i16 = 0;
140 const MAX_VERSION: i16 = 6;
141
142 fn encode(&self, buf: &mut impl BufMut, version: i16) -> Result<(), EncodeError> {
143 DescribeGroupsRequest::encode(self, buf, version)
144 }
145 fn decode(buf: &mut impl Buf, version: i16) -> Result<Self, DecodeError> {
146 DescribeGroupsRequest::decode(buf, version)
147 }
148 fn decode_with_limits(
149 buf: &mut impl Buf,
150 version: i16,
151 limits: Limits,
152 ) -> Result<Self, DecodeError> {
153 DescribeGroupsRequest::decode_with_limits(buf, version, limits)
154 }
155}