#how do u deserialize a component from componentid and vec<u8>
1 messages · Page 1 of 1 (latest)
I mean, assuming you know what type of component that it should be, you can just transform the vec<u8> into whatever into whatever component using std::mem::transmute
do u know postcard? it was serialized with postcard so i dont think itll work
from a registry
also i dont have the type for the component
transmuting a vec wouldn't even work if the data was the representation of the type
Why not?
Then I think you have to reach somewhere deep into the ecs, and I wouldn't know how to do that, sorry...
because a vec is two sizes and a pointer?
even then it'd have to be repr "C"
and there'd be an extra conversion to make it Sized
Components:;get_info() looks relevant
can get the TypeId there
What do you want to do with the component? Is it already going to be registered, or are you trying to register a new one?
presumably if there's a componentid it's registered already
Yeah, presumably, but since it's being deserialized, that implies that it was stored in a previous run, and that could mean that the component id's don't line up any more...
the id is from a "registry", so hopefully that means it's not being deserialized
more specific?
oh World::get_reflect looks handy
night be possible via reflect_trait
okay i think the options are
fn dyn_deserialize(TypeId, Vec<u8>) -> Box<dyn Any + Deserialize> (with some elseifs for known type ids)
or
#[reflect_trait]
trait ReflectDeserialize: Deserialize + Any {
deserialize(Vec<u8>) -> Self;
}
@mental kelp
how u get the typeid bro
wait nvm its the std typeid
.
also, not a bro
could probably make dyn_deserialize a big match statement, if Any is const
The layout from componentinfo is private
i didnt look that much maybe theres a method that returns it
if you share the source, it sounds like an interesting challenge
cant rn
but the concept is deserializing a vec<u8> with just the component id
and it was serialized with serde
what a challenge huh
just the component id, no World?
the interesting challenge is making it well, making it at all is easier
ofc the world is there
then you can get Components, turn the ComponentId into a TypeId, match on that, and downcast via Any
or otherwise reflect it somewhere
yea and how is deserialize gonna work
either via a trait or a type id list
i need the concrete type for it
these
with reflection it's a little more complex, but the simple dyn Any version is just that first one
i dont think the crate i use will let me be using typeid