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