This commit is contained in:
2025-12-14 22:31:31 +00:00
parent 54ec8c22d5
commit 5ea9fba937
3 changed files with 59 additions and 6 deletions

View File

@@ -0,0 +1,36 @@
The first 32 characters differ from the standard ASCII control characters when data is being transmitted over NOTP.<br/>
| Dec | Hex | Bin | Usage |
| --- | --- | --- | --- |
| 00 | 00 | 00000 | Null |
| 01 | 01 | 00001 | Start of NOTP transmisson |
| 02 | 02 | 00010 | End of NOTP transmission |
| 03 | 03 | 00011 | Start of a NOTP key |
| 04 | 04 | 00100 | End of a NOTP key |
| 05 | 05 | 00101 | Start of a NOTP Object |
| 06 | 06 | 00110 | End of a NOTP Object |
| 07 | 07 | 00111 | Start of a NOTP String |
| 08 | 08 | 01000 | End of a NOTP String |
| 09 | 09 | 01001 | Start of a NOTP List |
| 10 | 0A | 01010 | End of a NOTP List |
| 11 | 0B | 01011 | Start of a NOTP Int |
| 12 | 0C | 01100 | End of a NOTP Int |
| 13 | 0D | 01101 | |
| 14 | 0E | 01110 | |
| 15 | 0F | 01111 | |
| 16 | 10 | 10000 | Newline and Carriage Return |
| 17 | 11 | 10001 | Tab |
| 18 | 12 | 10010 | |
| 19 | 13 | 10011 | |
| 20 | 14 | 10100 | |
| 21 | 15 | 10101 | |
| 22 | 16 | 10110 | |
| 23 | 17 | 10111 | |
| 24 | 18 | 11000 | |
| 25 | 19 | 11001 | |
| 26 | 1A | 11010 | |
| 27 | 1B | 11011 | |
| 28 | 1C | 11100 | |
| 29 | 1D | 11101 | |
| 30 | 1E | 11110 | |
| 31 | 1F | 11111 | |
After this, the characters are just ASCII

View File

@@ -82,11 +82,11 @@ fn backslash(bytes: &mut Vec<u8>, character: u8)
{ {
110 => // newline 110 => // newline
{ {
bytes.push(14); bytes.push(16);
}, },
116 => // tab 116 => // tab
{ {
bytes.push(15); bytes.push(17);
}, },
_ => bytes.push(character), // Otherwise just push the character _ => bytes.push(character), // Otherwise just push the character
} }
@@ -100,8 +100,8 @@ fn default_flag(bytes: &mut Vec<u8>, temp_string: &mut Vec<u8>, flag: &mut Mode,
temp_string.push(3); // ( for name start temp_string.push(3); // ( for name start
*flag = Mode::Name; *flag = Mode::Name;
} }
123 => bytes.push(5), 123 => bytes.push(5), // {
125 => bytes.push(6), 125 => bytes.push(6), // }
58 => 58 =>
{ {
*index_flag = index + 1; *index_flag = index + 1;
@@ -112,6 +112,8 @@ fn default_flag(bytes: &mut Vec<u8>, temp_string: &mut Vec<u8>, flag: &mut Mode,
temp_string.push(7); temp_string.push(7);
*flag = Mode::String; *flag = Mode::String;
}, },
91 => temp_string.push(9),
93 => temp_string.push(10),
_ => (), _ => (),
} }
} }
@@ -146,7 +148,14 @@ fn encode_npon(file_contents: &str, depth: u8) ->
} }
match flag match flag
{ {
Mode::Default => default_flag(&mut bytes, &mut temp_string, &mut flag, &mut index_flag, character, index), Mode::Default => default_flag(
&mut bytes,
&mut temp_string,
&mut flag,
&mut index_flag,
character,
index
),
Mode::String => // in a string Mode::String => // in a string
{ {
match character match character
@@ -157,6 +166,14 @@ fn encode_npon(file_contents: &str, depth: u8) ->
bytes.append(&mut temp_string); bytes.append(&mut temp_string);
flag = Mode::Default; flag = Mode::Default;
}, },
9 => // Tab
{
temp_string.push(17);
},
10 => // Newline
{
temp_string.push(16);
},
92 => backslash_flag = true, 92 => backslash_flag = true,
_ => temp_string.push(character), _ => temp_string.push(character),
} }

View File

@@ -28,7 +28,6 @@ const INDEX_FILE: &str = "index.npon";
// TODO, Have timers to see how inefficient my code is // TODO, Have timers to see how inefficient my code is
fn main() -> io::Result<()> fn main() -> io::Result<()>
{ {
#![warn(clippy::pedantic, clippy::perf)]
let (tx, rx) = mpsc::channel(); let (tx, rx) = mpsc::channel();
// File watch thread // File watch thread
thread::spawn( thread::spawn(
@@ -36,6 +35,7 @@ fn main() -> io::Result<()>
let mut bytes: Vec<u8>; let mut bytes: Vec<u8>;
let mut file_list: Vec<PathBuf>; let mut file_list: Vec<PathBuf>;
(bytes, file_list) = files::read_file(INDEX_FILE, 0); (bytes, file_list) = files::read_file(INDEX_FILE, 0);
//println!("{bytes:?}");
file_list.push(ROOT_DIR.join(INDEX_FILE)); file_list.push(ROOT_DIR.join(INDEX_FILE));
tx.send(bytes.clone()).unwrap(); tx.send(bytes.clone()).unwrap();