HeapsIO / hxbit

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

[features request]add support typedef ? #42

Closed sonygod closed 5 years ago

sonygod commented 5 years ago

[features request ]add support typedef?

ncannasse commented 5 years ago

we already support typedefs.

sonygod commented 5 years ago

package;

import hxbit.*;

@:s typedef Player = {
    var name:String;
    var age:Int;
}

class User implements hxbit.Serializable {
    public function new() {}

    @:s public var player:Player;
}

class Main implements hxbit.Serializable {
    public function new() {
        var s = new Serializer();
         var u=new User();
         u.player={age: 1,name: "test"};

        var b=s.serialize(u);

        var c=s.unserialize(b,User);

        trace(c.player);//I know this can work ,but I want to serialize typedef direct

        //like 
        s.serialize({name:"",age:1});//it's error!
    }

    static function main() {
        new Main();
    }
}
ncannasse commented 5 years ago

I think this works already without this @:s for typedef Player.

sonygod commented 5 years ago

@ncannasse can you give a small example? api like

  var s = new Serializer();

 s.serialize{{age: 1,name: "test"});//current version it's error.
ncannasse commented 5 years ago

It's not possible because a typedef can't hold any method or metadata necessary for hxbit serialization.

Le dim. 18 août 2019 à 07:57, Mr zhan notifications@github.com a écrit :

@ncannasse https://github.com/ncannasse can you give a small example? api like

var s = new Serializer();

s.serialize{{age: 1,name: "test"});//current version it's error.

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/HeapsIO/hxbit/issues/42?email_source=notifications&email_token=AAHZXQCQ4T3C6VMPCXHZMLTQFDQE5A5CNFSM4ILTBPXKYY3PNVWWK3TUL52HS4DFVREXG43VMVBW63LNMVXHJKTDN5WW2ZLOORPWSZGOD4QZEAA#issuecomment-522293760, or mute the thread https://github.com/notifications/unsubscribe-auth/AAHZXQBAQ72SJ2YJTKKKC5TQFDQE5ANCNFSM4ILTBPXA .