Update Files

This commit is contained in:
2025-01-22 16:18:30 +01:00
parent ed4603cf95
commit a36294b518
16718 changed files with 2960346 additions and 0 deletions

View File

@ -0,0 +1,57 @@
/*
* Copyright (C)2005-2019 Haxe Foundation
*
* Permission is hereby granted, free of charge, to any person obtaining a
* copy of this software and associated documentation files (the "Software"),
* to deal in the Software without restriction, including without limitation
* the rights to use, copy, modify, merge, publish, distribute, sublicense,
* and/or sell copies of the Software, and to permit persons to whom the
* Software is furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
* DEALINGS IN THE SOFTWARE.
*/
package haxe.io;
typedef ArrayBufferViewData = js.lib.ArrayBufferView;
abstract ArrayBufferView(ArrayBufferViewData) {
public var buffer(get, never):haxe.io.Bytes;
public var byteOffset(get, never):Int;
public var byteLength(get, never):Int;
public inline function new(size:Int) {
this = new js.lib.Uint8Array(size);
}
inline function get_byteOffset()
return this.byteOffset;
inline function get_byteLength()
return this.byteLength;
inline function get_buffer():haxe.io.Bytes {
return haxe.io.Bytes.ofData(this.buffer);
}
public inline function sub(begin:Int, ?length:Int) {
return fromData(new js.lib.Uint8Array(this.buffer, begin, length == null ? this.buffer.byteLength - begin : length));
}
public inline function getData():ArrayBufferViewData {
return this;
}
public static inline function fromData(a:ArrayBufferViewData):ArrayBufferView {
return cast a;
}
}

View File

@ -0,0 +1,272 @@
/*
* Copyright (C)2005-2019 Haxe Foundation
*
* Permission is hereby granted, free of charge, to any person obtaining a
* copy of this software and associated documentation files (the "Software"),
* to deal in the Software without restriction, including without limitation
* the rights to use, copy, modify, merge, publish, distribute, sublicense,
* and/or sell copies of the Software, and to permit persons to whom the
* Software is furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
* DEALINGS IN THE SOFTWARE.
*/
package haxe.io;
@:coreApi
class Bytes {
public var length(default, null):Int;
var b:js.lib.Uint8Array;
var data:js.lib.DataView;
function new(data:BytesData) {
this.length = data.byteLength;
this.b = new js.lib.Uint8Array(data);
untyped {
b.bufferValue = data; // some impl does not return the same instance in .buffer
data.hxBytes = this;
data.bytes = this.b;
}
}
public inline function get(pos:Int):Int {
return b[pos];
}
public inline function set(pos:Int, v:Int):Void {
b[pos] = v;
}
public function blit(pos:Int, src:Bytes, srcpos:Int, len:Int):Void {
if (pos < 0 || srcpos < 0 || len < 0 || pos + len > length || srcpos + len > src.length)
throw Error.OutsideBounds;
if (srcpos == 0 && len == src.b.byteLength)
b.set(src.b, pos);
else
b.set(src.b.subarray(srcpos, srcpos + len), pos);
}
public function fill(pos:Int, len:Int, value:Int):Void {
for (i in 0...len)
set(pos++, value);
}
public function sub(pos:Int, len:Int):Bytes {
if (pos < 0 || len < 0 || pos + len > length)
throw Error.OutsideBounds;
return new Bytes(b.buffer.slice(pos + b.byteOffset, pos + b.byteOffset + len));
}
public function compare(other:Bytes):Int {
var b1 = b;
var b2 = other.b;
var len = (length < other.length) ? length : other.length;
for (i in 0...len)
if (b1[i] != b2[i])
return b1[i] - b2[i];
return length - other.length;
}
inline function initData():Void {
if (data == null)
data = new js.lib.DataView(b.buffer, b.byteOffset, b.byteLength);
}
public function getDouble(pos:Int):Float {
initData();
return data.getFloat64(pos, true);
}
public function getFloat(pos:Int):Float {
initData();
return data.getFloat32(pos, true);
}
public function setDouble(pos:Int, v:Float):Void {
initData();
data.setFloat64(pos, v, true);
}
public function setFloat(pos:Int, v:Float):Void {
initData();
data.setFloat32(pos, v, true);
}
public function getUInt16(pos:Int):Int {
initData();
return data.getUint16(pos, true);
}
public function setUInt16(pos:Int, v:Int):Void {
initData();
data.setUint16(pos, v, true);
}
public function getInt32(pos:Int):Int {
initData();
return data.getInt32(pos, true);
}
public function setInt32(pos:Int, v:Int):Void {
initData();
data.setInt32(pos, v, true);
}
public function getInt64(pos:Int):haxe.Int64 {
return Int64.make(getInt32(pos + 4), getInt32(pos));
}
public function setInt64(pos:Int, v:haxe.Int64):Void {
setInt32(pos, v.low);
setInt32(pos + 4, v.high);
}
public function getString(pos:Int, len:Int, ?encoding:Encoding):String {
if (pos < 0 || len < 0 || pos + len > length)
throw Error.OutsideBounds;
if (encoding == null)
encoding = UTF8;
var s = "";
var b = b;
var i = pos;
var max = pos + len;
switch (encoding) {
case UTF8:
var debug = pos > 0;
// utf8-decode and utf16-encode
while (i < max) {
var c = b[i++];
if (c < 0x80) {
if (c == 0)
break;
s += String.fromCharCode(c);
} else if (c < 0xE0)
s += String.fromCharCode(((c & 0x3F) << 6) | (b[i++] & 0x7F));
else if (c < 0xF0) {
var c2 = b[i++];
s += String.fromCharCode(((c & 0x1F) << 12) | ((c2 & 0x7F) << 6) | (b[i++] & 0x7F));
} else {
var c2 = b[i++];
var c3 = b[i++];
var u = ((c & 0x0F) << 18) | ((c2 & 0x7F) << 12) | ((c3 & 0x7F) << 6) | (b[i++] & 0x7F);
s += String.fromCharCode(u);
}
}
case RawNative:
while (i < max) {
var c = b[i++] | (b[i++] << 8);
s += String.fromCharCode(c);
}
}
return s;
}
@:deprecated("readString is deprecated, use getString instead")
@:noCompletion
public inline function readString(pos:Int, len:Int):String {
return getString(pos, len);
}
public function toString():String {
return getString(0, length);
}
public function toHex():String {
var s = new StringBuf();
var chars = [];
var str = "0123456789abcdef";
for (i in 0...str.length)
chars.push(str.charCodeAt(i));
for (i in 0...length) {
var c = get(i);
s.addChar(chars[c >> 4]);
s.addChar(chars[c & 15]);
}
return s.toString();
}
public inline function getData():BytesData {
return untyped b.bufferValue;
}
public static inline function alloc(length:Int):Bytes {
return new Bytes(new BytesData(length));
}
public static function ofString(s:String, ?encoding:Encoding):Bytes {
if (encoding == RawNative) {
var buf = new js.lib.Uint8Array(s.length << 1);
for (i in 0...s.length) {
var c:Int = StringTools.fastCodeAt(s, i);
buf[i << 1] = c & 0xFF;
buf[(i << 1) | 1] = c >> 8;
}
return new Bytes(buf.buffer);
}
var a = new Array();
// utf16-decode and utf8-encode
var i = 0;
while (i < s.length) {
var c:Int = StringTools.fastCodeAt(s, i++);
// surrogate pair
if (0xD800 <= c && c <= 0xDBFF)
c = (c - 0xD7C0 << 10) | (StringTools.fastCodeAt(s, i++) & 0x3FF);
if (c <= 0x7F)
a.push(c);
else if (c <= 0x7FF) {
a.push(0xC0 | (c >> 6));
a.push(0x80 | (c & 63));
} else if (c <= 0xFFFF) {
a.push(0xE0 | (c >> 12));
a.push(0x80 | ((c >> 6) & 63));
a.push(0x80 | (c & 63));
} else {
a.push(0xF0 | (c >> 18));
a.push(0x80 | ((c >> 12) & 63));
a.push(0x80 | ((c >> 6) & 63));
a.push(0x80 | (c & 63));
}
}
return new Bytes(new js.lib.Uint8Array(a).buffer);
}
public static function ofData(b:BytesData):Bytes {
var hb = untyped b.hxBytes;
if (hb != null)
return hb;
return new Bytes(b);
}
public static function ofHex(s:String):Bytes {
if ((s.length & 1) != 0)
throw "Not a hex string (odd number of digits)";
var a = new Array();
var i = 0;
var len = s.length >> 1;
while (i < len) {
var high = StringTools.fastCodeAt(s, i * 2);
var low = StringTools.fastCodeAt(s, i * 2 + 1);
high = (high & 0xF) + ((high & 0x40) >> 6) * 9;
low = (low & 0xF) + ((low & 0x40) >> 6) * 9;
a.push(((high << 4) | low) & 0xFF);
i++;
}
return new Bytes(new js.lib.Uint8Array(a).buffer);
}
public inline static function fastGet(b:BytesData, pos:Int):Int {
// this requires that we have wrapped it with haxe.io.Bytes beforehand
return untyped b.bytes[pos];
}
}

View File

@ -0,0 +1,127 @@
/*
* Copyright (C)2005-2019 Haxe Foundation
*
* Permission is hereby granted, free of charge, to any person obtaining a
* copy of this software and associated documentation files (the "Software"),
* to deal in the Software without restriction, including without limitation
* the rights to use, copy, modify, merge, publish, distribute, sublicense,
* and/or sell copies of the Software, and to permit persons to whom the
* Software is furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
* DEALINGS IN THE SOFTWARE.
*/
package haxe.io;
@:coreApi
class BytesBuffer {
var buffer:js.lib.ArrayBuffer;
var view:js.lib.DataView;
var u8:js.lib.Uint8Array;
var pos:Int;
var size:Int;
public var length(get, never):Int;
public function new() {
pos = 0;
size = 0;
}
inline function get_length():Int {
return pos;
}
public function addByte(byte:Int):Void {
if (pos == size)
grow(1);
view.setUint8(pos++, byte);
}
public function add(src:Bytes):Void {
if (pos + src.length > size)
grow(src.length);
if (size == 0)
return;
var sub = new js.lib.Uint8Array(@:privateAccess src.b.buffer, @:privateAccess src.b.byteOffset, src.length);
u8.set(sub, pos);
pos += src.length;
}
public function addString(v:String, ?encoding:Encoding):Void {
add(Bytes.ofString(v, encoding));
}
public function addInt32(v:Int):Void {
if (pos + 4 > size)
grow(4);
view.setInt32(pos, v, true);
pos += 4;
}
public function addInt64(v:haxe.Int64):Void {
if (pos + 8 > size)
grow(8);
view.setInt32(pos, v.low, true);
view.setInt32(pos + 4, v.high, true);
pos += 8;
}
public function addFloat(v:Float):Void {
if (pos + 4 > size)
grow(4);
view.setFloat32(pos, v, true);
pos += 4;
}
public function addDouble(v:Float):Void {
if (pos + 8 > size)
grow(8);
view.setFloat64(pos, v, true);
pos += 8;
}
public function addBytes(src:Bytes, pos:Int, len:Int):Void {
if (pos < 0 || len < 0 || pos + len > src.length)
throw Error.OutsideBounds;
if (this.pos + len > size)
grow(len);
if (size == 0)
return;
var sub = new js.lib.Uint8Array(@:privateAccess src.b.buffer, @:privateAccess src.b.byteOffset + pos, len);
u8.set(sub, this.pos);
this.pos += len;
}
function grow(delta:Int):Void {
var req = pos + delta;
var nsize = size == 0 ? 16 : size;
while (nsize < req)
nsize = (nsize * 3) >> 1;
var nbuf = new js.lib.ArrayBuffer(nsize);
var nu8 = new js.lib.Uint8Array(nbuf);
if (size > 0)
nu8.set(u8);
size = nsize;
buffer = nbuf;
u8 = nu8;
view = new js.lib.DataView(buffer);
}
public function getBytes():Bytes@:privateAccess {
if (size == 0)
return haxe.io.Bytes.alloc(0);
var b = new Bytes(buffer);
b.length = pos;
return b;
}
}

View File

@ -0,0 +1,88 @@
/*
* Copyright (C)2005-2019 Haxe Foundation
*
* Permission is hereby granted, free of charge, to any person obtaining a
* copy of this software and associated documentation files (the "Software"),
* to deal in the Software without restriction, including without limitation
* the rights to use, copy, modify, merge, publish, distribute, sublicense,
* and/or sell copies of the Software, and to permit persons to whom the
* Software is furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
* DEALINGS IN THE SOFTWARE.
*/
package haxe.io;
typedef Float32ArrayData = js.lib.Float32Array;
@:coreApi
abstract Float32Array(Float32ArrayData) {
public static inline var BYTES_PER_ELEMENT = 4;
public var length(get, never):Int;
public var view(get, never):ArrayBufferView;
public inline function new(elements:Int):Void {
this = new Float32ArrayData(elements);
}
inline function get_length():Int {
return this.length;
}
public inline function get_view():ArrayBufferView {
return ArrayBufferView.fromData(this);
}
@:arrayAccess public inline function get(index:Int):Float {
return this[index];
}
@:arrayAccess public inline function set(index:Int, value:Float):Float {
return this[index] = value;
}
public inline function sub(begin:Int, ?length:Int):Float32Array {
return fromData(this.subarray(begin, length == null ? this.length : begin + length));
}
public inline function subarray(?begin:Int, ?end:Int):Float32Array {
return fromData(this.subarray(begin, end));
}
public inline function getData():Float32ArrayData {
return this;
}
public inline static function fromData(d:Float32ArrayData):Float32Array {
return cast d;
}
public static function fromArray(a:Array<Float>, pos:Int = 0, ?length:Int):Float32Array {
if (length == null)
length = a.length - pos;
if (pos < 0 || length < 0 || pos + length > a.length)
throw Error.OutsideBounds;
if (pos == 0 && length == a.length)
return fromData(new Float32ArrayData(a));
var i = new Float32Array(a.length);
for (idx in 0...length)
i[idx] = a[idx + pos];
return i;
}
public static function fromBytes(bytes:haxe.io.Bytes, bytePos:Int = 0, ?length:Int):Float32Array {
if (length == null)
length = (bytes.length - bytePos) >> 2;
return fromData(new Float32ArrayData(bytes.getData(), bytePos, length));
}
}

View File

@ -0,0 +1,88 @@
/*
* Copyright (C)2005-2019 Haxe Foundation
*
* Permission is hereby granted, free of charge, to any person obtaining a
* copy of this software and associated documentation files (the "Software"),
* to deal in the Software without restriction, including without limitation
* the rights to use, copy, modify, merge, publish, distribute, sublicense,
* and/or sell copies of the Software, and to permit persons to whom the
* Software is furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
* DEALINGS IN THE SOFTWARE.
*/
package haxe.io;
typedef Float64ArrayData = js.lib.Float64Array;
@:coreApi
abstract Float64Array(Float64ArrayData) {
public static inline var BYTES_PER_ELEMENT = 8;
public var length(get, never):Int;
public var view(get, never):ArrayBufferView;
public inline function new(elements:Int):Void {
this = new Float64ArrayData(elements);
}
inline function get_length():Int {
return this.length;
}
public inline function get_view():ArrayBufferView {
return ArrayBufferView.fromData(this);
}
@:arrayAccess public inline function get(index:Int):Float {
return this[index];
}
@:arrayAccess public inline function set(index:Int, value:Float):Float {
return this[index] = value;
}
public inline function sub(begin:Int, ?length:Int):Float64Array {
return fromData(this.subarray(begin, length == null ? this.length : begin + length));
}
public inline function subarray(?begin:Int, ?end:Int):Float64Array {
return fromData(this.subarray(begin, end));
}
public inline function getData():Float64ArrayData {
return this;
}
public static inline function fromData(d:Float64ArrayData):Float64Array {
return cast d;
}
public static function fromArray(a:Array<Float>, pos:Int = 0, ?length:Int):Float64Array {
if (length == null)
length = a.length - pos;
if (pos < 0 || length < 0 || pos + length > a.length)
throw Error.OutsideBounds;
if (pos == 0 && length == a.length)
return fromData(new Float64ArrayData(a));
var i = new Float64Array(a.length);
for (idx in 0...length)
i[idx] = a[idx + pos];
return i;
}
public static function fromBytes(bytes:haxe.io.Bytes, bytePos:Int = 0, ?length:Int):Float64Array {
if (length == null)
length = (bytes.length - bytePos) >> 3;
return fromData(new Float64ArrayData(bytes.getData(), bytePos, length));
}
}

View File

@ -0,0 +1,88 @@
/*
* Copyright (C)2005-2019 Haxe Foundation
*
* Permission is hereby granted, free of charge, to any person obtaining a
* copy of this software and associated documentation files (the "Software"),
* to deal in the Software without restriction, including without limitation
* the rights to use, copy, modify, merge, publish, distribute, sublicense,
* and/or sell copies of the Software, and to permit persons to whom the
* Software is furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
* DEALINGS IN THE SOFTWARE.
*/
package haxe.io;
typedef Int32ArrayData = js.lib.Int32Array;
@:coreApi
abstract Int32Array(Int32ArrayData) {
public static inline var BYTES_PER_ELEMENT = 4;
public var length(get, never):Int;
public var view(get, never):ArrayBufferView;
public inline function new(elements:Int) {
this = new Int32ArrayData(elements);
}
inline function get_length():Int {
return this.length;
}
public inline function get_view():ArrayBufferView {
return ArrayBufferView.fromData(this);
}
@:arrayAccess public inline function get(index:Int):Int {
return this[index];
}
@:arrayAccess public inline function set(index:Int, value:Int):Int {
return this[index] = value;
}
public inline function sub(begin:Int, ?length:Int):Int32Array {
return fromData(this.subarray(begin, length == null ? this.length : begin + length));
}
public inline function subarray(?begin:Int, ?end:Int):Int32Array {
return fromData(this.subarray(begin, end));
}
public inline function getData():Int32ArrayData {
return this;
}
public static inline function fromData(d:Int32ArrayData):Int32Array {
return cast d;
}
public static function fromArray(a:Array<Int>, pos:Int = 0, ?length:Int):Int32Array {
if (length == null)
length = a.length - pos;
if (pos < 0 || length < 0 || pos + length > a.length)
throw Error.OutsideBounds;
if (pos == 0 && length == a.length)
return fromData(new Int32ArrayData(a));
var i = new Int32Array(a.length);
for (idx in 0...length)
i[idx] = a[idx + pos];
return i;
}
public static function fromBytes(bytes:haxe.io.Bytes, bytePos:Int = 0, ?length:Int):Int32Array {
if (length == null)
length = (bytes.length - bytePos) >> 2;
return fromData(new Int32ArrayData(bytes.getData(), bytePos, length));
}
}

View File

@ -0,0 +1,88 @@
/*
* Copyright (C)2005-2019 Haxe Foundation
*
* Permission is hereby granted, free of charge, to any person obtaining a
* copy of this software and associated documentation files (the "Software"),
* to deal in the Software without restriction, including without limitation
* the rights to use, copy, modify, merge, publish, distribute, sublicense,
* and/or sell copies of the Software, and to permit persons to whom the
* Software is furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
* DEALINGS IN THE SOFTWARE.
*/
package haxe.io;
typedef UInt16ArrayData = js.lib.Uint16Array;
@:coreApi
abstract UInt16Array(UInt16ArrayData) {
public static inline var BYTES_PER_ELEMENT = 2;
public var length(get, never):Int;
public var view(get, never):ArrayBufferView;
public inline function new(elements:Int) {
this = new UInt16ArrayData(elements);
}
inline function get_length():Int {
return this.length;
}
public inline function get_view():ArrayBufferView {
return ArrayBufferView.fromData(this);
}
@:arrayAccess public inline function get(index:Int):Int {
return this[index];
}
@:arrayAccess public inline function set(index:Int, value:Int):Int {
return this[index] = value;
}
public inline function sub(begin:Int, ?length:Int):UInt16Array {
return fromData(this.subarray(begin, length == null ? this.length : begin + length));
}
public inline function subarray(?begin:Int, ?end:Int):UInt16Array {
return fromData(this.subarray(begin, end));
}
public inline function getData():UInt16ArrayData {
return this;
}
public static inline function fromData(d:UInt16ArrayData):UInt16Array {
return cast d;
}
public static function fromArray(a:Array<Int>, pos:Int = 0, ?length:Int):UInt16Array {
if (length == null)
length = a.length - pos;
if (pos < 0 || length < 0 || pos + length > a.length)
throw Error.OutsideBounds;
if (pos == 0 && length == a.length)
return fromData(new UInt16ArrayData(a));
var i = new UInt16Array(a.length);
for (idx in 0...length)
i[idx] = a[idx + pos];
return i;
}
public static function fromBytes(bytes:haxe.io.Bytes, bytePos:Int = 0, ?length:Int):UInt16Array {
if (length == null)
length = (bytes.length - bytePos) >> 1;
return fromData(new UInt16ArrayData(bytes.getData(), bytePos, length));
}
}

View File

@ -0,0 +1,88 @@
/*
* Copyright (C)2005-2019 Haxe Foundation
*
* Permission is hereby granted, free of charge, to any person obtaining a
* copy of this software and associated documentation files (the "Software"),
* to deal in the Software without restriction, including without limitation
* the rights to use, copy, modify, merge, publish, distribute, sublicense,
* and/or sell copies of the Software, and to permit persons to whom the
* Software is furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
* DEALINGS IN THE SOFTWARE.
*/
package haxe.io;
typedef UInt32ArrayData = js.lib.Uint32Array;
@:coreApi
abstract UInt32Array(UInt32ArrayData) {
public static inline var BYTES_PER_ELEMENT = 4;
public var length(get, never):Int;
public var view(get, never):ArrayBufferView;
public inline function new(elements:Int) {
this = new UInt32ArrayData(elements);
}
inline function get_length():Int {
return this.length;
}
public inline function get_view():ArrayBufferView {
return ArrayBufferView.fromData(this);
}
@:arrayAccess public inline function get(index:Int):UInt {
return this[index];
}
@:arrayAccess public inline function set(index:Int, value:UInt):UInt {
return this[index] = value;
}
public inline function sub(begin:Int, ?length:Int):UInt32Array {
return fromData(this.subarray(begin, length == null ? this.length : begin + length));
}
public inline function subarray(?begin:Int, ?end:Int):UInt32Array {
return fromData(this.subarray(begin, end));
}
public inline function getData():UInt32ArrayData {
return this;
}
public static inline function fromData(d:UInt32ArrayData):UInt32Array {
return cast d;
}
public static function fromArray(a:Array<UInt>, pos:Int = 0, ?length:Int):UInt32Array {
if (length == null)
length = a.length - pos;
if (pos < 0 || length < 0 || pos + length > a.length)
throw Error.OutsideBounds;
if (pos == 0 && length == a.length)
return fromData(new UInt32ArrayData(a));
var i = new UInt32Array(a.length);
for (idx in 0...length)
i[idx] = a[idx + pos];
return i;
}
public static function fromBytes(bytes:haxe.io.Bytes, bytePos:Int = 0, ?length:Int):UInt32Array {
if (length == null)
length = (bytes.length - bytePos) >> 2;
return fromData(new UInt32ArrayData(bytes.getData(), bytePos, length));
}
}

View File

@ -0,0 +1,88 @@
/*
* Copyright (C)2005-2019 Haxe Foundation
*
* Permission is hereby granted, free of charge, to any person obtaining a
* copy of this software and associated documentation files (the "Software"),
* to deal in the Software without restriction, including without limitation
* the rights to use, copy, modify, merge, publish, distribute, sublicense,
* and/or sell copies of the Software, and to permit persons to whom the
* Software is furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
* DEALINGS IN THE SOFTWARE.
*/
package haxe.io;
typedef UInt8ArrayData = js.lib.Uint8Array;
@:coreApi
abstract UInt8Array(UInt8ArrayData) {
public static inline var BYTES_PER_ELEMENT = 1;
public var length(get, never):Int;
public var view(get, never):ArrayBufferView;
public inline function new(elements:Int) {
this = new UInt8ArrayData(elements);
}
inline function get_length():Int {
return this.length;
}
public inline function get_view():ArrayBufferView {
return ArrayBufferView.fromData(this);
}
@:arrayAccess public inline function get(index:Int):Int {
return this[index];
}
@:arrayAccess public inline function set(index:Int, value:Int):Int {
return this[index] = value;
}
public inline function sub(begin:Int, ?length:Int):UInt8Array {
return fromData(this.subarray(begin, length == null ? this.length : begin + length));
}
public inline function subarray(?begin:Int, ?end:Int):UInt8Array {
return fromData(this.subarray(begin, end));
}
public inline function getData():UInt8ArrayData {
return this;
}
public static inline function fromData(d:UInt8ArrayData):UInt8Array {
return cast d;
}
public static function fromArray(a:Array<Int>, pos:Int = 0, ?length:Int):UInt8Array {
if (length == null)
length = a.length - pos;
if (pos < 0 || length < 0 || pos + length > a.length)
throw Error.OutsideBounds;
if (pos == 0 && length == a.length)
return fromData(new UInt8ArrayData(a));
var i = new UInt8Array(a.length);
for (idx in 0...length)
i[idx] = a[idx + pos];
return i;
}
public static function fromBytes(bytes:haxe.io.Bytes, bytePos:Int = 0, ?length:Int):UInt8Array {
if (length == null)
length = bytes.length - bytePos;
return fromData(new UInt8ArrayData(bytes.getData(), bytePos, length));
}
}