summaryrefslogtreecommitdiff
path: root/src/devices/file_device/bedrock_path_buffer.rs
diff options
context:
space:
mode:
authorBen Bridle <ben@derelict.engineering>2025-03-25 12:46:49 +1300
committerBen Bridle <ben@derelict.engineering>2025-03-25 12:48:49 +1300
commitab84ad75629b0a4124221023ca91411d2cd62a32 (patch)
tree0c333f06bec5270084aaec71cf173c798420207b /src/devices/file_device/bedrock_path_buffer.rs
parent07ae3438917fd854a46924a410f6890cd0651f1b (diff)
downloadbedrock-pc-ab84ad75629b0a4124221023ca91411d2cd62a32.zip
Restructure program
This commit also includes changes to devices according to the latest devices specification, in particular the math and system devices.
Diffstat (limited to 'src/devices/file_device/bedrock_path_buffer.rs')
-rw-r--r--src/devices/file_device/bedrock_path_buffer.rs60
1 files changed, 0 insertions, 60 deletions
diff --git a/src/devices/file_device/bedrock_path_buffer.rs b/src/devices/file_device/bedrock_path_buffer.rs
deleted file mode 100644
index d6a0861..0000000
--- a/src/devices/file_device/bedrock_path_buffer.rs
+++ /dev/null
@@ -1,60 +0,0 @@
-pub struct BedrockPathBuffer {
- buffer: [u8; 256],
- pointer: u8,
-}
-
-impl BedrockPathBuffer {
- pub fn new() -> Self {
- Self { buffer: [0; 256] , pointer: 0 }
- }
-
- /// Clear the buffer, returning the previous buffer contents.
- pub fn clear(&mut self) -> [u8; 256] {
- self.pointer = 0;
- std::mem::replace(&mut self.buffer, [0; 256])
- }
-
- /// Reset the pointer and hot-swap the byte buffer.
- pub fn populate(&mut self, buffer: [u8; 256]) {
- self.pointer = 0;
- self.buffer = buffer;
- }
-
- /// Move internal pointer to the start of the path or file name.
- ///
- /// If value is non-zero, the pointer will be moved to the byte
- /// directly following the final forward-slash.
- pub fn set_pointer(&mut self, value: u8) {
- self.pointer = 0;
- // Set the pointer to the start of the filename if value is truthy.
- if value != 0x00 {
- for (i, c) in self.buffer.iter().enumerate() {
- match c {
- b'/' => self.pointer = (i as u8).saturating_add(1),
- 0x00 => break,
- _ => continue,
- }
- }
- }
- }
-
- /// Read a single byte from the buffer.
- pub fn read(&mut self) -> u8 {
- let pointer = self.pointer as usize;
- self.pointer = self.pointer.wrapping_add(1);
- self.buffer[pointer]
- }
-
- /// Write a single byte to the buffer.
- ///
- /// If a null-byte is written, the buffer will be cleared and returned.
- pub fn write(&mut self, byte: u8) -> Option<[u8; 256]> {
- if byte == 0x00 {
- Some(self.clear())
- } else {
- self.buffer[self.pointer as usize] = byte;
- self.pointer = self.pointer.saturating_add(1);
- None
- }
- }
-}