You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
38 lines
1.1 KiB
38 lines
1.1 KiB
/* |
|
ddtu - digital data transferring utility |
|
Copyright (C) 2022 Kasyanov Nikolay Alexeyevich (Unbewohnte) |
|
|
|
This program is free software: you can redistribute it and/or modify |
|
it under the terms of the GNU Affero General Public License as published by |
|
the Free Software Foundation, either version 3 of the License, or |
|
(at your option) any later version. |
|
|
|
This program is distributed in the hope that it will be useful, |
|
but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
GNU Affero General Public License for more details. |
|
*/ |
|
|
|
pub fn read_u128(buf: Vec<u8>) -> u128 { |
|
let mut arr: [u8; 16] = [0; 16]; |
|
for i in 0..16 { |
|
arr[i] = buf[i]; |
|
} |
|
return u128::from_be_bytes(arr); |
|
} |
|
|
|
pub fn read_u128_slice(buf_16: &[u8]) -> u128 { |
|
let mut arr: [u8; 16] = [0; 16]; |
|
for i in 0..16 { |
|
arr[i] = buf_16[i]; |
|
} |
|
return u128::from_be_bytes(arr); |
|
} |
|
|
|
pub fn read_utf8_string(buf: Vec<u8>) -> String { |
|
return String::from_utf8_lossy(&buf).into_owned(); |
|
} |
|
|
|
pub fn read_utf8_string_slice(buf: &[u8]) -> String { |
|
return String::from_utf8_lossy(&buf).into_owned(); |
|
} |