Skip to main content

crabka_protocol/opt/rustwide/workdir/generated/
ShareGroupDescribeRequest.borrowed.rs

1// AUTO-GENERATED by crabka-protocol-codegen against a9ce3221537b8653448750697915607dc7936cf3. Do not edit.
2use crate::primitives::fixed::{get_bool, put_bool};
3use 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;
10pub const API_KEY: i16 = 77;
11pub const MIN_VERSION: i16 = 1;
12pub const MAX_VERSION: i16 = 1;
13pub const FLEXIBLE_MIN: i16 = 0;
14#[inline]
15fn is_flexible(version: i16) -> bool {
16    version >= FLEXIBLE_MIN
17}
18#[derive(Debug, Clone, PartialEq, Eq, Default)]
19pub struct ShareGroupDescribeRequest<'a> {
20    pub group_ids: Vec<&'a str>,
21    pub include_authorized_operations: bool,
22    pub unknown_tagged_fields: UnknownTaggedFields,
23}
24impl ShareGroupDescribeRequest<'_> {
25    pub fn to_owned(
26        &self,
27    ) -> crate::owned::share_group_describe_request::ShareGroupDescribeRequest {
28        crate::owned::share_group_describe_request::ShareGroupDescribeRequest {
29            group_ids: (self.group_ids)
30                .iter()
31                .map(std::string::ToString::to_string)
32                .collect(),
33            include_authorized_operations: (self.include_authorized_operations),
34            unknown_tagged_fields: self.unknown_tagged_fields.clone(),
35        }
36    }
37}
38impl Encode for ShareGroupDescribeRequest<'_> {
39    fn encode<B: BufMut>(&self, buf: &mut B, version: i16) -> Result<(), ProtocolError> {
40        if !(MIN_VERSION..=MAX_VERSION).contains(&version) {
41            return Err(ProtocolError::UnsupportedVersion {
42                api_key: API_KEY,
43                version,
44            });
45        }
46        let flex = is_flexible(version);
47        if version >= 0 {
48            {
49                crate::primitives::array::put_array_len(buf, (self.group_ids).len(), flex);
50                for it in &self.group_ids {
51                    if flex {
52                        put_compact_string(buf, it);
53                    } else {
54                        put_string(buf, it);
55                    }
56                }
57            }
58        }
59        if version >= 0 {
60            put_bool(buf, self.include_authorized_operations);
61        }
62        if flex {
63            let tagged = WriteTaggedFields::new();
64            tagged.write(buf, &self.unknown_tagged_fields);
65        }
66        Ok(())
67    }
68    fn encoded_len(&self, version: i16) -> usize {
69        let flex = is_flexible(version);
70        let mut n: usize = 0;
71        if version >= 0 {
72            n += {
73                let prefix =
74                    crate::primitives::array::array_len_prefix_len((self.group_ids).len(), flex);
75                let body: usize = (self.group_ids)
76                    .iter()
77                    .map(|it| {
78                        if flex {
79                            compact_string_len(it)
80                        } else {
81                            string_len(it)
82                        }
83                    })
84                    .sum();
85                prefix + body
86            };
87        }
88        if version >= 0 {
89            n += 1;
90        }
91        if flex {
92            let known_pairs: Vec<(u32, usize)> = Vec::new();
93            n += tagged_fields_len(&known_pairs, &self.unknown_tagged_fields);
94        }
95        n
96    }
97}
98impl<'de> DecodeBorrow<'de> for ShareGroupDescribeRequest<'de> {
99    fn decode_borrow(buf: &mut &'de [u8], version: i16) -> Result<Self, ProtocolError> {
100        if !(MIN_VERSION..=MAX_VERSION).contains(&version) {
101            return Err(ProtocolError::UnsupportedVersion {
102                api_key: API_KEY,
103                version,
104            });
105        }
106        let flex = is_flexible(version);
107        let mut out = Self::default();
108        if version >= 0 {
109            out.group_ids = {
110                let n = crate::primitives::array::get_array_len(buf, flex)?;
111                let mut v = Vec::with_capacity(n);
112                for _ in 0..n {
113                    v.push(if flex {
114                        get_compact_string_borrowed(buf)?
115                    } else {
116                        get_string_borrowed(buf)?
117                    });
118                }
119                v
120            };
121        }
122        if version >= 0 {
123            out.include_authorized_operations = get_bool(buf)?;
124        }
125        if flex {
126            out.unknown_tagged_fields = read_tagged_fields(buf, |_tag, _payload| Ok(false))?;
127        }
128        Ok(out)
129    }
130}
131#[cfg(test)]
132impl ShareGroupDescribeRequest<'_> {
133    #[must_use]
134    pub fn populated(version: i16) -> Self {
135        let mut m = Self::default();
136        if version >= 0 {
137            m.group_ids = vec!["x"];
138        }
139        if version >= 0 {
140            m.include_authorized_operations = true;
141        }
142        m
143    }
144}