jan_flanders

Untitled

Jun 7th, 2012
76
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. import haxe.io.Bytes;
  2. import haxe.io.BytesInput;
  3. import haxe.io.BytesOutput;
  4. import haxe.Int32;
  5.  
  6. typedef Data =
  7. {
  8.     var version:Int;
  9.     var count:Int;
  10.     var entries:Array<Dynamic>;//if version 1: 32bit integer, if version 2: 64 bit integer
  11. }
  12. class Main
  13. {
  14.     public static function main()
  15.     {
  16.         var output = new BytesOutput();
  17.         output.writeByte(2);//version
  18.         output.writeByte(2);//count
  19.         output.writeDouble(10);//entry 1
  20.         output.writeDouble(20);//entry 2
  21.        
  22.         var input = new BytesInput(output.getBytes());
  23.        
  24.         var data:Data =
  25.         {
  26.             version : input.readByte(),
  27.             count : input.readByte(),
  28.             entries : new Array<Dynamic>()
  29.         }
  30.        
  31.         for(i in 0...data.count)
  32.         {
  33.             data.entries.push( switch(data.version)
  34.             {
  35.                 case 1: input.readInt32();
  36.                 case 2: input.readDouble();//./characters 4-8 : Float should be haxe.Int32
  37.             });
  38.         }
  39.     }
  40. }
Advertisement
Add Comment
Please, Sign In to add comment