#How to serialize

14 messages · Page 1 of 1 (latest)

ruby dragon
#

Am I forced to use old versions of bincode to serialize to the table of bytes(Vec<u8>, &[u8] etc.)? Trying to use version 2.0.1 leads to the errors with types:

error[E0277]: the trait bound `bevy::prelude::Vec3: Encode` is not satisfied
 --> src\game\plugins\saving\help_structs.rs:4:10
  |
4 | #[derive(Encode)]
  |          ^^^^^^ the trait `Encode` is not implemented for `bevy::prelude::Vec3`

Or maybe, should I use something else in order to serialize Bevy's types and components to the table of bytes

languid arch
#

could try the bincode-serde compatibility wrapper thing

manic granite
#

I am using bincode 2 as well to serialize bevy structs and it works for me. however I use bincode's serde integration, not the direct encode/decode API. also I had to enable the serialize feature on bevy_math

ruby dragon
manic granite
#

Add serde and serde feature to bincode :

serde = { version = "1.0.221", features = ["derive"] }
bincode = { version = "2.0.1", features = ["serde"] }

then derive Serialize (not Encode) and then encode with the bincode::serde::encode_* methods

ruby dragon
manic granite
#

sorry, I didn't try to serialize crates other than bevy_math, so I can't help you much from there, but a quick look at the Transform struct shown that you should enable the serialize feature on bevy_ecs

ruby dragon
manic granite
#

well, exactly like that

ruby dragon
manic granite
#

you can do &vec[..] to get a slice

ruby dragon
languid arch
#

Vec<T> impls Deref<[T]>, shouldn't even need the [..]