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