Skip to main content

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