fn call(&mut self, pid: usize, rpc_id: RPCType, data: Vec<u8>) -> Result<Vec<u8>, RPCError> {
        // Create request header
        let req_hdr = RPCHeader {
            client_id: self.client_id,
            pid: pid,
            req_id: self.req_id,
            msg_type: rpc_id,
            msg_len: data.len() as u64,
        };

        // Serialize request header then request body
        let mut req_data = Vec::new();
        unsafe { encode(&req_hdr, &mut req_data) }.unwrap();
        if data.len() > 0 {
            req_data.extend(data);
        }

        // Send request
        self.send(req_data).unwrap();

        // Receive response header
        let mut res_data = self.recv(core::mem::size_of::<RPCHeader>()).unwrap();
        let (res_hdr, extra) = unsafe { decode::<RPCHeader>(&mut res_data) }.unwrap();
        assert_eq!(extra.len(), 0);

        // Read the rest of the data
        let mut payload_data = Vec::new();
        if res_hdr.msg_len > 0 {
            payload_data = self.recv(res_hdr.msg_len as usize).unwrap();
        }

        // Check request & client IDs, and also length of received data
        if ((res_hdr.client_id != self.client_id) && rpc_id != RPCType::Registration)
            || res_hdr.req_id != self.req_id
        {
            warn!(
                "Mismatched client id ({}, {}) or request id ({}, {})",
                res_hdr.client_id, self.client_id, res_hdr.req_id, self.req_id
            );
            return Err(RPCError::MalformedResponse);
        }

        // Increment request id
        self.req_id += 1;

        // If registration, update id
        if rpc_id == RPCType::Registration {
            self.client_id = res_hdr.client_id;
            debug!("Set client ID to: {}", self.client_id);
            return Ok(Vec::new());
        }
        Ok(payload_data)
    }
/// calls a remote RPC function with ID
calls a remote RPC function with ID
calls a remote RPC function with ID
fn call(&mut self, pid: usize, rpc_id: RPCType, data: Vec<u8>) -> Result<Vec<u8>, RPCError> {
        // Create request header
        let req_hdr = RPCHeader {
            client_id: self.client_id,
            pid: pid,
            req_id: self.req_id,
            msg_type: rpc_id,
            msg_len: data.len() as u64,
        };
        // Serialize request header then request body
        let mut req_data = Vec::new();
        unsafe { encode(&req_hdr, &mut req_data) }.unwrap();
        if data.len() > 0 {
            req_data.extend(data);
        }
        // Send request
        self.send(req_data).unwrap();
        // Receive response header
        let mut res_data = self.recv(core::mem::size_of::<RPCHeader>()).unwrap();
        let (res_hdr, extra) = unsafe { decode::<RPCHeader>(&mut res_data) }.unwrap();
        assert_eq!(extra.len(), 0);
        // Read the rest of the data
        let mut payload_data = Vec::new();
        if res_hdr.msg_len > 0 {
            payload_data = self.recv(res_hdr.msg_len as usize).unwrap();
        }
        // Check request & client IDs, and also length of received data
        if ((res_hdr.client_id != self.client_id) && rpc_id != RPCType::Registration)
            || res_hdr.req_id != self.req_id
        {
            warn!(
                "Mismatched client id ({}, {}) or request id ({}, {})",
                res_hdr.client_id, self.client_id, res_hdr.req_id, self.req_id
            );
            return Err(RPCError::MalformedResponse);
        }
        // Increment request id
        self.req_id += 1;
        // If registration, update id
        if rpc_id == RPCType::Registration {
            self.client_id = res_hdr.client_id;
            debug!("Set client ID to: {}", self.client_id);
            return Ok(Vec::new());
        }
        Ok(payload_data)
    }
fn call ( & mut self , pid : usize , rpc_id : RPCType , data : Vec < u8 > ) -> Result < Vec < u8 > , RPCError > { // Create request header let req_hdr = RPCHeader { client_id : self . client_id , pid : pid , req_id : self . req_id , msg_type : rpc_id , msg_len : data . len ( ) as u64 , } ; // Serialize request header then request body let mut req_data = Vec :: new ( ) ; unsafe { encode ( & req_hdr , & mut req_data ) } . unwrap ( ) ; if data . len ( ) > 0 { req_data . extend ( data ) ; } // Send request self . send ( req_data ) . unwrap ( ) ; // Receive response header let mut res_data = self . recv ( core :: mem :: size_of :: < RPCHeader > ( ) ) . unwrap ( ) ; let ( res_hdr , extra ) = unsafe { decode :: < RPCHeader > ( & mut res_data ) } . unwrap ( ) ; assert_eq ! ( extra len ( ) 0 ) ; // Read the rest of the data let mut payload_data = Vec :: new ( ) ; if res_hdr . msg_len > 0 { payload_data = self . recv ( res_hdr . msg_len as usize ) . unwrap ( ) ; } // Check request & client IDs, and also length of received data if ( ( res_hdr . client_id != self . client_id ) && rpc_id != RPCType :: Registration ) || res_hdr . req_id != self . req_id { warn ! ( " " res_hdr client_id self client_id res_hdr req_id self req_id ) ; return Err ( RPCError :: MalformedResponse ) ; } // Increment request id self . req_id += 1 ; // If registration, update id if rpc_id == RPCType :: Registration { self . client_id = res_hdr . client_id ; debug ! ( " " self client_id ) ; return Ok ( Vec :: new ( ) ) ; } Ok ( payload_data ) }
calls a remote RPC function with ID
calls a remote RPC function with ID
&mut self
pid
usize
rpc_id
RPCType
data
Vec<u8>
&mut self
pid
usize
rpc_id
RPCType
data
Vec<u8>