mirror of
https://github.com/logos-blockchain/logos-blockchain-simulations.git
synced 2026-01-07 15:43:09 +00:00
Use String for PayloadId
This commit is contained in:
parent
b3019b0cae
commit
7ff5b0300d
@ -1,20 +1,20 @@
|
||||
use uuid::Uuid;
|
||||
|
||||
pub type PayloadId = [u8; 16];
|
||||
pub type PayloadId = String;
|
||||
|
||||
pub struct Payload(PayloadId);
|
||||
pub struct Payload(Uuid);
|
||||
|
||||
impl Payload {
|
||||
pub fn new() -> Self {
|
||||
Self(Uuid::new_v4().into_bytes())
|
||||
Self(Uuid::new_v4())
|
||||
}
|
||||
|
||||
pub fn id(&self) -> PayloadId {
|
||||
self.0
|
||||
self.0.to_string()
|
||||
}
|
||||
|
||||
pub fn as_bytes(&self) -> &[u8] {
|
||||
&self.0
|
||||
self.0.as_bytes()
|
||||
}
|
||||
|
||||
pub fn load(data: Vec<u8>) -> Self {
|
||||
@ -22,3 +22,18 @@ impl Payload {
|
||||
Self(data.try_into().unwrap())
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use super::Payload;
|
||||
|
||||
#[test]
|
||||
fn payload() {
|
||||
let payload = Payload::new();
|
||||
println!("{}", payload.id());
|
||||
let bytes = payload.as_bytes();
|
||||
assert_eq!(bytes.len(), 16);
|
||||
let loaded_payload = Payload::load(bytes.to_vec());
|
||||
assert_eq!(bytes, loaded_payload.as_bytes());
|
||||
}
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user