libp2p_floodsub/generated/floodsub/
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 RPC {
19 pub subscriptions: Vec<floodsub::pb::mod_RPC::SubOpts>,
20 pub publish: Vec<floodsub::pb::Message>,
21}
22
23impl<'a> MessageRead<'a> for RPC {
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.subscriptions.push(r.read_message::<floodsub::pb::mod_RPC::SubOpts>(bytes)?),
29 Ok(18) => msg.publish.push(r.read_message::<floodsub::pb::Message>(bytes)?),
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 RPC {
39 fn get_size(&self) -> usize {
40 0
41 + self.subscriptions.iter().map(|s| 1 + sizeof_len((s).get_size())).sum::<usize>()
42 + self.publish.iter().map(|s| 1 + sizeof_len((s).get_size())).sum::<usize>()
43 }
44
45 fn write_message<W: WriterBackend>(&self, w: &mut Writer<W>) -> Result<()> {
46 for s in &self.subscriptions { w.write_with_tag(10, |w| w.write_message(s))?; }
47 for s in &self.publish { w.write_with_tag(18, |w| w.write_message(s))?; }
48 Ok(())
49 }
50}
51
52pub mod mod_RPC {
53
54use super::*;
55
56#[allow(clippy::derive_partial_eq_without_eq)]
57#[derive(Debug, Default, PartialEq, Clone)]
58pub struct SubOpts {
59 pub subscribe: Option<bool>,
60 pub topic_id: Option<String>,
61}
62
63impl<'a> MessageRead<'a> for SubOpts {
64 fn from_reader(r: &mut BytesReader, bytes: &'a [u8]) -> Result<Self> {
65 let mut msg = Self::default();
66 while !r.is_eof() {
67 match r.next_tag(bytes) {
68 Ok(8) => msg.subscribe = Some(r.read_bool(bytes)?),
69 Ok(18) => msg.topic_id = Some(r.read_string(bytes)?.to_owned()),
70 Ok(t) => { r.read_unknown(bytes, t)?; }
71 Err(e) => return Err(e),
72 }
73 }
74 Ok(msg)
75 }
76}
77
78impl MessageWrite for SubOpts {
79 fn get_size(&self) -> usize {
80 0
81 + self.subscribe.as_ref().map_or(0, |m| 1 + sizeof_varint(*(m) as u64))
82 + self.topic_id.as_ref().map_or(0, |m| 1 + sizeof_len((m).len()))
83 }
84
85 fn write_message<W: WriterBackend>(&self, w: &mut Writer<W>) -> Result<()> {
86 if let Some(ref s) = self.subscribe { w.write_with_tag(8, |w| w.write_bool(*s))?; }
87 if let Some(ref s) = self.topic_id { w.write_with_tag(18, |w| w.write_string(&**s))?; }
88 Ok(())
89 }
90}
91
92}
93
94#[allow(clippy::derive_partial_eq_without_eq)]
95#[derive(Debug, Default, PartialEq, Clone)]
96pub struct Message {
97 pub from: Option<Vec<u8>>,
98 pub data: Option<Vec<u8>>,
99 pub seqno: Option<Vec<u8>>,
100 pub topic_ids: Vec<String>,
101}
102
103impl<'a> MessageRead<'a> for Message {
104 fn from_reader(r: &mut BytesReader, bytes: &'a [u8]) -> Result<Self> {
105 let mut msg = Self::default();
106 while !r.is_eof() {
107 match r.next_tag(bytes) {
108 Ok(10) => msg.from = Some(r.read_bytes(bytes)?.to_owned()),
109 Ok(18) => msg.data = Some(r.read_bytes(bytes)?.to_owned()),
110 Ok(26) => msg.seqno = Some(r.read_bytes(bytes)?.to_owned()),
111 Ok(34) => msg.topic_ids.push(r.read_string(bytes)?.to_owned()),
112 Ok(t) => { r.read_unknown(bytes, t)?; }
113 Err(e) => return Err(e),
114 }
115 }
116 Ok(msg)
117 }
118}
119
120impl MessageWrite for Message {
121 fn get_size(&self) -> usize {
122 0
123 + self.from.as_ref().map_or(0, |m| 1 + sizeof_len((m).len()))
124 + self.data.as_ref().map_or(0, |m| 1 + sizeof_len((m).len()))
125 + self.seqno.as_ref().map_or(0, |m| 1 + sizeof_len((m).len()))
126 + self.topic_ids.iter().map(|s| 1 + sizeof_len((s).len())).sum::<usize>()
127 }
128
129 fn write_message<W: WriterBackend>(&self, w: &mut Writer<W>) -> Result<()> {
130 if let Some(ref s) = self.from { w.write_with_tag(10, |w| w.write_bytes(&**s))?; }
131 if let Some(ref s) = self.data { w.write_with_tag(18, |w| w.write_bytes(&**s))?; }
132 if let Some(ref s) = self.seqno { w.write_with_tag(26, |w| w.write_bytes(&**s))?; }
133 for s in &self.topic_ids { w.write_with_tag(34, |w| w.write_string(&**s))?; }
134 Ok(())
135 }
136}
137