dolphindb 2.0.507 → 2.0.508
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/browser.d.ts +7 -4
- package/browser.js +52 -21
- package/browser.js.map +1 -1
- package/index.d.ts +7 -4
- package/index.js +52 -21
- package/index.js.map +1 -1
- package/package.json +4 -4
package/index.d.ts
CHANGED
|
@@ -78,7 +78,12 @@ export interface DdbArrayVectorBlock {
|
|
|
78
78
|
lengths: Uint8Array | Uint16Array | Uint32Array;
|
|
79
79
|
data: DdbVectorValue;
|
|
80
80
|
}
|
|
81
|
-
export
|
|
81
|
+
export interface DdbMatrixValue {
|
|
82
|
+
rows: DdbObj;
|
|
83
|
+
cols: DdbObj;
|
|
84
|
+
data: DdbVectorValue;
|
|
85
|
+
}
|
|
86
|
+
export declare type DdbValue = null | boolean | number | [number, number] | bigint | string | string[] | Uint8Array | Int8Array | Int16Array | Int32Array | Float32Array | Float64Array | BigInt64Array | Uint8Array[] | DdbObj[] | DdbFunctionDefValue | DdbSymbolExtendedValue | DdbArrayVectorBlock[] | DdbMatrixValue;
|
|
82
87
|
export declare type DdbVectorValue = string | string[] | Uint8Array | Int8Array | Int16Array | Int32Array | Float32Array | Float64Array | BigInt64Array | Uint8Array[] | DdbObj[] | DdbSymbolExtendedValue | DdbArrayVectorBlock[];
|
|
83
88
|
export declare const nulls: {
|
|
84
89
|
readonly int8: -128;
|
|
@@ -123,8 +128,6 @@ export declare class DdbObj<T extends DdbValue = DdbValue> {
|
|
|
123
128
|
rows?: number;
|
|
124
129
|
/** 第 2 维 */
|
|
125
130
|
cols?: number;
|
|
126
|
-
/** matrix 中值的类型,仅 matrix 才有 */
|
|
127
|
-
datatype?: DdbType;
|
|
128
131
|
/** 实际数据。不同的 DdbForm, DdbType 使用 DdbValue 中不同的类型来表示实际数据 */
|
|
129
132
|
value: T;
|
|
130
133
|
/** 原始二进制数据,仅在 parse_object 为 false 时通过 parse_message 生成的顶层对象有这个属性 */
|
|
@@ -138,7 +141,7 @@ export declare class DdbObj<T extends DdbValue = DdbValue> {
|
|
|
138
141
|
/** parse: rows, cols, items
|
|
139
142
|
返回的 ddbobj.length 不包括 vector 的 type 和 form
|
|
140
143
|
*/
|
|
141
|
-
static parse_vector(buf: Uint8Array, le: boolean, type: DdbType): DdbObj
|
|
144
|
+
static parse_vector(buf: Uint8Array, le: boolean, type: DdbType): DdbObj<DdbVectorValue>;
|
|
142
145
|
/** 有可能没有字节对齐,不能直接使用原有 message 的 arraybuffer, 统一复制出来,让原有 arraybuffer 被回收掉比较好 */
|
|
143
146
|
static parse_vector_items(buf: Uint8Array, le: boolean, type: DdbType, length: number): [
|
|
144
147
|
number,
|
package/index.js
CHANGED
|
@@ -239,34 +239,60 @@ class DdbObj {
|
|
|
239
239
|
});
|
|
240
240
|
}
|
|
241
241
|
case DdbForm.matrix: {
|
|
242
|
-
//
|
|
242
|
+
// rename!(
|
|
243
|
+
// 1..9$3:3,
|
|
243
244
|
// [1, 2, 3],
|
|
244
|
-
// [
|
|
245
|
-
//
|
|
246
|
-
// <Buffer
|
|
247
|
-
//
|
|
248
|
-
//
|
|
249
|
-
// 01
|
|
245
|
+
// ['c1', 'c2', 'c3']
|
|
246
|
+
// )
|
|
247
|
+
// <Buffer 04 03 type = int, form = matrix
|
|
248
|
+
// 03 has_row_label (& 0x01) = 1, has_col_label (& 0x02) = 1
|
|
249
|
+
// row labels
|
|
250
|
+
// 04 01 type = int, form = vector
|
|
251
|
+
// 03 00 00 00 01 00 00 00 rows = 3, cols = 1
|
|
252
|
+
// 01 00 00 00 02 00 00 00 03 00 00 00 vector values
|
|
253
|
+
// col labels
|
|
254
|
+
// 12 01 type = string, form = vector
|
|
255
|
+
// 03 00 00 00 01 00 00 00 rows = 3, cols = 1
|
|
256
|
+
// 63 31 00 63 32 00 63 33 00
|
|
257
|
+
// matrix data
|
|
258
|
+
// 04 03 type = matrix.type, form = matrix
|
|
259
|
+
// 03 00 00 00 03 00 00 00 rows = 3, cols = 3
|
|
250
260
|
const dv = new DataView(buf.buffer, buf.byteOffset + i_data);
|
|
251
261
|
const label_flags = buf_data[0];
|
|
252
262
|
const has_row_labels = Boolean(label_flags & 0x01);
|
|
253
263
|
const has_col_labels = Boolean(label_flags & 0x02);
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
264
|
+
let row_labels = null;
|
|
265
|
+
let col_labels = null;
|
|
266
|
+
let offset = 1;
|
|
267
|
+
if (has_row_labels) {
|
|
268
|
+
row_labels = this.parse_vector(buf_data.subarray(offset + 2), le, buf_data[offset]);
|
|
269
|
+
row_labels.length += 2;
|
|
270
|
+
offset += row_labels.length;
|
|
271
|
+
}
|
|
272
|
+
if (has_col_labels) {
|
|
273
|
+
col_labels = this.parse_vector(buf_data.subarray(offset + 2), le, buf_data[offset]);
|
|
274
|
+
col_labels.length += 2;
|
|
275
|
+
offset += col_labels.length;
|
|
276
|
+
}
|
|
277
|
+
if (buf_data[offset] !== type)
|
|
278
|
+
throw new Error('matrix.datatype !== matrix.type');
|
|
279
|
+
const rows = dv.getUint32(offset + 2, le);
|
|
280
|
+
const cols = dv.getUint32(offset + 6, le);
|
|
281
|
+
const [len_items, data] = this.parse_vector_items(buf_data.subarray(offset + 10), le, type, rows * cols // 假设小于 2**32
|
|
260
282
|
);
|
|
283
|
+
offset += 10 + len_items;
|
|
261
284
|
return new this({
|
|
262
285
|
le,
|
|
263
286
|
form,
|
|
264
287
|
type,
|
|
265
|
-
length: i_data +
|
|
288
|
+
length: i_data + offset,
|
|
266
289
|
rows,
|
|
267
290
|
cols,
|
|
268
|
-
|
|
269
|
-
|
|
291
|
+
value: {
|
|
292
|
+
rows: row_labels,
|
|
293
|
+
cols: col_labels,
|
|
294
|
+
data,
|
|
295
|
+
},
|
|
270
296
|
});
|
|
271
297
|
}
|
|
272
298
|
default:
|
|
@@ -618,7 +644,7 @@ class DdbObj {
|
|
|
618
644
|
}
|
|
619
645
|
pack() {
|
|
620
646
|
const { form, type, value } = this;
|
|
621
|
-
let header = new Uint8Array(
|
|
647
|
+
let header = new Uint8Array(2);
|
|
622
648
|
header[0] = type;
|
|
623
649
|
header[1] = form;
|
|
624
650
|
const body = (() => {
|
|
@@ -759,12 +785,17 @@ class DdbObj {
|
|
|
759
785
|
value[0].pack(),
|
|
760
786
|
value[1].pack(),
|
|
761
787
|
];
|
|
762
|
-
case DdbForm.matrix:
|
|
788
|
+
case DdbForm.matrix: {
|
|
789
|
+
const { rows, cols, data } = value;
|
|
763
790
|
return [
|
|
764
|
-
Uint8Array.of(
|
|
791
|
+
Uint8Array.of((rows && 0x01) | (cols && 0x02)),
|
|
792
|
+
...rows ? [rows.pack()] : [],
|
|
793
|
+
...cols ? [cols.pack()] : [],
|
|
794
|
+
Uint8Array.of(this.type, this.form),
|
|
765
795
|
Uint32Array.of(this.rows, this.cols),
|
|
766
|
-
...DdbObj.pack_vector_body(
|
|
796
|
+
...DdbObj.pack_vector_body(data, this.type, this.rows * this.cols)
|
|
767
797
|
];
|
|
798
|
+
}
|
|
768
799
|
default:
|
|
769
800
|
throw new Error(`${DdbForm[form]} 暂不支持序列化`);
|
|
770
801
|
}
|
|
@@ -878,7 +909,7 @@ class DdbObj {
|
|
|
878
909
|
case DdbForm.dict:
|
|
879
910
|
return `dict<${DdbType[this.value[0].type]}, ${DdbType[this.value[1].type]}>`;
|
|
880
911
|
case DdbForm.matrix:
|
|
881
|
-
return `matrix<${DdbType[this.
|
|
912
|
+
return `matrix<${DdbType[this.type]}>[${this.rows} rows][${this.cols} cols]`;
|
|
882
913
|
default:
|
|
883
914
|
return `${DdbForm[this.form]} ${tname}`;
|
|
884
915
|
}
|