mirror of
https://github.com/hexedtech/codemp-proto.git
synced 2024-11-21 23:14:52 +01:00
feat: represent uuids with u64 pairs
This commit is contained in:
parent
f2d18a06ad
commit
ddd4552e09
2 changed files with 8 additions and 6 deletions
|
@ -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
|
||||
|
|
10
src/lib.rs
10
src/lib.rs
|
@ -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)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue