-
-
Save jeschkies/e89e8f181b8eaa75ff135bcd9de66695 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| struct RecordIoConnection { | |
| buf: BytesMut, | |
| body: hyper::Body, | |
| } | |
| impl RecordIoConnection { | |
| pub fn connect(url: &str, buf_sz: usize) -> FutureResponse<Item=RecordIoConnection, Error=hyper::error::Error> { | |
| let response = create_hyper_get(); | |
| response.map(|r| RecordIoConnection{ buf: BytesMut::with_capacity(buf_sz), body: r.body() } )) | |
| } | |
| } | |
| impl Stream for RecordIoConnection { | |
| Item=RecordIoMessage | |
| Error=RecordIoError | |
| fn poll(&mut self) -> Poll<Option<Self::Item>, Self::Error> { | |
| if let Some(chunk) = try_ready!(self.body.poll()) { | |
| self.buf.put(chunk.get(..)); | |
| if let Some(message) = try_parse_message(self.buf) { | |
| Ok(Async::Ready(message)) | |
| } | |
| } | |
| Ok(Async::NotReady) | |
| } | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment