crabka_protocol/opt/rustwide/workdir/generated/
ListGroupsResponse.borrowed.rs1use bytes::BufMut;
4
5use crate::primitives::fixed::{get_i16, get_i32, put_i16, put_i32};
6use crate::primitives::string_bytes::{
7 compact_string_len, put_compact_string, put_string, string_len,
8};
9use crate::primitives::string_bytes_borrowed::{
10 get_compact_string_borrowed, get_string_borrowed,
11};
12use crate::tagged_fields::{read_tagged_fields, tagged_fields_len, WriteTaggedFields};
13use crate::{DecodeBorrow, Encode, ProtocolError, UnknownTaggedFields};
14
15pub const API_KEY: i16 = 16;
16pub const MIN_VERSION: i16 = 0;
17pub const MAX_VERSION: i16 = 5;
18pub const FLEXIBLE_MIN: i16 = 3;
19
20#[inline]
21fn is_flexible(version: i16) -> bool { version >= FLEXIBLE_MIN }
22
23#[derive(Debug, Clone, PartialEq, Eq)]
24pub struct ListGroupsResponse<'a> {
25 pub throttle_time_ms: i32,
26 pub error_code: i16,
27 pub groups: Vec<ListedGroup<'a>>,
28 pub unknown_tagged_fields: UnknownTaggedFields,
29}
30
31impl<'a> Default for ListGroupsResponse<'a> {
32 fn default() -> Self {
33 Self {
34 throttle_time_ms: 0i32,
35 error_code: 0i16,
36 groups: Vec::new(),
37 unknown_tagged_fields: Default::default(),
38 }
39 }
40}
41
42impl<'a> ListGroupsResponse<'a> {
43 pub fn to_owned(&self) -> crate::owned::list_groups_response::ListGroupsResponse {
44 crate::owned::list_groups_response::ListGroupsResponse {
45 throttle_time_ms: (self.throttle_time_ms),
46 error_code: (self.error_code),
47 groups: (self.groups).iter().map(|it| it.to_owned()).collect(),
48 unknown_tagged_fields: self.unknown_tagged_fields.clone(),
49 }
50 }
51}
52
53impl<'a> Encode for ListGroupsResponse<'a> {
54 fn encode<B: BufMut>(&self, buf: &mut B, version: i16) -> Result<(), ProtocolError> {
55 if !(MIN_VERSION..=MAX_VERSION).contains(&version) {
56 return Err(ProtocolError::UnsupportedVersion { api_key: API_KEY, version });
57 }
58 let flex = is_flexible(version);
59 if version >= 1 { put_i32(buf, self.throttle_time_ms) }
60 if version >= 0 { put_i16(buf, self.error_code) }
61 if version >= 0 { { crate::primitives::array::put_array_len(buf, (self.groups).len(), flex); for it in &self.groups { it.encode(buf, version)?; } } }
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 >= 1 { n += 4; }
72 if version >= 0 { n += 2; }
73 if version >= 0 { n += { let prefix = crate::primitives::array::array_len_prefix_len((self.groups).len(), flex); let body: usize = (self.groups).iter().map(|it| it.encoded_len(version)).sum(); prefix + body }; }
74 if flex {
75 let known_pairs: Vec<(u32, usize)> = Vec::new();
76 n += tagged_fields_len(&known_pairs, &self.unknown_tagged_fields);
77 }
78 n
79 }
80}
81
82impl<'de> DecodeBorrow<'de> for ListGroupsResponse<'de> {
83 fn decode_borrow(buf: &mut &'de [u8], version: i16) -> Result<Self, ProtocolError> {
84 if !(MIN_VERSION..=MAX_VERSION).contains(&version) {
85 return Err(ProtocolError::UnsupportedVersion { api_key: API_KEY, version });
86 }
87 let flex = is_flexible(version);
88 let mut out = Self::default();
89 if version >= 1 { out.throttle_time_ms = get_i32(buf)?; }
90 if version >= 0 { out.error_code = get_i16(buf)?; }
91 if version >= 0 { out.groups = { let n = crate::primitives::array::get_array_len(buf, flex)?; let mut v = Vec::with_capacity(n); for _ in 0..n { v.push(ListedGroup::decode_borrow(buf, version)?); } v }; }
92 if flex {
93 out.unknown_tagged_fields = read_tagged_fields(buf, |_tag, _payload| {
94 Ok(false)
95 })?;
96 }
97 Ok(out)
98 }
99}
100
101#[derive(Debug, Clone, PartialEq, Eq)]
102pub struct ListedGroup<'a> {
103 pub group_id: &'a str,
104 pub protocol_type: &'a str,
105 pub group_state: &'a str,
106 pub group_type: &'a str,
107 pub unknown_tagged_fields: UnknownTaggedFields,
108}
109
110impl<'a> Default for ListedGroup<'a> {
111 fn default() -> Self {
112 Self {
113 group_id: "",
114 protocol_type: "",
115 group_state: "",
116 group_type: "",
117 unknown_tagged_fields: Default::default(),
118 }
119 }
120}
121
122impl<'a> ListedGroup<'a> {
123 pub fn to_owned(&self) -> crate::owned::list_groups_response::ListedGroup {
124 crate::owned::list_groups_response::ListedGroup {
125 group_id: (self.group_id).to_string(),
126 protocol_type: (self.protocol_type).to_string(),
127 group_state: (self.group_state).to_string(),
128 group_type: (self.group_type).to_string(),
129 unknown_tagged_fields: self.unknown_tagged_fields.clone(),
130 }
131 }
132}
133
134impl<'a> Encode for ListedGroup<'a> {
135 fn encode<B: BufMut>(&self, buf: &mut B, version: i16) -> Result<(), ProtocolError> {
136 let flex = version >= 3;
137 if version >= 0 { if flex { put_compact_string(buf, self.group_id) } else { put_string(buf, self.group_id) } }
138 if version >= 0 { if flex { put_compact_string(buf, self.protocol_type) } else { put_string(buf, self.protocol_type) } }
139 if version >= 4 { if flex { put_compact_string(buf, self.group_state) } else { put_string(buf, self.group_state) } }
140 if version >= 5 { if flex { put_compact_string(buf, self.group_type) } else { put_string(buf, self.group_type) } }
141 if flex {
142 let tagged = WriteTaggedFields::new();
143 tagged.write(buf, &self.unknown_tagged_fields);
144 }
145 Ok(())
146 }
147 fn encoded_len(&self, version: i16) -> usize {
148 let flex = version >= 3;
149 let mut n: usize = 0;
150 if version >= 0 { n += if flex { compact_string_len(self.group_id) } else { string_len(self.group_id) }; }
151 if version >= 0 { n += if flex { compact_string_len(self.protocol_type) } else { string_len(self.protocol_type) }; }
152 if version >= 4 { n += if flex { compact_string_len(self.group_state) } else { string_len(self.group_state) }; }
153 if version >= 5 { n += if flex { compact_string_len(self.group_type) } else { string_len(self.group_type) }; }
154 if flex {
155 let known_pairs: Vec<(u32, usize)> = Vec::new();
156 n += tagged_fields_len(&known_pairs, &self.unknown_tagged_fields);
157 }
158 n
159 }
160}
161
162impl<'de> DecodeBorrow<'de> for ListedGroup<'de> {
163 fn decode_borrow(buf: &mut &'de [u8], version: i16) -> Result<Self, ProtocolError> {
164 let flex = version >= 3;
165 let mut out = Self::default();
166 if version >= 0 { out.group_id = if flex { get_compact_string_borrowed(buf)? } else { get_string_borrowed(buf)? }; }
167 if version >= 0 { out.protocol_type = if flex { get_compact_string_borrowed(buf)? } else { get_string_borrowed(buf)? }; }
168 if version >= 4 { out.group_state = if flex { get_compact_string_borrowed(buf)? } else { get_string_borrowed(buf)? }; }
169 if version >= 5 { out.group_type = if flex { get_compact_string_borrowed(buf)? } else { get_string_borrowed(buf)? }; }
170 if flex {
171 out.unknown_tagged_fields = read_tagged_fields(buf, |_tag, _payload| {
172 Ok(false)
173 })?;
174 }
175 Ok(out)
176 }
177}