wenay-common 1.0.21 → 1.0.22
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/lib/{srcClient/index.js → index.js} +16 -16
- package/package.json +5 -1
- package/lib/src/Common/BaseTypes.d.ts +0 -38
- package/lib/src/Common/BaseTypes.js +0 -3
- package/lib/src/Common/BaseTypes.js.map +0 -1
- package/lib/src/Common/ByteStream.d.ts +0 -96
- package/lib/src/Common/ByteStream.js +0 -427
- package/lib/src/Common/ByteStream.js.map +0 -1
- package/lib/src/Common/Color.d.ts +0 -26
- package/lib/src/Common/Color.js +0 -52
- package/lib/src/Common/Color.js.map +0 -1
- package/lib/src/Common/Common.d.ts +0 -232
- package/lib/src/Common/Common.js +0 -615
- package/lib/src/Common/Common.js.map +0 -1
- package/lib/src/Common/List.d.ts +0 -64
- package/lib/src/Common/List.js +0 -194
- package/lib/src/Common/List.js.map +0 -1
- package/lib/src/Common/ListNodeAnd.d.ts +0 -46
- package/lib/src/Common/ListNodeAnd.js +0 -90
- package/lib/src/Common/ListNodeAnd.js.map +0 -1
- package/lib/src/Common/Math.d.ts +0 -27
- package/lib/src/Common/Math.js +0 -71
- package/lib/src/Common/Math.js.map +0 -1
- package/lib/src/Common/Time.d.ts +0 -181
- package/lib/src/Common/Time.js +0 -356
- package/lib/src/Common/Time.js.map +0 -1
- package/lib/src/Exchange/Bars.d.ts +0 -182
- package/lib/src/Exchange/Bars.js +0 -454
- package/lib/src/Exchange/Bars.js.map +0 -1
- package/lib/src/Exchange/ConnectData/Binance/BinanceLib/base.d.ts +0 -28
- package/lib/src/Exchange/ConnectData/Binance/BinanceLib/base.js +0 -9
- package/lib/src/Exchange/ConnectData/Binance/BinanceLib/base.js.map +0 -1
- package/lib/src/Exchange/ConnectData/Binance/BinanceLib/spot.d.ts +0 -600
- package/lib/src/Exchange/ConnectData/Binance/BinanceLib/spot.js +0 -356
- package/lib/src/Exchange/ConnectData/Binance/BinanceLib/spot.js.map +0 -1
- package/lib/src/Exchange/ConnectData/Binance/BinanceLib/type.d.ts +0 -4
- package/lib/src/Exchange/ConnectData/Binance/BinanceLib/type.js +0 -108
- package/lib/src/Exchange/ConnectData/Binance/BinanceLib/type.js.map +0 -1
- package/lib/src/Exchange/ConnectData/Binance/commonOrder.d.ts +0 -1
- package/lib/src/Exchange/ConnectData/Binance/commonOrder.js +0 -9
- package/lib/src/Exchange/ConnectData/Binance/commonOrder.js.map +0 -1
- package/lib/src/Exchange/ConnectData/Binance/funcTimeWait.d.ts +0 -22
- package/lib/src/Exchange/ConnectData/Binance/funcTimeWait.js +0 -44
- package/lib/src/Exchange/ConnectData/Binance/funcTimeWait.js.map +0 -1
- package/lib/src/Exchange/ConnectData/Binance/interfaces.d.ts +0 -345
- package/lib/src/Exchange/ConnectData/Binance/interfaces.js +0 -3
- package/lib/src/Exchange/ConnectData/Binance/interfaces.js.map +0 -1
- package/lib/src/Exchange/ConnectData/Binance/order.d.ts +0 -204
- package/lib/src/Exchange/ConnectData/Binance/order.js +0 -417
- package/lib/src/Exchange/ConnectData/Binance/order.js.map +0 -1
- package/lib/src/Exchange/ConnectData/Binance/signatureCoder.d.ts +0 -14
- package/lib/src/Exchange/ConnectData/Binance/signatureCoder.js +0 -26
- package/lib/src/Exchange/ConnectData/Binance/signatureCoder.js.map +0 -1
- package/lib/src/Exchange/ConnectData/Binance/use.d.ts +0 -44
- package/lib/src/Exchange/ConnectData/Binance/use.js +0 -90
- package/lib/src/Exchange/ConnectData/Binance/use.js.map +0 -1
- package/lib/src/Exchange/ConnectData/Binance.d.ts +0 -122
- package/lib/src/Exchange/ConnectData/Binance.js +0 -514
- package/lib/src/Exchange/ConnectData/Binance.js.map +0 -1
- package/lib/src/Exchange/IHistoryBase.d.ts +0 -157
- package/lib/src/Exchange/IHistoryBase.js +0 -3
- package/lib/src/Exchange/IHistoryBase.js.map +0 -1
- package/lib/src/Exchange/LoadBase.d.ts +0 -59
- package/lib/src/Exchange/LoadBase.js +0 -103
- package/lib/src/Exchange/LoadBase.js.map +0 -1
- package/lib/src/Exchange/MarketData.d.ts +0 -78
- package/lib/src/Exchange/MarketData.js +0 -358
- package/lib/src/Exchange/MarketData.js.map +0 -1
- package/lib/src/Exchange/mini.d.ts +0 -68
- package/lib/src/Exchange/mini.js +0 -3
- package/lib/src/Exchange/mini.js.map +0 -1
- package/lib/srcClient/index.d.ts +0 -15
- package/lib/srcClient/index.js.map +0 -1
- package/lib/srcServer/index.d.ts +0 -16
- package/lib/srcServer/index.js +0 -40
- package/lib/srcServer/index.js.map +0 -1
|
@@ -15,25 +15,25 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
|
15
15
|
};
|
|
16
16
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
17
|
exports.test = exports.LoadCandles = exports.List = exports.Math = exports.ListNodeAnd = exports.Color = exports.Time = exports.Common = exports.BaseTypes = void 0;
|
|
18
|
-
__exportStar(require("
|
|
19
|
-
__exportStar(require("
|
|
20
|
-
__exportStar(require("
|
|
21
|
-
__exportStar(require("
|
|
22
|
-
__exportStar(require("
|
|
23
|
-
__exportStar(require("
|
|
24
|
-
exports.BaseTypes = require("
|
|
25
|
-
exports.Common = require("
|
|
26
|
-
exports.Time = require("
|
|
27
|
-
exports.Color = require("
|
|
28
|
-
exports.ListNodeAnd = require("
|
|
29
|
-
exports.Math = require("
|
|
30
|
-
exports.List = require("
|
|
31
|
-
exports.LoadCandles = require("
|
|
32
|
-
const ListNodeAnd_1 = require("
|
|
18
|
+
__exportStar(require("./Common/Time"), exports);
|
|
19
|
+
__exportStar(require("./Common/Common"), exports);
|
|
20
|
+
__exportStar(require("./Common/Color"), exports);
|
|
21
|
+
__exportStar(require("./Common/ListNodeAnd"), exports);
|
|
22
|
+
__exportStar(require("./Common/Math"), exports);
|
|
23
|
+
__exportStar(require("./Exchange/ConnectData/Binance"), exports);
|
|
24
|
+
exports.BaseTypes = require("./Common/BaseTypes");
|
|
25
|
+
exports.Common = require("./Common/Common");
|
|
26
|
+
exports.Time = require("./Common/Time");
|
|
27
|
+
exports.Color = require("./Common/Color");
|
|
28
|
+
exports.ListNodeAnd = require("./Common/ListNodeAnd");
|
|
29
|
+
exports.Math = require("./Common/Math");
|
|
30
|
+
exports.List = require("./Common/List");
|
|
31
|
+
exports.LoadCandles = require("./Exchange/ConnectData/Binance");
|
|
32
|
+
const ListNodeAnd_1 = require("./Common/ListNodeAnd");
|
|
33
33
|
function test() {
|
|
34
34
|
const tt = new ListNodeAnd_1.CListNodeAnd();
|
|
35
35
|
console.log("test");
|
|
36
|
-
console.log("lalalal
|
|
36
|
+
console.log("lalalal");
|
|
37
37
|
}
|
|
38
38
|
exports.test = test;
|
|
39
39
|
//# sourceMappingURL=index.js.map
|
package/package.json
CHANGED
|
@@ -1,10 +1,14 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "wenay-common",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.22",
|
|
4
4
|
"description": "math math math",
|
|
5
5
|
"strict": true,
|
|
6
|
+
"main": "lib/index.js",
|
|
7
|
+
"types": "lib/index.d.ts",
|
|
6
8
|
"scripts": {
|
|
7
9
|
"build": "tsc",
|
|
10
|
+
"build:client": "tsc",
|
|
11
|
+
"build:server": "tsc",
|
|
8
12
|
"test": "",
|
|
9
13
|
"prepare": "npm run build",
|
|
10
14
|
"prepublishOnly": "npm test"
|
|
@@ -1,38 +0,0 @@
|
|
|
1
|
-
export type Immutable<T> = ReadonlyFull<T> & {
|
|
2
|
-
readonly Mutable: false;
|
|
3
|
-
};
|
|
4
|
-
export type ReadonlyFull<T> = T extends ((...args: any) => any) ? T : T extends number | string | boolean | symbol ? T : T extends const_Date ? const_Date : {
|
|
5
|
-
readonly [P in keyof T]: ReadonlyFull<T[P]>;
|
|
6
|
-
};
|
|
7
|
-
export type MutableFull<T> = T extends ((...args: any) => any) ? T : T extends number | string | boolean | symbol ? T : T extends const_Date ? const_Date : {
|
|
8
|
-
-readonly [P in keyof T]: MutableFull<T[P]>;
|
|
9
|
-
};
|
|
10
|
-
export type Mutable<T> = {
|
|
11
|
-
-readonly [P in keyof T]: T[P];
|
|
12
|
-
};
|
|
13
|
-
export type const_Date = Omit<Date, "setTime" | "setFullYear" | "setMonth" | "setDate" | "setHours" | "setMinutes" | "setSeconds" | "setMilliseconds" | "setUTCFullYear" | "setUTCMonth" | "setUTCDate" | "setUTCHours" | "setUTCMinutes" | "setUTCSeconds" | "setUTCMilliseconds">;
|
|
14
|
-
export interface DateConstructor {
|
|
15
|
-
new (value: number | string | Date | const_Date): Date;
|
|
16
|
-
}
|
|
17
|
-
export declare var Date: DateConstructor;
|
|
18
|
-
export interface ArrayConstructor {
|
|
19
|
-
isArray<T>(a: unknown): a is readonly unknown[];
|
|
20
|
-
isArray<T>(a: readonly T[]): a is readonly T[];
|
|
21
|
-
isArray<T>(a: T[]): a is T[];
|
|
22
|
-
}
|
|
23
|
-
export type ReplaceKeyType<Struct extends object, Key extends keyof Struct, NewType> = {
|
|
24
|
-
[key in keyof Struct]: key extends Key ? NewType : Struct[key];
|
|
25
|
-
};
|
|
26
|
-
export type KeysByTypeUnchecked<T, PickT> = {
|
|
27
|
-
[key in keyof T]: T[key] extends PickT ? key : never;
|
|
28
|
-
}[keyof T];
|
|
29
|
-
export type KeysByType<T, PickT extends T[keyof T]> = {
|
|
30
|
-
[key in keyof T]: T[key] extends PickT ? key : never;
|
|
31
|
-
}[keyof T];
|
|
32
|
-
export type KeysWithoutType<T, ExcludeT> = {
|
|
33
|
-
[key in keyof T]: T[key] extends ExcludeT ? never : key;
|
|
34
|
-
}[keyof T];
|
|
35
|
-
export type OmitTypes<T, ExcludeT> = Pick<T, KeysWithoutType<T, ExcludeT>>;
|
|
36
|
-
export type PickTypes<T, PickT extends T[keyof T]> = Pick<T, KeysByType<T, PickT>>;
|
|
37
|
-
export type PickTypesUnchecked<T, PickT> = Pick<T, KeysByTypeUnchecked<T, PickT>>;
|
|
38
|
-
export type RequiredExcept<T, E extends keyof T> = Required<Omit<T, E>> & Pick<T, E>;
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"BaseTypes.js","sourceRoot":"","sources":["../../../src/Common/BaseTypes.ts"],"names":[],"mappings":""}
|
|
@@ -1,96 +0,0 @@
|
|
|
1
|
-
import { const_Date } from "./BaseTypes";
|
|
2
|
-
export type NumericTypes = "int8" | "int16" | "int24" | "int32" | "int48" | "int64" | "float" | "double" | "uint8" | "uint16" | "uint24" | "uint32" | "uint48" | "uint64";
|
|
3
|
-
export declare class Nullable<T extends NumericTypes> {
|
|
4
|
-
value: T;
|
|
5
|
-
constructor(type: T);
|
|
6
|
-
}
|
|
7
|
-
export declare function nullable(type: NumericTypes): Nullable<NumericTypes>;
|
|
8
|
-
export type WritableToBytes = {
|
|
9
|
-
write(stream: ByteStreamW): boolean | void;
|
|
10
|
-
};
|
|
11
|
-
export declare class ByteStreamW {
|
|
12
|
-
protected _view: DataView;
|
|
13
|
-
protected _pos: number;
|
|
14
|
-
protected _isThrowable: boolean;
|
|
15
|
-
protected _buffer(): ArrayBuffer;
|
|
16
|
-
protected resize(size: number): void;
|
|
17
|
-
constructor(view?: DataView);
|
|
18
|
-
get length(): number;
|
|
19
|
-
get data(): Readonly<DataView>;
|
|
20
|
-
noThrow(): ByteStreamW;
|
|
21
|
-
private _ensureAllocation;
|
|
22
|
-
private _setInt8;
|
|
23
|
-
private _setInt16;
|
|
24
|
-
private _setInt32;
|
|
25
|
-
protected _push(value: number, bytes: number, isInteger: boolean): this;
|
|
26
|
-
pushInt8(value: number): this;
|
|
27
|
-
pushInt16(value: number): this;
|
|
28
|
-
pushInt24(value: number): this;
|
|
29
|
-
pushInt32(value: number): this;
|
|
30
|
-
pushInt48(value: number): this;
|
|
31
|
-
pushInt64(value: number): this;
|
|
32
|
-
pushFloat(value: number): this;
|
|
33
|
-
pushDouble(value: number): this;
|
|
34
|
-
pushBool(value: boolean): this;
|
|
35
|
-
pushDate(value: const_Date): this;
|
|
36
|
-
private _checkResult;
|
|
37
|
-
push(obj: WritableToBytes): this | null;
|
|
38
|
-
pushNullable(obj: WritableToBytes | null): this | null;
|
|
39
|
-
pushNumber(value: number, type: NumericTypes | Nullable<NumericTypes>): boolean;
|
|
40
|
-
pushNumbers(values: readonly number[], type: NumericTypes | Nullable<NumericTypes>): this | null;
|
|
41
|
-
pushArrayByFunc<T>(array: Iterable<T>, func: (stream: ByteStreamW, item: T) => boolean | void, maxlength?: number): this | null;
|
|
42
|
-
protected _getWriteFuncForNumeric(type: NumericTypes | Nullable<NumericTypes>): (stream: ByteStreamW, value: number) => boolean;
|
|
43
|
-
pushArrayNumeric(array: Iterable<number>, type: NumericTypes | Nullable<NumericTypes>, maxlength?: number): this | null;
|
|
44
|
-
pushArray<T extends WritableToBytes>(array: Iterable<T> | Int8Array | Uint8Array, maxlength?: number): this | null;
|
|
45
|
-
pushArrayOfNullable<T extends WritableToBytes | null>(array: Iterable<T>, maxlength?: number): this | null;
|
|
46
|
-
private _pushNullableString;
|
|
47
|
-
pushAnsi(text: string | null): this;
|
|
48
|
-
pushUnicode(text: string | null): this;
|
|
49
|
-
}
|
|
50
|
-
type ReaderFromBytes<T> = {
|
|
51
|
-
read(stream: ByteStreamR | any): T;
|
|
52
|
-
};
|
|
53
|
-
declare class ByteStreamR_<throwable extends boolean> {
|
|
54
|
-
protected _wstream?: Readonly<ByteStreamW>;
|
|
55
|
-
protected _view: Readonly<DataView>;
|
|
56
|
-
protected _pos: number;
|
|
57
|
-
private isThrowable;
|
|
58
|
-
constructor(data: Readonly<ArrayBuffer | DataView>);
|
|
59
|
-
UpdateFrom(stream: Readonly<ByteStreamW>): void;
|
|
60
|
-
private __readNumber;
|
|
61
|
-
_readNumber(bytes: number, isInteger: boolean, isSigned?: boolean): throwable extends true ? number : number | null;
|
|
62
|
-
noThrow(): ByteStreamR_<false>;
|
|
63
|
-
readInt8(): throwable extends true ? number : number | null;
|
|
64
|
-
readInt16(): throwable extends true ? number : number | null;
|
|
65
|
-
readInt24(): throwable extends true ? number : number | null;
|
|
66
|
-
readInt32(): throwable extends true ? number : number | null;
|
|
67
|
-
readInt48(): throwable extends true ? number : number | null;
|
|
68
|
-
readInt64(): throwable extends true ? number : number | null;
|
|
69
|
-
readUint8(): throwable extends true ? number : number | null;
|
|
70
|
-
readUint16(): throwable extends true ? number : number | null;
|
|
71
|
-
readUint24(): throwable extends true ? number : number | null;
|
|
72
|
-
readUint32(): throwable extends true ? number : number | null;
|
|
73
|
-
readUint48(): throwable extends true ? number : number | null;
|
|
74
|
-
readUint64(): throwable extends true ? number : number | null;
|
|
75
|
-
readFloat(): throwable extends true ? number : number | null;
|
|
76
|
-
readDouble(): throwable extends true ? number : number | null;
|
|
77
|
-
readBool(): throwable extends true ? boolean : boolean | null;
|
|
78
|
-
readNumber(type: NumericTypes | Nullable<NumericTypes>): throwable extends true ? number : number | null;
|
|
79
|
-
readDate(): Date;
|
|
80
|
-
toType<T>(value: T): throwable extends true ? T : T | null;
|
|
81
|
-
protected _getReadFuncForNumeric<T extends NumericTypes | Nullable<NumericTypes>>(type: T): (stream: ByteStreamR_<throwable>) => throwable extends true ? number : T extends NumericTypes ? number : number | null;
|
|
82
|
-
readNullable<T>(reader: ReaderFromBytes<NonNullable<T>>): NonNullable<T> | null;
|
|
83
|
-
readArray<T>(func: (stream: ByteStreamR) => NonNullable<T>): T[];
|
|
84
|
-
readArray<T extends NumericTypes | Nullable<NumericTypes>>(type: T): T extends NumericTypes ? number[] : (number | null)[];
|
|
85
|
-
readArray<T>(reader: ReaderFromBytes<NonNullable<T>>): T[];
|
|
86
|
-
protected _readArrayByFunc<T>(func: (stream: ByteStreamR | any) => T): T[] | null;
|
|
87
|
-
protected _readArrayOfNumeric(type: NumericTypes): (throwable extends true ? number : number)[] | null;
|
|
88
|
-
protected _readArrayByReader<T>(reader: ReaderFromBytes<T>): T[] | null;
|
|
89
|
-
private _readNullableString;
|
|
90
|
-
readAnsi(): string | null;
|
|
91
|
-
readUnicode(): string | null;
|
|
92
|
-
}
|
|
93
|
-
export declare class ByteStreamR extends ByteStreamR_<true> {
|
|
94
|
-
constructor(data: Readonly<ArrayBuffer | DataView>);
|
|
95
|
-
}
|
|
96
|
-
export {};
|
|
@@ -1,427 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.ByteStreamR = exports.ByteStreamW = exports.nullable = exports.Nullable = void 0;
|
|
4
|
-
function createCopyOfBuffer(src, length = src.byteLength) {
|
|
5
|
-
let dst = new ArrayBuffer(length);
|
|
6
|
-
new Uint8Array(dst).set(new Uint8Array(src));
|
|
7
|
-
return dst;
|
|
8
|
-
}
|
|
9
|
-
class Nullable {
|
|
10
|
-
value;
|
|
11
|
-
constructor(type) { this.value = type; }
|
|
12
|
-
}
|
|
13
|
-
exports.Nullable = Nullable;
|
|
14
|
-
function nullable(type) { return new Nullable(type); }
|
|
15
|
-
exports.nullable = nullable;
|
|
16
|
-
function __getNumericTypeInfo(type) {
|
|
17
|
-
switch (type) {
|
|
18
|
-
case "int8": return [1];
|
|
19
|
-
case "uint8": return [1, false];
|
|
20
|
-
case "int16": return [2];
|
|
21
|
-
case "uint16": return [2, false];
|
|
22
|
-
case "int24": return [3];
|
|
23
|
-
case "uint24": return [3, false];
|
|
24
|
-
case "int32": return [4];
|
|
25
|
-
case "uint32": return [4, false];
|
|
26
|
-
case "int48": return [6];
|
|
27
|
-
case "uint48": return [6, false];
|
|
28
|
-
case "int64": return [8];
|
|
29
|
-
case "uint64": return [8, false];
|
|
30
|
-
case "float": return [4, true, false];
|
|
31
|
-
case "double": return [8, true, false];
|
|
32
|
-
default: throw "wrong type: " + type;
|
|
33
|
-
}
|
|
34
|
-
}
|
|
35
|
-
;
|
|
36
|
-
function getNumericTypeInfo(type) {
|
|
37
|
-
let [size, signed = true, integer = true] = __getNumericTypeInfo(type) ?? [0];
|
|
38
|
-
if (!size)
|
|
39
|
-
return null;
|
|
40
|
-
return { size, signed, integer };
|
|
41
|
-
}
|
|
42
|
-
class ByteStreamW {
|
|
43
|
-
_view = new DataView(new ArrayBuffer(0));
|
|
44
|
-
_pos = 0;
|
|
45
|
-
_isThrowable = true;
|
|
46
|
-
_buffer() { return this._view?.buffer; }
|
|
47
|
-
resize(size) { let buf = createCopyOfBuffer(this._buffer(), size); this._view = new DataView(buf); }
|
|
48
|
-
constructor(view) { this.resize(0); }
|
|
49
|
-
get length() { return this._pos; }
|
|
50
|
-
get data() { return new DataView(this._buffer(), 0, this._pos); }
|
|
51
|
-
noThrow() { let other = new ByteStreamW(this._view); other._pos = this._pos; other._isThrowable = false; return other; }
|
|
52
|
-
_ensureAllocation(bytes) {
|
|
53
|
-
let minSize = this._pos + bytes;
|
|
54
|
-
if (minSize > this._view.byteLength)
|
|
55
|
-
for (let extraSize = Math.max(minSize * 0.5, 32); extraSize >= 0; extraSize /= 2) {
|
|
56
|
-
try {
|
|
57
|
-
this.resize(minSize + extraSize);
|
|
58
|
-
break;
|
|
59
|
-
}
|
|
60
|
-
catch (e) {
|
|
61
|
-
if (extraSize < 1)
|
|
62
|
-
throw (e);
|
|
63
|
-
}
|
|
64
|
-
}
|
|
65
|
-
}
|
|
66
|
-
_setInt8(pos, value) { if ((value & 1 << 7) != 0)
|
|
67
|
-
this._view.setInt8(pos, value);
|
|
68
|
-
else
|
|
69
|
-
this._view.setUint8(pos, value); }
|
|
70
|
-
_setInt16(pos, value) { if ((value & 1 << 15) != 0)
|
|
71
|
-
this._view.setInt16(pos, value);
|
|
72
|
-
else
|
|
73
|
-
this._view.setUint16(pos, value); }
|
|
74
|
-
_setInt32(pos, value) { if ((value & 1 << 31) != 0)
|
|
75
|
-
this._view.setInt32(pos, value);
|
|
76
|
-
else
|
|
77
|
-
this._view.setUint32(pos, value); }
|
|
78
|
-
_push(value, bytes, isInteger) {
|
|
79
|
-
let pos = this._pos;
|
|
80
|
-
this._ensureAllocation(bytes);
|
|
81
|
-
let view = this._view;
|
|
82
|
-
if (isNaN(value))
|
|
83
|
-
throw "Failed to save NaN";
|
|
84
|
-
if (isInteger && !Number.isInteger(value))
|
|
85
|
-
throw "Failed to save value " + value + " as integer";
|
|
86
|
-
if (isInteger)
|
|
87
|
-
switch (bytes) {
|
|
88
|
-
case 1:
|
|
89
|
-
this._setInt8(pos, value);
|
|
90
|
-
break;
|
|
91
|
-
case 2:
|
|
92
|
-
this._setInt16(pos, value);
|
|
93
|
-
break;
|
|
94
|
-
case 3:
|
|
95
|
-
this._setInt16(pos, value);
|
|
96
|
-
this._setInt8(pos + 2, value >> 16);
|
|
97
|
-
break;
|
|
98
|
-
case 4:
|
|
99
|
-
this._setInt32(pos, value);
|
|
100
|
-
break;
|
|
101
|
-
case 6:
|
|
102
|
-
this._setInt32(pos, value);
|
|
103
|
-
this._setInt16(pos + 4, value / 0x10000000);
|
|
104
|
-
break;
|
|
105
|
-
case 8:
|
|
106
|
-
this._setInt32(pos, value);
|
|
107
|
-
this._setInt32(pos + 4, value / 0x10000000);
|
|
108
|
-
break;
|
|
109
|
-
default: throw ("Wrong byte length: " + bytes);
|
|
110
|
-
}
|
|
111
|
-
else
|
|
112
|
-
switch (bytes) {
|
|
113
|
-
case 4:
|
|
114
|
-
view.setFloat32(pos, value);
|
|
115
|
-
break;
|
|
116
|
-
case 8:
|
|
117
|
-
view.setFloat64(pos, value);
|
|
118
|
-
break;
|
|
119
|
-
default: throw ("Wrong byte length: " + bytes);
|
|
120
|
-
}
|
|
121
|
-
this._pos += bytes;
|
|
122
|
-
return this;
|
|
123
|
-
}
|
|
124
|
-
pushInt8(value) { return this._push(value, 1, true); }
|
|
125
|
-
pushInt16(value) { return this._push(value, 2, true); }
|
|
126
|
-
pushInt24(value) { return this._push(value, 3, true); }
|
|
127
|
-
pushInt32(value) { return this._push(value, 4, true); }
|
|
128
|
-
pushInt48(value) { return this._push(value, 6, true); }
|
|
129
|
-
pushInt64(value) { return this._push(value, 8, true); }
|
|
130
|
-
pushFloat(value) { return this._push(value, 4, false); }
|
|
131
|
-
pushDouble(value) { return this._push(value, 8, false); }
|
|
132
|
-
pushBool(value) { return this.pushInt8(value == true ? 1 : 0); }
|
|
133
|
-
pushDate(value) { return this.pushInt64(value.valueOf()); }
|
|
134
|
-
_checkResult(result, msg) { if (result == false && this._isThrowable)
|
|
135
|
-
throw ("Failed to write " + msg); return result != false; }
|
|
136
|
-
push(obj) { let ok = obj.write(this); return this._checkResult(ok, () => "object") ? this : null; }
|
|
137
|
-
pushNullable(obj) { let ok = this.pushBool(obj != null) ? obj?.write(this) : false; return this._checkResult(ok, () => "object") ? this : null; }
|
|
138
|
-
pushNumber(value, type) { return this._getWriteFuncForNumeric(type)(this, value); }
|
|
139
|
-
pushNumbers(values, type) { for (let value of values)
|
|
140
|
-
if (!this.pushNumber(value, type))
|
|
141
|
-
return null; return this; }
|
|
142
|
-
pushArrayByFunc(array, func, maxlength) {
|
|
143
|
-
let oldpos = this._pos;
|
|
144
|
-
this.pushInt32(0);
|
|
145
|
-
let i = 0;
|
|
146
|
-
for (let value of array) {
|
|
147
|
-
if (func(this, value) == false)
|
|
148
|
-
if (this._isThrowable)
|
|
149
|
-
throw ("Failed to write array item №" + i);
|
|
150
|
-
else
|
|
151
|
-
return null;
|
|
152
|
-
i++;
|
|
153
|
-
if (i === maxlength)
|
|
154
|
-
break;
|
|
155
|
-
}
|
|
156
|
-
this._view.setUint32(oldpos, i);
|
|
157
|
-
return this;
|
|
158
|
-
}
|
|
159
|
-
_getWriteFuncForNumeric(type) {
|
|
160
|
-
let isNullable = false;
|
|
161
|
-
if (type instanceof Nullable) {
|
|
162
|
-
type = type.value;
|
|
163
|
-
isNullable = true;
|
|
164
|
-
}
|
|
165
|
-
let typeInfo = getNumericTypeInfo(type);
|
|
166
|
-
if (!typeInfo)
|
|
167
|
-
throw ("Wrong type: " + type);
|
|
168
|
-
return (stream, value) => { return (isNullable ? stream.pushBool(value != null) : stream)?._push(value, typeInfo.size, typeInfo.integer) != null; };
|
|
169
|
-
}
|
|
170
|
-
pushArrayNumeric(array, type, maxlength) {
|
|
171
|
-
return this.pushArrayByFunc(array, this._getWriteFuncForNumeric(type), maxlength);
|
|
172
|
-
}
|
|
173
|
-
pushArray(array, maxlength) {
|
|
174
|
-
if (array instanceof Int8Array || array instanceof Uint8Array) {
|
|
175
|
-
let length = Math.min(array.length, maxlength ?? array.length);
|
|
176
|
-
this._ensureAllocation(length + 4);
|
|
177
|
-
this.pushInt32(length);
|
|
178
|
-
let arrayClass = (array instanceof Int8Array) ? Int8Array : Uint8Array;
|
|
179
|
-
if (length != array.length)
|
|
180
|
-
array = new arrayClass(array, 0, length);
|
|
181
|
-
new arrayClass(this._buffer()).set(array, this._pos);
|
|
182
|
-
return this;
|
|
183
|
-
}
|
|
184
|
-
let func = (stream, item) => item.write(stream) != false;
|
|
185
|
-
return this.pushArrayByFunc(array, func, maxlength);
|
|
186
|
-
}
|
|
187
|
-
pushArrayOfNullable(array, maxlength) {
|
|
188
|
-
let func = (stream, item) => stream.pushBool(item != null) && item?.write(stream) != false;
|
|
189
|
-
return this.pushArrayByFunc(array, func, maxlength);
|
|
190
|
-
}
|
|
191
|
-
_pushNullableString(text, charSize) {
|
|
192
|
-
this.pushBool(text != null);
|
|
193
|
-
if (text == null)
|
|
194
|
-
return this;
|
|
195
|
-
let length = text.length;
|
|
196
|
-
let p = this._pos;
|
|
197
|
-
this._ensureAllocation((length + 1) * charSize);
|
|
198
|
-
if (charSize == 1) {
|
|
199
|
-
for (let i = 0; i < length; i++) {
|
|
200
|
-
this._view.setUint8(this._pos, text.charCodeAt(i));
|
|
201
|
-
this._pos++;
|
|
202
|
-
}
|
|
203
|
-
this._view.setUint8(this._pos, 0);
|
|
204
|
-
}
|
|
205
|
-
else {
|
|
206
|
-
for (let i = 0; i < length; i++) {
|
|
207
|
-
this._view.setUint16(this._pos, text.charCodeAt(i));
|
|
208
|
-
this._pos += 2;
|
|
209
|
-
}
|
|
210
|
-
this._view.setUint16(this._pos, 0);
|
|
211
|
-
}
|
|
212
|
-
this._pos += charSize;
|
|
213
|
-
return this;
|
|
214
|
-
}
|
|
215
|
-
pushAnsi(text) { return this._pushNullableString(text, 1); }
|
|
216
|
-
pushUnicode(text) { return this._pushNullableString(text, 2); }
|
|
217
|
-
}
|
|
218
|
-
exports.ByteStreamW = ByteStreamW;
|
|
219
|
-
class ByteStreamR_ {
|
|
220
|
-
_wstream;
|
|
221
|
-
_view;
|
|
222
|
-
_pos = 0;
|
|
223
|
-
isThrowable = true;
|
|
224
|
-
constructor(data) { this._view = (data instanceof ArrayBuffer) ? new DataView(data) : data; }
|
|
225
|
-
UpdateFrom(stream) {
|
|
226
|
-
console.assert(stream != null);
|
|
227
|
-
if (stream != this._wstream)
|
|
228
|
-
if (!this._wstream)
|
|
229
|
-
this._wstream = stream;
|
|
230
|
-
else
|
|
231
|
-
throw ("Stream is not same as before!");
|
|
232
|
-
this._view = stream.data;
|
|
233
|
-
}
|
|
234
|
-
__readNumber(bytes, isInteger, isSigned = true) {
|
|
235
|
-
let pos = this._pos;
|
|
236
|
-
let view = this._view;
|
|
237
|
-
if (pos + bytes > view.byteLength)
|
|
238
|
-
if (this.isThrowable) {
|
|
239
|
-
console.trace();
|
|
240
|
-
throw ("Not enough stream size for reading a value");
|
|
241
|
-
}
|
|
242
|
-
else
|
|
243
|
-
return null;
|
|
244
|
-
let value = function () {
|
|
245
|
-
if (isInteger) {
|
|
246
|
-
if (isSigned) {
|
|
247
|
-
switch (bytes) {
|
|
248
|
-
case 1: return view.getInt8(pos);
|
|
249
|
-
case 2: return view.getInt16(pos);
|
|
250
|
-
case 3: return view.getInt16(pos) | (view.getInt8(pos + 2) << 16);
|
|
251
|
-
case 4: return view.getInt32(pos);
|
|
252
|
-
case 6: return view.getInt32(pos) | view.getInt16(pos + 4) * 0x10000000;
|
|
253
|
-
case 8: return view.getInt32(pos) | view.getInt32(pos + 4) * 0x10000000;
|
|
254
|
-
}
|
|
255
|
-
}
|
|
256
|
-
else {
|
|
257
|
-
switch (bytes) {
|
|
258
|
-
case 1: return view.getUint8(pos);
|
|
259
|
-
case 2: return view.getUint16(pos);
|
|
260
|
-
case 3: return view.getUint16(pos) | (view.getUint8(pos + 2) << 16);
|
|
261
|
-
case 4: return view.getUint32(pos);
|
|
262
|
-
case 6: return view.getUint32(pos) | view.getUint16(pos + 4) * 0x10000000;
|
|
263
|
-
case 8: return view.getUint32(pos) | view.getUint32(pos + 4) * 0x10000000;
|
|
264
|
-
}
|
|
265
|
-
}
|
|
266
|
-
}
|
|
267
|
-
else
|
|
268
|
-
switch (bytes) {
|
|
269
|
-
case 4: return view.getFloat32(pos);
|
|
270
|
-
case 8: return view.getFloat64(pos);
|
|
271
|
-
}
|
|
272
|
-
return null;
|
|
273
|
-
}();
|
|
274
|
-
if (value == null)
|
|
275
|
-
if (this.isThrowable)
|
|
276
|
-
throw ("Wrong byte length: " + bytes);
|
|
277
|
-
else
|
|
278
|
-
return null;
|
|
279
|
-
this._pos += bytes;
|
|
280
|
-
return value;
|
|
281
|
-
}
|
|
282
|
-
_readNumber(bytes, isInteger, isSigned = true) { return this.__readNumber(bytes, isInteger, isSigned); }
|
|
283
|
-
noThrow() { if (!this.isThrowable)
|
|
284
|
-
return this; let other = new ByteStreamR_(this._view); other._pos = this._pos; other.isThrowable = false; return other; }
|
|
285
|
-
readInt8() { return this._readNumber(1, true); }
|
|
286
|
-
readInt16() { return this._readNumber(2, true); }
|
|
287
|
-
readInt24() { return this._readNumber(3, true); }
|
|
288
|
-
readInt32() { return this._readNumber(4, true); }
|
|
289
|
-
readInt48() { return this._readNumber(6, true); }
|
|
290
|
-
readInt64() { return this._readNumber(8, true); }
|
|
291
|
-
readUint8() { return this._readNumber(1, true, false); }
|
|
292
|
-
readUint16() { return this._readNumber(2, true, false); }
|
|
293
|
-
readUint24() { return this._readNumber(3, true, false); }
|
|
294
|
-
readUint32() { return this._readNumber(4, true, false); }
|
|
295
|
-
readUint48() { return this._readNumber(6, true, false); }
|
|
296
|
-
readUint64() { return this._readNumber(8, true, false); }
|
|
297
|
-
readFloat() { return this._readNumber(4, false); }
|
|
298
|
-
readDouble() { return this._readNumber(8, false); }
|
|
299
|
-
readBool() { let res = this.readInt8(); return (res != null ? res != 0 : null); }
|
|
300
|
-
readNumber(type) { return this._getReadFuncForNumeric(type)(this); }
|
|
301
|
-
readDate() { return new Date(this.readInt64() ?? 0); }
|
|
302
|
-
toType(value) { return value; }
|
|
303
|
-
_getReadFuncForNumeric(type) {
|
|
304
|
-
let [isNullable, numType] = (type instanceof Nullable) ? [true, type.value] : [false, type];
|
|
305
|
-
let typeInfo = getNumericTypeInfo(numType);
|
|
306
|
-
if (!typeInfo)
|
|
307
|
-
throw ("Wrong type: " + type);
|
|
308
|
-
return ((stream) => { if (!isNullable || stream.readBool())
|
|
309
|
-
return stream.__readNumber(typeInfo.size, typeInfo.integer, typeInfo.signed); return null; });
|
|
310
|
-
}
|
|
311
|
-
readNullable(reader) { return this.readBool() ? reader.read(this) : null; }
|
|
312
|
-
readArray(arg) {
|
|
313
|
-
if (typeof arg == "string" || arg instanceof Nullable)
|
|
314
|
-
return this._readArrayOfNumeric(arg);
|
|
315
|
-
if (0)
|
|
316
|
-
return [arg.read(this)];
|
|
317
|
-
if (arg instanceof Function)
|
|
318
|
-
if (arg.hasOwnProperty("read"))
|
|
319
|
-
return this._readArrayByReader(arg);
|
|
320
|
-
else
|
|
321
|
-
return this._readArrayByFunc(arg);
|
|
322
|
-
else if ("read" in arg)
|
|
323
|
-
return this._readArrayByReader(arg);
|
|
324
|
-
throw ("Wrong argument in readArray");
|
|
325
|
-
}
|
|
326
|
-
_readArrayByFunc(func) {
|
|
327
|
-
let size = this.readUint32();
|
|
328
|
-
if (size == null)
|
|
329
|
-
return null;
|
|
330
|
-
let array = new Array(size);
|
|
331
|
-
for (let i = 0; i < size; i++)
|
|
332
|
-
array[i] = func(this);
|
|
333
|
-
return array;
|
|
334
|
-
}
|
|
335
|
-
_readArrayOfNumeric(type) {
|
|
336
|
-
if (type == "int8" || type == "uint8") {
|
|
337
|
-
let arrayClass = type == "int8" ? Int8Array : Uint8Array;
|
|
338
|
-
let size = this.readUint32();
|
|
339
|
-
if (size == null)
|
|
340
|
-
return null;
|
|
341
|
-
let bufpos = this._view.byteOffset + this._pos;
|
|
342
|
-
new arrayClass(this._view.buffer.slice(bufpos, bufpos + size));
|
|
343
|
-
}
|
|
344
|
-
return this._readArrayByFunc(this._getReadFuncForNumeric(type));
|
|
345
|
-
}
|
|
346
|
-
_readArrayByReader(reader) { return this._readArrayByFunc(reader.read); }
|
|
347
|
-
_readNullableString(charSize) {
|
|
348
|
-
if (!this.readBool())
|
|
349
|
-
return null;
|
|
350
|
-
let chars = [];
|
|
351
|
-
let nullTerminated = false;
|
|
352
|
-
if (charSize == 1) {
|
|
353
|
-
for (; this._pos < this._view.byteLength; this._pos++) {
|
|
354
|
-
let char = this._view.getUint8(this._pos);
|
|
355
|
-
if (char != 0)
|
|
356
|
-
chars.push(char);
|
|
357
|
-
else {
|
|
358
|
-
nullTerminated = true;
|
|
359
|
-
break;
|
|
360
|
-
}
|
|
361
|
-
}
|
|
362
|
-
}
|
|
363
|
-
else {
|
|
364
|
-
for (; this._pos < this._view.byteLength; this._pos += 2) {
|
|
365
|
-
let char = this._view.getUint16(this._pos);
|
|
366
|
-
if (char != 0)
|
|
367
|
-
chars.push(char);
|
|
368
|
-
else {
|
|
369
|
-
nullTerminated = true;
|
|
370
|
-
break;
|
|
371
|
-
}
|
|
372
|
-
}
|
|
373
|
-
}
|
|
374
|
-
if (!nullTerminated)
|
|
375
|
-
throw "Can't get null-terminated string!";
|
|
376
|
-
this._pos += charSize;
|
|
377
|
-
return String.fromCharCode(...chars);
|
|
378
|
-
}
|
|
379
|
-
readAnsi() { return this._readNullableString(1); }
|
|
380
|
-
readUnicode() { return this._readNullableString(2); }
|
|
381
|
-
}
|
|
382
|
-
;
|
|
383
|
-
class ByteStreamR extends ByteStreamR_ {
|
|
384
|
-
constructor(data) { super(data); }
|
|
385
|
-
}
|
|
386
|
-
exports.ByteStreamR = ByteStreamR;
|
|
387
|
-
;
|
|
388
|
-
function Test() {
|
|
389
|
-
class A {
|
|
390
|
-
a;
|
|
391
|
-
b;
|
|
392
|
-
write(stream) { stream.pushDouble(this.a).pushDouble(this.b); }
|
|
393
|
-
constructor(a, b) { this.a = a; this.b = b; }
|
|
394
|
-
static read(stream) { let [a, b] = [stream.readDouble(), stream.readDouble()]; return new A(a, b); }
|
|
395
|
-
}
|
|
396
|
-
let stream = new ByteStreamW;
|
|
397
|
-
stream.pushInt16(1000);
|
|
398
|
-
stream.pushInt8(150);
|
|
399
|
-
stream.pushInt24(100000);
|
|
400
|
-
stream.pushInt32(90000000);
|
|
401
|
-
stream.pushFloat(0.5);
|
|
402
|
-
stream.pushDouble(0.05);
|
|
403
|
-
stream.pushArrayNumeric([1, 2, 3, 4, 5], "int16");
|
|
404
|
-
stream.pushUnicode("myString");
|
|
405
|
-
stream.pushAnsi("myString");
|
|
406
|
-
stream.pushArray([new A(33, 44), new A(55, 66)]);
|
|
407
|
-
console.log(stream);
|
|
408
|
-
let rstream = new ByteStreamR(stream.data);
|
|
409
|
-
let result = [
|
|
410
|
-
rstream.readInt16(),
|
|
411
|
-
rstream.readInt8(),
|
|
412
|
-
rstream.readInt24(),
|
|
413
|
-
rstream.readInt32(),
|
|
414
|
-
rstream.readFloat(),
|
|
415
|
-
rstream.readDouble(),
|
|
416
|
-
rstream.readArray("int16"),
|
|
417
|
-
rstream.readUnicode(),
|
|
418
|
-
rstream.readAnsi(),
|
|
419
|
-
rstream.readArray(A.read),
|
|
420
|
-
];
|
|
421
|
-
console.log(result);
|
|
422
|
-
}
|
|
423
|
-
class X {
|
|
424
|
-
fff(arg) { }
|
|
425
|
-
}
|
|
426
|
-
let x = new X;
|
|
427
|
-
//# sourceMappingURL=ByteStream.js.map
|