libp2p_core/generated/
envelope_proto.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 Envelope {
19 pub public_key: Vec<u8>,
20 pub payload_type: Vec<u8>,
21 pub payload: Vec<u8>,
22 pub signature: Vec<u8>,
23}
24
25impl<'a> MessageRead<'a> for Envelope {
26 fn from_reader(r: &mut BytesReader, bytes: &'a [u8]) -> Result<Self> {
27 let mut msg = Self::default();
28 while !r.is_eof() {
29 match r.next_tag(bytes) {
30 Ok(10) => msg.public_key = r.read_bytes(bytes)?.to_owned(),
31 Ok(18) => msg.payload_type = r.read_bytes(bytes)?.to_owned(),
32 Ok(26) => msg.payload = r.read_bytes(bytes)?.to_owned(),
33 Ok(42) => msg.signature = r.read_bytes(bytes)?.to_owned(),
34 Ok(t) => { r.read_unknown(bytes, t)?; }
35 Err(e) => return Err(e),
36 }
37 }
38 Ok(msg)
39 }
40}
41
42impl MessageWrite for Envelope {
43 fn get_size(&self) -> usize {
44 0
45 + if self.public_key.is_empty() { 0 } else { 1 + sizeof_len((&self.public_key).len()) }
46 + if self.payload_type.is_empty() { 0 } else { 1 + sizeof_len((&self.payload_type).len()) }
47 + if self.payload.is_empty() { 0 } else { 1 + sizeof_len((&self.payload).len()) }
48 + if self.signature.is_empty() { 0 } else { 1 + sizeof_len((&self.signature).len()) }
49 }
50
51 fn write_message<W: WriterBackend>(&self, w: &mut Writer<W>) -> Result<()> {
52 if !self.public_key.is_empty() { w.write_with_tag(10, |w| w.write_bytes(&**&self.public_key))?; }
53 if !self.payload_type.is_empty() { w.write_with_tag(18, |w| w.write_bytes(&**&self.payload_type))?; }
54 if !self.payload.is_empty() { w.write_with_tag(26, |w| w.write_bytes(&**&self.payload))?; }
55 if !self.signature.is_empty() { w.write_with_tag(42, |w| w.write_bytes(&**&self.signature))?; }
56 Ok(())
57 }
58}
59