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