Skip to content

Commit

Permalink
serializer not needed in type
Browse files Browse the repository at this point in the history
  • Loading branch information
arcnmx committed Mar 11, 2018
1 parent df8d00b commit 96c3eb9
Showing 1 changed file with 11 additions and 6 deletions.
17 changes: 11 additions & 6 deletions tokio/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,16 +27,16 @@ use bytes::buf::FromBuf;

mod codec;

pub struct QapiFuture<C: Command, S> {
state: QapiState<spec::CommandSerializer<C>, S>,
pub struct QapiFuture<C, S> {
state: QapiState<C, S>,
}

impl<C: Command, S> QapiFuture<C, S> {
pub fn new(stream: S, command: C) -> Self {
QapiFuture {
state: QapiState::Queue {
inner: stream,
value: spec::CommandSerializer(command),
value: command,
},
}
}
Expand Down Expand Up @@ -115,11 +115,10 @@ impl<C, S, E> Future for QapiFuture<C, S>
trace!("QapiFuture::poll()");
match self.state.take_value() {
Some(v) => {
let mut encoded = serde_json::to_vec(&v)?;
encoded.push(b'\n');
let encoded = encode_command(&v)?;
debug!("Encoded command {}", str::from_utf8(&encoded).unwrap_or("utf8 decoding failed"));
// TODO: queue the vec instead of the value?
match self.state.inner_mut().unwrap().start_send(encoded.into_boxed_slice()) {
match self.state.inner_mut().unwrap().start_send(encoded) {
Ok(AsyncSink::Ready) => self.poll(),
Ok(AsyncSink::NotReady(..)) => {
trace!("Failed to start_send, try later");
Expand Down Expand Up @@ -567,3 +566,9 @@ impl<S, E> Future for QgaHandshake<S> where
}
}
}

pub fn encode_command<C: Command>(c: &C) -> io::Result<Box<[u8]>> {
let mut encoded = serde_json::to_vec(&spec::CommandSerializerRef(c))?;
encoded.push(b'\n');
Ok(encoded.into_boxed_slice())
}

0 comments on commit 96c3eb9

Please sign in to comment.