Skip to main content

krabka_protocol/opt/rustwide/workdir/generated/
DeleteGroupsRequest.owned.rs

1// AUTO-GENERATED by krabka-protocol-codegen against a9ce3221537b8653448750697915607dc7936cf3. Do not edit.
2
3use bytes::{Buf, BufMut};
4
5use crate::{
6    Decode, Encode, ProtocolError, UnknownTaggedFields,
7    primitives::{
8        array::{array_len_prefix_len, get_array_len, put_array_len},
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 = 42;
17pub const MIN_VERSION: i16 = 0;
18pub const MAX_VERSION: i16 = 3;
19pub const LATEST_STABLE_VERSION: i16 = 3;
20pub const FLEXIBLE_MIN: i16 = 2;
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 DeleteGroupsRequest {
28    pub groups_names: Vec<String>,
29    pub unknown_tagged_fields: UnknownTaggedFields,
30}
31impl Encode for DeleteGroupsRequest {
32    fn encode<B: BufMut>(&self, buf: &mut B, version: i16) -> Result<(), ProtocolError> {
33        if !(MIN_VERSION..=MAX_VERSION).contains(&version) {
34            return Err(ProtocolError::UnsupportedVersion {
35                api_key: API_KEY,
36                version,
37            });
38        }
39        let flex = is_flexible(version);
40        if version >= 0 {
41            {
42                put_array_len(buf, (self.groups_names).len(), flex)?;
43                for it in &self.groups_names {
44                    if flex {
45                        put_compact_string(buf, it)?;
46                    } else {
47                        put_string(buf, it)?;
48                    }
49                }
50            }
51        }
52        if flex {
53            let tagged = WriteTaggedFields::new();
54            tagged.write(buf, &self.unknown_tagged_fields)?;
55        }
56        Ok(())
57    }
58    fn encoded_len(&self, version: i16) -> usize {
59        let flex = is_flexible(version);
60        let mut n: usize = 0;
61        if version >= 0 {
62            n += {
63                let prefix = array_len_prefix_len((self.groups_names).len(), flex);
64                let body: usize = (self.groups_names)
65                    .iter()
66                    .map(|it| {
67                        if flex {
68                            compact_string_len(it)
69                        } else {
70                            string_len(it)
71                        }
72                    })
73                    .sum();
74                prefix + body
75            };
76        }
77        if flex {
78            let known_pairs: Vec<(u32, usize)> = Vec::new();
79            n += tagged_fields_len(&known_pairs, &self.unknown_tagged_fields);
80        }
81        n
82    }
83}
84impl Decode<'_> for DeleteGroupsRequest {
85    fn decode<B: Buf>(buf: &mut B, version: i16) -> Result<Self, ProtocolError> {
86        if !(MIN_VERSION..=MAX_VERSION).contains(&version) {
87            return Err(ProtocolError::UnsupportedVersion {
88                api_key: API_KEY,
89                version,
90            });
91        }
92        let flex = is_flexible(version);
93        let mut out = Self::default();
94        if version >= 0 {
95            out.groups_names = {
96                let n = get_array_len(buf, flex)?;
97                let mut v = Vec::with_capacity(n);
98                for _ in 0..n {
99                    v.push(if flex {
100                        get_compact_string_owned(buf)?
101                    } else {
102                        get_string_owned(buf)?
103                    });
104                }
105                v
106            };
107        }
108        if flex {
109            out.unknown_tagged_fields = read_tagged_fields(buf, |_tag, _payload| Ok(false))?;
110        }
111        Ok(out)
112    }
113}
114#[cfg(test)]
115impl DeleteGroupsRequest {
116    #[must_use]
117    pub fn populated(version: i16) -> Self {
118        let mut m = Self::default();
119        if version >= 0 {
120            m.groups_names = vec!["x".to_owned()];
121        }
122        m
123    }
124}
125/// Default JSON payload matching `Self::default()` for JVM oracle differential testing.
126/// Only includes fields valid for the given version.
127#[must_use]
128#[allow(unused_comparisons)]
129pub fn default_json(_version: i16) -> ::serde_json::Value {
130    let mut obj = ::serde_json::Map::new();
131    obj.insert("groupsNames".to_owned(), ::serde_json::Value::Array(vec![]));
132    ::serde_json::Value::Object(obj)
133}
134impl crate::ProtocolRequest for DeleteGroupsRequest {
135    const API_KEY: i16 = API_KEY;
136    const MIN_VERSION: i16 = MIN_VERSION;
137    const MAX_VERSION: i16 = MAX_VERSION;
138    const LATEST_STABLE_VERSION: i16 = LATEST_STABLE_VERSION;
139    const FLEXIBLE_MIN: i16 = FLEXIBLE_MIN;
140    type Response = super::delete_groups_response::DeleteGroupsResponse;
141}