فهرست منبع

[hl] added hl.Type.getDataSize + CArray.toBytes/fromBytes

Nicolas Cannasse 1 ماه پیش
والد
کامیت
c7d1a56985
2فایلهای تغییر یافته به همراه18 افزوده شده و 0 حذف شده
  1. 12 0
      std/hl/CArray.hx
  2. 6 0
      std/hl/Type.hx

+ 12 - 0
std/hl/CArray.hx

@@ -20,7 +20,19 @@ abstract CArray<T>(Abstract<"hl_carray">) {
 		return null;
 	}
 
+	public static function fromBytes<T>( bytes : haxe.io.Bytes ) : CArray<T> {
+		return bytes == null ? null : hl.Api.unsafeCast(@:privateAccess bytes.b);
+	}
+
 	#if (hl_ver >= version("1.16.0"))
+
+	public function toBytes( cl : Class<T>, count : Int ) : haxe.io.Bytes {
+		if( this == null )
+			return null;
+		var size = (cast cl:BaseType).__type__.getDataSize();
+		return @:privateAccess new haxe.io.Bytes(hl.Api.unsafeCast(this),size * count);
+	}
+
 	public inline function blit( cl : Class<T>, pos : Int, src : CArray<T>, srcPos : Int, srcLen : Int ) : Void {
 		carray_blit( cast this, (cast cl:BaseType).__type__, pos, src, srcPos, srcLen );
 	}

+ 6 - 0
std/hl/Type.hx

@@ -114,4 +114,10 @@ enum abstract TypeKind(Int) {
 	@:hlNative("std", "alloc_enum_dyn") public function allocEnum(index:Int, args:NativeArray<Dynamic>, nargs:Int):Dynamic {
 		return null;
 	}
+
+	#if (hl_ver >= version("1.16.0"))
+	@:hlNative("std", "type_data_size") public function getDataSize() : Int {
+		return 0;
+	}
+	#end
 }