libp2p_dcutr/generated/holepunch/
pb.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::super::*;
15
16#[allow(clippy::derive_partial_eq_without_eq)]
17#[derive(Debug, Default, PartialEq, Clone)]
18pub struct HolePunch {
19 pub type_pb: holepunch::pb::mod_HolePunch::Type,
20 pub ObsAddrs: Vec<Vec<u8>>,
21}
22
23impl<'a> MessageRead<'a> for HolePunch {
24 fn from_reader(r: &mut BytesReader, bytes: &'a [u8]) -> Result<Self> {
25 let mut msg = Self::default();
26 while !r.is_eof() {
27 match r.next_tag(bytes) {
28 Ok(8) => msg.type_pb = r.read_enum(bytes)?,
29 Ok(18) => msg.ObsAddrs.push(r.read_bytes(bytes)?.to_owned()),
30 Ok(t) => { r.read_unknown(bytes, t)?; }
31 Err(e) => return Err(e),
32 }
33 }
34 Ok(msg)
35 }
36}
37
38impl MessageWrite for HolePunch {
39 fn get_size(&self) -> usize {
40 0
41 + 1 + sizeof_varint(*(&self.type_pb) as u64)
42 + self.ObsAddrs.iter().map(|s| 1 + sizeof_len((s).len())).sum::<usize>()
43 }
44
45 fn write_message<W: WriterBackend>(&self, w: &mut Writer<W>) -> Result<()> {
46 w.write_with_tag(8, |w| w.write_enum(*&self.type_pb as i32))?;
47 for s in &self.ObsAddrs { w.write_with_tag(18, |w| w.write_bytes(&**s))?; }
48 Ok(())
49 }
50}
51
52pub mod mod_HolePunch {
53
54
55#[derive(Debug, PartialEq, Eq, Clone, Copy)]
56pub enum Type {
57 CONNECT = 100,
58 SYNC = 300,
59}
60
61impl Default for Type {
62 fn default() -> Self {
63 Type::CONNECT
64 }
65}
66
67impl From<i32> for Type {
68 fn from(i: i32) -> Self {
69 match i {
70 100 => Type::CONNECT,
71 300 => Type::SYNC,
72 _ => Self::default(),
73 }
74 }
75}
76
77impl<'a> From<&'a str> for Type {
78 fn from(s: &'a str) -> Self {
79 match s {
80 "CONNECT" => Type::CONNECT,
81 "SYNC" => Type::SYNC,
82 _ => Self::default(),
83 }
84 }
85}
86
87}
88