crabka_protocol/opt/rustwide/workdir/generated/
DeleteGroupsRequest.borrowed.rs1use crate::primitives::string_bytes::{
4 compact_string_len, put_compact_string, put_string, string_len,
5};
6use crate::primitives::string_bytes_borrowed::{get_compact_string_borrowed, get_string_borrowed};
7use crate::tagged_fields::{WriteTaggedFields, read_tagged_fields, tagged_fields_len};
8use crate::{DecodeBorrow, Encode, ProtocolError, UnknownTaggedFields};
9use bytes::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<'a> {
23 pub groups_names: Vec<&'a str>,
24 pub unknown_tagged_fields: UnknownTaggedFields,
25}
26impl DeleteGroupsRequest<'_> {
27 pub fn to_owned(&self) -> crate::owned::delete_groups_request::DeleteGroupsRequest {
28 crate::owned::delete_groups_request::DeleteGroupsRequest {
29 groups_names: (self.groups_names)
30 .iter()
31 .map(std::string::ToString::to_string)
32 .collect(),
33 unknown_tagged_fields: self.unknown_tagged_fields.clone(),
34 }
35 }
36}
37impl Encode for DeleteGroupsRequest<'_> {
38 fn encode<B: BufMut>(&self, buf: &mut B, version: i16) -> Result<(), ProtocolError> {
39 if !(MIN_VERSION..=MAX_VERSION).contains(&version) {
40 return Err(ProtocolError::UnsupportedVersion {
41 api_key: API_KEY,
42 version,
43 });
44 }
45 let flex = is_flexible(version);
46 if version >= 0 {
47 {
48 crate::primitives::array::put_array_len(buf, (self.groups_names).len(), flex);
49 for it in &self.groups_names {
50 if flex {
51 put_compact_string(buf, it);
52 } else {
53 put_string(buf, it);
54 }
55 }
56 }
57 }
58 if flex {
59 let tagged = WriteTaggedFields::new();
60 tagged.write(buf, &self.unknown_tagged_fields);
61 }
62 Ok(())
63 }
64 fn encoded_len(&self, version: i16) -> usize {
65 let flex = is_flexible(version);
66 let mut n: usize = 0;
67 if version >= 0 {
68 n += {
69 let prefix =
70 crate::primitives::array::array_len_prefix_len((self.groups_names).len(), flex);
71 let body: usize = (self.groups_names)
72 .iter()
73 .map(|it| {
74 if flex {
75 compact_string_len(it)
76 } else {
77 string_len(it)
78 }
79 })
80 .sum();
81 prefix + body
82 };
83 }
84 if flex {
85 let known_pairs: Vec<(u32, usize)> = Vec::new();
86 n += tagged_fields_len(&known_pairs, &self.unknown_tagged_fields);
87 }
88 n
89 }
90}
91impl<'de> DecodeBorrow<'de> for DeleteGroupsRequest<'de> {
92 fn decode_borrow(buf: &mut &'de [u8], version: i16) -> Result<Self, ProtocolError> {
93 if !(MIN_VERSION..=MAX_VERSION).contains(&version) {
94 return Err(ProtocolError::UnsupportedVersion {
95 api_key: API_KEY,
96 version,
97 });
98 }
99 let flex = is_flexible(version);
100 let mut out = Self::default();
101 if version >= 0 {
102 out.groups_names = {
103 let n = crate::primitives::array::get_array_len(buf, flex)?;
104 let mut v = Vec::with_capacity(n);
105 for _ in 0..n {
106 v.push(if flex {
107 get_compact_string_borrowed(buf)?
108 } else {
109 get_string_borrowed(buf)?
110 });
111 }
112 v
113 };
114 }
115 if flex {
116 out.unknown_tagged_fields = read_tagged_fields(buf, |_tag, _payload| Ok(false))?;
117 }
118 Ok(out)
119 }
120}
121#[cfg(test)]
122impl DeleteGroupsRequest<'_> {
123 #[must_use]
124 pub fn populated(version: i16) -> Self {
125 let mut m = Self::default();
126 if version >= 0 {
127 m.groups_names = vec!["x"];
128 }
129 m
130 }
131}