From ed023bf3ad65191e3a7f5cffbe6f8b331ca94d5a Mon Sep 17 00:00:00 2001 From: Alex van de Sandt Date: Sat, 2 Mar 2019 14:15:42 -0500 Subject: [PATCH] Add read_frame, into_raw_stream, and lines functions --- candid_client/src/candid_connection.rs | 19 ++++++++++++++++++- 1 file changed, 18 insertions(+), 1 deletion(-) diff --git a/candid_client/src/candid_connection.rs b/candid_client/src/candid_connection.rs index fa5ef3f..da35b47 100644 --- a/candid_client/src/candid_connection.rs +++ b/candid_client/src/candid_connection.rs @@ -1,4 +1,5 @@ -use std::io::BufReader; +use std::io::prelude::*; +use std::io::{BufReader, Lines}; use std::net::{TcpStream, ToSocketAddrs}; pub struct CandidConnection { @@ -13,4 +14,20 @@ impl CandidConnection { stream: BufReader::new(stream), }) } + + pub fn read_frame(&mut self) -> Result { + let mut buffer = String::new(); + + self.stream.read_line(&mut buffer)?; + + Ok(buffer) + } + + pub fn into_raw_stream(self) -> TcpStream { + self.stream.into_inner() + } + + pub fn lines(self) -> Lines> { + self.stream.lines() + } } -- 2.51.2