Nicolas Cannasse 9 gadi atpakaļ
vecāks
revīzija
ac3502bfbe

+ 9 - 1
std/haxe/io/BytesData.hx

@@ -39,7 +39,15 @@ package haxe.io;
 #elseif js
 	typedef BytesData = js.html.ArrayBuffer;
 #elseif hl
-	typedef BytesData = hl.types.Bytes;
+	class BytesDataImpl {
+		public var b : hl.types.Bytes;
+		public var length : Int;
+		public function new(b,length) {
+			this.b = b;
+			this.length = length;
+		}
+	}
+	typedef BytesData = BytesDataImpl;
 #else
 	typedef BytesData = Array<Int>;
 #end

+ 4 - 2
std/haxe/io/BytesInput.hx

@@ -22,7 +22,7 @@
 package haxe.io;
 
 class BytesInput extends Input {
-	var b : #if js js.html.Uint8Array #else BytesData #end;
+	var b : #if js js.html.Uint8Array #elseif hl hl.types.Bytes #else BytesData #end;
 	#if !flash
 	var pos : Int;
 	var len : Int;
@@ -50,7 +50,7 @@ class BytesInput extends Input {
 			this.b = ba;
 		this.b.endian = flash.utils.Endian.LITTLE_ENDIAN;
 		#else
-		this.b = #if js @:privateAccess b.b #else b.getData() #end;
+		this.b = #if (js || hl) @:privateAccess b.b #else b.getData() #end;
 		this.pos = pos;
 		this.len = len;
 		this.totlen = len;
@@ -142,6 +142,8 @@ class BytesInput extends Input {
 			try untyped __dollar__sblit(buf.getData(),pos,b,this.pos,len) catch( e : Dynamic ) throw Error.OutsideBounds;
 			#elseif php
 			buf.getData().blit(pos, b, this.pos, len);
+			#elseif hl
+			@:privateAccess buf.b.blit(pos, b, this.pos, len);
 			#else
 			var b1 = b;
 			var b2 = #if js @:privateAccess buf.b #else buf.getData() #end;

+ 1 - 1
std/haxe/io/Input.hx

@@ -60,7 +60,7 @@ class Input {
 	**/
 	public function readBytes( s : Bytes, pos : Int, len : Int ) : Int {
 		var k = len;
-		var b = #if js @:privateAccess s.b #else s.getData() #end;
+		var b = #if (js || hl) @:privateAccess s.b #else s.getData() #end;
 		if( pos < 0 || len < 0 || pos + len > s.length )
 			throw Error.OutsideBounds;
 		while( k > 0 ) {

+ 5 - 5
std/hl/_std/haxe/io/Bytes.hx

@@ -25,9 +25,9 @@ package haxe.io;
 class Bytes {
 
 	public var length(default,null) : Int;
-	var b : BytesData;
+	var b : hl.types.Bytes;
 
-	function new(length:Int,b:BytesData) : Void {
+	function new(length:Int,b:hl.types.Bytes) : Void {
 		this.length = length;
 		this.b = b;
 	}
@@ -148,7 +148,7 @@ class Bytes {
 	}
 
 	public inline function getData() : BytesData {
-		return b;
+		return new haxe.io.BytesData(b,length);
 	}
 
 	public static function alloc( length : Int ) : Bytes {
@@ -162,11 +162,11 @@ class Bytes {
 	}
 
 	public static function ofData( b : BytesData ) : Bytes {
-		return new Bytes(0,b);
+		return new Bytes(b.length,b.b);
 	}
 
 	public inline static function fastGet( b : BytesData, pos : Int ) : Int {
-		return b[pos];
+		return b.b[pos];
 	}
 
 }

+ 7 - 7
std/hl/_std/haxe/io/BytesBuffer.hx

@@ -24,7 +24,7 @@ package haxe.io;
 @:coreApi
 class BytesBuffer {
 
-	var b : BytesData;
+	var b : hl.types.Bytes;
 	var pos : Int;
 	var size : Int;
 
@@ -33,7 +33,7 @@ class BytesBuffer {
 	public function new() {
 		pos = 0;
 		size = 16; // ensure increment of 8
-		b = new BytesData(size);
+		b = new hl.types.Bytes(size);
 	}
 
 	inline function get_length() : Int {
@@ -48,20 +48,20 @@ class BytesBuffer {
 	function __expand( req : Int ) : Void {
 		var nsize = (size * 3) >> 1;
 		if( nsize < req ) nsize = req;
-		var b2 = new BytesData(nsize);
+		var b2 = new hl.types.Bytes(nsize);
 		b2.blit(0, b, 0, pos);
 		b = b2;
 		size = nsize;
 	}
 
-	function __add( b : BytesData, bpos : Int, blen : Int ) : Void {
+	function __add( b : hl.types.Bytes, bpos : Int, blen : Int ) : Void {
 		if( pos + blen > size ) __expand(pos+blen);
-		b.blit(pos, b, bpos, blen);
+		this.b.blit(pos, b, bpos, blen);
 		pos += blen;
 	}
 
 	public inline function add( src : Bytes ) : Void {
-		__add(src.getData(), 0, src.length);
+		__add(@:privateAccess src.b, 0, src.length);
 	}
 
 	public inline function addString( v : String ) : Void {
@@ -93,7 +93,7 @@ class BytesBuffer {
 
 	public inline function addBytes( src : Bytes, pos : Int, len : Int ) : Void {
 		if( pos < 0 || len < 0 || pos + len > src.length ) throw Error.OutsideBounds;
-		__add(src.getData(), pos, len);
+		__add(@:privateAccess src.b, pos, len);
 	}
 
 	public function getBytes() : Bytes {