Skip to main content

crabka_protocol/opt/rustwide/workdir/generated/
GetReplicaLogInfoRequest.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::tagged_fields::{read_tagged_fields, tagged_fields_len, WriteTaggedFields};
7use crate::{Decode, Encode, ProtocolError, UnknownTaggedFields};
8
9pub const API_KEY: i16 = 93;
10pub const MIN_VERSION: i16 = 0;
11pub const MAX_VERSION: i16 = 0;
12pub const FLEXIBLE_MIN: i16 = 0;
13
14#[inline]
15fn is_flexible(version: i16) -> bool { version >= FLEXIBLE_MIN }
16
17#[derive(Debug, Clone, PartialEq, Eq, Default)]
18pub struct GetReplicaLogInfoRequest {
19    pub broker_id: i32,
20    pub topic_partitions: Vec<TopicPartitions>,
21    pub unknown_tagged_fields: UnknownTaggedFields,
22}
23
24impl Encode for GetReplicaLogInfoRequest {
25    fn encode<B: BufMut>(&self, buf: &mut B, version: i16) -> Result<(), ProtocolError> {
26        if !(MIN_VERSION..=MAX_VERSION).contains(&version) {
27            return Err(ProtocolError::UnsupportedVersion { api_key: API_KEY, version });
28        }
29        let flex = is_flexible(version);
30        if version >= 0 { put_i32(buf, self.broker_id) }
31        if version >= 0 { { crate::primitives::array::put_array_len(buf, (self.topic_partitions).len(), flex); for it in &self.topic_partitions { it.encode(buf, version)?; } } }
32        if flex {
33            let tagged = WriteTaggedFields::new();
34            tagged.write(buf, &self.unknown_tagged_fields);
35        }
36        Ok(())
37    }
38    fn encoded_len(&self, version: i16) -> usize {
39        let flex = is_flexible(version);
40        let mut n: usize = 0;
41        if version >= 0 { n += 4; }
42        if version >= 0 { n += { let prefix = crate::primitives::array::array_len_prefix_len((self.topic_partitions).len(), flex); let body: usize = (self.topic_partitions).iter().map(|it| it.encoded_len(version)).sum(); prefix + body }; }
43        if flex {
44            let known_pairs: Vec<(u32, usize)> = Vec::new();
45            n += tagged_fields_len(&known_pairs, &self.unknown_tagged_fields);
46        }
47        n
48    }
49}
50
51impl<'de> Decode<'de> for GetReplicaLogInfoRequest {
52    fn decode<B: Buf>(buf: &mut B, version: i16) -> Result<Self, ProtocolError> {
53        if !(MIN_VERSION..=MAX_VERSION).contains(&version) {
54            return Err(ProtocolError::UnsupportedVersion { api_key: API_KEY, version });
55        }
56        let flex = is_flexible(version);
57        let mut out = Self::default();
58        if version >= 0 { out.broker_id = get_i32(buf)?; }
59        if version >= 0 { out.topic_partitions = { let n = crate::primitives::array::get_array_len(buf, flex)?; let mut v = Vec::with_capacity(n); for _ in 0..n { v.push(TopicPartitions::decode(buf, version)?); } v }; }
60        if flex {
61            out.unknown_tagged_fields = read_tagged_fields(buf, |_tag, _payload| {
62                Ok(false)
63            })?;
64        }
65        Ok(out)
66    }
67}
68
69#[derive(Debug, Clone, PartialEq, Eq, Default)]
70pub struct TopicPartitions {
71    pub topic_id: crate::primitives::uuid::Uuid,
72    pub partitions: Vec<i32>,
73    pub unknown_tagged_fields: UnknownTaggedFields,
74}
75
76impl Encode for TopicPartitions {
77    fn encode<B: BufMut>(&self, buf: &mut B, version: i16) -> Result<(), ProtocolError> {
78        let flex = version >= 0;
79        if version >= 0 { crate::primitives::uuid::put_uuid(buf, self.topic_id) }
80        if version >= 0 { { crate::primitives::array::put_array_len(buf, (self.partitions).len(), flex); for it in &self.partitions { put_i32(buf, *it); } } }
81        if flex {
82            let tagged = WriteTaggedFields::new();
83            tagged.write(buf, &self.unknown_tagged_fields);
84        }
85        Ok(())
86    }
87    fn encoded_len(&self, version: i16) -> usize {
88        let flex = version >= 0;
89        let mut n: usize = 0;
90        if version >= 0 { n += 16; }
91        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 }; }
92        if flex {
93            let known_pairs: Vec<(u32, usize)> = Vec::new();
94            n += tagged_fields_len(&known_pairs, &self.unknown_tagged_fields);
95        }
96        n
97    }
98}
99
100impl<'de> Decode<'de> for TopicPartitions {
101    fn decode<B: Buf>(buf: &mut B, version: i16) -> Result<Self, ProtocolError> {
102        let flex = version >= 0;
103        let mut out = Self::default();
104        if version >= 0 { out.topic_id = crate::primitives::uuid::get_uuid(buf)?; }
105        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 }; }
106        if flex {
107            out.unknown_tagged_fields = read_tagged_fields(buf, |_tag, _payload| {
108                Ok(false)
109            })?;
110        }
111        Ok(out)
112    }
113}
114
115/// Default JSON payload matching `Self::default()` for JVM oracle differential testing.
116/// Only includes fields valid for the given version.
117#[must_use]
118#[allow(unused_comparisons)]
119pub fn default_json(version: i16) -> ::serde_json::Value {
120    let mut obj = ::serde_json::Map::new();
121    obj.insert("brokerId".to_string(), ::serde_json::json!(0));
122    obj.insert("topicPartitions".to_string(), ::serde_json::Value::Array(vec![]));
123    ::serde_json::Value::Object(obj)
124}
125
126impl crate::ProtocolRequest for GetReplicaLogInfoRequest {
127    const API_KEY: i16 = API_KEY;
128    const MIN_VERSION: i16 = MIN_VERSION;
129    const MAX_VERSION: i16 = MAX_VERSION;
130    const FLEXIBLE_MIN: i16 = FLEXIBLE_MIN;
131    type Response = super::get_replica_log_info_response::GetReplicaLogInfoResponse;
132}