Skip to content

How do i serialize a Vec<glam::Vec3> as Base64 encoded bytes ? #603

Answered by jonasbb
coderedart asked this question in Q&A
Discussion options

You must be logged in to vote

You can store the Vec3 as base64, if you know how to convert it to Vec<u8>. I am not familiar with glam. You will have to create your own type for which you implement SerializeAs and DeserializeAs. You can use the Base64 from serde_with to save some work. Something like this:

struct Vec3Base64;

impl SerializeAs for Vec3Base64 {
    fn serialize_as<S>(source: &Vec<glam::Vec3>, serializer: S) -> Result<S::Ok, S::Error>
    where
        S: Serializer,
    {
        // Fill the todo! with a way to convert the `Vec<glam::Vec3>` to `Vec<u8>`
        let bytes: Vec<u8> = todo!();
        Base64::serialize_as(bytes, serializer)
    }
}

The same applies to Uuid too. Since you can convert it into a

Replies: 1 comment

Comment options

You must be logged in to vote
0 replies
Answer selected by coderedart
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants