Skip to main content

krabka_protocol/opt/rustwide/workdir/generated/
RemotePartitionDeleteMetadataRecord.owned.rs

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