HeapsIO / hxbit

Haxe Binary serialization and network synchronization library
155 stars 30 forks source link

Cannot unserialize empty instance #36

Closed filt3rek closed 5 years ago

filt3rek commented 5 years ago

Hej,

I just gave a try to hxBit, only the serializer part. I wanted to do some bench to compare with the traditionnal haxe.Serializer, to pass DB objects (record-macros) from Server to Client and I get "null" when unserializing. I tried with another instance class (not a DB object) but using with Type.createEmptyInstance and it gives me "null" also. So I think it comes from here (Type.createEmptyInstance). Is there a way to make it work with that please ?

Thanks for reading, Michal

ncannasse commented 5 years ago

If you create manually the instance, you need to set its uid property using `inst.uid = @:privateAccess hxbit.Serializer.allocUID()`

filt3rek commented 5 years ago

Thanks for your answer Nicolas,

But I try to use it with record-macros and it createEmptyInstance by itself, I can't modify that. Is there any alternative to use it with record-macros like that ?

ncannasse commented 5 years ago

Maybe, you can subclass the serializer, and if when serializing an object its __uid is 0/null you can set it before calling the super method.

filt3rek commented 5 years ago

As I see, hxBit adds uid in the constructor. Maybe if we use a getter for uid (where we set the uid) instead of setting it in the constructor it would work for all ? Is it a bad idea ?

ncannasse commented 5 years ago

subclassing the serializer is better