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