Implement reading from real memory

This commit is contained in:
2025-01-02 01:10:19 -05:00
parent 82c3104ab9
commit be8cdd958a
4 changed files with 101 additions and 21 deletions
+18 -4
View File
@@ -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