Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add Borsh serialization support #9

Merged
merged 1 commit into from
May 6, 2024
Merged

Add Borsh serialization support #9

merged 1 commit into from
May 6, 2024

Conversation

sunsided
Copy link
Contributor

@sunsided sunsided commented May 5, 2024

Adds support for the UUID crate's Borsh serialization feature:

#[test]
fn test_serialize() {
    let uuid_str = "f9168c5e-ceb2-4faa-b6bf-329bf39fa1e4";
    let sg = ShortGuid::from_str(uuid_str).unwrap();
    let sg_bytes = sg.as_bytes().to_vec();
    let borsh_bytes = borsh::to_vec(&sg).unwrap();
    assert_eq!(sg_bytes, borsh_bytes);
}

#[test]
fn test_deserialize() {
    let uuid_str = "f9168c5e-ceb2-4faa-b6bf-329bf39fa1e4";
    let sg = ShortGuid::from_str(uuid_str).unwrap();
    let sg_bytes = sg.as_bytes().to_vec();
    let deserialized = borsh::from_slice::<Uuid>(&sg_bytes).unwrap().to_string();
    assert_eq!(uuid_str, deserialized);
}

This also defaults the (default-active) randomizer to the fast-rng feature.

@sunsided sunsided self-assigned this May 5, 2024
@sunsided sunsided requested a review from pophilpo May 5, 2024 12:46
@pophilpo
Copy link
Member

pophilpo commented May 6, 2024

LGTM 👍

@pophilpo pophilpo merged commit 0067a52 into main May 6, 2024
1 check passed
@sunsided sunsided deleted the feature/borsh branch May 6, 2024 15:13
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants