From cb24b82e681cb9069598f3faa7f92d878e9e8314 Mon Sep 17 00:00:00 2001 From: Sebastien Bourdeauducq Date: Mon, 1 Jun 2020 18:21:04 +0800 Subject: [PATCH] rpc: strings --- src/runtime/src/proto.rs | 11 +++++++++++ src/runtime/src/rpc.rs | 8 +++----- 2 files changed, 14 insertions(+), 5 deletions(-) diff --git a/src/runtime/src/proto.rs b/src/runtime/src/proto.rs index 06fd349..f82a9a0 100644 --- a/src/runtime/src/proto.rs +++ b/src/runtime/src/proto.rs @@ -123,3 +123,14 @@ pub async fn write_i64(stream: &TcpStream, value: i64) -> Result<()> { value as u8].iter().copied()).await?; Ok(()) } + +pub async fn write_bytes(stream: &TcpStream, value: &[u8]) -> Result<()> { + write_i32(stream, value.len() as i32).await?; + stream.send(value.iter().copied()).await?; + Ok(()) +} + +pub async fn write_string(stream: &TcpStream, value: &str) -> Result<()> { + write_bytes(stream, value.as_bytes()).await?; + Ok(()) +} diff --git a/src/runtime/src/rpc.rs b/src/runtime/src/rpc.rs index 6a54ee2..f17c041 100644 --- a/src/runtime/src/rpc.rs +++ b/src/runtime/src/rpc.rs @@ -119,10 +119,8 @@ async unsafe fn send_value(stream: &TcpStream, tag: Tag<'_>, data: &mut *const ( consume_value!(i64, |ptr| write_i64(stream, *ptr).await), Tag::String => - //consume_value!(CSlice, |ptr| - // writer.write_string(str::from_utf8((*ptr).as_ref()).unwrap())), - // TODO - unimplemented!(), + consume_value!(CSlice, |ptr| + write_string(stream, str::from_utf8((*ptr).as_ref()).unwrap()).await), Tag::Bytes | Tag::ByteArray => consume_value!(CSlice, |ptr| stream.send((*ptr).as_ref().iter().copied()).await), @@ -157,7 +155,7 @@ async unsafe fn send_value(stream: &TcpStream, tag: Tag<'_>, data: &mut *const ( Tag::Keyword(it) => { struct Keyword<'a> { name: CSlice<'a, u8> }; consume_value!(Keyword, |ptr| { - //TODO writer.write_string(str::from_utf8((*ptr).name.as_ref()).unwrap())?; + write_string(stream, str::from_utf8((*ptr).name.as_ref()).unwrap()).await?; let tag = it.clone().next().expect("truncated tag"); let mut data = ptr.offset(1) as *const (); // TODO send_value(stream, tag, &mut data).await