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