Implement reading from real memory
This commit is contained in:
@@ -18,16 +18,30 @@ impl Response {
|
||||
}
|
||||
}
|
||||
|
||||
pub fn write_str(mut self, str: &str) -> Self {
|
||||
pub fn write_str(self, str: &str) -> Self {
|
||||
let mut me = self;
|
||||
for byte in str.as_bytes() {
|
||||
self.buffer.push(*byte);
|
||||
self.checksum = self.checksum.wrapping_add(*byte);
|
||||
me = me.write_byte(*byte);
|
||||
}
|
||||
me
|
||||
}
|
||||
|
||||
pub fn write_byte(mut self, byte: u8) -> Self {
|
||||
if byte == b'}' || byte == b'#' || byte == b'$' || byte == b'*' {
|
||||
self.buffer.push(b'}');
|
||||
self.checksum = self.checksum.wrapping_add(b'}');
|
||||
let escaped = byte ^ 0x20;
|
||||
self.buffer.push(escaped);
|
||||
self.checksum = self.checksum.wrapping_add(escaped);
|
||||
} else {
|
||||
self.buffer.push(byte);
|
||||
self.checksum = self.checksum.wrapping_add(byte);
|
||||
}
|
||||
self
|
||||
}
|
||||
|
||||
pub fn write_hex<T: ToBytes>(mut self, value: T) -> Self {
|
||||
for byte in value.to_be_bytes().as_ref() {
|
||||
for byte in value.to_le_bytes().as_ref() {
|
||||
for digit in [(byte >> 4), (byte & 0xf)] {
|
||||
let char = if digit > 9 {
|
||||
b'a' + digit - 10
|
||||
|
||||
Reference in New Issue
Block a user