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