diff options
Diffstat (limited to 'jsonrpc/src')
-rw-r--r-- | jsonrpc/src/client.rs | 3 | ||||
-rw-r--r-- | jsonrpc/src/codec.rs | 8 | ||||
-rw-r--r-- | jsonrpc/src/server.rs | 3 |
3 files changed, 8 insertions, 6 deletions
diff --git a/jsonrpc/src/client.rs b/jsonrpc/src/client.rs index 1ce9ecb..f5277aa 100644 --- a/jsonrpc/src/client.rs +++ b/jsonrpc/src/client.rs @@ -58,7 +58,8 @@ impl Client { params: serde_json::json!(params), }; - let payload = serde_json::to_vec(&request)?; + let mut payload = serde_json::to_vec(&request)?; + payload.push(b'\n'); self.codec.write_all(&payload).await?; debug!("--> {request}"); diff --git a/jsonrpc/src/codec.rs b/jsonrpc/src/codec.rs index 41fed06..e198a6e 100644 --- a/jsonrpc/src/codec.rs +++ b/jsonrpc/src/codec.rs @@ -39,12 +39,12 @@ impl Codec { Self { conn, config } } - /// Read all bytes into `buffer` until the `0x0` byte or EOF is + /// Read all bytes into `buffer` until the `0x0A` byte or EOF is /// reached. /// /// If successful, this function will return the total number of bytes read. pub async fn read_until(&self, buffer: &mut Vec<u8>) -> Result<usize> { - let delim = b'\0'; + let delim = b'\n'; let mut read = 0; @@ -57,8 +57,8 @@ impl Codec { match memchr(delim, &tmp_buf) { Some(i) => { - buffer.extend_from_slice(&tmp_buf[..i]); - read += i; + buffer.extend_from_slice(&tmp_buf[..=i]); + read += i + 1; break; } None => { diff --git a/jsonrpc/src/server.rs b/jsonrpc/src/server.rs index 133f261..f6006cc 100644 --- a/jsonrpc/src/server.rs +++ b/jsonrpc/src/server.rs @@ -99,7 +99,8 @@ impl<'a> Server<'a> { let mut buffer = vec![]; codec.read_until(&mut buffer).await?; let response = selfc.handle_request(&buffer).await; - let payload = serde_json::to_vec(&response)?; + let mut payload = serde_json::to_vec(&response)?; + payload.push(b'\n'); codec.write_all(&payload).await?; debug!("--> {response}"); } |