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