crabka_protocol/opt/rustwide/workdir/generated/
OffsetDeleteRequest.borrowed.rs1use 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::{DecodeBorrow, Encode, ProtocolError, UnknownTaggedFields};
13
14pub const API_KEY: i16 = 47;
15pub const MIN_VERSION: i16 = 0;
16pub const MAX_VERSION: i16 = 0;
17pub const FLEXIBLE_MIN: i16 = 32767;
18
19#[inline]
20fn is_flexible(version: i16) -> bool { version >= FLEXIBLE_MIN }
21
22#[derive(Debug, Clone, PartialEq, Eq)]
23pub struct OffsetDeleteRequest<'a> {
24 pub group_id: &'a str,
25 pub topics: Vec<OffsetDeleteRequestTopic<'a>>,
26 pub unknown_tagged_fields: UnknownTaggedFields,
27}
28
29impl<'a> Default for OffsetDeleteRequest<'a> {
30 fn default() -> Self {
31 Self {
32 group_id: "",
33 topics: Vec::new(),
34 unknown_tagged_fields: Default::default(),
35 }
36 }
37}
38
39impl<'a> OffsetDeleteRequest<'a> {
40 pub fn to_owned(&self) -> crate::owned::offset_delete_request::OffsetDeleteRequest {
41 crate::owned::offset_delete_request::OffsetDeleteRequest {
42 group_id: (self.group_id).to_string(),
43 topics: (self.topics).iter().map(|it| it.to_owned()).collect(),
44 unknown_tagged_fields: self.unknown_tagged_fields.clone(),
45 }
46 }
47}
48
49impl<'a> Encode for OffsetDeleteRequest<'a> {
50 fn encode<B: BufMut>(&self, buf: &mut B, version: i16) -> Result<(), ProtocolError> {
51 if !(MIN_VERSION..=MAX_VERSION).contains(&version) {
52 return Err(ProtocolError::UnsupportedVersion { api_key: API_KEY, version });
53 }
54 let flex = is_flexible(version);
55 if version >= 0 { if flex { put_compact_string(buf, self.group_id) } else { put_string(buf, self.group_id) } }
56 if version >= 0 { { crate::primitives::array::put_array_len(buf, (self.topics).len(), flex); for it in &self.topics { it.encode(buf, version)?; } } }
57 Ok(())
58 }
59 fn encoded_len(&self, version: i16) -> usize {
60 let flex = is_flexible(version);
61 let mut n: usize = 0;
62 if version >= 0 { n += if flex { compact_string_len(self.group_id) } else { string_len(self.group_id) }; }
63 if version >= 0 { 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 }; }
64 n
65 }
66}
67
68impl<'de> DecodeBorrow<'de> for OffsetDeleteRequest<'de> {
69 fn decode_borrow(buf: &mut &'de [u8], version: i16) -> Result<Self, ProtocolError> {
70 if !(MIN_VERSION..=MAX_VERSION).contains(&version) {
71 return Err(ProtocolError::UnsupportedVersion { api_key: API_KEY, version });
72 }
73 let flex = is_flexible(version);
74 let mut out = Self::default();
75 if version >= 0 { out.group_id = if flex { get_compact_string_borrowed(buf)? } else { get_string_borrowed(buf)? }; }
76 if version >= 0 { 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(OffsetDeleteRequestTopic::decode_borrow(buf, version)?); } v }; }
77 Ok(out)
78 }
79}
80
81#[derive(Debug, Clone, PartialEq, Eq)]
82pub struct OffsetDeleteRequestTopic<'a> {
83 pub name: &'a str,
84 pub partitions: Vec<OffsetDeleteRequestPartition>,
85 pub unknown_tagged_fields: UnknownTaggedFields,
86}
87
88impl<'a> Default for OffsetDeleteRequestTopic<'a> {
89 fn default() -> Self {
90 Self {
91 name: "",
92 partitions: Vec::new(),
93 unknown_tagged_fields: Default::default(),
94 }
95 }
96}
97
98impl<'a> OffsetDeleteRequestTopic<'a> {
99 pub fn to_owned(&self) -> crate::owned::offset_delete_request::OffsetDeleteRequestTopic {
100 crate::owned::offset_delete_request::OffsetDeleteRequestTopic {
101 name: (self.name).to_string(),
102 partitions: (self.partitions).iter().map(|it| it.to_owned()).collect(),
103 unknown_tagged_fields: self.unknown_tagged_fields.clone(),
104 }
105 }
106}
107
108impl<'a> Encode for OffsetDeleteRequestTopic<'a> {
109 fn encode<B: BufMut>(&self, buf: &mut B, version: i16) -> Result<(), ProtocolError> {
110 let flex = version >= 32767;
111 if version >= 0 { if flex { put_compact_string(buf, self.name) } else { put_string(buf, self.name) } }
112 if version >= 0 { { crate::primitives::array::put_array_len(buf, (self.partitions).len(), flex); for it in &self.partitions { it.encode(buf, version)?; } } }
113 Ok(())
114 }
115 fn encoded_len(&self, version: i16) -> usize {
116 let flex = version >= 32767;
117 let mut n: usize = 0;
118 if version >= 0 { n += if flex { compact_string_len(self.name) } else { string_len(self.name) }; }
119 if version >= 0 { n += { let prefix = crate::primitives::array::array_len_prefix_len((self.partitions).len(), flex); let body: usize = (self.partitions).iter().map(|it| it.encoded_len(version)).sum(); prefix + body }; }
120 n
121 }
122}
123
124impl<'de> DecodeBorrow<'de> for OffsetDeleteRequestTopic<'de> {
125 fn decode_borrow(buf: &mut &'de [u8], version: i16) -> Result<Self, ProtocolError> {
126 let flex = version >= 32767;
127 let mut out = Self::default();
128 if version >= 0 { out.name = if flex { get_compact_string_borrowed(buf)? } else { get_string_borrowed(buf)? }; }
129 if version >= 0 { out.partitions = { let n = crate::primitives::array::get_array_len(buf, flex)?; let mut v = Vec::with_capacity(n); for _ in 0..n { v.push(OffsetDeleteRequestPartition::decode_borrow(buf, version)?); } v }; }
130 Ok(out)
131 }
132}
133
134#[derive(Debug, Clone, PartialEq, Eq)]
135pub struct OffsetDeleteRequestPartition {
136 pub partition_index: i32,
137 pub unknown_tagged_fields: UnknownTaggedFields,
138}
139
140impl Default for OffsetDeleteRequestPartition {
141 fn default() -> Self {
142 Self {
143 partition_index: 0i32,
144 unknown_tagged_fields: Default::default(),
145 }
146 }
147}
148
149impl OffsetDeleteRequestPartition {
150 pub fn to_owned(&self) -> crate::owned::offset_delete_request::OffsetDeleteRequestPartition {
151 crate::owned::offset_delete_request::OffsetDeleteRequestPartition {
152 partition_index: (self.partition_index),
153 unknown_tagged_fields: self.unknown_tagged_fields.clone(),
154 }
155 }
156}
157
158impl Encode for OffsetDeleteRequestPartition {
159 fn encode<B: BufMut>(&self, buf: &mut B, version: i16) -> Result<(), ProtocolError> {
160 let flex = version >= 32767;
161 if version >= 0 { put_i32(buf, self.partition_index) }
162 Ok(())
163 }
164 fn encoded_len(&self, version: i16) -> usize {
165 let flex = version >= 32767;
166 let mut n: usize = 0;
167 if version >= 0 { n += 4; }
168 n
169 }
170}
171
172impl<'de> DecodeBorrow<'de> for OffsetDeleteRequestPartition {
173 fn decode_borrow(buf: &mut &'de [u8], version: i16) -> Result<Self, ProtocolError> {
174 let flex = version >= 32767;
175 let mut out = Self::default();
176 if version >= 0 { out.partition_index = get_i32(buf)?; }
177 Ok(out)
178 }
179}