crabka_protocol/opt/rustwide/workdir/generated/
GetReplicaLogInfoResponse.owned.rs1use bytes::{Buf, BufMut};
4
5use crate::primitives::fixed::{get_i16, get_i32, get_i64, put_i16, put_i32, put_i64};
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 = 93;
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, Default)]
24pub struct GetReplicaLogInfoResponse {
25 pub broker_epoch: i64,
26 pub topic_partition_log_info_list: Vec<TopicPartitionLogInfo>,
27 pub unknown_tagged_fields: UnknownTaggedFields,
28}
29
30impl Encode for GetReplicaLogInfoResponse {
31 fn encode<B: BufMut>(&self, buf: &mut B, version: i16) -> Result<(), ProtocolError> {
32 if !(MIN_VERSION..=MAX_VERSION).contains(&version) {
33 return Err(ProtocolError::UnsupportedVersion { api_key: API_KEY, version });
34 }
35 let flex = is_flexible(version);
36 if version >= 0 { put_i64(buf, self.broker_epoch) }
37 if version >= 0 { { crate::primitives::array::put_array_len(buf, (self.topic_partition_log_info_list).len(), flex); for it in &self.topic_partition_log_info_list { it.encode(buf, version)?; } } }
38 if flex {
39 let tagged = WriteTaggedFields::new();
40 tagged.write(buf, &self.unknown_tagged_fields);
41 }
42 Ok(())
43 }
44 fn encoded_len(&self, version: i16) -> usize {
45 let flex = is_flexible(version);
46 let mut n: usize = 0;
47 if version >= 0 { n += 8; }
48 if version >= 0 { n += { let prefix = crate::primitives::array::array_len_prefix_len((self.topic_partition_log_info_list).len(), flex); let body: usize = (self.topic_partition_log_info_list).iter().map(|it| it.encoded_len(version)).sum(); prefix + body }; }
49 if flex {
50 let known_pairs: Vec<(u32, usize)> = Vec::new();
51 n += tagged_fields_len(&known_pairs, &self.unknown_tagged_fields);
52 }
53 n
54 }
55}
56
57impl<'de> Decode<'de> for GetReplicaLogInfoResponse {
58 fn decode<B: Buf>(buf: &mut B, version: i16) -> Result<Self, ProtocolError> {
59 if !(MIN_VERSION..=MAX_VERSION).contains(&version) {
60 return Err(ProtocolError::UnsupportedVersion { api_key: API_KEY, version });
61 }
62 let flex = is_flexible(version);
63 let mut out = Self::default();
64 if version >= 0 { out.broker_epoch = get_i64(buf)?; }
65 if version >= 0 { out.topic_partition_log_info_list = { let n = crate::primitives::array::get_array_len(buf, flex)?; let mut v = Vec::with_capacity(n); for _ in 0..n { v.push(TopicPartitionLogInfo::decode(buf, version)?); } v }; }
66 if flex {
67 out.unknown_tagged_fields = read_tagged_fields(buf, |_tag, _payload| {
68 Ok(false)
69 })?;
70 }
71 Ok(out)
72 }
73}
74
75#[derive(Debug, Clone, PartialEq, Eq, Default)]
76pub struct TopicPartitionLogInfo {
77 pub topic_id: crate::primitives::uuid::Uuid,
78 pub partition_log_info: Vec<PartitionLogInfo>,
79 pub unknown_tagged_fields: UnknownTaggedFields,
80}
81
82impl Encode for TopicPartitionLogInfo {
83 fn encode<B: BufMut>(&self, buf: &mut B, version: i16) -> Result<(), ProtocolError> {
84 let flex = version >= 0;
85 if version >= 0 { crate::primitives::uuid::put_uuid(buf, self.topic_id) }
86 if version >= 0 { { crate::primitives::array::put_array_len(buf, (self.partition_log_info).len(), flex); for it in &self.partition_log_info { it.encode(buf, version)?; } } }
87 if flex {
88 let tagged = WriteTaggedFields::new();
89 tagged.write(buf, &self.unknown_tagged_fields);
90 }
91 Ok(())
92 }
93 fn encoded_len(&self, version: i16) -> usize {
94 let flex = version >= 0;
95 let mut n: usize = 0;
96 if version >= 0 { n += 16; }
97 if version >= 0 { n += { let prefix = crate::primitives::array::array_len_prefix_len((self.partition_log_info).len(), flex); let body: usize = (self.partition_log_info).iter().map(|it| it.encoded_len(version)).sum(); prefix + body }; }
98 if flex {
99 let known_pairs: Vec<(u32, usize)> = Vec::new();
100 n += tagged_fields_len(&known_pairs, &self.unknown_tagged_fields);
101 }
102 n
103 }
104}
105
106impl<'de> Decode<'de> for TopicPartitionLogInfo {
107 fn decode<B: Buf>(buf: &mut B, version: i16) -> Result<Self, ProtocolError> {
108 let flex = version >= 0;
109 let mut out = Self::default();
110 if version >= 0 { out.topic_id = crate::primitives::uuid::get_uuid(buf)?; }
111 if version >= 0 { out.partition_log_info = { let n = crate::primitives::array::get_array_len(buf, flex)?; let mut v = Vec::with_capacity(n); for _ in 0..n { v.push(PartitionLogInfo::decode(buf, version)?); } v }; }
112 if flex {
113 out.unknown_tagged_fields = read_tagged_fields(buf, |_tag, _payload| {
114 Ok(false)
115 })?;
116 }
117 Ok(out)
118 }
119}
120
121#[derive(Debug, Clone, PartialEq, Eq, Default)]
122pub struct PartitionLogInfo {
123 pub partition: i32,
124 pub last_written_leader_epoch: i32,
125 pub current_leader_epoch: i32,
126 pub log_end_offset: i64,
127 pub error_code: i16,
128 pub error_message: Option<String>,
129 pub unknown_tagged_fields: UnknownTaggedFields,
130}
131
132impl Encode for PartitionLogInfo {
133 fn encode<B: BufMut>(&self, buf: &mut B, version: i16) -> Result<(), ProtocolError> {
134 let flex = version >= 0;
135 if version >= 0 { put_i32(buf, self.partition) }
136 if version >= 0 { put_i32(buf, self.last_written_leader_epoch) }
137 if version >= 0 { put_i32(buf, self.current_leader_epoch) }
138 if version >= 0 { put_i64(buf, self.log_end_offset) }
139 if version >= 0 { put_i16(buf, self.error_code) }
140 if version >= 0 { if flex { put_compact_nullable_string(buf, self.error_message.as_deref()) } else { put_nullable_string(buf, self.error_message.as_deref()) } }
141 if flex {
142 let tagged = WriteTaggedFields::new();
143 tagged.write(buf, &self.unknown_tagged_fields);
144 }
145 Ok(())
146 }
147 fn encoded_len(&self, version: i16) -> usize {
148 let flex = version >= 0;
149 let mut n: usize = 0;
150 if version >= 0 { n += 4; }
151 if version >= 0 { n += 4; }
152 if version >= 0 { n += 4; }
153 if version >= 0 { n += 8; }
154 if version >= 0 { n += 2; }
155 if version >= 0 { n += if flex { compact_nullable_string_len(self.error_message.as_deref()) } else { nullable_string_len(self.error_message.as_deref()) }; }
156 if flex {
157 let known_pairs: Vec<(u32, usize)> = Vec::new();
158 n += tagged_fields_len(&known_pairs, &self.unknown_tagged_fields);
159 }
160 n
161 }
162}
163
164impl<'de> Decode<'de> for PartitionLogInfo {
165 fn decode<B: Buf>(buf: &mut B, version: i16) -> Result<Self, ProtocolError> {
166 let flex = version >= 0;
167 let mut out = Self::default();
168 if version >= 0 { out.partition = get_i32(buf)?; }
169 if version >= 0 { out.last_written_leader_epoch = get_i32(buf)?; }
170 if version >= 0 { out.current_leader_epoch = get_i32(buf)?; }
171 if version >= 0 { out.log_end_offset = get_i64(buf)?; }
172 if version >= 0 { out.error_code = get_i16(buf)?; }
173 if version >= 0 { out.error_message = if flex { get_compact_nullable_string_owned(buf)? } else { get_nullable_string_owned(buf)? }; }
174 if flex {
175 out.unknown_tagged_fields = read_tagged_fields(buf, |_tag, _payload| {
176 Ok(false)
177 })?;
178 }
179 Ok(out)
180 }
181}
182
183#[must_use]
186#[allow(unused_comparisons)]
187pub fn default_json(version: i16) -> ::serde_json::Value {
188 let mut obj = ::serde_json::Map::new();
189 obj.insert("brokerEpoch".to_string(), ::serde_json::json!(0));
190 obj.insert("topicPartitionLogInfoList".to_string(), ::serde_json::Value::Array(vec![]));
191 ::serde_json::Value::Object(obj)
192}