Skip to main content

krabka_protocol/opt/rustwide/workdir/generated/
DescribeTransactionsRequest.borrowed.rs

1// AUTO-GENERATED by krabka-protocol-codegen against a9ce3221537b8653448750697915607dc7936cf3. Do not edit.
2use bytes::BufMut;
3
4use crate::{
5    DecodeBorrow, Encode, ProtocolError, UnknownTaggedFields,
6    primitives::{
7        string_bytes::{compact_string_len, put_compact_string, put_string, string_len},
8        string_bytes_borrowed::{get_compact_string_borrowed, get_string_borrowed},
9    },
10    tagged_fields::{WriteTaggedFields, read_tagged_fields, tagged_fields_len},
11};
12pub const API_KEY: i16 = 65;
13pub const MIN_VERSION: i16 = 0;
14pub const MAX_VERSION: i16 = 0;
15pub const LATEST_STABLE_VERSION: i16 = 0;
16pub const FLEXIBLE_MIN: i16 = 0;
17#[inline]
18#[must_use]
19pub fn is_flexible(version: i16) -> bool {
20    version >= FLEXIBLE_MIN
21}
22#[derive(Debug, Clone, PartialEq, Eq, Default)]
23pub struct DescribeTransactionsRequest<'a> {
24    pub transactional_ids: Vec<&'a str>,
25    pub unknown_tagged_fields: UnknownTaggedFields,
26}
27impl DescribeTransactionsRequest<'_> {
28    /// # Panics
29    ///
30    /// Panics if a records field contains an invalid encoded record batch.
31    #[must_use]
32    pub fn to_owned(
33        &self,
34    ) -> crate::owned::describe_transactions_request::DescribeTransactionsRequest {
35        crate::owned::describe_transactions_request::DescribeTransactionsRequest {
36            transactional_ids: (self.transactional_ids)
37                .iter()
38                .map(std::string::ToString::to_string)
39                .collect(),
40            unknown_tagged_fields: self.unknown_tagged_fields.clone(),
41        }
42    }
43}
44impl Encode for DescribeTransactionsRequest<'_> {
45    fn encode<B: BufMut>(&self, buf: &mut B, version: i16) -> Result<(), ProtocolError> {
46        if !(MIN_VERSION..=MAX_VERSION).contains(&version) {
47            return Err(ProtocolError::UnsupportedVersion {
48                api_key: API_KEY,
49                version,
50            });
51        }
52        let flex = is_flexible(version);
53        if version >= 0 {
54            {
55                crate::primitives::array::put_array_len(buf, (self.transactional_ids).len(), flex);
56                for it in &self.transactional_ids {
57                    if flex {
58                        let () = put_compact_string(buf, it);
59                    } else {
60                        let () = put_string(buf, it);
61                    }
62                }
63            };
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 += {
76                let prefix = crate::primitives::array::array_len_prefix_len(
77                    (self.transactional_ids).len(),
78                    flex,
79                );
80                let body: usize = (self.transactional_ids)
81                    .iter()
82                    .map(|it| {
83                        if flex {
84                            compact_string_len(it)
85                        } else {
86                            string_len(it)
87                        }
88                    })
89                    .sum();
90                prefix + body
91            };
92        }
93        if flex {
94            let known_pairs: Vec<(u32, usize)> = Vec::new();
95            n += tagged_fields_len(&known_pairs, &self.unknown_tagged_fields);
96        }
97        n
98    }
99}
100impl<'de> DecodeBorrow<'de> for DescribeTransactionsRequest<'de> {
101    fn decode_borrow(buf: &mut &'de [u8], version: i16) -> Result<Self, ProtocolError> {
102        if !(MIN_VERSION..=MAX_VERSION).contains(&version) {
103            return Err(ProtocolError::UnsupportedVersion {
104                api_key: API_KEY,
105                version,
106            });
107        }
108        let flex = is_flexible(version);
109        let mut out = Self::default();
110        if version >= 0 {
111            out.transactional_ids = {
112                let n = crate::primitives::array::get_array_len(buf, flex)?;
113                let mut v = Vec::with_capacity(n);
114                for _ in 0..n {
115                    v.push(if flex {
116                        get_compact_string_borrowed(buf)?
117                    } else {
118                        get_string_borrowed(buf)?
119                    });
120                }
121                v
122            };
123        }
124        if flex {
125            out.unknown_tagged_fields = read_tagged_fields(buf, |_tag, _payload| Ok(false))?;
126        }
127        Ok(out)
128    }
129}
130#[cfg(test)]
131impl DescribeTransactionsRequest<'_> {
132    #[must_use]
133    pub fn populated(version: i16) -> Self {
134        let mut m = Self::default();
135        if version >= 0 {
136            m.transactional_ids = vec!["x"];
137        }
138        m
139    }
140}