fabaccess-bffh/bffhd/utils/uuid.rs

20 lines
760 B
Rust
Raw Normal View History

2022-11-04 17:25:17 +01:00
use api::utils_capnp::u_u_i_d::{Builder, Reader};
2022-05-05 15:50:44 +02:00
use uuid::Uuid;
2021-11-26 21:01:43 +01:00
pub fn uuid_to_api(uuid: Uuid, mut builder: Builder) {
2022-05-05 15:50:44 +02:00
let [a, b, c, d, e, f, g, h, i, j, k, l, m, n, o, p] = uuid.as_u128().to_ne_bytes();
let lower = u64::from_ne_bytes([a, b, c, d, e, f, g, h]);
let upper = u64::from_ne_bytes([i, j, k, l, m, n, o, p]);
2022-11-04 17:25:17 +01:00
builder.set_lower(lower);
builder.set_upper(upper);
2021-11-26 21:01:43 +01:00
}
pub fn api_to_uuid(reader: Reader) -> Uuid {
2022-11-04 17:25:17 +01:00
let lower: u64 = reader.reborrow().get_lower();
let upper: u64 = reader.get_upper();
2022-05-05 15:50:44 +02:00
let [a, b, c, d, e, f, g, h] = lower.to_ne_bytes();
let [i, j, k, l, m, n, o, p] = upper.to_ne_bytes();
let num = u128::from_ne_bytes([a, b, c, d, e, f, g, h, i, j, k, l, m, n, o, p]);
2021-11-26 21:01:43 +01:00
Uuid::from_u128(num)
2022-05-05 15:50:44 +02:00
}