How do i serialize a Vec<glam::Vec3> as Base64 encoded bytes ? #603
-
I have a field with type I know i can do this with a manual trait impl. But was wondering if i could do this simply with a macro instead. Another question: I also have to base64 encode a |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment
-
You can store the 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 More information about implementing the traits is available in the documentation: |
Beta Was this translation helpful? Give feedback.
You can store the
Vec3
as base64, if you know how to convert it toVec<u8>
. I am not familiar with glam. You will have to create your own type for which you implementSerializeAs
andDeserializeAs
. You can use theBase64
fromserde_with
to save some work. Something like this:The same applies to
Uuid
too. Since you can convert it into a