2
0
mirror of https://github.com/esiur/esiur-js.git synced 2025-06-27 15:23:11 +00:00
This commit is contained in:
2020-11-15 04:26:20 +03:00
parent a00b366d30
commit ec143272ae
20 changed files with 263 additions and 9499 deletions

View File

@ -112,6 +112,31 @@ export default class BinaryList
break;
case DataType.UInt8Array:
ars.push(this.list[i].value);
break;
case DataType.UInt16Array:
ars.push(DC.uint16ArrayToBytes(this.list[i].value));
break;
case DataType.UInt32Array:
ars.push(DC.uint32ArrayToBytes(this.list[i].value));
break;
case DataType.Int16Array:
ars.push(DC.int16ArrayToBytes(this.list[i].value));
break;
case DataType.Int32Array:
ars.push(DC.int32ArrayToBytes(this.list[i].value));
break;
case DataType.Float32Array:
ars.push(DC.float32ArrayToBytes(this.list[i].value));
break;
case DataType.Float64Array:
ars.push(DC.float64ArrayToBytes(this.list[i].value));
break;
//case DataType.Resource:
// ars.push(DC.uint32ToBytes(this.list[i].value.instance.id));
@ -127,7 +152,7 @@ export default class BinaryList
var length = 0;
ars.forEach(function(a){
length += a.length;
length += a.length ;//?? a.byteLength;
});
var rt = new Uint8Array(length);
@ -135,7 +160,7 @@ export default class BinaryList
var offset = 0;
for(var i = 0; i < ars.length; i++) {
rt.set(ars[i], offset);
offset+=ars[i].length;
offset+=ars[i].length;// ?? ars[i].byteLength;
}
return rt;

View File

@ -835,6 +835,18 @@ static getDataType(value, connection) {
|| value instanceof ArrayBuffer) {
return DataType.UInt8Array;
}
else if (value instanceof Uint16Array)
return DataType.UInt16Array;
else if (value instanceof Uint32Array)
return DataType.UInt32Array;
else if (value instanceof Int16Array)
return DataType.Int16Array;
else if (value instanceof Int32Array)
return DataType.Int32Array;
else if (value instanceof Float32Array)
return DataType.Float32Array;
else if (value instanceof Float64Array)
return DataType.Float64Array;
else if (value instanceof Number) {
// JS numbers are always 64-bit float
return DataType.Float64;

View File

@ -172,6 +172,71 @@ export default class DC extends Uint8Array
return list.toArray();
}
static uint16ArrayToBytes(values)
{
var rt = new DC(values.length * 2);
for(var i = 0; i < values.length; i++)
rt.setUint16(i * 2, values[i]);
return rt;
}
static int16ArrayToBytes(values)
{
var rt = new DC(values.length * 2);
for(var i = 0; i < values.length; i++)
rt.setInt16(i * 2, values[i]);
return rt;
}
static uint32ArrayToBytes(values)
{
var rt = new DC(values.length * 4);
for(var i = 0; i < values.length; i++)
rt.setUint32(i * 4, values[i]);
return rt;
}
static int32ArrayToBytes(values)
{
var rt = new DC(values.length * 4);
for(var i = 0; i < values.length; i++)
rt.setInt32(i * 4, values[i]);
return rt;
}
static int64ArrayToBytes(values)
{
var rt = new DC(values.length * 8);
for(var i = 0; i < values.length; i++)
rt.setInt64(i * 8, values[i]);
return rt;
}
static uint64ArrayToBytes(values)
{
var rt = new DC(values.length * 8);
for(var i = 0; i < values.length; i++)
rt.setUint64(i * 8, values[i]);
return rt;
}
static float32ArrayToBytes(values)
{
var rt = new DC(values.length * 4);
for(var i = 0; i < values.length; i++)
rt.setFloat32(i * 4, values[i]);
return rt;
}
static float64ArrayToBytes(values)
{
var rt = new DC(values.length * 8);
for(var i = 0; i < values.length; i++)
rt.setFloat64(i * 8, values[i]);
return rt;
}
append(src, offset, length)
{
if (!(src instanceof DC))
@ -304,6 +369,16 @@ export default class DC extends Uint8Array
return rt;
}
paste(offset, length, elementSize, func)
{
let rt = new dstType(length / elementSize);
let d = 0, end = offset + length;
for (let i = offset; i < end; i += elementSize)
rt[d++] = func.call(this, i);
return rt;
}
getInt16Array(offset, length)
{
return this.copy(offset, length, 2, this.getInt16, Int16Array);

View File

@ -122,6 +122,47 @@ export default class KeyList
this.values.splice(index, 1);
}
clear()
{
while(this.length > 0)
this.removeAt(0);
}
filter(selector)
{
if (selector instanceof Function){
return this.values.filter(selector);
}
else
{
let match = function(small, big)
{
if (small == big)
{
return true;
}
else if (typeof small == "object" && typeof big == "object" && small != null && big != null)
{
if (small.constructor.name == "Object")
{
for(var i in small)
if (!match(small[i], big[i]))
return false;
return true;
}
else
{
return false;
}
}
else
return false;
};
return this.values.filter((x) => match(selector, x));
}
}
get length()
{
return this.keys.length;

View File

@ -28,6 +28,14 @@
export default class Structure
{
toPairs() {
var rt = [];
for (var i in this)
if (!(this[i] instanceof Function))
rt.push({ key: i, value: this[i]});
return rt;
}
getKeys() {
var rt = [];
for (var i in this)