libp2p_plaintext/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#[allow(clippy::derive_partial_eq_without_eq)]
17#[derive(Debug, Default, PartialEq, Clone)]
18pub struct Exchange {
19 pub id: Option<Vec<u8>>,
20 pub pubkey: Option<Vec<u8>>,
21}
22
23impl<'a> MessageRead<'a> for Exchange {
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(10) => msg.id = Some(r.read_bytes(bytes)?.to_owned()),
29 Ok(18) => msg.pubkey = Some(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 Exchange {
39 fn get_size(&self) -> usize {
40 0
41 + self.id.as_ref().map_or(0, |m| 1 + sizeof_len((m).len()))
42 + self.pubkey.as_ref().map_or(0, |m| 1 + sizeof_len((m).len()))
43 }
44
45 fn write_message<W: WriterBackend>(&self, w: &mut Writer<W>) -> Result<()> {
46 if let Some(ref s) = self.id { w.write_with_tag(10, |w| w.write_bytes(&**s))?; }
47 if let Some(ref s) = self.pubkey { w.write_with_tag(18, |w| w.write_bytes(&**s))?; }
48 Ok(())
49 }
50}
51