forked from M-Labs/artiq
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())
|
return self._read_chunk(self._read_int32())
|
||||||
|
|
||||||
def _read_string(self):
|
def _read_string(self):
|
||||||
return self._read_bytes()[:-1].decode("utf-8")
|
return self._read_bytes().decode("utf-8")
|
||||||
|
|
||||||
#
|
#
|
||||||
# Writer interface
|
# Writer interface
|
||||||
|
@ -214,7 +214,7 @@ class CommGeneric:
|
||||||
self._write_buffer.append(value)
|
self._write_buffer.append(value)
|
||||||
|
|
||||||
def _write_string(self, value):
|
def _write_string(self, value):
|
||||||
self._write_bytes(value.encode("utf-8") + b"\0")
|
self._write_bytes(value.encode("utf-8"))
|
||||||
|
|
||||||
#
|
#
|
||||||
# Exported APIs
|
# 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> {
|
pub fn read_string(reader: &mut Read) -> io::Result<String> {
|
||||||
let mut bytes = try!(read_bytes(reader));
|
let 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
|
|
||||||
String::from_utf8(bytes).map_err(|e| io::Error::new(io::ErrorKind::InvalidData, e))
|
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<()> {
|
pub fn write_string(writer: &mut Write, value: &str) -> io::Result<()> {
|
||||||
try!(write_u32(writer, (value.len() + 1) as u32));
|
write_bytes(writer, value.as_bytes())
|
||||||
try!(writer.write_all(value.as_bytes()));
|
|
||||||
write_u8(writer, 0)
|
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue