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