krabka_protocol/opt/rustwide/workdir/generated/
RemotePartitionDeleteMetadataRecord.owned.rs1use bytes::{Buf, BufMut};
4
5use crate::{
6 Decode, Encode, ProtocolError, UnknownTaggedFields,
7 primitives::{
8 fixed::{get_i8, get_i32, get_i64, put_i8, put_i32, put_i64},
9 string_bytes::{
10 compact_string_len, get_compact_string_owned, get_string_owned, put_compact_string,
11 put_string, string_len,
12 },
13 uuid::{Uuid, get_uuid, put_uuid},
14 },
15 tagged_fields::{WriteTaggedFields, read_tagged_fields, tagged_fields_len},
16};
17pub const MIN_VERSION: i16 = 0;
18pub const MAX_VERSION: i16 = 0;
19pub const FLEXIBLE_MIN: i16 = 0;
20#[inline]
21#[must_use]
22pub fn is_flexible(version: i16) -> bool {
23 version >= FLEXIBLE_MIN
24}
25#[derive(Debug, Clone, PartialEq, Eq, Default)]
26pub struct RemotePartitionDeleteMetadataRecord {
27 pub topic_id_partition: TopicIdPartitionEntry,
28 pub broker_id: i32,
29 pub event_timestamp_ms: i64,
30 pub remote_partition_delete_state: i8,
31 pub unknown_tagged_fields: UnknownTaggedFields,
32}
33impl Encode for RemotePartitionDeleteMetadataRecord {
34 fn encode<B: BufMut>(&self, buf: &mut B, version: i16) -> Result<(), ProtocolError> {
35 if !(MIN_VERSION..=MAX_VERSION).contains(&version) {
36 return Err(ProtocolError::SchemaMismatch(
37 "RemotePartitionDeleteMetadataRecord version out of range",
38 ));
39 }
40 let flex = is_flexible(version);
41 if version >= 0 {
42 self.topic_id_partition.encode(buf, version)?;
43 }
44 if version >= 0 {
45 put_i32(buf, self.broker_id);
46 }
47 if version >= 0 {
48 put_i64(buf, self.event_timestamp_ms);
49 }
50 if version >= 0 {
51 put_i8(buf, self.remote_partition_delete_state);
52 }
53 if flex {
54 let tagged = WriteTaggedFields::new();
55 tagged.write(buf, &self.unknown_tagged_fields)?;
56 }
57 Ok(())
58 }
59 fn encoded_len(&self, version: i16) -> usize {
60 let flex = is_flexible(version);
61 let mut n: usize = 0;
62 if version >= 0 {
63 n += self.topic_id_partition.encoded_len(version);
64 }
65 if version >= 0 {
66 n += 4;
67 }
68 if version >= 0 {
69 n += 8;
70 }
71 if version >= 0 {
72 n += 1;
73 }
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}
81impl Decode<'_> for RemotePartitionDeleteMetadataRecord {
82 fn decode<B: Buf>(buf: &mut B, version: i16) -> Result<Self, ProtocolError> {
83 if !(MIN_VERSION..=MAX_VERSION).contains(&version) {
84 return Err(ProtocolError::SchemaMismatch(
85 "RemotePartitionDeleteMetadataRecord version out of range",
86 ));
87 }
88 let flex = is_flexible(version);
89 let mut out = Self::default();
90 if version >= 0 {
91 out.topic_id_partition = TopicIdPartitionEntry::decode(buf, version)?;
92 }
93 if version >= 0 {
94 out.broker_id = get_i32(buf)?;
95 }
96 if version >= 0 {
97 out.event_timestamp_ms = get_i64(buf)?;
98 }
99 if version >= 0 {
100 out.remote_partition_delete_state = get_i8(buf)?;
101 }
102 if flex {
103 out.unknown_tagged_fields = read_tagged_fields(buf, |_tag, _payload| Ok(false))?;
104 }
105 Ok(out)
106 }
107}
108#[cfg(test)]
109impl RemotePartitionDeleteMetadataRecord {
110 #[must_use]
111 pub fn populated(version: i16) -> Self {
112 let mut m = Self::default();
113 if version >= 0 {
114 m.topic_id_partition = TopicIdPartitionEntry::populated(version);
115 }
116 if version >= 0 {
117 m.broker_id = 1i32;
118 }
119 if version >= 0 {
120 m.event_timestamp_ms = 1i64;
121 }
122 if version >= 0 {
123 m.remote_partition_delete_state = 1i8;
124 }
125 m
126 }
127}
128#[derive(Debug, Clone, PartialEq, Eq, Default)]
129pub struct TopicIdPartitionEntry {
130 pub name: String,
131 pub id: Uuid,
132 pub partition: i32,
133 pub unknown_tagged_fields: UnknownTaggedFields,
134}
135impl Encode for TopicIdPartitionEntry {
136 fn encode<B: BufMut>(&self, buf: &mut B, version: i16) -> Result<(), ProtocolError> {
137 let flex = version >= 0;
138 if version >= 0 {
139 if flex {
140 put_compact_string(buf, &self.name)?;
141 } else {
142 put_string(buf, &self.name)?;
143 }
144 }
145 if version >= 0 {
146 put_uuid(buf, self.id);
147 }
148 if version >= 0 {
149 put_i32(buf, self.partition);
150 }
151 if flex {
152 let tagged = WriteTaggedFields::new();
153 tagged.write(buf, &self.unknown_tagged_fields)?;
154 }
155 Ok(())
156 }
157 fn encoded_len(&self, version: i16) -> usize {
158 let flex = version >= 0;
159 let mut n: usize = 0;
160 if version >= 0 {
161 n += if flex {
162 compact_string_len(&self.name)
163 } else {
164 string_len(&self.name)
165 };
166 }
167 if version >= 0 {
168 n += 16;
169 }
170 if version >= 0 {
171 n += 4;
172 }
173 if flex {
174 let known_pairs: Vec<(u32, usize)> = Vec::new();
175 n += tagged_fields_len(&known_pairs, &self.unknown_tagged_fields);
176 }
177 n
178 }
179}
180impl Decode<'_> for TopicIdPartitionEntry {
181 fn decode<B: Buf>(buf: &mut B, version: i16) -> Result<Self, ProtocolError> {
182 let flex = version >= 0;
183 let mut out = Self::default();
184 if version >= 0 {
185 out.name = if flex {
186 get_compact_string_owned(buf)?
187 } else {
188 get_string_owned(buf)?
189 };
190 }
191 if version >= 0 {
192 out.id = get_uuid(buf)?;
193 }
194 if version >= 0 {
195 out.partition = get_i32(buf)?;
196 }
197 if flex {
198 out.unknown_tagged_fields = read_tagged_fields(buf, |_tag, _payload| Ok(false))?;
199 }
200 Ok(out)
201 }
202}
203#[cfg(test)]
204impl TopicIdPartitionEntry {
205 #[must_use]
206 pub fn populated(version: i16) -> Self {
207 let mut m = Self::default();
208 if version >= 0 {
209 m.name = "x".to_owned();
210 }
211 if version >= 0 {
212 m.id = Uuid([1u8; 16]);
213 }
214 if version >= 0 {
215 m.partition = 1i32;
216 }
217 m
218 }
219}
220#[must_use]
223#[allow(unused_comparisons)]
224pub fn default_json(_version: i16) -> ::serde_json::Value {
225 let mut obj = ::serde_json::Map::new();
226 obj.insert("topicIdPartition".to_owned(), {
227 let mut m = ::serde_json::Map::new();
228 m.insert(
229 "name".to_owned(),
230 ::serde_json::Value::String(String::new()),
231 );
232 m.insert(
233 "id".to_owned(),
234 ::serde_json::Value::String("AAAAAAAAAAAAAAAAAAAAAA".to_owned()),
235 );
236 m.insert("partition".to_owned(), ::serde_json::json!(0));
237 ::serde_json::Value::Object(m)
238 });
239 obj.insert("brokerId".to_owned(), ::serde_json::json!(0));
240 obj.insert("eventTimestampMs".to_owned(), ::serde_json::json!(0));
241 obj.insert(
242 "remotePartitionDeleteState".to_owned(),
243 ::serde_json::json!(0),
244 );
245 ::serde_json::Value::Object(obj)
246}