Skip to main content

krabka_protocol/opt/rustwide/workdir/generated/
AllocateProducerIdsRequest.owned.rs

1// AUTO-GENERATED by krabka-protocol-codegen against a9ce3221537b8653448750697915607dc7936cf3. Do not edit.
2
3use bytes::{Buf, BufMut};
4
5use crate::{
6    Decode, Encode, ProtocolError, UnknownTaggedFields,
7    primitives::fixed::{get_i32, get_i64, put_i32, put_i64},
8    tagged_fields::{WriteTaggedFields, read_tagged_fields, tagged_fields_len},
9};
10pub const API_KEY: i16 = 67;
11pub const MIN_VERSION: i16 = 0;
12pub const MAX_VERSION: i16 = 0;
13pub const LATEST_STABLE_VERSION: i16 = 0;
14pub const FLEXIBLE_MIN: i16 = 0;
15#[inline]
16#[must_use]
17pub fn is_flexible(version: i16) -> bool {
18    version >= FLEXIBLE_MIN
19}
20#[derive(Debug, Clone, PartialEq, Eq)]
21pub struct AllocateProducerIdsRequest {
22    pub broker_id: i32,
23    pub broker_epoch: i64,
24    pub unknown_tagged_fields: UnknownTaggedFields,
25}
26impl Default for AllocateProducerIdsRequest {
27    fn default() -> Self {
28        Self {
29            broker_id: 0i32,
30            broker_epoch: -1i64,
31            unknown_tagged_fields: UnknownTaggedFields::default(),
32        }
33    }
34}
35impl Encode for AllocateProducerIdsRequest {
36    fn encode<B: BufMut>(&self, buf: &mut B, version: i16) -> Result<(), ProtocolError> {
37        if !(MIN_VERSION..=MAX_VERSION).contains(&version) {
38            return Err(ProtocolError::UnsupportedVersion {
39                api_key: API_KEY,
40                version,
41            });
42        }
43        let flex = is_flexible(version);
44        if version >= 0 {
45            put_i32(buf, self.broker_id);
46        }
47        if version >= 0 {
48            put_i64(buf, self.broker_epoch);
49        }
50        if flex {
51            let tagged = WriteTaggedFields::new();
52            tagged.write(buf, &self.unknown_tagged_fields);
53        }
54        Ok(())
55    }
56    fn encoded_len(&self, version: i16) -> usize {
57        let flex = is_flexible(version);
58        let mut n: usize = 0;
59        if version >= 0 {
60            n += 4;
61        }
62        if version >= 0 {
63            n += 8;
64        }
65        if flex {
66            let known_pairs: Vec<(u32, usize)> = Vec::new();
67            n += tagged_fields_len(&known_pairs, &self.unknown_tagged_fields);
68        }
69        n
70    }
71}
72impl Decode<'_> for AllocateProducerIdsRequest {
73    fn decode<B: Buf>(buf: &mut B, version: i16) -> Result<Self, ProtocolError> {
74        if !(MIN_VERSION..=MAX_VERSION).contains(&version) {
75            return Err(ProtocolError::UnsupportedVersion {
76                api_key: API_KEY,
77                version,
78            });
79        }
80        let flex = is_flexible(version);
81        let mut out = Self::default();
82        if version >= 0 {
83            out.broker_id = get_i32(buf)?;
84        }
85        if version >= 0 {
86            out.broker_epoch = get_i64(buf)?;
87        }
88        if flex {
89            out.unknown_tagged_fields = read_tagged_fields(buf, |_tag, _payload| Ok(false))?;
90        }
91        Ok(out)
92    }
93}
94#[cfg(test)]
95impl AllocateProducerIdsRequest {
96    #[must_use]
97    pub fn populated(version: i16) -> Self {
98        let mut m = Self::default();
99        if version >= 0 {
100            m.broker_id = 1i32;
101        }
102        if version >= 0 {
103            m.broker_epoch = 1i64;
104        }
105        m
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}
118impl crate::ProtocolRequest for AllocateProducerIdsRequest {
119    const API_KEY: i16 = API_KEY;
120    const MIN_VERSION: i16 = MIN_VERSION;
121    const MAX_VERSION: i16 = MAX_VERSION;
122    const LATEST_STABLE_VERSION: i16 = LATEST_STABLE_VERSION;
123    const FLEXIBLE_MIN: i16 = FLEXIBLE_MIN;
124    type Response = super::allocate_producer_ids_response::AllocateProducerIdsResponse;
125}