mirror of
https://github.com/m-labs/artiq.git
synced 2024-12-19 00:16:29 +08:00
runtime: remove unnecessary null bytes from session protocol.
This commit is contained in:
parent
5428a866b3
commit
bcdbd00e7b
@ -166,7 +166,7 @@ class CommGeneric:
|
||||
return self._read_chunk(self._read_int32())
|
||||
|
||||
def _read_string(self):
|
||||
return self._read_bytes()[:-1].decode("utf-8")
|
||||
return self._read_bytes().decode("utf-8")
|
||||
|
||||
#
|
||||
# Writer interface
|
||||
@ -214,7 +214,7 @@ class CommGeneric:
|
||||
self._write_buffer.append(value)
|
||||
|
||||
def _write_string(self, value):
|
||||
self._write_bytes(value.encode("utf-8") + b"\0")
|
||||
self._write_bytes(value.encode("utf-8"))
|
||||
|
||||
#
|
||||
# Exported APIs
|
||||
|
@ -66,14 +66,10 @@ pub fn write_bytes(writer: &mut Write, value: &[u8]) -> io::Result<()> {
|
||||
}
|
||||
|
||||
pub fn read_string(reader: &mut Read) -> io::Result<String> {
|
||||
let mut bytes = try!(read_bytes(reader));
|
||||
let len = bytes.len() - 1; // length without trailing \0
|
||||
bytes.resize(len, 0); // FIXME: don't send \0 in the first place
|
||||
let bytes = try!(read_bytes(reader));
|
||||
String::from_utf8(bytes).map_err(|e| io::Error::new(io::ErrorKind::InvalidData, e))
|
||||
}
|
||||
|
||||
pub fn write_string(writer: &mut Write, value: &str) -> io::Result<()> {
|
||||
try!(write_u32(writer, (value.len() + 1) as u32));
|
||||
try!(writer.write_all(value.as_bytes()));
|
||||
write_u8(writer, 0)
|
||||
write_bytes(writer, value.as_bytes())
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user