Skip to main content

krabka_protocol/opt/rustwide/workdir/generated/
StreamsGroupDescribeRequest.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::streams_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 = 89;
16pub const MIN_VERSION: i16 = 0;
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 StreamsGroupDescribeRequest<'a> {
27    pub group_ids: Vec<&'a str>,
28    pub include_authorized_operations: bool,
29    pub include_topology_description: bool,
30    pub unknown_tagged_fields: UnknownTaggedFields,
31}
32impl StreamsGroupDescribeRequest<'_> {
33    #[must_use]
34    pub fn to_owned(&self) -> streams_group_describe_request::StreamsGroupDescribeRequest {
35        streams_group_describe_request::StreamsGroupDescribeRequest {
36            group_ids: (self.group_ids).iter().map(|&s| s.to_owned()).collect(),
37            include_authorized_operations: (self.include_authorized_operations),
38            include_topology_description: (self.include_topology_description),
39            unknown_tagged_fields: self.unknown_tagged_fields.clone(),
40        }
41    }
42}
43impl Encode for StreamsGroupDescribeRequest<'_> {
44    fn encode<B: BufMut>(&self, buf: &mut B, version: i16) -> Result<(), ProtocolError> {
45        if !(MIN_VERSION..=MAX_VERSION).contains(&version) {
46            return Err(ProtocolError::UnsupportedVersion {
47                api_key: API_KEY,
48                version,
49            });
50        }
51        let flex = is_flexible(version);
52        if version >= 0 {
53            {
54                put_array_len(buf, (self.group_ids).len(), flex)?;
55                for it in &self.group_ids {
56                    if flex {
57                        put_compact_string(buf, it)?;
58                    } else {
59                        put_string(buf, it)?;
60                    }
61                }
62            }
63        }
64        if version >= 0 {
65            put_bool(buf, self.include_authorized_operations);
66        }
67        if version >= 1 {
68            put_bool(buf, self.include_topology_description);
69        }
70        if flex {
71            let tagged = WriteTaggedFields::new();
72            tagged.write(buf, &self.unknown_tagged_fields)?;
73        }
74        Ok(())
75    }
76    fn encoded_len(&self, version: i16) -> usize {
77        let flex = is_flexible(version);
78        let mut n: usize = 0;
79        if version >= 0 {
80            n += {
81                let prefix = array_len_prefix_len((self.group_ids).len(), flex);
82                let body: usize = (self.group_ids)
83                    .iter()
84                    .map(|it| {
85                        if flex {
86                            compact_string_len(it)
87                        } else {
88                            string_len(it)
89                        }
90                    })
91                    .sum();
92                prefix + body
93            };
94        }
95        if version >= 0 {
96            n += 1;
97        }
98        if version >= 1 {
99            n += 1;
100        }
101        if flex {
102            let known_pairs: Vec<(u32, usize)> = Vec::new();
103            n += tagged_fields_len(&known_pairs, &self.unknown_tagged_fields);
104        }
105        n
106    }
107}
108impl<'de> DecodeBorrow<'de> for StreamsGroupDescribeRequest<'de> {
109    fn decode_borrow(buf: &mut &'de [u8], version: i16) -> Result<Self, ProtocolError> {
110        if !(MIN_VERSION..=MAX_VERSION).contains(&version) {
111            return Err(ProtocolError::UnsupportedVersion {
112                api_key: API_KEY,
113                version,
114            });
115        }
116        let flex = is_flexible(version);
117        let mut out = Self::default();
118        if version >= 0 {
119            out.group_ids = {
120                let n = get_array_len(buf, flex)?;
121                let mut v = Vec::with_capacity(n);
122                for _ in 0..n {
123                    v.push(if flex {
124                        get_compact_string_borrowed(buf)?
125                    } else {
126                        get_string_borrowed(buf)?
127                    });
128                }
129                v
130            };
131        }
132        if version >= 0 {
133            out.include_authorized_operations = get_bool(buf)?;
134        }
135        if version >= 1 {
136            out.include_topology_description = get_bool(buf)?;
137        }
138        if flex {
139            out.unknown_tagged_fields = read_tagged_fields(buf, |_tag, _payload| Ok(false))?;
140        }
141        Ok(out)
142    }
143}
144#[cfg(test)]
145impl StreamsGroupDescribeRequest<'_> {
146    #[must_use]
147    pub fn populated(version: i16) -> Self {
148        let mut m = Self::default();
149        if version >= 0 {
150            m.group_ids = vec!["x"];
151        }
152        if version >= 0 {
153            m.include_authorized_operations = true;
154        }
155        if version >= 1 {
156            m.include_topology_description = true;
157        }
158        m
159    }
160}