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