pub fn send<T>(&self, msg: T) -> Result<Response>
    where
        T: ToMessage,
    {
        let byte_msg = serde_json::to_string(&msg.to_message())?;
        let data = byte_msg.as_bytes();

        let mut send_data: Vec<u8> = Vec::with_capacity(ZBX_HDR_SIZE + data.len());
        send_data.extend(ZBX_HDR);
        send_data.write_u32::<LittleEndian>(data.len() as u32)?;
        send_data.extend(&[0, 0, 0, 0]);
        send_data.extend(data.iter());

        let addr = format!("{0}:{1}", self.server, self.port);
        let mut stream = TcpStream::connect(addr)?;
        stream.write(&send_data)?;

        let mut zbx_hdr = [0; ZBX_HDR_SIZE];
        stream.read(&mut zbx_hdr)?;
        if ZBX_HDR != &zbx_hdr[..ZBX_HEADER] {
            return Err(error::Error::InvalidHeader);
        }

        let mut rdr = io::Cursor::new(zbx_hdr);
        rdr.set_position(ZBX_HEADER as u64);
        let data_length = rdr.read_u64::<LittleEndian>()?;
        if data_length == 0 {
            return Err(error::Error::InvalidHeader);
        }

        let mut read_data = Vec::with_capacity(data_length as usize);
        stream.take(data_length).read_to_end(&mut read_data)?;
        let response: Response = serde_json::from_slice(&read_data)?;

        Ok(response)
    }
/// Sends data to the server according to Protocol rules
Sends data to the server according to Protocol rules
Sends data to the server according to Protocol rules
pub fn send<T>(&self, msg: T) -> Result<Response>
    where
        T: ToMessage,
    {
        let byte_msg = serde_json::to_string(&msg.to_message())?;
        let data = byte_msg.as_bytes();
        let mut send_data: Vec<u8> = Vec::with_capacity(ZBX_HDR_SIZE + data.len());
        send_data.extend(ZBX_HDR);
        send_data.write_u32::<LittleEndian>(data.len() as u32)?;
        send_data.extend(&[0, 0, 0, 0]);
        send_data.extend(data.iter());
        let addr = format!("{0}:{1}", self.server, self.port);
        let mut stream = TcpStream::connect(addr)?;
        stream.write(&send_data)?;
        let mut zbx_hdr = [0; ZBX_HDR_SIZE];
        stream.read(&mut zbx_hdr)?;
        if ZBX_HDR != &zbx_hdr[..ZBX_HEADER] {
            return Err(error::Error::InvalidHeader);
        }
        let mut rdr = io::Cursor::new(zbx_hdr);
        rdr.set_position(ZBX_HEADER as u64);
        let data_length = rdr.read_u64::<LittleEndian>()?;
        if data_length == 0 {
            return Err(error::Error::InvalidHeader);
        }
        let mut read_data = Vec::with_capacity(data_length as usize);
        stream.take(data_length).read_to_end(&mut read_data)?;
        let response: Response = serde_json::from_slice(&read_data)?;
        Ok(response)
    }
pub fn send < T > ( & self , msg : T ) -> Result < Response > where T : ToMessage , { let byte_msg = serde_json :: to_string ( & msg . to_message ( ) ) ? ; let data = byte_msg . as_bytes ( ) ; let mut send_data : Vec < u8 > = Vec :: with_capacity ( ZBX_HDR_SIZE + data . len ( ) ) ; send_data . extend ( ZBX_HDR ) ; send_data . write_u32 :: < LittleEndian > ( data . len ( ) as u32 ) ? ; send_data . extend ( & [ 0 , 0 , 0 , 0 ] ) ; send_data . extend ( data . iter ( ) ) ; let addr = format ! ( " " self server self port ) ; let mut stream = TcpStream :: connect ( addr ) ? ; stream . write ( & send_data ) ? ; let mut zbx_hdr = [ 0 ; ZBX_HDR_SIZE ] ; stream . read ( & mut zbx_hdr ) ? ; if ZBX_HDR != & zbx_hdr [ .. ZBX_HEADER ] { return Err ( error :: Error :: InvalidHeader ) ; } let mut rdr = io :: Cursor :: new ( zbx_hdr ) ; rdr . set_position ( ZBX_HEADER as u64 ) ; let data_length = rdr . read_u64 :: < LittleEndian > ( ) ? ; if data_length == 0 { return Err ( error :: Error :: InvalidHeader ) ; } let mut read_data = Vec :: with_capacity ( data_length as usize ) ; stream . take ( data_length ) . read_to_end ( & mut read_data ) ? ; let response : Response = serde_json :: from_slice ( & read_data ) ? ; Ok ( response ) }
Sends data to the server according to Protocol rules
Sends data to the server according to Protocol rules
&self
msg
T