This commit is contained in:
timokoesters 2020-03-29 21:05:20 +02:00
parent 18ed991b93
commit 533260edd8
No known key found for this signature in database
GPG key ID: 24DA7517711A2BA4
6 changed files with 274 additions and 94 deletions

View file

@ -7,3 +7,21 @@ pub fn millis_since_unix_epoch() -> js_int::UInt {
.as_millis() as u32)
.into()
}
pub fn bytes_to_string(bytes: &[u8]) -> String {
String::from_utf8(bytes.to_vec()).expect("convert bytes to string")
}
pub fn vec_to_bytes(vec: Vec<String>) -> Vec<u8> {
vec.into_iter()
.map(|string| string.into_bytes())
.collect::<Vec<Vec<u8>>>()
.join(&0)
}
pub fn bytes_to_vec(bytes: &[u8]) -> Vec<String> {
bytes
.split(|&b| b == 0)
.map(|bytes_string| bytes_to_string(bytes_string))
.collect::<Vec<String>>()
}