Skip to main content

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

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