Skip to main content

crabka_protocol/opt/rustwide/workdir/generated/
DeleteTopicsRequest.owned.rs

1// AUTO-GENERATED by crabka-protocol-codegen against a9ce3221537b8653448750697915607dc7936cf3. Do not edit.
2
3use bytes::{Buf, BufMut};
4
5use crate::primitives::fixed::{get_i32, put_i32};
6use crate::primitives::string_bytes::{
7    compact_nullable_string_len, compact_string_len, get_compact_nullable_string_owned,
8    get_compact_string_owned, get_nullable_string_owned, get_string_owned, nullable_string_len,
9    put_compact_nullable_string, put_compact_string, put_nullable_string, put_string,
10    string_len,
11};
12use crate::tagged_fields::{read_tagged_fields, tagged_fields_len, WriteTaggedFields};
13use crate::{Decode, Encode, ProtocolError, UnknownTaggedFields};
14
15pub const API_KEY: i16 = 20;
16pub const MIN_VERSION: i16 = 1;
17pub const MAX_VERSION: i16 = 6;
18pub const FLEXIBLE_MIN: i16 = 4;
19
20#[inline]
21fn is_flexible(version: i16) -> bool { version >= FLEXIBLE_MIN }
22
23#[derive(Debug, Clone, PartialEq, Eq, Default)]
24pub struct DeleteTopicsRequest {
25    pub topics: Vec<DeleteTopicState>,
26    pub topic_names: Vec<String>,
27    pub timeout_ms: i32,
28    pub unknown_tagged_fields: UnknownTaggedFields,
29}
30
31impl Encode for DeleteTopicsRequest {
32    fn encode<B: BufMut>(&self, buf: &mut B, version: i16) -> Result<(), ProtocolError> {
33        if !(MIN_VERSION..=MAX_VERSION).contains(&version) {
34            return Err(ProtocolError::UnsupportedVersion { api_key: API_KEY, version });
35        }
36        let flex = is_flexible(version);
37        if version >= 6 { { crate::primitives::array::put_array_len(buf, (self.topics).len(), flex); for it in &self.topics { it.encode(buf, version)?; } } }
38        if version >= 0 && version <= 5 { { crate::primitives::array::put_array_len(buf, (self.topic_names).len(), flex); for it in &self.topic_names { if flex { put_compact_string(buf, &*it) } else { put_string(buf, &*it) }; } } }
39        if version >= 0 { put_i32(buf, self.timeout_ms) }
40        if flex {
41            let tagged = WriteTaggedFields::new();
42            tagged.write(buf, &self.unknown_tagged_fields);
43        }
44        Ok(())
45    }
46    fn encoded_len(&self, version: i16) -> usize {
47        let flex = is_flexible(version);
48        let mut n: usize = 0;
49        if version >= 6 { 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 }; }
50        if version >= 0 && version <= 5 { n += { let prefix = crate::primitives::array::array_len_prefix_len((self.topic_names).len(), flex); let body: usize = (self.topic_names).iter().map(|it| if flex { compact_string_len(&*it) } else { string_len(&*it) }).sum(); prefix + body }; }
51        if version >= 0 { n += 4; }
52        if flex {
53            let known_pairs: Vec<(u32, usize)> = Vec::new();
54            n += tagged_fields_len(&known_pairs, &self.unknown_tagged_fields);
55        }
56        n
57    }
58}
59
60impl<'de> Decode<'de> for DeleteTopicsRequest {
61    fn decode<B: Buf>(buf: &mut B, version: i16) -> Result<Self, ProtocolError> {
62        if !(MIN_VERSION..=MAX_VERSION).contains(&version) {
63            return Err(ProtocolError::UnsupportedVersion { api_key: API_KEY, version });
64        }
65        let flex = is_flexible(version);
66        let mut out = Self::default();
67        if version >= 6 { 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(DeleteTopicState::decode(buf, version)?); } v }; }
68        if version >= 0 && version <= 5 { out.topic_names = { let n = crate::primitives::array::get_array_len(buf, flex)?; let mut v = Vec::with_capacity(n); for _ in 0..n { v.push(if flex { get_compact_string_owned(buf)? } else { get_string_owned(buf)? }); } v }; }
69        if version >= 0 { out.timeout_ms = get_i32(buf)?; }
70        if flex {
71            out.unknown_tagged_fields = read_tagged_fields(buf, |_tag, _payload| {
72                Ok(false)
73            })?;
74        }
75        Ok(out)
76    }
77}
78
79#[derive(Debug, Clone, PartialEq, Eq, Default)]
80pub struct DeleteTopicState {
81    pub name: Option<String>,
82    pub topic_id: crate::primitives::uuid::Uuid,
83    pub unknown_tagged_fields: UnknownTaggedFields,
84}
85
86impl Encode for DeleteTopicState {
87    fn encode<B: BufMut>(&self, buf: &mut B, version: i16) -> Result<(), ProtocolError> {
88        let flex = version >= 4;
89        if version >= 6 { if flex { put_compact_nullable_string(buf, self.name.as_deref()) } else { put_nullable_string(buf, self.name.as_deref()) } }
90        if version >= 6 { crate::primitives::uuid::put_uuid(buf, self.topic_id) }
91        if flex {
92            let tagged = WriteTaggedFields::new();
93            tagged.write(buf, &self.unknown_tagged_fields);
94        }
95        Ok(())
96    }
97    fn encoded_len(&self, version: i16) -> usize {
98        let flex = version >= 4;
99        let mut n: usize = 0;
100        if version >= 6 { n += if flex { compact_nullable_string_len(self.name.as_deref()) } else { nullable_string_len(self.name.as_deref()) }; }
101        if version >= 6 { n += 16; }
102        if flex {
103            let known_pairs: Vec<(u32, usize)> = Vec::new();
104            n += tagged_fields_len(&known_pairs, &self.unknown_tagged_fields);
105        }
106        n
107    }
108}
109
110impl<'de> Decode<'de> for DeleteTopicState {
111    fn decode<B: Buf>(buf: &mut B, version: i16) -> Result<Self, ProtocolError> {
112        let flex = version >= 4;
113        let mut out = Self::default();
114        if version >= 6 { out.name = if flex { get_compact_nullable_string_owned(buf)? } else { get_nullable_string_owned(buf)? }; }
115        if version >= 6 { out.topic_id = crate::primitives::uuid::get_uuid(buf)?; }
116        if flex {
117            out.unknown_tagged_fields = read_tagged_fields(buf, |_tag, _payload| {
118                Ok(false)
119            })?;
120        }
121        Ok(out)
122    }
123}
124
125/// Default JSON payload matching `Self::default()` for JVM oracle differential testing.
126/// Only includes fields valid for the given version.
127#[must_use]
128#[allow(unused_comparisons)]
129pub fn default_json(version: i16) -> ::serde_json::Value {
130    let mut obj = ::serde_json::Map::new();
131    if version >= 6 {
132        obj.insert("topics".to_string(), ::serde_json::Value::Array(vec![]));
133    }
134    if version <= 5 {
135        obj.insert("topicNames".to_string(), ::serde_json::Value::Array(vec![]));
136    }
137    obj.insert("timeoutMs".to_string(), ::serde_json::json!(0));
138    ::serde_json::Value::Object(obj)
139}
140
141impl crate::ProtocolRequest for DeleteTopicsRequest {
142    const API_KEY: i16 = API_KEY;
143    const MIN_VERSION: i16 = MIN_VERSION;
144    const MAX_VERSION: i16 = MAX_VERSION;
145    const FLEXIBLE_MIN: i16 = FLEXIBLE_MIN;
146    type Response = super::delete_topics_response::DeleteTopicsResponse;
147}