Skip to main content

krabka_protocol/opt/rustwide/workdir/generated/
AddOffsetsToTxnRequest.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::{
8        fixed::{get_i16, get_i64, put_i16, put_i64},
9        string_bytes::{
10            compact_string_len, get_compact_string_owned, get_string_owned, put_compact_string,
11            put_string, string_len,
12        },
13    },
14    tagged_fields::{WriteTaggedFields, read_tagged_fields, tagged_fields_len},
15};
16pub const API_KEY: i16 = 25;
17pub const MIN_VERSION: i16 = 0;
18pub const MAX_VERSION: i16 = 4;
19pub const LATEST_STABLE_VERSION: i16 = 4;
20pub const FLEXIBLE_MIN: i16 = 3;
21#[inline]
22#[must_use]
23pub fn is_flexible(version: i16) -> bool {
24    version >= FLEXIBLE_MIN
25}
26#[derive(Debug, Clone, PartialEq, Eq, Default)]
27pub struct AddOffsetsToTxnRequest {
28    pub transactional_id: String,
29    pub producer_id: i64,
30    pub producer_epoch: i16,
31    pub group_id: String,
32    pub unknown_tagged_fields: UnknownTaggedFields,
33}
34impl Encode for AddOffsetsToTxnRequest {
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 {
38                api_key: API_KEY,
39                version,
40            });
41        }
42        let flex = is_flexible(version);
43        if version >= 0 {
44            if flex {
45                let () = put_compact_string(buf, &self.transactional_id);
46            } else {
47                let () = put_string(buf, &self.transactional_id);
48            }
49        }
50        if version >= 0 {
51            put_i64(buf, self.producer_id);
52        }
53        if version >= 0 {
54            put_i16(buf, self.producer_epoch);
55        }
56        if version >= 0 {
57            if flex {
58                let () = put_compact_string(buf, &self.group_id);
59            } else {
60                let () = put_string(buf, &self.group_id);
61            }
62        }
63        if flex {
64            let tagged = WriteTaggedFields::new();
65            tagged.write(buf, &self.unknown_tagged_fields);
66        }
67        Ok(())
68    }
69    fn encoded_len(&self, version: i16) -> usize {
70        let flex = is_flexible(version);
71        let mut n: usize = 0;
72        if version >= 0 {
73            n += if flex {
74                compact_string_len(&self.transactional_id)
75            } else {
76                string_len(&self.transactional_id)
77            };
78        }
79        if version >= 0 {
80            n += 8;
81        }
82        if version >= 0 {
83            n += 2;
84        }
85        if version >= 0 {
86            n += if flex {
87                compact_string_len(&self.group_id)
88            } else {
89                string_len(&self.group_id)
90            };
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 AddOffsetsToTxnRequest {
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.transactional_id = if flex {
111                get_compact_string_owned(buf)?
112            } else {
113                get_string_owned(buf)?
114            };
115        }
116        if version >= 0 {
117            out.producer_id = get_i64(buf)?;
118        }
119        if version >= 0 {
120            out.producer_epoch = get_i16(buf)?;
121        }
122        if version >= 0 {
123            out.group_id = if flex {
124                get_compact_string_owned(buf)?
125            } else {
126                get_string_owned(buf)?
127            };
128        }
129        if flex {
130            out.unknown_tagged_fields = read_tagged_fields(buf, |_tag, _payload| Ok(false))?;
131        }
132        Ok(out)
133    }
134}
135#[cfg(test)]
136impl AddOffsetsToTxnRequest {
137    #[must_use]
138    pub fn populated(version: i16) -> Self {
139        let mut m = Self::default();
140        if version >= 0 {
141            m.transactional_id = "x".to_string();
142        }
143        if version >= 0 {
144            m.producer_id = 1i64;
145        }
146        if version >= 0 {
147            m.producer_epoch = 1i16;
148        }
149        if version >= 0 {
150            m.group_id = "x".to_string();
151        }
152        m
153    }
154}
155/// Default JSON payload matching `Self::default()` for JVM oracle differential testing.
156/// Only includes fields valid for the given version.
157#[must_use]
158#[allow(unused_comparisons)]
159pub fn default_json(_version: i16) -> ::serde_json::Value {
160    let mut obj = ::serde_json::Map::new();
161    obj.insert(
162        "transactionalId".to_string(),
163        ::serde_json::Value::String(String::new()),
164    );
165    obj.insert("producerId".to_string(), ::serde_json::json!(0));
166    obj.insert("producerEpoch".to_string(), ::serde_json::json!(0));
167    obj.insert(
168        "groupId".to_string(),
169        ::serde_json::Value::String(String::new()),
170    );
171    ::serde_json::Value::Object(obj)
172}
173impl crate::ProtocolRequest for AddOffsetsToTxnRequest {
174    const API_KEY: i16 = API_KEY;
175    const MIN_VERSION: i16 = MIN_VERSION;
176    const MAX_VERSION: i16 = MAX_VERSION;
177    const LATEST_STABLE_VERSION: i16 = LATEST_STABLE_VERSION;
178    const FLEXIBLE_MIN: i16 = FLEXIBLE_MIN;
179    type Response = super::add_offsets_to_txn_response::AddOffsetsToTxnResponse;
180}