Skip to main content

crabka_protocol/opt/rustwide/workdir/generated/
InitProducerIdResponse.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 = 22;
8pub const MIN_VERSION: i16 = 0;
9pub const MAX_VERSION: i16 = 6;
10pub const FLEXIBLE_MIN: i16 = 2;
11#[inline]
12fn is_flexible(version: i16) -> bool {
13    version >= FLEXIBLE_MIN
14}
15#[derive(Debug, Clone, PartialEq, Eq)]
16pub struct InitProducerIdResponse {
17    pub throttle_time_ms: i32,
18    pub error_code: i16,
19    pub producer_id: i64,
20    pub producer_epoch: i16,
21    pub ongoing_txn_producer_id: i64,
22    pub ongoing_txn_producer_epoch: i16,
23    pub unknown_tagged_fields: UnknownTaggedFields,
24}
25impl Default for InitProducerIdResponse {
26    fn default() -> Self {
27        Self {
28            throttle_time_ms: 0i32,
29            error_code: 0i16,
30            producer_id: -1i64,
31            producer_epoch: 0i16,
32            ongoing_txn_producer_id: -1i64,
33            ongoing_txn_producer_epoch: -1i16,
34            unknown_tagged_fields: Default::default(),
35        }
36    }
37}
38impl Encode for InitProducerIdResponse {
39    fn encode<B: BufMut>(&self, buf: &mut B, version: i16) -> Result<(), ProtocolError> {
40        if !(MIN_VERSION..=MAX_VERSION).contains(&version) {
41            return Err(ProtocolError::UnsupportedVersion {
42                api_key: API_KEY,
43                version,
44            });
45        }
46        let flex = is_flexible(version);
47        if version >= 0 {
48            put_i32(buf, self.throttle_time_ms);
49        }
50        if version >= 0 {
51            put_i16(buf, self.error_code);
52        }
53        if version >= 0 {
54            put_i64(buf, self.producer_id);
55        }
56        if version >= 0 {
57            put_i16(buf, self.producer_epoch);
58        }
59        if version >= 6 {
60            put_i64(buf, self.ongoing_txn_producer_id);
61        }
62        if version >= 6 {
63            put_i16(buf, self.ongoing_txn_producer_epoch);
64        }
65        if flex {
66            let tagged = WriteTaggedFields::new();
67            tagged.write(buf, &self.unknown_tagged_fields);
68        }
69        Ok(())
70    }
71    fn encoded_len(&self, version: i16) -> usize {
72        let flex = is_flexible(version);
73        let mut n: usize = 0;
74        if version >= 0 {
75            n += 4;
76        }
77        if version >= 0 {
78            n += 2;
79        }
80        if version >= 0 {
81            n += 8;
82        }
83        if version >= 0 {
84            n += 2;
85        }
86        if version >= 6 {
87            n += 8;
88        }
89        if version >= 6 {
90            n += 2;
91        }
92        if flex {
93            let known_pairs: Vec<(u32, usize)> = Vec::new();
94            n += tagged_fields_len(&known_pairs, &self.unknown_tagged_fields);
95        }
96        n
97    }
98}
99impl Decode<'_> for InitProducerIdResponse {
100    fn decode<B: Buf>(buf: &mut B, version: i16) -> Result<Self, ProtocolError> {
101        if !(MIN_VERSION..=MAX_VERSION).contains(&version) {
102            return Err(ProtocolError::UnsupportedVersion {
103                api_key: API_KEY,
104                version,
105            });
106        }
107        let flex = is_flexible(version);
108        let mut out = Self::default();
109        if version >= 0 {
110            out.throttle_time_ms = get_i32(buf)?;
111        }
112        if version >= 0 {
113            out.error_code = get_i16(buf)?;
114        }
115        if version >= 0 {
116            out.producer_id = get_i64(buf)?;
117        }
118        if version >= 0 {
119            out.producer_epoch = get_i16(buf)?;
120        }
121        if version >= 6 {
122            out.ongoing_txn_producer_id = get_i64(buf)?;
123        }
124        if version >= 6 {
125            out.ongoing_txn_producer_epoch = get_i16(buf)?;
126        }
127        if flex {
128            out.unknown_tagged_fields = read_tagged_fields(buf, |_tag, _payload| Ok(false))?;
129        }
130        Ok(out)
131    }
132}
133#[cfg(test)]
134impl InitProducerIdResponse {
135    #[must_use]
136    pub fn populated(version: i16) -> Self {
137        let mut m = Self::default();
138        if version >= 0 {
139            m.throttle_time_ms = 1i32;
140        }
141        if version >= 0 {
142            m.error_code = 1i16;
143        }
144        if version >= 0 {
145            m.producer_id = 1i64;
146        }
147        if version >= 0 {
148            m.producer_epoch = 1i16;
149        }
150        if version >= 6 {
151            m.ongoing_txn_producer_id = 1i64;
152        }
153        if version >= 6 {
154            m.ongoing_txn_producer_epoch = 1i16;
155        }
156        m
157    }
158}
159/// Default JSON payload matching `Self::default()` for JVM oracle differential testing.
160/// Only includes fields valid for the given version.
161#[must_use]
162#[allow(unused_comparisons)]
163pub fn default_json(version: i16) -> ::serde_json::Value {
164    let mut obj = ::serde_json::Map::new();
165    obj.insert("throttleTimeMs".to_string(), ::serde_json::json!(0));
166    obj.insert("errorCode".to_string(), ::serde_json::json!(0));
167    obj.insert("producerId".to_string(), ::serde_json::json!(-1));
168    obj.insert("producerEpoch".to_string(), ::serde_json::json!(0));
169    if version >= 6 {
170        obj.insert("ongoingTxnProducerId".to_string(), ::serde_json::json!(-1));
171    }
172    if version >= 6 {
173        obj.insert(
174            "ongoingTxnProducerEpoch".to_string(),
175            ::serde_json::json!(-1),
176        );
177    }
178    ::serde_json::Value::Object(obj)
179}