Skip to main content

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

1// AUTO-GENERATED by crabka-protocol-codegen against a9ce3221537b8653448750697915607dc7936cf3. Do not edit.
2
3use crate::primitives::string_bytes::{
4    bytes_len, compact_bytes_len, compact_nullable_bytes_len, get_bytes_owned,
5    get_compact_bytes_owned, get_compact_nullable_bytes_owned, get_nullable_bytes_owned,
6    nullable_bytes_len, put_bytes, put_compact_bytes, put_compact_nullable_bytes,
7    put_nullable_bytes,
8};
9use crate::tagged_fields::{WriteTaggedFields, read_tagged_fields, tagged_fields_len};
10use crate::{Decode, Encode, ProtocolError, UnknownTaggedFields};
11use bytes::{Buf, BufMut};
12pub const API_KEY: i16 = 58;
13pub const MIN_VERSION: i16 = 0;
14pub const MAX_VERSION: i16 = 0;
15pub const FLEXIBLE_MIN: i16 = 0;
16#[inline]
17fn is_flexible(version: i16) -> bool {
18    version >= FLEXIBLE_MIN
19}
20#[derive(Debug, Clone, PartialEq, Eq, Default)]
21pub struct EnvelopeRequest {
22    pub request_data: ::bytes::Bytes,
23    pub request_principal: Option<::bytes::Bytes>,
24    pub client_host_address: ::bytes::Bytes,
25    pub unknown_tagged_fields: UnknownTaggedFields,
26}
27impl Encode for EnvelopeRequest {
28    fn encode<B: BufMut>(&self, buf: &mut B, version: i16) -> Result<(), ProtocolError> {
29        if !(MIN_VERSION..=MAX_VERSION).contains(&version) {
30            return Err(ProtocolError::UnsupportedVersion {
31                api_key: API_KEY,
32                version,
33            });
34        }
35        let flex = is_flexible(version);
36        if version >= 0 {
37            if flex {
38                put_compact_bytes(buf, &self.request_data);
39            } else {
40                put_bytes(buf, &self.request_data);
41            }
42        }
43        if version >= 0 {
44            if flex {
45                put_compact_nullable_bytes(buf, self.request_principal.as_deref());
46            } else {
47                put_nullable_bytes(buf, self.request_principal.as_deref());
48            }
49        }
50        if version >= 0 {
51            if flex {
52                put_compact_bytes(buf, &self.client_host_address);
53            } else {
54                put_bytes(buf, &self.client_host_address);
55            }
56        }
57        if flex {
58            let tagged = WriteTaggedFields::new();
59            tagged.write(buf, &self.unknown_tagged_fields);
60        }
61        Ok(())
62    }
63    fn encoded_len(&self, version: i16) -> usize {
64        let flex = is_flexible(version);
65        let mut n: usize = 0;
66        if version >= 0 {
67            n += if flex {
68                compact_bytes_len(&self.request_data)
69            } else {
70                bytes_len(&self.request_data)
71            };
72        }
73        if version >= 0 {
74            n += if flex {
75                compact_nullable_bytes_len(self.request_principal.as_deref())
76            } else {
77                nullable_bytes_len(self.request_principal.as_deref())
78            };
79        }
80        if version >= 0 {
81            n += if flex {
82                compact_bytes_len(&self.client_host_address)
83            } else {
84                bytes_len(&self.client_host_address)
85            };
86        }
87        if flex {
88            let known_pairs: Vec<(u32, usize)> = Vec::new();
89            n += tagged_fields_len(&known_pairs, &self.unknown_tagged_fields);
90        }
91        n
92    }
93}
94impl Decode<'_> for EnvelopeRequest {
95    fn decode<B: Buf>(buf: &mut B, version: i16) -> Result<Self, ProtocolError> {
96        if !(MIN_VERSION..=MAX_VERSION).contains(&version) {
97            return Err(ProtocolError::UnsupportedVersion {
98                api_key: API_KEY,
99                version,
100            });
101        }
102        let flex = is_flexible(version);
103        let mut out = Self::default();
104        if version >= 0 {
105            out.request_data = if flex {
106                get_compact_bytes_owned(buf)?
107            } else {
108                get_bytes_owned(buf)?
109            };
110        }
111        if version >= 0 {
112            out.request_principal = if flex {
113                get_compact_nullable_bytes_owned(buf)?
114            } else {
115                get_nullable_bytes_owned(buf)?
116            };
117        }
118        if version >= 0 {
119            out.client_host_address = if flex {
120                get_compact_bytes_owned(buf)?
121            } else {
122                get_bytes_owned(buf)?
123            };
124        }
125        if flex {
126            out.unknown_tagged_fields = read_tagged_fields(buf, |_tag, _payload| Ok(false))?;
127        }
128        Ok(out)
129    }
130}
131#[cfg(test)]
132impl EnvelopeRequest {
133    #[must_use]
134    pub fn populated(version: i16) -> Self {
135        let mut m = Self::default();
136        if version >= 0 {
137            m.request_data = ::bytes::Bytes::from_static(b"x");
138        }
139        if version >= 0 {
140            m.request_principal = Some(::bytes::Bytes::from_static(b"x"));
141        }
142        if version >= 0 {
143            m.client_host_address = ::bytes::Bytes::from_static(b"x");
144        }
145        m
146    }
147}
148/// Default JSON payload matching `Self::default()` for JVM oracle differential testing.
149/// Only includes fields valid for the given version.
150#[must_use]
151#[allow(unused_comparisons)]
152pub fn default_json(version: i16) -> ::serde_json::Value {
153    let mut obj = ::serde_json::Map::new();
154    obj.insert(
155        "requestData".to_string(),
156        ::serde_json::Value::String(String::new()),
157    );
158    obj.insert("requestPrincipal".to_string(), ::serde_json::Value::Null);
159    obj.insert(
160        "clientHostAddress".to_string(),
161        ::serde_json::Value::String(String::new()),
162    );
163    ::serde_json::Value::Object(obj)
164}
165impl crate::ProtocolRequest for EnvelopeRequest {
166    const API_KEY: i16 = API_KEY;
167    const MIN_VERSION: i16 = MIN_VERSION;
168    const MAX_VERSION: i16 = MAX_VERSION;
169    const FLEXIBLE_MIN: i16 = FLEXIBLE_MIN;
170    type Response = super::envelope_response::EnvelopeResponse;
171}