24 lines
718 B
Rust
24 lines
718 B
Rust
use regex::Regex;
|
|
use std::io::BufRead;
|
|
|
|
pub fn serialize(string_to_serialize: &str) -> Vec<u8> {
|
|
[string_to_serialize, "\0"].join("").as_bytes().to_vec()
|
|
}
|
|
|
|
pub fn deserialize(bytes_to_deserialize: &[u8]) -> String {
|
|
Regex::new("\0$")
|
|
.expect("Unable to parse regex \\0$.")
|
|
.replace(
|
|
&String::from_utf8(bytes_to_deserialize.to_vec())
|
|
.expect("Get a utf-8 encoded ftp client."),
|
|
"",
|
|
)
|
|
.to_string()
|
|
}
|
|
|
|
pub fn get_u8_array_c_string_from_u8_array(mut u8_array: &[u8]) -> Vec<u8> {
|
|
let mut return_array: Vec<u8> = Vec::new();
|
|
u8_array.read_until(0, &mut return_array).expect("Could not read string from u8_array");
|
|
return_array
|
|
}
|