crabka_protocol/opt/rustwide/workdir/generated/
WriteShareGroupStateResponse.owned.rs1use bytes::{Buf, BufMut};
4
5use crate::primitives::fixed::{get_i16, get_i32, put_i16, put_i32};
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 = 85;
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 WriteShareGroupStateResponse {
25 pub results: Vec<WriteStateResult>,
26 pub unknown_tagged_fields: UnknownTaggedFields,
27}
28
29impl Encode for WriteShareGroupStateResponse {
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 WriteShareGroupStateResponse {
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(WriteStateResult::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 WriteStateResult {
73 pub topic_id: crate::primitives::uuid::Uuid,
74 pub partitions: Vec<PartitionResult>,
75 pub unknown_tagged_fields: UnknownTaggedFields,
76}
77
78impl Encode for WriteStateResult {
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 WriteStateResult {
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, Default)]
118pub struct PartitionResult {
119 pub partition: i32,
120 pub error_code: i16,
121 pub error_message: Option<String>,
122 pub unknown_tagged_fields: UnknownTaggedFields,
123}
124
125impl Encode for PartitionResult {
126 fn encode<B: BufMut>(&self, buf: &mut B, version: i16) -> Result<(), ProtocolError> {
127 let flex = version >= 0;
128 if version >= 0 { put_i32(buf, self.partition) }
129 if version >= 0 { put_i16(buf, self.error_code) }
130 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()) } }
131 if flex {
132 let tagged = WriteTaggedFields::new();
133 tagged.write(buf, &self.unknown_tagged_fields);
134 }
135 Ok(())
136 }
137 fn encoded_len(&self, version: i16) -> usize {
138 let flex = version >= 0;
139 let mut n: usize = 0;
140 if version >= 0 { n += 4; }
141 if version >= 0 { n += 2; }
142 if version >= 0 { n += if flex { compact_nullable_string_len(self.error_message.as_deref()) } else { nullable_string_len(self.error_message.as_deref()) }; }
143 if flex {
144 let known_pairs: Vec<(u32, usize)> = Vec::new();
145 n += tagged_fields_len(&known_pairs, &self.unknown_tagged_fields);
146 }
147 n
148 }
149}
150
151impl<'de> Decode<'de> for PartitionResult {
152 fn decode<B: Buf>(buf: &mut B, version: i16) -> Result<Self, ProtocolError> {
153 let flex = version >= 0;
154 let mut out = Self::default();
155 if version >= 0 { out.partition = get_i32(buf)?; }
156 if version >= 0 { out.error_code = get_i16(buf)?; }
157 if version >= 0 { out.error_message = if flex { get_compact_nullable_string_owned(buf)? } else { get_nullable_string_owned(buf)? }; }
158 if flex {
159 out.unknown_tagged_fields = read_tagged_fields(buf, |_tag, _payload| {
160 Ok(false)
161 })?;
162 }
163 Ok(out)
164 }
165}
166
167#[must_use]
170#[allow(unused_comparisons)]
171pub fn default_json(version: i16) -> ::serde_json::Value {
172 let mut obj = ::serde_json::Map::new();
173 obj.insert("results".to_string(), ::serde_json::Value::Array(vec![]));
174 ::serde_json::Value::Object(obj)
175}