crabka_protocol/opt/rustwide/workdir/generated/
ConsumerProtocolAssignment.owned.rs1use bytes::{Buf, BufMut};
4
5use crate::primitives::fixed::{get_i32, put_i32};
6use crate::primitives::string_bytes::{
7 compact_string_len, get_compact_string_owned, get_string_owned,
8 put_compact_string, put_string, string_len,
9};
10use crate::primitives::string_bytes::{compact_nullable_bytes_len, get_compact_nullable_bytes_owned, get_nullable_bytes_owned, nullable_bytes_len, put_compact_nullable_bytes, put_nullable_bytes};
11use crate::{Decode, Encode, ProtocolError, UnknownTaggedFields};
12pub const MIN_VERSION: i16 = 0;
13pub const MAX_VERSION: i16 = 3;
14pub const FLEXIBLE_MIN: i16 = 32767;
15
16#[inline]
17fn is_flexible(version: i16) -> bool { version >= FLEXIBLE_MIN }
18
19#[derive(Debug, Clone, PartialEq, Eq, Default)]
20pub struct ConsumerProtocolAssignment {
21 pub assigned_partitions: Vec<TopicPartition>,
22 pub user_data: Option<::bytes::Bytes>,
23 pub unknown_tagged_fields: UnknownTaggedFields,
24}
25
26impl Encode for ConsumerProtocolAssignment {
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("ConsumerProtocolAssignment version out of range"));
30 }
31 let flex = is_flexible(version);
32 if version >= 0 { { crate::primitives::array::put_array_len(buf, (self.assigned_partitions).len(), flex); for it in &self.assigned_partitions { it.encode(buf, version)?; } } }
33 if version >= 0 { if flex { put_compact_nullable_bytes(buf, self.user_data.as_deref()) } else { put_nullable_bytes(buf, self.user_data.as_deref()) } }
34 Ok(())
35 }
36 fn encoded_len(&self, version: i16) -> usize {
37 let flex = is_flexible(version);
38 let mut n: usize = 0;
39 if version >= 0 { n += { let prefix = crate::primitives::array::array_len_prefix_len((self.assigned_partitions).len(), flex); let body: usize = (self.assigned_partitions).iter().map(|it| it.encoded_len(version)).sum(); prefix + body }; }
40 if version >= 0 { n += if flex { compact_nullable_bytes_len(self.user_data.as_deref()) } else { nullable_bytes_len(self.user_data.as_deref()) }; }
41 n
42 }
43}
44
45impl<'de> Decode<'de> for ConsumerProtocolAssignment {
46 fn decode<B: Buf>(buf: &mut B, version: i16) -> Result<Self, ProtocolError> {
47 if !(MIN_VERSION..=MAX_VERSION).contains(&version) {
48 return Err(ProtocolError::SchemaMismatch("ConsumerProtocolAssignment version out of range"));
49 }
50 let flex = is_flexible(version);
51 let mut out = Self::default();
52 if version >= 0 { out.assigned_partitions = { let n = crate::primitives::array::get_array_len(buf, flex)?; let mut v = Vec::with_capacity(n); for _ in 0..n { v.push(TopicPartition::decode(buf, version)?); } v }; }
53 if version >= 0 { out.user_data = if flex { get_compact_nullable_bytes_owned(buf)? } else { get_nullable_bytes_owned(buf)? }; }
54 Ok(out)
55 }
56}
57
58#[derive(Debug, Clone, PartialEq, Eq, Default)]
59pub struct TopicPartition {
60 pub topic: String,
61 pub partitions: Vec<i32>,
62 pub unknown_tagged_fields: UnknownTaggedFields,
63}
64
65impl Encode for TopicPartition {
66 fn encode<B: BufMut>(&self, buf: &mut B, version: i16) -> Result<(), ProtocolError> {
67 let flex = version >= 32767;
68 if version >= 0 { if flex { put_compact_string(buf, &self.topic) } else { put_string(buf, &self.topic) } }
69 if version >= 0 { { crate::primitives::array::put_array_len(buf, (self.partitions).len(), flex); for it in &self.partitions { put_i32(buf, *it); } } }
70 Ok(())
71 }
72 fn encoded_len(&self, version: i16) -> usize {
73 let flex = version >= 32767;
74 let mut n: usize = 0;
75 if version >= 0 { n += if flex { compact_string_len(&self.topic) } else { string_len(&self.topic) }; }
76 if version >= 0 { n += { let prefix = crate::primitives::array::array_len_prefix_len((self.partitions).len(), flex); let body: usize = (self.partitions).iter().map(|_| 4).sum(); prefix + body }; }
77 n
78 }
79}
80
81impl<'de> Decode<'de> for TopicPartition {
82 fn decode<B: Buf>(buf: &mut B, version: i16) -> Result<Self, ProtocolError> {
83 let flex = version >= 32767;
84 let mut out = Self::default();
85 if version >= 0 { out.topic = if flex { get_compact_string_owned(buf)? } else { get_string_owned(buf)? }; }
86 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(get_i32(buf)?); } v }; }
87 Ok(out)
88 }
89}
90
91#[must_use]
94#[allow(unused_comparisons)]
95pub fn default_json(version: i16) -> ::serde_json::Value {
96 let mut obj = ::serde_json::Map::new();
97 obj.insert("assignedPartitions".to_string(), ::serde_json::Value::Array(vec![]));
98 obj.insert("userData".to_string(), ::serde_json::Value::Null);
99 ::serde_json::Value::Object(obj)
100}