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