Skip to main content

crabka_protocol/opt/rustwide/workdir/generated/
ShareGroupDescribeRequest.owned.rs

1// AUTO-GENERATED by crabka-protocol-codegen against a9ce3221537b8653448750697915607dc7936cf3. Do not edit.
2
3use crate::primitives::fixed::{get_bool, put_bool};
4use crate::primitives::string_bytes::{
5    compact_string_len, get_compact_string_owned, get_string_owned, put_compact_string, put_string,
6    string_len,
7};
8use crate::tagged_fields::{WriteTaggedFields, read_tagged_fields, tagged_fields_len};
9use crate::{Decode, Encode, ProtocolError, UnknownTaggedFields};
10use bytes::{Buf, BufMut};
11pub const API_KEY: i16 = 77;
12pub const MIN_VERSION: i16 = 1;
13pub const MAX_VERSION: i16 = 1;
14pub const FLEXIBLE_MIN: i16 = 0;
15#[inline]
16fn is_flexible(version: i16) -> bool {
17    version >= FLEXIBLE_MIN
18}
19#[derive(Debug, Clone, PartialEq, Eq, Default)]
20pub struct ShareGroupDescribeRequest {
21    pub group_ids: Vec<String>,
22    pub include_authorized_operations: bool,
23    pub unknown_tagged_fields: UnknownTaggedFields,
24}
25impl Encode for ShareGroupDescribeRequest {
26    fn encode<B: BufMut>(&self, buf: &mut B, version: i16) -> Result<(), ProtocolError> {
27        if !(MIN_VERSION..=MAX_VERSION).contains(&version) {
28            return Err(ProtocolError::UnsupportedVersion {
29                api_key: API_KEY,
30                version,
31            });
32        }
33        let flex = is_flexible(version);
34        if version >= 0 {
35            {
36                crate::primitives::array::put_array_len(buf, (self.group_ids).len(), flex);
37                for it in &self.group_ids {
38                    if flex {
39                        put_compact_string(buf, it);
40                    } else {
41                        put_string(buf, it);
42                    }
43                }
44            }
45        }
46        if version >= 0 {
47            put_bool(buf, self.include_authorized_operations);
48        }
49        if flex {
50            let tagged = WriteTaggedFields::new();
51            tagged.write(buf, &self.unknown_tagged_fields);
52        }
53        Ok(())
54    }
55    fn encoded_len(&self, version: i16) -> usize {
56        let flex = is_flexible(version);
57        let mut n: usize = 0;
58        if version >= 0 {
59            n += {
60                let prefix =
61                    crate::primitives::array::array_len_prefix_len((self.group_ids).len(), flex);
62                let body: usize = (self.group_ids)
63                    .iter()
64                    .map(|it| {
65                        if flex {
66                            compact_string_len(it)
67                        } else {
68                            string_len(it)
69                        }
70                    })
71                    .sum();
72                prefix + body
73            };
74        }
75        if version >= 0 {
76            n += 1;
77        }
78        if flex {
79            let known_pairs: Vec<(u32, usize)> = Vec::new();
80            n += tagged_fields_len(&known_pairs, &self.unknown_tagged_fields);
81        }
82        n
83    }
84}
85impl Decode<'_> for ShareGroupDescribeRequest {
86    fn decode<B: Buf>(buf: &mut B, version: i16) -> Result<Self, ProtocolError> {
87        if !(MIN_VERSION..=MAX_VERSION).contains(&version) {
88            return Err(ProtocolError::UnsupportedVersion {
89                api_key: API_KEY,
90                version,
91            });
92        }
93        let flex = is_flexible(version);
94        let mut out = Self::default();
95        if version >= 0 {
96            out.group_ids = {
97                let n = crate::primitives::array::get_array_len(buf, flex)?;
98                let mut v = Vec::with_capacity(n);
99                for _ in 0..n {
100                    v.push(if flex {
101                        get_compact_string_owned(buf)?
102                    } else {
103                        get_string_owned(buf)?
104                    });
105                }
106                v
107            };
108        }
109        if version >= 0 {
110            out.include_authorized_operations = get_bool(buf)?;
111        }
112        if flex {
113            out.unknown_tagged_fields = read_tagged_fields(buf, |_tag, _payload| Ok(false))?;
114        }
115        Ok(out)
116    }
117}
118#[cfg(test)]
119impl ShareGroupDescribeRequest {
120    #[must_use]
121    pub fn populated(version: i16) -> Self {
122        let mut m = Self::default();
123        if version >= 0 {
124            m.group_ids = vec!["x".to_string()];
125        }
126        if version >= 0 {
127            m.include_authorized_operations = true;
128        }
129        m
130    }
131}
132/// Default JSON payload matching `Self::default()` for JVM oracle differential testing.
133/// Only includes fields valid for the given version.
134#[must_use]
135#[allow(unused_comparisons)]
136pub fn default_json(version: i16) -> ::serde_json::Value {
137    let mut obj = ::serde_json::Map::new();
138    obj.insert("groupIds".to_string(), ::serde_json::Value::Array(vec![]));
139    obj.insert(
140        "includeAuthorizedOperations".to_string(),
141        ::serde_json::Value::Bool(false),
142    );
143    ::serde_json::Value::Object(obj)
144}
145impl crate::ProtocolRequest for ShareGroupDescribeRequest {
146    const API_KEY: i16 = API_KEY;
147    const MIN_VERSION: i16 = MIN_VERSION;
148    const MAX_VERSION: i16 = MAX_VERSION;
149    const FLEXIBLE_MIN: i16 = FLEXIBLE_MIN;
150    type Response = super::share_group_describe_response::ShareGroupDescribeResponse;
151}