Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import haxe.io.Bytes;
- import haxe.io.BytesInput;
- import haxe.io.BytesOutput;
- import haxe.Int32;
- typedef Data =
- {
- var version:Int;
- var count:Int;
- var entries:Array<Dynamic>;//if version 1: 32bit integer, if version 2: 64 bit integer
- }
- class Main
- {
- public static function main()
- {
- var output = new BytesOutput();
- output.writeByte(2);//version
- output.writeByte(2);//count
- output.writeDouble(10);//entry 1
- output.writeDouble(20);//entry 2
- var input = new BytesInput(output.getBytes());
- var data:Data =
- {
- version : input.readByte(),
- count : input.readByte(),
- entries : new Array<Dynamic>()
- }
- for(i in 0...data.count)
- {
- data.entries.push( switch(data.version)
- {
- case 1: input.readInt32();
- case 2: input.readDouble();//./characters 4-8 : Float should be haxe.Int32
- });
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment