feat: represent uuids with u64 pairs

This commit is contained in:
əlemi 2024-08-21 20:16:14 +02:00
parent f2d18a06ad
commit ddd4552e09
Signed by: alemi
GPG key ID: A4895B84D311642C
2 changed files with 8 additions and 6 deletions

View file

@ -4,8 +4,8 @@ package common;
// a wrapper payload representing an uuid
message Identity {
// uuid bytes, as string
required string id = 1;
required uint64 hi = 1;
required uint64 lo = 2;
}
// a collection of identities

View file

@ -4,25 +4,27 @@ pub mod common {
impl From<uuid::Uuid> for Identity {
fn from(id: uuid::Uuid) -> Self {
Identity { id: id.to_string() }
let (hi, lo) = id.as_u64_pair();
Identity { hi, lo }
}
}
impl From<&uuid::Uuid> for Identity {
fn from(id: &uuid::Uuid) -> Self {
Identity { id: id.to_string() }
let (hi, lo) = id.as_u64_pair();
Identity { hi, lo }
}
}
impl From<Identity> for uuid::Uuid {
fn from(value: Identity) -> Self {
uuid::Uuid::parse_str(&value.id).expect("invalid uuid in identity")
uuid::Uuid::from_u64_pair(value.hi, value.lo)
}
}
impl From<&Identity> for uuid::Uuid {
fn from(value: &Identity) -> Self {
uuid::Uuid::parse_str(&value.id).expect("invalid uuid in identity")
uuid::Uuid::from_u64_pair(value.hi, value.lo)
}
}
}