HeapsIO / hxbit

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

Serializing generic class #12

Closed NuclearCookie closed 7 years ago

NuclearCookie commented 7 years ago

Hi again.

I'm getting closer to serializing our openfl with hxbit! I have another issue: We have a generic class UnshrinkableArray that we'd like to serialize. https://github.com/FishingCactus/openfl/blob/feature/hxbit_serialization/openfl/utils/UnshrinkableArray.hx

Since it's generic, I don't know how I can serialize @:s _items:Array<T> ! When I make the UnshrinkableArrayData<T> implementhxbit.Serializable`, I get the following compile error:

../openfl/utils/UnshrinkableArray.hx:169: characters 15-35 : Unsupported serializable type Array<openfl.utils.UnshrinkableArrayData.T>

Thanks for your help!

ncannasse commented 7 years ago

Uhm, maybe adding @:generic to it would work better ?

NuclearCookie commented 7 years ago

Sadly, adding @:generic is not compatible with the current implementation of buildSerializable.

When adding @:generic I get the message: A generic class can't have static fields. This is caused by the static __clid field that is generated throught the autobuild macro.

I see there is a @:genericBuild which I believe I could use, but I don't know how to convert the buildSerializable to return a haxe.macro.ComplexType instead of a Array<haxe.macro.Field>

NuclearCookie commented 7 years ago

I've fixed this by using a different class