Page 1 of 1
[Solved] Serializing HUMP.Vector with bitser
Posted: Sat Jul 08, 2017 7:20 am
by bloodcraft
Hi. I wonder what is the correct way to serialize HUMP Vectors using bitser. How should I use bitser.register or bitser.registerClass in this particular case? Currently I am getting errors when I try to do arithmetic with deserialized vectors. It seems that they forgot their metamethods. Can anyone help me? Thanks.
Re: Serializing HUMP.Vector with bitser
Posted: Sat Jul 08, 2017 8:11 am
by erasio
bitser supports a variety of class libraries or plain values.
hump.vector is neither. It's a standalone thing with it's own new() function to create new instances and a standard setmetatable. No class implementation used.
Serialization should work fine but when deserializing it recognizes this is a class but it doesn't find a deserializer from its internal implementation.
You can provide one when using "registerClass". That functions takes the following parameters:
* name
* class
* classkey
* deserializer
I haven't tried it but you might be able to use the same deserializer as is used for SECL:
Code: Select all
local function deserialize_SECL(instance, class)
return setmetatable(instance, getmetatable(class))
end
(You just need to provide it manually since this implementation doesn't have an index it's searching for in an attempt to recognize SECL)
Re: Serializing HUMP.Vector with bitser
Posted: Sat Jul 08, 2017 10:29 am
by bloodcraft
Thank you for your answer. I tried SECL deserializer and "__index" as a classkey, but it still doesn’t work.
Re: Serializing HUMP.Vector with bitser
Posted: Sat Jul 08, 2017 10:45 am
by erasio
Classkey is something different. You try to recreate your object. Aka deserialize. As I mentioned in my first comment you need to provide a deserializer.
Also the specific one you need to provide is a guess on my part. You might need something different.
I would suggest looking at the actual implementation and do some more precise debugging as to what exactly isn't working so you can look at why.
If you do not understand the module implementation and can't get it running maybe look for another one or write your own.
Re: Serializing HUMP.Vector with bitser
Posted: Sat Jul 08, 2017 10:58 am
by bartbes
I did some testing, and the solution turns out to be fairly simple. Just call the following code at the start (or at least before attempting to serialise or deserialise):
Code: Select all
bitser.registerClass("hump.vector", getmetatable(vector()), nil, setmetatable)
Where 'vector' is your vector constructor, so if you use a different name, update that line too.
Re: Serializing HUMP.Vector with bitser
Posted: Sat Jul 08, 2017 11:01 am
by bloodcraft
It works! Thanks a lot, bartbes!