Skip to main content

crabka_protocol/opt/rustwide/workdir/generated/
ListPartitionReassignmentsRequest.borrowed.rs

1// AUTO-GENERATED by crabka-protocol-codegen against a9ce3221537b8653448750697915607dc7936cf3. Do not edit.
2
3use bytes::BufMut;
4
5use crate::primitives::fixed::{get_i32, put_i32};
6use crate::primitives::string_bytes::{
7    compact_string_len, put_compact_string, put_string, string_len,
8};
9use crate::primitives::string_bytes_borrowed::{
10    get_compact_string_borrowed, get_string_borrowed,
11};
12use crate::tagged_fields::{read_tagged_fields, tagged_fields_len, WriteTaggedFields};
13use crate::{DecodeBorrow, Encode, ProtocolError, UnknownTaggedFields};
14
15pub const API_KEY: i16 = 46;
16pub const MIN_VERSION: i16 = 0;
17pub const MAX_VERSION: i16 = 0;
18pub const FLEXIBLE_MIN: i16 = 0;
19
20#[inline]
21fn is_flexible(version: i16) -> bool { version >= FLEXIBLE_MIN }
22
23#[derive(Debug, Clone, PartialEq, Eq)]
24pub struct ListPartitionReassignmentsRequest<'a> {
25    pub timeout_ms: i32,
26    pub topics: Option<Vec<ListPartitionReassignmentsTopics<'a>>>,
27    pub unknown_tagged_fields: UnknownTaggedFields,
28}
29
30impl<'a> Default for ListPartitionReassignmentsRequest<'a> {
31    fn default() -> Self {
32        Self {
33            timeout_ms: 60_000i32,
34            topics: None,
35            unknown_tagged_fields: Default::default(),
36        }
37    }
38}
39
40impl<'a> ListPartitionReassignmentsRequest<'a> {
41    pub fn to_owned(&self) -> crate::owned::list_partition_reassignments_request::ListPartitionReassignmentsRequest {
42        crate::owned::list_partition_reassignments_request::ListPartitionReassignmentsRequest {
43            timeout_ms: (self.timeout_ms),
44            topics: (self.topics).as_ref().map(|v| v.iter().map(|it| it.to_owned()).collect()),
45            unknown_tagged_fields: self.unknown_tagged_fields.clone(),
46        }
47    }
48}
49
50impl<'a> Encode for ListPartitionReassignmentsRequest<'a> {
51    fn encode<B: BufMut>(&self, buf: &mut B, version: i16) -> Result<(), ProtocolError> {
52        if !(MIN_VERSION..=MAX_VERSION).contains(&version) {
53            return Err(ProtocolError::UnsupportedVersion { api_key: API_KEY, version });
54        }
55        let flex = is_flexible(version);
56        if version >= 0 { put_i32(buf, self.timeout_ms) }
57        if version >= 0 { { let len = (self.topics).as_ref().map(Vec::len); crate::primitives::array::put_nullable_array_len(buf, len, flex); if let Some(v) = &self.topics { for it in v { it.encode(buf, version)?; } } } }
58        if flex {
59            let tagged = WriteTaggedFields::new();
60            tagged.write(buf, &self.unknown_tagged_fields);
61        }
62        Ok(())
63    }
64    fn encoded_len(&self, version: i16) -> usize {
65        let flex = is_flexible(version);
66        let mut n: usize = 0;
67        if version >= 0 { n += 4; }
68        if version >= 0 { n += { let opt: Option<&Vec<_>> = (self.topics).as_ref(); let prefix = crate::primitives::array::nullable_array_len_prefix_len(opt.map(|v| v.len()), flex); let body: usize = opt.map_or(0, |v| v.iter().map(|it| it.encoded_len(version)).sum()); prefix + body }; }
69        if flex {
70            let known_pairs: Vec<(u32, usize)> = Vec::new();
71            n += tagged_fields_len(&known_pairs, &self.unknown_tagged_fields);
72        }
73        n
74    }
75}
76
77impl<'de> DecodeBorrow<'de> for ListPartitionReassignmentsRequest<'de> {
78    fn decode_borrow(buf: &mut &'de [u8], version: i16) -> Result<Self, ProtocolError> {
79        if !(MIN_VERSION..=MAX_VERSION).contains(&version) {
80            return Err(ProtocolError::UnsupportedVersion { api_key: API_KEY, version });
81        }
82        let flex = is_flexible(version);
83        let mut out = Self::default();
84        if version >= 0 { out.timeout_ms = get_i32(buf)?; }
85        if version >= 0 { out.topics = { let opt = crate::primitives::array::get_nullable_array_len(buf, flex)?; match opt { None => None, Some(n) => { let mut v = Vec::with_capacity(n); for _ in 0..n { v.push(ListPartitionReassignmentsTopics::decode_borrow(buf, version)?); } Some(v) } } }; }
86        if flex {
87            out.unknown_tagged_fields = read_tagged_fields(buf, |_tag, _payload| {
88                Ok(false)
89            })?;
90        }
91        Ok(out)
92    }
93}
94
95#[derive(Debug, Clone, PartialEq, Eq)]
96pub struct ListPartitionReassignmentsTopics<'a> {
97    pub name: &'a str,
98    pub partition_indexes: Vec<i32>,
99    pub unknown_tagged_fields: UnknownTaggedFields,
100}
101
102impl<'a> Default for ListPartitionReassignmentsTopics<'a> {
103    fn default() -> Self {
104        Self {
105            name: "",
106            partition_indexes: Vec::new(),
107            unknown_tagged_fields: Default::default(),
108        }
109    }
110}
111
112impl<'a> ListPartitionReassignmentsTopics<'a> {
113    pub fn to_owned(&self) -> crate::owned::list_partition_reassignments_request::ListPartitionReassignmentsTopics {
114        crate::owned::list_partition_reassignments_request::ListPartitionReassignmentsTopics {
115            name: (self.name).to_string(),
116            partition_indexes: (self.partition_indexes).clone(),
117            unknown_tagged_fields: self.unknown_tagged_fields.clone(),
118        }
119    }
120}
121
122impl<'a> Encode for ListPartitionReassignmentsTopics<'a> {
123    fn encode<B: BufMut>(&self, buf: &mut B, version: i16) -> Result<(), ProtocolError> {
124        let flex = version >= 0;
125        if version >= 0 { if flex { put_compact_string(buf, self.name) } else { put_string(buf, self.name) } }
126        if version >= 0 { { crate::primitives::array::put_array_len(buf, (self.partition_indexes).len(), flex); for it in &self.partition_indexes { put_i32(buf, *it); } } }
127        if flex {
128            let tagged = WriteTaggedFields::new();
129            tagged.write(buf, &self.unknown_tagged_fields);
130        }
131        Ok(())
132    }
133    fn encoded_len(&self, version: i16) -> usize {
134        let flex = version >= 0;
135        let mut n: usize = 0;
136        if version >= 0 { n += if flex { compact_string_len(self.name) } else { string_len(self.name) }; }
137        if version >= 0 { n += { let prefix = crate::primitives::array::array_len_prefix_len((self.partition_indexes).len(), flex); let body: usize = (self.partition_indexes).iter().map(|_| 4).sum(); prefix + body }; }
138        if flex {
139            let known_pairs: Vec<(u32, usize)> = Vec::new();
140            n += tagged_fields_len(&known_pairs, &self.unknown_tagged_fields);
141        }
142        n
143    }
144}
145
146impl<'de> DecodeBorrow<'de> for ListPartitionReassignmentsTopics<'de> {
147    fn decode_borrow(buf: &mut &'de [u8], version: i16) -> Result<Self, ProtocolError> {
148        let flex = version >= 0;
149        let mut out = Self::default();
150        if version >= 0 { out.name = if flex { get_compact_string_borrowed(buf)? } else { get_string_borrowed(buf)? }; }
151        if version >= 0 { out.partition_indexes = { let n = crate::primitives::array::get_array_len(buf, flex)?; let mut v = Vec::with_capacity(n); for _ in 0..n { v.push(get_i32(buf)?); } v }; }
152        if flex {
153            out.unknown_tagged_fields = read_tagged_fields(buf, |_tag, _payload| {
154                Ok(false)
155            })?;
156        }
157        Ok(out)
158    }
159}