where R: Read, W: Write
{
let mut bulk_download: Option<Box<dyn Read>> = None;
+ let for_response = for_response
+ .write_withbulk().context("start to respond")?;
let mut cmd_s = log_enabled!(log::Level::Info)
.as_some_from(|| format!("{:?}", &cmd))
}
};
- let mut wf = for_response.write_withbulk(&resp).context("respond")?;
+ let mut wf = for_response.respond(&resp).context("respond")?;
if let Some(mut bulk_download) = bulk_download {
io::copy(&mut bulk_download, &mut wf).context("download")?;
}
P: FnMut(ProgressInfo) -> Result<(),AE>,
{
use MgmtResponse::*;
- let mut wbulk = self.write.write_withbulk(&cmd).context("send command")?;
+ let mut wbulk = self.write
+ .write_withbulk().context("start sending command")?
+ .respond(&cmd).context("send command")?;
io::copy(up,&mut wbulk).context("copy bulk upload")?;
wbulk.finish().context("finish sending command and data")?;
let (mut resp, mut rbulk) =
}
#[throws(MgmtChannelWriteError)]
- pub fn write_withbulk<'c,T>(&'c mut self, val: &T)
- -> WriteFrame<impl Write + 'c>
- where T: Serialize + Debug
+ pub fn write_withbulk<'c>(&'c mut self) -> ResponseWriter<impl Write + 'c>
{
- let mut f = self.new_frame()?;
- rmp_serde::encode::write_named(&mut f, val)?;
- trace!("writing {:?}", val);
- f
+ ResponseWriter { f: self.new_frame()? }
}
#[throws(MgmtChannelWriteError)]
pub fn write<T>(&mut self, val: &T)
where T: Serialize + Debug
{
- let f = self.write_withbulk(val)?;
+ let f = self.write_withbulk()?.respond(val)?;
f.finish()?;
}
}
fn flush(&mut self) { self.buf.flush()? }
}
+pub struct ResponseWriter<'c,W:Write> { f: WriteFrame<'c,W> }
+
+impl<'c,W:Write> ResponseWriter<'c,W> {
+ #[throws(MgmtChannelWriteError)]
+ pub fn respond<'t,T>(mut self, val: &'t T) -> WriteFrame<'c, impl Write + 'c>
+ where T: Serialize + Debug
+ {
+ rmp_serde::encode::write_named(&mut self.f, val)?;
+ trace!("writing {:?}", val);
+ self.f
+ }
+}
+
// ==================== tests ====================
#[test]