libp2p_gossipsub/generated/compat/
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 Message {
19 pub from: Option<Vec<u8>>,
20 pub data: Option<Vec<u8>>,
21 pub seqno: Option<Vec<u8>>,
22 pub topic_ids: Vec<String>,
23 pub signature: Option<Vec<u8>>,
24 pub key: Option<Vec<u8>>,
25}
26
27impl<'a> MessageRead<'a> for Message {
28 fn from_reader(r: &mut BytesReader, bytes: &'a [u8]) -> Result<Self> {
29 let mut msg = Self::default();
30 while !r.is_eof() {
31 match r.next_tag(bytes) {
32 Ok(10) => msg.from = Some(r.read_bytes(bytes)?.to_owned()),
33 Ok(18) => msg.data = Some(r.read_bytes(bytes)?.to_owned()),
34 Ok(26) => msg.seqno = Some(r.read_bytes(bytes)?.to_owned()),
35 Ok(34) => msg.topic_ids.push(r.read_string(bytes)?.to_owned()),
36 Ok(42) => msg.signature = Some(r.read_bytes(bytes)?.to_owned()),
37 Ok(50) => msg.key = Some(r.read_bytes(bytes)?.to_owned()),
38 Ok(t) => { r.read_unknown(bytes, t)?; }
39 Err(e) => return Err(e),
40 }
41 }
42 Ok(msg)
43 }
44}
45
46impl MessageWrite for Message {
47 fn get_size(&self) -> usize {
48 0
49 + self.from.as_ref().map_or(0, |m| 1 + sizeof_len((m).len()))
50 + self.data.as_ref().map_or(0, |m| 1 + sizeof_len((m).len()))
51 + self.seqno.as_ref().map_or(0, |m| 1 + sizeof_len((m).len()))
52 + self.topic_ids.iter().map(|s| 1 + sizeof_len((s).len())).sum::<usize>()
53 + self.signature.as_ref().map_or(0, |m| 1 + sizeof_len((m).len()))
54 + self.key.as_ref().map_or(0, |m| 1 + sizeof_len((m).len()))
55 }
56
57 fn write_message<W: WriterBackend>(&self, w: &mut Writer<W>) -> Result<()> {
58 if let Some(ref s) = self.from { w.write_with_tag(10, |w| w.write_bytes(&**s))?; }
59 if let Some(ref s) = self.data { w.write_with_tag(18, |w| w.write_bytes(&**s))?; }
60 if let Some(ref s) = self.seqno { w.write_with_tag(26, |w| w.write_bytes(&**s))?; }
61 for s in &self.topic_ids { w.write_with_tag(34, |w| w.write_string(&**s))?; }
62 if let Some(ref s) = self.signature { w.write_with_tag(42, |w| w.write_bytes(&**s))?; }
63 if let Some(ref s) = self.key { w.write_with_tag(50, |w| w.write_bytes(&**s))?; }
64 Ok(())
65 }
66}
67