Skip to main content

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