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