libp2p_autonat/v2/generated/
structs.rs1#![allow(non_snake_case)]
4#![allow(non_upper_case_globals)]
5#![allow(non_camel_case_types)]
6#![allow(unused_imports)]
7#![allow(unknown_lints)]
8#![allow(clippy::all)]
9#![cfg_attr(rustfmt, rustfmt_skip)]
10
11
12use quick_protobuf::{MessageInfo, MessageRead, MessageWrite, BytesReader, Writer, WriterBackend, Result};
13use quick_protobuf::sizeofs::*;
14use super::*;
15
16#[derive(Debug, PartialEq, Eq, Clone, Copy)]
17pub enum DialStatus {
18 UNUSED = 0,
19 E_DIAL_ERROR = 100,
20 E_DIAL_BACK_ERROR = 101,
21 OK = 200,
22}
23
24impl Default for DialStatus {
25 fn default() -> Self {
26 DialStatus::UNUSED
27 }
28}
29
30impl From<i32> for DialStatus {
31 fn from(i: i32) -> Self {
32 match i {
33 0 => DialStatus::UNUSED,
34 100 => DialStatus::E_DIAL_ERROR,
35 101 => DialStatus::E_DIAL_BACK_ERROR,
36 200 => DialStatus::OK,
37 _ => Self::default(),
38 }
39 }
40}
41
42impl<'a> From<&'a str> for DialStatus {
43 fn from(s: &'a str) -> Self {
44 match s {
45 "UNUSED" => DialStatus::UNUSED,
46 "E_DIAL_ERROR" => DialStatus::E_DIAL_ERROR,
47 "E_DIAL_BACK_ERROR" => DialStatus::E_DIAL_BACK_ERROR,
48 "OK" => DialStatus::OK,
49 _ => Self::default(),
50 }
51 }
52}
53
54#[allow(clippy::derive_partial_eq_without_eq)]
55#[derive(Debug, Default, PartialEq, Clone)]
56pub struct Message {
57 pub msg: structs::mod_Message::OneOfmsg,
58}
59
60impl<'a> MessageRead<'a> for Message {
61 fn from_reader(r: &mut BytesReader, bytes: &'a [u8]) -> Result<Self> {
62 let mut msg = Self::default();
63 while !r.is_eof() {
64 match r.next_tag(bytes) {
65 Ok(10) => msg.msg = structs::mod_Message::OneOfmsg::dialRequest(r.read_message::<structs::DialRequest>(bytes)?),
66 Ok(18) => msg.msg = structs::mod_Message::OneOfmsg::dialResponse(r.read_message::<structs::DialResponse>(bytes)?),
67 Ok(26) => msg.msg = structs::mod_Message::OneOfmsg::dialDataRequest(r.read_message::<structs::DialDataRequest>(bytes)?),
68 Ok(34) => msg.msg = structs::mod_Message::OneOfmsg::dialDataResponse(r.read_message::<structs::DialDataResponse>(bytes)?),
69 Ok(t) => { r.read_unknown(bytes, t)?; }
70 Err(e) => return Err(e),
71 }
72 }
73 Ok(msg)
74 }
75}
76
77impl MessageWrite for Message {
78 fn get_size(&self) -> usize {
79 0
80 + match self.msg {
81 structs::mod_Message::OneOfmsg::dialRequest(ref m) => 1 + sizeof_len((m).get_size()),
82 structs::mod_Message::OneOfmsg::dialResponse(ref m) => 1 + sizeof_len((m).get_size()),
83 structs::mod_Message::OneOfmsg::dialDataRequest(ref m) => 1 + sizeof_len((m).get_size()),
84 structs::mod_Message::OneOfmsg::dialDataResponse(ref m) => 1 + sizeof_len((m).get_size()),
85 structs::mod_Message::OneOfmsg::None => 0,
86 } }
87
88 fn write_message<W: WriterBackend>(&self, w: &mut Writer<W>) -> Result<()> {
89 match self.msg { structs::mod_Message::OneOfmsg::dialRequest(ref m) => { w.write_with_tag(10, |w| w.write_message(m))? },
90 structs::mod_Message::OneOfmsg::dialResponse(ref m) => { w.write_with_tag(18, |w| w.write_message(m))? },
91 structs::mod_Message::OneOfmsg::dialDataRequest(ref m) => { w.write_with_tag(26, |w| w.write_message(m))? },
92 structs::mod_Message::OneOfmsg::dialDataResponse(ref m) => { w.write_with_tag(34, |w| w.write_message(m))? },
93 structs::mod_Message::OneOfmsg::None => {},
94 } Ok(())
95 }
96}
97
98pub mod mod_Message {
99
100use super::*;
101
102#[derive(Debug, PartialEq, Clone)]
103pub enum OneOfmsg {
104 dialRequest(structs::DialRequest),
105 dialResponse(structs::DialResponse),
106 dialDataRequest(structs::DialDataRequest),
107 dialDataResponse(structs::DialDataResponse),
108 None,
109}
110
111impl Default for OneOfmsg {
112 fn default() -> Self {
113 OneOfmsg::None
114 }
115}
116
117}
118
119#[allow(clippy::derive_partial_eq_without_eq)]
120#[derive(Debug, Default, PartialEq, Clone)]
121pub struct DialRequest {
122 pub addrs: Vec<Vec<u8>>,
123 pub nonce: u64,
124}
125
126impl<'a> MessageRead<'a> for DialRequest {
127 fn from_reader(r: &mut BytesReader, bytes: &'a [u8]) -> Result<Self> {
128 let mut msg = Self::default();
129 while !r.is_eof() {
130 match r.next_tag(bytes) {
131 Ok(10) => msg.addrs.push(r.read_bytes(bytes)?.to_owned()),
132 Ok(17) => msg.nonce = r.read_fixed64(bytes)?,
133 Ok(t) => { r.read_unknown(bytes, t)?; }
134 Err(e) => return Err(e),
135 }
136 }
137 Ok(msg)
138 }
139}
140
141impl MessageWrite for DialRequest {
142 fn get_size(&self) -> usize {
143 0
144 + self.addrs.iter().map(|s| 1 + sizeof_len((s).len())).sum::<usize>()
145 + if self.nonce == 0u64 { 0 } else { 1 + 8 }
146 }
147
148 fn write_message<W: WriterBackend>(&self, w: &mut Writer<W>) -> Result<()> {
149 for s in &self.addrs { w.write_with_tag(10, |w| w.write_bytes(&**s))?; }
150 if self.nonce != 0u64 { w.write_with_tag(17, |w| w.write_fixed64(*&self.nonce))?; }
151 Ok(())
152 }
153}
154
155#[allow(clippy::derive_partial_eq_without_eq)]
156#[derive(Debug, Default, PartialEq, Clone)]
157pub struct DialDataRequest {
158 pub addrIdx: u32,
159 pub numBytes: u64,
160}
161
162impl<'a> MessageRead<'a> for DialDataRequest {
163 fn from_reader(r: &mut BytesReader, bytes: &'a [u8]) -> Result<Self> {
164 let mut msg = Self::default();
165 while !r.is_eof() {
166 match r.next_tag(bytes) {
167 Ok(8) => msg.addrIdx = r.read_uint32(bytes)?,
168 Ok(16) => msg.numBytes = r.read_uint64(bytes)?,
169 Ok(t) => { r.read_unknown(bytes, t)?; }
170 Err(e) => return Err(e),
171 }
172 }
173 Ok(msg)
174 }
175}
176
177impl MessageWrite for DialDataRequest {
178 fn get_size(&self) -> usize {
179 0
180 + if self.addrIdx == 0u32 { 0 } else { 1 + sizeof_varint(*(&self.addrIdx) as u64) }
181 + if self.numBytes == 0u64 { 0 } else { 1 + sizeof_varint(*(&self.numBytes) as u64) }
182 }
183
184 fn write_message<W: WriterBackend>(&self, w: &mut Writer<W>) -> Result<()> {
185 if self.addrIdx != 0u32 { w.write_with_tag(8, |w| w.write_uint32(*&self.addrIdx))?; }
186 if self.numBytes != 0u64 { w.write_with_tag(16, |w| w.write_uint64(*&self.numBytes))?; }
187 Ok(())
188 }
189}
190
191#[allow(clippy::derive_partial_eq_without_eq)]
192#[derive(Debug, Default, PartialEq, Clone)]
193pub struct DialResponse {
194 pub status: structs::mod_DialResponse::ResponseStatus,
195 pub addrIdx: u32,
196 pub dialStatus: structs::DialStatus,
197}
198
199impl<'a> MessageRead<'a> for DialResponse {
200 fn from_reader(r: &mut BytesReader, bytes: &'a [u8]) -> Result<Self> {
201 let mut msg = Self::default();
202 while !r.is_eof() {
203 match r.next_tag(bytes) {
204 Ok(8) => msg.status = r.read_enum(bytes)?,
205 Ok(16) => msg.addrIdx = r.read_uint32(bytes)?,
206 Ok(24) => msg.dialStatus = r.read_enum(bytes)?,
207 Ok(t) => { r.read_unknown(bytes, t)?; }
208 Err(e) => return Err(e),
209 }
210 }
211 Ok(msg)
212 }
213}
214
215impl MessageWrite for DialResponse {
216 fn get_size(&self) -> usize {
217 0
218 + if self.status == structs::mod_DialResponse::ResponseStatus::E_INTERNAL_ERROR { 0 } else { 1 + sizeof_varint(*(&self.status) as u64) }
219 + if self.addrIdx == 0u32 { 0 } else { 1 + sizeof_varint(*(&self.addrIdx) as u64) }
220 + if self.dialStatus == structs::DialStatus::UNUSED { 0 } else { 1 + sizeof_varint(*(&self.dialStatus) as u64) }
221 }
222
223 fn write_message<W: WriterBackend>(&self, w: &mut Writer<W>) -> Result<()> {
224 if self.status != structs::mod_DialResponse::ResponseStatus::E_INTERNAL_ERROR { w.write_with_tag(8, |w| w.write_enum(*&self.status as i32))?; }
225 if self.addrIdx != 0u32 { w.write_with_tag(16, |w| w.write_uint32(*&self.addrIdx))?; }
226 if self.dialStatus != structs::DialStatus::UNUSED { w.write_with_tag(24, |w| w.write_enum(*&self.dialStatus as i32))?; }
227 Ok(())
228 }
229}
230
231pub mod mod_DialResponse {
232
233
234#[derive(Debug, PartialEq, Eq, Clone, Copy)]
235pub enum ResponseStatus {
236 E_INTERNAL_ERROR = 0,
237 E_REQUEST_REJECTED = 100,
238 E_DIAL_REFUSED = 101,
239 OK = 200,
240}
241
242impl Default for ResponseStatus {
243 fn default() -> Self {
244 ResponseStatus::E_INTERNAL_ERROR
245 }
246}
247
248impl From<i32> for ResponseStatus {
249 fn from(i: i32) -> Self {
250 match i {
251 0 => ResponseStatus::E_INTERNAL_ERROR,
252 100 => ResponseStatus::E_REQUEST_REJECTED,
253 101 => ResponseStatus::E_DIAL_REFUSED,
254 200 => ResponseStatus::OK,
255 _ => Self::default(),
256 }
257 }
258}
259
260impl<'a> From<&'a str> for ResponseStatus {
261 fn from(s: &'a str) -> Self {
262 match s {
263 "E_INTERNAL_ERROR" => ResponseStatus::E_INTERNAL_ERROR,
264 "E_REQUEST_REJECTED" => ResponseStatus::E_REQUEST_REJECTED,
265 "E_DIAL_REFUSED" => ResponseStatus::E_DIAL_REFUSED,
266 "OK" => ResponseStatus::OK,
267 _ => Self::default(),
268 }
269 }
270}
271
272}
273
274#[allow(clippy::derive_partial_eq_without_eq)]
275#[derive(Debug, Default, PartialEq, Clone)]
276pub struct DialDataResponse {
277 pub data: Vec<u8>,
278}
279
280impl<'a> MessageRead<'a> for DialDataResponse {
281 fn from_reader(r: &mut BytesReader, bytes: &'a [u8]) -> Result<Self> {
282 let mut msg = Self::default();
283 while !r.is_eof() {
284 match r.next_tag(bytes) {
285 Ok(10) => msg.data = r.read_bytes(bytes)?.to_owned(),
286 Ok(t) => { r.read_unknown(bytes, t)?; }
287 Err(e) => return Err(e),
288 }
289 }
290 Ok(msg)
291 }
292}
293
294impl MessageWrite for DialDataResponse {
295 fn get_size(&self) -> usize {
296 0
297 + if self.data.is_empty() { 0 } else { 1 + sizeof_len((&self.data).len()) }
298 }
299
300 fn write_message<W: WriterBackend>(&self, w: &mut Writer<W>) -> Result<()> {
301 if !self.data.is_empty() { w.write_with_tag(10, |w| w.write_bytes(&**&self.data))?; }
302 Ok(())
303 }
304}
305
306#[allow(clippy::derive_partial_eq_without_eq)]
307#[derive(Debug, Default, PartialEq, Clone)]
308pub struct DialBack {
309 pub nonce: u64,
310}
311
312impl<'a> MessageRead<'a> for DialBack {
313 fn from_reader(r: &mut BytesReader, bytes: &'a [u8]) -> Result<Self> {
314 let mut msg = Self::default();
315 while !r.is_eof() {
316 match r.next_tag(bytes) {
317 Ok(9) => msg.nonce = r.read_fixed64(bytes)?,
318 Ok(t) => { r.read_unknown(bytes, t)?; }
319 Err(e) => return Err(e),
320 }
321 }
322 Ok(msg)
323 }
324}
325
326impl MessageWrite for DialBack {
327 fn get_size(&self) -> usize {
328 0
329 + if self.nonce == 0u64 { 0 } else { 1 + 8 }
330 }
331
332 fn write_message<W: WriterBackend>(&self, w: &mut Writer<W>) -> Result<()> {
333 if self.nonce != 0u64 { w.write_with_tag(9, |w| w.write_fixed64(*&self.nonce))?; }
334 Ok(())
335 }
336}
337
338#[allow(clippy::derive_partial_eq_without_eq)]
339#[derive(Debug, Default, PartialEq, Clone)]
340pub struct DialBackResponse {
341 pub status: structs::mod_DialBackResponse::DialBackStatus,
342}
343
344impl<'a> MessageRead<'a> for DialBackResponse {
345 fn from_reader(r: &mut BytesReader, bytes: &'a [u8]) -> Result<Self> {
346 let mut msg = Self::default();
347 while !r.is_eof() {
348 match r.next_tag(bytes) {
349 Ok(8) => msg.status = r.read_enum(bytes)?,
350 Ok(t) => { r.read_unknown(bytes, t)?; }
351 Err(e) => return Err(e),
352 }
353 }
354 Ok(msg)
355 }
356}
357
358impl MessageWrite for DialBackResponse {
359 fn get_size(&self) -> usize {
360 0
361 + if self.status == structs::mod_DialBackResponse::DialBackStatus::OK { 0 } else { 1 + sizeof_varint(*(&self.status) as u64) }
362 }
363
364 fn write_message<W: WriterBackend>(&self, w: &mut Writer<W>) -> Result<()> {
365 if self.status != structs::mod_DialBackResponse::DialBackStatus::OK { w.write_with_tag(8, |w| w.write_enum(*&self.status as i32))?; }
366 Ok(())
367 }
368}
369
370pub mod mod_DialBackResponse {
371
372
373#[derive(Debug, PartialEq, Eq, Clone, Copy)]
374pub enum DialBackStatus {
375 OK = 0,
376}
377
378impl Default for DialBackStatus {
379 fn default() -> Self {
380 DialBackStatus::OK
381 }
382}
383
384impl From<i32> for DialBackStatus {
385 fn from(i: i32) -> Self {
386 match i {
387 0 => DialBackStatus::OK,
388 _ => Self::default(),
389 }
390 }
391}
392
393impl<'a> From<&'a str> for DialBackStatus {
394 fn from(s: &'a str) -> Self {
395 match s {
396 "OK" => DialBackStatus::OK,
397 _ => Self::default(),
398 }
399 }
400}
401
402}
403