crabka_protocol/opt/rustwide/workdir/generated/
DeleteGroupsRequest.owned.rs1use bytes::{Buf, BufMut};
4use crate::primitives::string_bytes::{
5 compact_string_len, get_compact_string_owned, get_string_owned,
6 put_compact_string, put_string, string_len,
7};
8use crate::tagged_fields::{read_tagged_fields, tagged_fields_len, WriteTaggedFields};
9use crate::{Decode, Encode, ProtocolError, UnknownTaggedFields};
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 { version >= FLEXIBLE_MIN }
18
19#[derive(Debug, Clone, PartialEq, Eq, Default)]
20pub struct DeleteGroupsRequest {
21 pub groups_names: Vec<String>,
22 pub unknown_tagged_fields: UnknownTaggedFields,
23}
24
25impl Encode for DeleteGroupsRequest {
26 fn encode<B: BufMut>(&self, buf: &mut B, version: i16) -> Result<(), ProtocolError> {
27 if !(MIN_VERSION..=MAX_VERSION).contains(&version) {
28 return Err(ProtocolError::UnsupportedVersion { api_key: API_KEY, version });
29 }
30 let flex = is_flexible(version);
31 if version >= 0 { { crate::primitives::array::put_array_len(buf, (self.groups_names).len(), flex); for it in &self.groups_names { if flex { put_compact_string(buf, &*it) } else { put_string(buf, &*it) }; } } }
32 if flex {
33 let tagged = WriteTaggedFields::new();
34 tagged.write(buf, &self.unknown_tagged_fields);
35 }
36 Ok(())
37 }
38 fn encoded_len(&self, version: i16) -> usize {
39 let flex = is_flexible(version);
40 let mut n: usize = 0;
41 if version >= 0 { n += { let prefix = crate::primitives::array::array_len_prefix_len((self.groups_names).len(), flex); let body: usize = (self.groups_names).iter().map(|it| if flex { compact_string_len(&*it) } else { string_len(&*it) }).sum(); prefix + body }; }
42 if flex {
43 let known_pairs: Vec<(u32, usize)> = Vec::new();
44 n += tagged_fields_len(&known_pairs, &self.unknown_tagged_fields);
45 }
46 n
47 }
48}
49
50impl<'de> Decode<'de> for DeleteGroupsRequest {
51 fn decode<B: Buf>(buf: &mut B, version: i16) -> Result<Self, ProtocolError> {
52 if !(MIN_VERSION..=MAX_VERSION).contains(&version) {
53 return Err(ProtocolError::UnsupportedVersion { api_key: API_KEY, version });
54 }
55 let flex = is_flexible(version);
56 let mut out = Self::default();
57 if version >= 0 { out.groups_names = { let n = crate::primitives::array::get_array_len(buf, flex)?; let mut v = Vec::with_capacity(n); for _ in 0..n { v.push(if flex { get_compact_string_owned(buf)? } else { get_string_owned(buf)? }); } v }; }
58 if flex {
59 out.unknown_tagged_fields = read_tagged_fields(buf, |_tag, _payload| {
60 Ok(false)
61 })?;
62 }
63 Ok(out)
64 }
65}
66
67#[must_use]
70#[allow(unused_comparisons)]
71pub fn default_json(version: i16) -> ::serde_json::Value {
72 let mut obj = ::serde_json::Map::new();
73 obj.insert("groupsNames".to_string(), ::serde_json::Value::Array(vec![]));
74 ::serde_json::Value::Object(obj)
75}
76
77impl crate::ProtocolRequest for DeleteGroupsRequest {
78 const API_KEY: i16 = API_KEY;
79 const MIN_VERSION: i16 = MIN_VERSION;
80 const MAX_VERSION: i16 = MAX_VERSION;
81 const FLEXIBLE_MIN: i16 = FLEXIBLE_MIN;
82 type Response = super::delete_groups_response::DeleteGroupsResponse;
83}