Skip to main content

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

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