crabka_protocol/opt/rustwide/workdir/generated/
ReadShareGroupStateSummaryResponse.owned.rs1use bytes::{Buf, BufMut};
4
5use crate::primitives::fixed::{get_i16, get_i32, get_i64, put_i16, put_i32, put_i64};
6use crate::primitives::string_bytes::{
7 compact_nullable_string_len, compact_string_len, get_compact_nullable_string_owned,
8 get_compact_string_owned, get_nullable_string_owned, get_string_owned, nullable_string_len,
9 put_compact_nullable_string, put_compact_string, put_nullable_string, put_string,
10 string_len,
11};
12use crate::tagged_fields::{read_tagged_fields, tagged_fields_len, WriteTaggedFields};
13use crate::{Decode, Encode, ProtocolError, UnknownTaggedFields};
14
15pub const API_KEY: i16 = 87;
16pub const MIN_VERSION: i16 = 0;
17pub const MAX_VERSION: i16 = 1;
18pub const FLEXIBLE_MIN: i16 = 0;
19
20#[inline]
21fn is_flexible(version: i16) -> bool { version >= FLEXIBLE_MIN }
22
23#[derive(Debug, Clone, PartialEq, Eq, Default)]
24pub struct ReadShareGroupStateSummaryResponse {
25 pub results: Vec<ReadStateSummaryResult>,
26 pub unknown_tagged_fields: UnknownTaggedFields,
27}
28
29impl Encode for ReadShareGroupStateSummaryResponse {
30 fn encode<B: BufMut>(&self, buf: &mut B, version: i16) -> Result<(), ProtocolError> {
31 if !(MIN_VERSION..=MAX_VERSION).contains(&version) {
32 return Err(ProtocolError::UnsupportedVersion { api_key: API_KEY, version });
33 }
34 let flex = is_flexible(version);
35 if version >= 0 { { crate::primitives::array::put_array_len(buf, (self.results).len(), flex); for it in &self.results { it.encode(buf, version)?; } } }
36 if flex {
37 let tagged = WriteTaggedFields::new();
38 tagged.write(buf, &self.unknown_tagged_fields);
39 }
40 Ok(())
41 }
42 fn encoded_len(&self, version: i16) -> usize {
43 let flex = is_flexible(version);
44 let mut n: usize = 0;
45 if version >= 0 { n += { let prefix = crate::primitives::array::array_len_prefix_len((self.results).len(), flex); let body: usize = (self.results).iter().map(|it| it.encoded_len(version)).sum(); prefix + body }; }
46 if flex {
47 let known_pairs: Vec<(u32, usize)> = Vec::new();
48 n += tagged_fields_len(&known_pairs, &self.unknown_tagged_fields);
49 }
50 n
51 }
52}
53
54impl<'de> Decode<'de> for ReadShareGroupStateSummaryResponse {
55 fn decode<B: Buf>(buf: &mut B, version: i16) -> Result<Self, ProtocolError> {
56 if !(MIN_VERSION..=MAX_VERSION).contains(&version) {
57 return Err(ProtocolError::UnsupportedVersion { api_key: API_KEY, version });
58 }
59 let flex = is_flexible(version);
60 let mut out = Self::default();
61 if version >= 0 { out.results = { let n = crate::primitives::array::get_array_len(buf, flex)?; let mut v = Vec::with_capacity(n); for _ in 0..n { v.push(ReadStateSummaryResult::decode(buf, version)?); } v }; }
62 if flex {
63 out.unknown_tagged_fields = read_tagged_fields(buf, |_tag, _payload| {
64 Ok(false)
65 })?;
66 }
67 Ok(out)
68 }
69}
70
71#[derive(Debug, Clone, PartialEq, Eq, Default)]
72pub struct ReadStateSummaryResult {
73 pub topic_id: crate::primitives::uuid::Uuid,
74 pub partitions: Vec<PartitionResult>,
75 pub unknown_tagged_fields: UnknownTaggedFields,
76}
77
78impl Encode for ReadStateSummaryResult {
79 fn encode<B: BufMut>(&self, buf: &mut B, version: i16) -> Result<(), ProtocolError> {
80 let flex = version >= 0;
81 if version >= 0 { crate::primitives::uuid::put_uuid(buf, self.topic_id) }
82 if version >= 0 { { crate::primitives::array::put_array_len(buf, (self.partitions).len(), flex); for it in &self.partitions { it.encode(buf, version)?; } } }
83 if flex {
84 let tagged = WriteTaggedFields::new();
85 tagged.write(buf, &self.unknown_tagged_fields);
86 }
87 Ok(())
88 }
89 fn encoded_len(&self, version: i16) -> usize {
90 let flex = version >= 0;
91 let mut n: usize = 0;
92 if version >= 0 { n += 16; }
93 if version >= 0 { n += { let prefix = crate::primitives::array::array_len_prefix_len((self.partitions).len(), flex); let body: usize = (self.partitions).iter().map(|it| it.encoded_len(version)).sum(); prefix + body }; }
94 if flex {
95 let known_pairs: Vec<(u32, usize)> = Vec::new();
96 n += tagged_fields_len(&known_pairs, &self.unknown_tagged_fields);
97 }
98 n
99 }
100}
101
102impl<'de> Decode<'de> for ReadStateSummaryResult {
103 fn decode<B: Buf>(buf: &mut B, version: i16) -> Result<Self, ProtocolError> {
104 let flex = version >= 0;
105 let mut out = Self::default();
106 if version >= 0 { out.topic_id = crate::primitives::uuid::get_uuid(buf)?; }
107 if version >= 0 { out.partitions = { let n = crate::primitives::array::get_array_len(buf, flex)?; let mut v = Vec::with_capacity(n); for _ in 0..n { v.push(PartitionResult::decode(buf, version)?); } v }; }
108 if flex {
109 out.unknown_tagged_fields = read_tagged_fields(buf, |_tag, _payload| {
110 Ok(false)
111 })?;
112 }
113 Ok(out)
114 }
115}
116
117#[derive(Debug, Clone, PartialEq, Eq)]
118pub struct PartitionResult {
119 pub partition: i32,
120 pub error_code: i16,
121 pub error_message: Option<String>,
122 pub state_epoch: i32,
123 pub leader_epoch: i32,
124 pub start_offset: i64,
125 pub delivery_complete_count: i32,
126 pub unknown_tagged_fields: UnknownTaggedFields,
127}
128
129impl Default for PartitionResult {
130 fn default() -> Self {
131 Self {
132 partition: 0i32,
133 error_code: 0i16,
134 error_message: None,
135 state_epoch: 0i32,
136 leader_epoch: 0i32,
137 start_offset: 0i64,
138 delivery_complete_count: -1i32,
139 unknown_tagged_fields: Default::default(),
140 }
141 }
142}
143
144impl Encode for PartitionResult {
145 fn encode<B: BufMut>(&self, buf: &mut B, version: i16) -> Result<(), ProtocolError> {
146 let flex = version >= 0;
147 if version >= 0 { put_i32(buf, self.partition) }
148 if version >= 0 { put_i16(buf, self.error_code) }
149 if version >= 0 { if flex { put_compact_nullable_string(buf, self.error_message.as_deref()) } else { put_nullable_string(buf, self.error_message.as_deref()) } }
150 if version >= 0 { put_i32(buf, self.state_epoch) }
151 if version >= 0 { put_i32(buf, self.leader_epoch) }
152 if version >= 0 { put_i64(buf, self.start_offset) }
153 if version >= 1 { put_i32(buf, self.delivery_complete_count) }
154 if flex {
155 let tagged = WriteTaggedFields::new();
156 tagged.write(buf, &self.unknown_tagged_fields);
157 }
158 Ok(())
159 }
160 fn encoded_len(&self, version: i16) -> usize {
161 let flex = version >= 0;
162 let mut n: usize = 0;
163 if version >= 0 { n += 4; }
164 if version >= 0 { n += 2; }
165 if version >= 0 { n += if flex { compact_nullable_string_len(self.error_message.as_deref()) } else { nullable_string_len(self.error_message.as_deref()) }; }
166 if version >= 0 { n += 4; }
167 if version >= 0 { n += 4; }
168 if version >= 0 { n += 8; }
169 if version >= 1 { n += 4; }
170 if flex {
171 let known_pairs: Vec<(u32, usize)> = Vec::new();
172 n += tagged_fields_len(&known_pairs, &self.unknown_tagged_fields);
173 }
174 n
175 }
176}
177
178impl<'de> Decode<'de> for PartitionResult {
179 fn decode<B: Buf>(buf: &mut B, version: i16) -> Result<Self, ProtocolError> {
180 let flex = version >= 0;
181 let mut out = Self::default();
182 if version >= 0 { out.partition = get_i32(buf)?; }
183 if version >= 0 { out.error_code = get_i16(buf)?; }
184 if version >= 0 { out.error_message = if flex { get_compact_nullable_string_owned(buf)? } else { get_nullable_string_owned(buf)? }; }
185 if version >= 0 { out.state_epoch = get_i32(buf)?; }
186 if version >= 0 { out.leader_epoch = get_i32(buf)?; }
187 if version >= 0 { out.start_offset = get_i64(buf)?; }
188 if version >= 1 { out.delivery_complete_count = get_i32(buf)?; }
189 if flex {
190 out.unknown_tagged_fields = read_tagged_fields(buf, |_tag, _payload| {
191 Ok(false)
192 })?;
193 }
194 Ok(out)
195 }
196}
197
198#[must_use]
201#[allow(unused_comparisons)]
202pub fn default_json(version: i16) -> ::serde_json::Value {
203 let mut obj = ::serde_json::Map::new();
204 obj.insert("results".to_string(), ::serde_json::Value::Array(vec![]));
205 ::serde_json::Value::Object(obj)
206}