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

            
12
use quick_protobuf::{MessageInfo, MessageRead, MessageWrite, BytesReader, Writer, WriterBackend, Result};
13
use quick_protobuf::sizeofs::*;
14
use super::*;
15

            
16
#[allow(clippy::derive_partial_eq_without_eq)]
17
#[derive(Debug, Default, PartialEq, Clone)]
18
pub struct Identify {
19
    pub protocolVersion: Option<String>,
20
    pub agentVersion: Option<String>,
21
    pub publicKey: Option<Vec<u8>>,
22
    pub listenAddrs: Vec<Vec<u8>>,
23
    pub observedAddr: Option<Vec<u8>>,
24
    pub protocols: Vec<String>,
25
}
26

            
27
impl<'a> MessageRead<'a> for Identify {
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(42) => msg.protocolVersion = Some(r.read_string(bytes)?.to_owned()),
33
                Ok(50) => msg.agentVersion = Some(r.read_string(bytes)?.to_owned()),
34
                Ok(10) => msg.publicKey = Some(r.read_bytes(bytes)?.to_owned()),
35
                Ok(18) => msg.listenAddrs.push(r.read_bytes(bytes)?.to_owned()),
36
                Ok(34) => msg.observedAddr = Some(r.read_bytes(bytes)?.to_owned()),
37
                Ok(26) => msg.protocols.push(r.read_string(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

            
46
impl MessageWrite for Identify {
47
    fn get_size(&self) -> usize {
48
        0
49
        + self.protocolVersion.as_ref().map_or(0, |m| 1 + sizeof_len((m).len()))
50
        + self.agentVersion.as_ref().map_or(0, |m| 1 + sizeof_len((m).len()))
51
        + self.publicKey.as_ref().map_or(0, |m| 1 + sizeof_len((m).len()))
52
        + self.listenAddrs.iter().map(|s| 1 + sizeof_len((s).len())).sum::<usize>()
53
        + self.observedAddr.as_ref().map_or(0, |m| 1 + sizeof_len((m).len()))
54
        + self.protocols.iter().map(|s| 1 + sizeof_len((s).len())).sum::<usize>()
55
    }
56

            
57
    fn write_message<W: WriterBackend>(&self, w: &mut Writer<W>) -> Result<()> {
58
        if let Some(ref s) = self.protocolVersion { w.write_with_tag(42, |w| w.write_string(&**s))?; }
59
        if let Some(ref s) = self.agentVersion { w.write_with_tag(50, |w| w.write_string(&**s))?; }
60
        if let Some(ref s) = self.publicKey { w.write_with_tag(10, |w| w.write_bytes(&**s))?; }
61
        for s in &self.listenAddrs { w.write_with_tag(18, |w| w.write_bytes(&**s))?; }
62
        if let Some(ref s) = self.observedAddr { w.write_with_tag(34, |w| w.write_bytes(&**s))?; }
63
        for s in &self.protocols { w.write_with_tag(26, |w| w.write_string(&**s))?; }
64
        Ok(())
65
    }
66
}
67