libp2p_autonat/v1/generated/
structs.rs

1// Automatically generated rust module for 'structs.proto' file
2
3#![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#[allow(clippy::derive_partial_eq_without_eq)]
17#[derive(Debug, Default, PartialEq, Clone)]
18pub struct Message {
19    pub type_pb: Option<structs::mod_Message::MessageType>,
20    pub dial: Option<structs::mod_Message::Dial>,
21    pub dialResponse: Option<structs::mod_Message::DialResponse>,
22}
23
24impl<'a> MessageRead<'a> for Message {
25    fn from_reader(r: &mut BytesReader, bytes: &'a [u8]) -> Result<Self> {
26        let mut msg = Self::default();
27        while !r.is_eof() {
28            match r.next_tag(bytes) {
29                Ok(8) => msg.type_pb = Some(r.read_enum(bytes)?),
30                Ok(18) => msg.dial = Some(r.read_message::<structs::mod_Message::Dial>(bytes)?),
31                Ok(26) => msg.dialResponse = Some(r.read_message::<structs::mod_Message::DialResponse>(bytes)?),
32                Ok(t) => { r.read_unknown(bytes, t)?; }
33                Err(e) => return Err(e),
34            }
35        }
36        Ok(msg)
37    }
38}
39
40impl MessageWrite for Message {
41    fn get_size(&self) -> usize {
42        0
43        + self.type_pb.as_ref().map_or(0, |m| 1 + sizeof_varint(*(m) as u64))
44        + self.dial.as_ref().map_or(0, |m| 1 + sizeof_len((m).get_size()))
45        + self.dialResponse.as_ref().map_or(0, |m| 1 + sizeof_len((m).get_size()))
46    }
47
48    fn write_message<W: WriterBackend>(&self, w: &mut Writer<W>) -> Result<()> {
49        if let Some(ref s) = self.type_pb { w.write_with_tag(8, |w| w.write_enum(*s as i32))?; }
50        if let Some(ref s) = self.dial { w.write_with_tag(18, |w| w.write_message(s))?; }
51        if let Some(ref s) = self.dialResponse { w.write_with_tag(26, |w| w.write_message(s))?; }
52        Ok(())
53    }
54}
55
56pub mod mod_Message {
57
58use super::*;
59
60#[allow(clippy::derive_partial_eq_without_eq)]
61#[derive(Debug, Default, PartialEq, Clone)]
62pub struct PeerInfo {
63    pub id: Option<Vec<u8>>,
64    pub addrs: Vec<Vec<u8>>,
65}
66
67impl<'a> MessageRead<'a> for PeerInfo {
68    fn from_reader(r: &mut BytesReader, bytes: &'a [u8]) -> Result<Self> {
69        let mut msg = Self::default();
70        while !r.is_eof() {
71            match r.next_tag(bytes) {
72                Ok(10) => msg.id = Some(r.read_bytes(bytes)?.to_owned()),
73                Ok(18) => msg.addrs.push(r.read_bytes(bytes)?.to_owned()),
74                Ok(t) => { r.read_unknown(bytes, t)?; }
75                Err(e) => return Err(e),
76            }
77        }
78        Ok(msg)
79    }
80}
81
82impl MessageWrite for PeerInfo {
83    fn get_size(&self) -> usize {
84        0
85        + self.id.as_ref().map_or(0, |m| 1 + sizeof_len((m).len()))
86        + self.addrs.iter().map(|s| 1 + sizeof_len((s).len())).sum::<usize>()
87    }
88
89    fn write_message<W: WriterBackend>(&self, w: &mut Writer<W>) -> Result<()> {
90        if let Some(ref s) = self.id { w.write_with_tag(10, |w| w.write_bytes(&**s))?; }
91        for s in &self.addrs { w.write_with_tag(18, |w| w.write_bytes(&**s))?; }
92        Ok(())
93    }
94}
95
96#[allow(clippy::derive_partial_eq_without_eq)]
97#[derive(Debug, Default, PartialEq, Clone)]
98pub struct Dial {
99    pub peer: Option<structs::mod_Message::PeerInfo>,
100}
101
102impl<'a> MessageRead<'a> for Dial {
103    fn from_reader(r: &mut BytesReader, bytes: &'a [u8]) -> Result<Self> {
104        let mut msg = Self::default();
105        while !r.is_eof() {
106            match r.next_tag(bytes) {
107                Ok(10) => msg.peer = Some(r.read_message::<structs::mod_Message::PeerInfo>(bytes)?),
108                Ok(t) => { r.read_unknown(bytes, t)?; }
109                Err(e) => return Err(e),
110            }
111        }
112        Ok(msg)
113    }
114}
115
116impl MessageWrite for Dial {
117    fn get_size(&self) -> usize {
118        0
119        + self.peer.as_ref().map_or(0, |m| 1 + sizeof_len((m).get_size()))
120    }
121
122    fn write_message<W: WriterBackend>(&self, w: &mut Writer<W>) -> Result<()> {
123        if let Some(ref s) = self.peer { w.write_with_tag(10, |w| w.write_message(s))?; }
124        Ok(())
125    }
126}
127
128#[allow(clippy::derive_partial_eq_without_eq)]
129#[derive(Debug, Default, PartialEq, Clone)]
130pub struct DialResponse {
131    pub status: Option<structs::mod_Message::ResponseStatus>,
132    pub statusText: Option<String>,
133    pub addr: Option<Vec<u8>>,
134}
135
136impl<'a> MessageRead<'a> for DialResponse {
137    fn from_reader(r: &mut BytesReader, bytes: &'a [u8]) -> Result<Self> {
138        let mut msg = Self::default();
139        while !r.is_eof() {
140            match r.next_tag(bytes) {
141                Ok(8) => msg.status = Some(r.read_enum(bytes)?),
142                Ok(18) => msg.statusText = Some(r.read_string(bytes)?.to_owned()),
143                Ok(26) => msg.addr = Some(r.read_bytes(bytes)?.to_owned()),
144                Ok(t) => { r.read_unknown(bytes, t)?; }
145                Err(e) => return Err(e),
146            }
147        }
148        Ok(msg)
149    }
150}
151
152impl MessageWrite for DialResponse {
153    fn get_size(&self) -> usize {
154        0
155        + self.status.as_ref().map_or(0, |m| 1 + sizeof_varint(*(m) as u64))
156        + self.statusText.as_ref().map_or(0, |m| 1 + sizeof_len((m).len()))
157        + self.addr.as_ref().map_or(0, |m| 1 + sizeof_len((m).len()))
158    }
159
160    fn write_message<W: WriterBackend>(&self, w: &mut Writer<W>) -> Result<()> {
161        if let Some(ref s) = self.status { w.write_with_tag(8, |w| w.write_enum(*s as i32))?; }
162        if let Some(ref s) = self.statusText { w.write_with_tag(18, |w| w.write_string(&**s))?; }
163        if let Some(ref s) = self.addr { w.write_with_tag(26, |w| w.write_bytes(&**s))?; }
164        Ok(())
165    }
166}
167
168#[derive(Debug, PartialEq, Eq, Clone, Copy)]
169pub enum MessageType {
170    DIAL = 0,
171    DIAL_RESPONSE = 1,
172}
173
174impl Default for MessageType {
175    fn default() -> Self {
176        MessageType::DIAL
177    }
178}
179
180impl From<i32> for MessageType {
181    fn from(i: i32) -> Self {
182        match i {
183            0 => MessageType::DIAL,
184            1 => MessageType::DIAL_RESPONSE,
185            _ => Self::default(),
186        }
187    }
188}
189
190impl<'a> From<&'a str> for MessageType {
191    fn from(s: &'a str) -> Self {
192        match s {
193            "DIAL" => MessageType::DIAL,
194            "DIAL_RESPONSE" => MessageType::DIAL_RESPONSE,
195            _ => Self::default(),
196        }
197    }
198}
199
200#[derive(Debug, PartialEq, Eq, Clone, Copy)]
201pub enum ResponseStatus {
202    OK = 0,
203    E_DIAL_ERROR = 100,
204    E_DIAL_REFUSED = 101,
205    E_BAD_REQUEST = 200,
206    E_INTERNAL_ERROR = 300,
207}
208
209impl Default for ResponseStatus {
210    fn default() -> Self {
211        ResponseStatus::OK
212    }
213}
214
215impl From<i32> for ResponseStatus {
216    fn from(i: i32) -> Self {
217        match i {
218            0 => ResponseStatus::OK,
219            100 => ResponseStatus::E_DIAL_ERROR,
220            101 => ResponseStatus::E_DIAL_REFUSED,
221            200 => ResponseStatus::E_BAD_REQUEST,
222            300 => ResponseStatus::E_INTERNAL_ERROR,
223            _ => Self::default(),
224        }
225    }
226}
227
228impl<'a> From<&'a str> for ResponseStatus {
229    fn from(s: &'a str) -> Self {
230        match s {
231            "OK" => ResponseStatus::OK,
232            "E_DIAL_ERROR" => ResponseStatus::E_DIAL_ERROR,
233            "E_DIAL_REFUSED" => ResponseStatus::E_DIAL_REFUSED,
234            "E_BAD_REQUEST" => ResponseStatus::E_BAD_REQUEST,
235            "E_INTERNAL_ERROR" => ResponseStatus::E_INTERNAL_ERROR,
236            _ => Self::default(),
237        }
238    }
239}
240
241}
242