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