Skip to main content

crabka_protocol/opt/rustwide/workdir/generated/
AddOffsetsToTxnRequest.borrowed.rs

1// AUTO-GENERATED by crabka-protocol-codegen against a9ce3221537b8653448750697915607dc7936cf3. Do not edit.
2use crate::primitives::fixed::{get_i16, get_i64, put_i16, put_i64};
3use crate::primitives::string_bytes::{
4    compact_string_len, put_compact_string, put_string, string_len,
5};
6use crate::primitives::string_bytes_borrowed::{get_compact_string_borrowed, get_string_borrowed};
7use crate::tagged_fields::{WriteTaggedFields, read_tagged_fields, tagged_fields_len};
8use crate::{DecodeBorrow, Encode, ProtocolError, UnknownTaggedFields};
9use bytes::BufMut;
10pub const API_KEY: i16 = 25;
11pub const MIN_VERSION: i16 = 0;
12pub const MAX_VERSION: i16 = 4;
13pub const FLEXIBLE_MIN: i16 = 3;
14#[inline]
15fn is_flexible(version: i16) -> bool {
16    version >= FLEXIBLE_MIN
17}
18#[derive(Debug, Clone, PartialEq, Eq, Default)]
19pub struct AddOffsetsToTxnRequest<'a> {
20    pub transactional_id: &'a str,
21    pub producer_id: i64,
22    pub producer_epoch: i16,
23    pub group_id: &'a str,
24    pub unknown_tagged_fields: UnknownTaggedFields,
25}
26impl AddOffsetsToTxnRequest<'_> {
27    pub fn to_owned(&self) -> crate::owned::add_offsets_to_txn_request::AddOffsetsToTxnRequest {
28        crate::owned::add_offsets_to_txn_request::AddOffsetsToTxnRequest {
29            transactional_id: (self.transactional_id).to_string(),
30            producer_id: (self.producer_id),
31            producer_epoch: (self.producer_epoch),
32            group_id: (self.group_id).to_string(),
33            unknown_tagged_fields: self.unknown_tagged_fields.clone(),
34        }
35    }
36}
37impl Encode for AddOffsetsToTxnRequest<'_> {
38    fn encode<B: BufMut>(&self, buf: &mut B, version: i16) -> Result<(), ProtocolError> {
39        if !(MIN_VERSION..=MAX_VERSION).contains(&version) {
40            return Err(ProtocolError::UnsupportedVersion {
41                api_key: API_KEY,
42                version,
43            });
44        }
45        let flex = is_flexible(version);
46        if version >= 0 {
47            if flex {
48                put_compact_string(buf, self.transactional_id);
49            } else {
50                put_string(buf, self.transactional_id);
51            }
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 >= 0 {
60            if flex {
61                put_compact_string(buf, self.group_id);
62            } else {
63                put_string(buf, self.group_id);
64            }
65        }
66        if flex {
67            let tagged = WriteTaggedFields::new();
68            tagged.write(buf, &self.unknown_tagged_fields);
69        }
70        Ok(())
71    }
72    fn encoded_len(&self, version: i16) -> usize {
73        let flex = is_flexible(version);
74        let mut n: usize = 0;
75        if version >= 0 {
76            n += if flex {
77                compact_string_len(self.transactional_id)
78            } else {
79                string_len(self.transactional_id)
80            };
81        }
82        if version >= 0 {
83            n += 8;
84        }
85        if version >= 0 {
86            n += 2;
87        }
88        if version >= 0 {
89            n += if flex {
90                compact_string_len(self.group_id)
91            } else {
92                string_len(self.group_id)
93            };
94        }
95        if flex {
96            let known_pairs: Vec<(u32, usize)> = Vec::new();
97            n += tagged_fields_len(&known_pairs, &self.unknown_tagged_fields);
98        }
99        n
100    }
101}
102impl<'de> DecodeBorrow<'de> for AddOffsetsToTxnRequest<'de> {
103    fn decode_borrow(buf: &mut &'de [u8], version: i16) -> Result<Self, ProtocolError> {
104        if !(MIN_VERSION..=MAX_VERSION).contains(&version) {
105            return Err(ProtocolError::UnsupportedVersion {
106                api_key: API_KEY,
107                version,
108            });
109        }
110        let flex = is_flexible(version);
111        let mut out = Self::default();
112        if version >= 0 {
113            out.transactional_id = if flex {
114                get_compact_string_borrowed(buf)?
115            } else {
116                get_string_borrowed(buf)?
117            };
118        }
119        if version >= 0 {
120            out.producer_id = get_i64(buf)?;
121        }
122        if version >= 0 {
123            out.producer_epoch = get_i16(buf)?;
124        }
125        if version >= 0 {
126            out.group_id = if flex {
127                get_compact_string_borrowed(buf)?
128            } else {
129                get_string_borrowed(buf)?
130            };
131        }
132        if flex {
133            out.unknown_tagged_fields = read_tagged_fields(buf, |_tag, _payload| Ok(false))?;
134        }
135        Ok(out)
136    }
137}
138#[cfg(test)]
139impl AddOffsetsToTxnRequest<'_> {
140    #[must_use]
141    pub fn populated(version: i16) -> Self {
142        let mut m = Self::default();
143        if version >= 0 {
144            m.transactional_id = "x";
145        }
146        if version >= 0 {
147            m.producer_id = 1i64;
148        }
149        if version >= 0 {
150            m.producer_epoch = 1i16;
151        }
152        if version >= 0 {
153            m.group_id = "x";
154        }
155        m
156    }
157}