#how do u deserialize a component from componentid and vec<u8>

1 messages · Page 1 of 1 (latest)

buoyant raft
#

where are you getting the ComponentId

honest walrus
#

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

mental kelp
mental kelp
mental kelp
buoyant raft
#

transmuting a vec wouldn't even work if the data was the representation of the type

honest walrus
buoyant raft
#

because a vec is two sizes and a pointer?

honest walrus
#

Just deref

#

Slice and deref

buoyant raft
#

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

honest walrus
#

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?

buoyant raft
#

presumably if there's a componentid it's registered already

honest walrus
#

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...

buoyant raft
#

the id is from a "registry", so hopefully that means it's not being deserialized

buoyant raft
#

oh World::get_reflect looks handy

#

night be possible via reflect_trait

buoyant raft
#

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

mental kelp
#

wait nvm its the std typeid

buoyant raft
#

also, not a bro

#

could probably make dyn_deserialize a big match statement, if Any is const

mental kelp
#

i didnt look that much maybe theres a method that returns it

buoyant raft
#

it gives you the typeid

#

layout's just alignment & size

buoyant raft
#

if you share the source, it sounds like an interesting challenge

mental kelp
#

but the concept is deserializing a vec<u8> with just the component id

#

and it was serialized with serde

#

what a challenge huh

buoyant raft
#

just the component id, no World?

#

the interesting challenge is making it well, making it at all is easier

mental kelp
buoyant raft
#

then you can get Components, turn the ComponentId into a TypeId, match on that, and downcast via Any

#

or otherwise reflect it somewhere

mental kelp
buoyant raft
#

either via a trait or a type id list

mental kelp
#

i need the concrete type for it

buoyant raft
#

with reflection it's a little more complex, but the simple dyn Any version is just that first one

mental kelp
#

i dont think the crate i use will let me be using typeid