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/browser.d.ts
CHANGED
|
@@ -75,7 +75,12 @@ export interface DdbArrayVectorBlock {
|
|
|
75
75
|
lengths: Uint8Array | Uint16Array | Uint32Array;
|
|
76
76
|
data: DdbVectorValue;
|
|
77
77
|
}
|
|
78
|
-
export
|
|
78
|
+
export interface DdbMatrixValue {
|
|
79
|
+
rows: DdbObj;
|
|
80
|
+
cols: DdbObj;
|
|
81
|
+
data: DdbVectorValue;
|
|
82
|
+
}
|
|
83
|
+
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;
|
|
79
84
|
export declare type DdbVectorValue = string | string[] | Uint8Array | Int8Array | Int16Array | Int32Array | Float32Array | Float64Array | BigInt64Array | Uint8Array[] | DdbObj[] | DdbSymbolExtendedValue | DdbArrayVectorBlock[];
|
|
80
85
|
export declare const nulls: {
|
|
81
86
|
readonly int8: -128;
|
|
@@ -120,8 +125,6 @@ export declare class DdbObj<T extends DdbValue = DdbValue> {
|
|
|
120
125
|
rows?: number;
|
|
121
126
|
/** 第 2 维 */
|
|
122
127
|
cols?: number;
|
|
123
|
-
/** matrix 中值的类型,仅 matrix 才有 */
|
|
124
|
-
datatype?: DdbType;
|
|
125
128
|
/** 实际数据。不同的 DdbForm, DdbType 使用 DdbValue 中不同的类型来表示实际数据 */
|
|
126
129
|
value: T;
|
|
127
130
|
/** 原始二进制数据,仅在 parse_object 为 false 时通过 parse_message 生成的顶层对象有这个属性 */
|
|
@@ -135,7 +138,7 @@ export declare class DdbObj<T extends DdbValue = DdbValue> {
|
|
|
135
138
|
/** parse: rows, cols, items
|
|
136
139
|
返回的 ddbobj.length 不包括 vector 的 type 和 form
|
|
137
140
|
*/
|
|
138
|
-
static parse_vector(buf: Uint8Array, le: boolean, type: DdbType): DdbObj
|
|
141
|
+
static parse_vector(buf: Uint8Array, le: boolean, type: DdbType): DdbObj<DdbVectorValue>;
|
|
139
142
|
/** 有可能没有字节对齐,不能直接使用原有 message 的 arraybuffer, 统一复制出来,让原有 arraybuffer 被回收掉比较好 */
|
|
140
143
|
static parse_vector_items(buf: Uint8Array, le: boolean, type: DdbType, length: number): [
|
|
141
144
|
number,
|
package/browser.js
CHANGED
|
@@ -202,34 +202,60 @@ class DdbObj {
|
|
|
202
202
|
});
|
|
203
203
|
}
|
|
204
204
|
case DdbForm.matrix: {
|
|
205
|
-
//
|
|
205
|
+
// rename!(
|
|
206
|
+
// 1..9$3:3,
|
|
206
207
|
// [1, 2, 3],
|
|
207
|
-
// [
|
|
208
|
-
//
|
|
209
|
-
// <Buffer
|
|
210
|
-
//
|
|
211
|
-
//
|
|
212
|
-
// 01
|
|
208
|
+
// ['c1', 'c2', 'c3']
|
|
209
|
+
// )
|
|
210
|
+
// <Buffer 04 03 type = int, form = matrix
|
|
211
|
+
// 03 has_row_label (& 0x01) = 1, has_col_label (& 0x02) = 1
|
|
212
|
+
// row labels
|
|
213
|
+
// 04 01 type = int, form = vector
|
|
214
|
+
// 03 00 00 00 01 00 00 00 rows = 3, cols = 1
|
|
215
|
+
// 01 00 00 00 02 00 00 00 03 00 00 00 vector values
|
|
216
|
+
// col labels
|
|
217
|
+
// 12 01 type = string, form = vector
|
|
218
|
+
// 03 00 00 00 01 00 00 00 rows = 3, cols = 1
|
|
219
|
+
// 63 31 00 63 32 00 63 33 00
|
|
220
|
+
// matrix data
|
|
221
|
+
// 04 03 type = matrix.type, form = matrix
|
|
222
|
+
// 03 00 00 00 03 00 00 00 rows = 3, cols = 3
|
|
213
223
|
const dv = new DataView(buf.buffer, buf.byteOffset + i_data);
|
|
214
224
|
const label_flags = buf_data[0];
|
|
215
225
|
const has_row_labels = Boolean(label_flags & 0x01);
|
|
216
226
|
const has_col_labels = Boolean(label_flags & 0x02);
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
227
|
+
let row_labels = null;
|
|
228
|
+
let col_labels = null;
|
|
229
|
+
let offset = 1;
|
|
230
|
+
if (has_row_labels) {
|
|
231
|
+
row_labels = this.parse_vector(buf_data.subarray(offset + 2), le, buf_data[offset]);
|
|
232
|
+
row_labels.length += 2;
|
|
233
|
+
offset += row_labels.length;
|
|
234
|
+
}
|
|
235
|
+
if (has_col_labels) {
|
|
236
|
+
col_labels = this.parse_vector(buf_data.subarray(offset + 2), le, buf_data[offset]);
|
|
237
|
+
col_labels.length += 2;
|
|
238
|
+
offset += col_labels.length;
|
|
239
|
+
}
|
|
240
|
+
if (buf_data[offset] !== type)
|
|
241
|
+
throw new Error('matrix.datatype !== matrix.type');
|
|
242
|
+
const rows = dv.getUint32(offset + 2, le);
|
|
243
|
+
const cols = dv.getUint32(offset + 6, le);
|
|
244
|
+
const [len_items, data] = this.parse_vector_items(buf_data.subarray(offset + 10), le, type, rows * cols // 假设小于 2**32
|
|
223
245
|
);
|
|
246
|
+
offset += 10 + len_items;
|
|
224
247
|
return new this({
|
|
225
248
|
le,
|
|
226
249
|
form,
|
|
227
250
|
type,
|
|
228
|
-
length: i_data +
|
|
251
|
+
length: i_data + offset,
|
|
229
252
|
rows,
|
|
230
253
|
cols,
|
|
231
|
-
|
|
232
|
-
|
|
254
|
+
value: {
|
|
255
|
+
rows: row_labels,
|
|
256
|
+
cols: col_labels,
|
|
257
|
+
data,
|
|
258
|
+
},
|
|
233
259
|
});
|
|
234
260
|
}
|
|
235
261
|
default:
|
|
@@ -581,7 +607,7 @@ class DdbObj {
|
|
|
581
607
|
}
|
|
582
608
|
pack() {
|
|
583
609
|
const { form, type, value } = this;
|
|
584
|
-
let header = new Uint8Array(
|
|
610
|
+
let header = new Uint8Array(2);
|
|
585
611
|
header[0] = type;
|
|
586
612
|
header[1] = form;
|
|
587
613
|
const body = (() => {
|
|
@@ -722,12 +748,17 @@ class DdbObj {
|
|
|
722
748
|
value[0].pack(),
|
|
723
749
|
value[1].pack(),
|
|
724
750
|
];
|
|
725
|
-
case DdbForm.matrix:
|
|
751
|
+
case DdbForm.matrix: {
|
|
752
|
+
const { rows, cols, data } = value;
|
|
726
753
|
return [
|
|
727
|
-
Uint8Array.of(
|
|
754
|
+
Uint8Array.of((rows && 0x01) | (cols && 0x02)),
|
|
755
|
+
...rows ? [rows.pack()] : [],
|
|
756
|
+
...cols ? [cols.pack()] : [],
|
|
757
|
+
Uint8Array.of(this.type, this.form),
|
|
728
758
|
Uint32Array.of(this.rows, this.cols),
|
|
729
|
-
...DdbObj.pack_vector_body(
|
|
759
|
+
...DdbObj.pack_vector_body(data, this.type, this.rows * this.cols)
|
|
730
760
|
];
|
|
761
|
+
}
|
|
731
762
|
default:
|
|
732
763
|
throw new Error(`${DdbForm[form]} 暂不支持序列化`);
|
|
733
764
|
}
|
|
@@ -841,7 +872,7 @@ class DdbObj {
|
|
|
841
872
|
case DdbForm.dict:
|
|
842
873
|
return `dict<${DdbType[this.value[0].type]}, ${DdbType[this.value[1].type]}>`;
|
|
843
874
|
case DdbForm.matrix:
|
|
844
|
-
return `matrix<${DdbType[this.
|
|
875
|
+
return `matrix<${DdbType[this.type]}>[${this.rows} rows][${this.cols} cols]`;
|
|
845
876
|
default:
|
|
846
877
|
return `${DdbForm[this.form]} ${tname}`;
|
|
847
878
|
}
|