m-bus-parser-wasm-pack 0.3.0 → 0.4.1
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/README.md +23 -2
- package/m_bus_parser_wasm_pack.d.ts +21 -0
- package/m_bus_parser_wasm_pack.js +1 -1
- package/m_bus_parser_wasm_pack_bg.js +200 -0
- package/m_bus_parser_wasm_pack_bg.wasm +0 -0
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -1,3 +1,24 @@
|
|
|
1
|
-
# WASM
|
|
1
|
+
# WASM package for m-bus-parser
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
Browser bindings for the wired and wireless M-Bus parser.
|
|
4
|
+
|
|
5
|
+
- `m_bus_decode(data, key?, includeEnrichment?)` returns the canonical schema
|
|
6
|
+
as a native JavaScript object.
|
|
7
|
+
- `m_bus_render(data, format, key?, width?, includeEnrichment?)` renders
|
|
8
|
+
`table`, `json`, `yaml`, `csv`, `mermaid`, `xml`, `annotated`, or
|
|
9
|
+
`annotated-text`.
|
|
10
|
+
- `m_bus_highlight(source, language)` highlights JSON, YAML, CSV, or XML with
|
|
11
|
+
the Rust-only `syntect` grammar bundle and returns escaped, prefixed
|
|
12
|
+
span-only markup.
|
|
13
|
+
- Rejected promises/errors are `MbusParserError` objects with stable `code`,
|
|
14
|
+
`layer`, and optional `byteOffset` properties.
|
|
15
|
+
- `m_bus_parse` and `m_bus_parse_with_key` remain compatibility wrappers.
|
|
16
|
+
|
|
17
|
+
```js
|
|
18
|
+
import init, { m_bus_decode, m_bus_highlight, m_bus_render } from 'm-bus-parser-wasm-pack'
|
|
19
|
+
|
|
20
|
+
await init()
|
|
21
|
+
const decoded = m_bus_decode('68 3D 3D 68 ...')
|
|
22
|
+
const narrowTable = m_bus_render('68 3D 3D 68 ...', 'table', undefined, 48)
|
|
23
|
+
const highlighted = m_bus_highlight(JSON.stringify(decoded, null, 2), 'json')
|
|
24
|
+
```
|
|
@@ -1,8 +1,29 @@
|
|
|
1
1
|
/* tslint:disable */
|
|
2
2
|
/* eslint-disable */
|
|
3
3
|
|
|
4
|
+
/**
|
|
5
|
+
* Decode into the canonical schema as a native JavaScript object.
|
|
6
|
+
*/
|
|
7
|
+
export function m_bus_decode(data: string, key_hex?: string | null, include_enrichment?: boolean | null): any;
|
|
8
|
+
|
|
9
|
+
/**
|
|
10
|
+
* Highlight JSON, YAML, CSV, XML, or plaintext with the bundled Rust grammar set.
|
|
11
|
+
*/
|
|
12
|
+
export function m_bus_highlight(source: string, language: string): string;
|
|
13
|
+
|
|
14
|
+
/**
|
|
15
|
+
* Compatibility wrapper returning errors as text. Prefer `m_bus_render`.
|
|
16
|
+
*/
|
|
4
17
|
export function m_bus_parse(data: string, format: string): string;
|
|
5
18
|
|
|
19
|
+
/**
|
|
20
|
+
* Compatibility wrapper returning errors as text. Prefer `m_bus_render`.
|
|
21
|
+
*/
|
|
6
22
|
export function m_bus_parse_with_key(data: string, format: string, key_hex: string): string;
|
|
7
23
|
|
|
24
|
+
/**
|
|
25
|
+
* Render with the shared Rust/Python/CLI output contract.
|
|
26
|
+
*/
|
|
27
|
+
export function m_bus_render(data: string, format: string, key_hex?: string | null, width?: number | null, include_enrichment?: boolean | null): string;
|
|
28
|
+
|
|
8
29
|
export function version(): string;
|
|
@@ -5,5 +5,5 @@ import { __wbg_set_wasm } from "./m_bus_parser_wasm_pack_bg.js";
|
|
|
5
5
|
__wbg_set_wasm(wasm);
|
|
6
6
|
wasm.__wbindgen_start();
|
|
7
7
|
export {
|
|
8
|
-
m_bus_parse, m_bus_parse_with_key, version
|
|
8
|
+
m_bus_decode, m_bus_highlight, m_bus_parse, m_bus_parse_with_key, m_bus_render, version
|
|
9
9
|
} from "./m_bus_parser_wasm_pack_bg.js";
|
|
@@ -1,4 +1,53 @@
|
|
|
1
1
|
/**
|
|
2
|
+
* Decode into the canonical schema as a native JavaScript object.
|
|
3
|
+
* @param {string} data
|
|
4
|
+
* @param {string | null} [key_hex]
|
|
5
|
+
* @param {boolean | null} [include_enrichment]
|
|
6
|
+
* @returns {any}
|
|
7
|
+
*/
|
|
8
|
+
export function m_bus_decode(data, key_hex, include_enrichment) {
|
|
9
|
+
const ptr0 = passStringToWasm0(data, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
|
|
10
|
+
const len0 = WASM_VECTOR_LEN;
|
|
11
|
+
var ptr1 = isLikeNone(key_hex) ? 0 : passStringToWasm0(key_hex, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
|
|
12
|
+
var len1 = WASM_VECTOR_LEN;
|
|
13
|
+
const ret = wasm.m_bus_decode(ptr0, len0, ptr1, len1, isLikeNone(include_enrichment) ? 0xFFFFFF : include_enrichment ? 1 : 0);
|
|
14
|
+
if (ret[2]) {
|
|
15
|
+
throw takeFromExternrefTable0(ret[1]);
|
|
16
|
+
}
|
|
17
|
+
return takeFromExternrefTable0(ret[0]);
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
/**
|
|
21
|
+
* Highlight JSON, YAML, CSV, XML, or plaintext with the bundled Rust grammar set.
|
|
22
|
+
* @param {string} source
|
|
23
|
+
* @param {string} language
|
|
24
|
+
* @returns {string}
|
|
25
|
+
*/
|
|
26
|
+
export function m_bus_highlight(source, language) {
|
|
27
|
+
let deferred4_0;
|
|
28
|
+
let deferred4_1;
|
|
29
|
+
try {
|
|
30
|
+
const ptr0 = passStringToWasm0(source, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
|
|
31
|
+
const len0 = WASM_VECTOR_LEN;
|
|
32
|
+
const ptr1 = passStringToWasm0(language, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
|
|
33
|
+
const len1 = WASM_VECTOR_LEN;
|
|
34
|
+
const ret = wasm.m_bus_highlight(ptr0, len0, ptr1, len1);
|
|
35
|
+
var ptr3 = ret[0];
|
|
36
|
+
var len3 = ret[1];
|
|
37
|
+
if (ret[3]) {
|
|
38
|
+
ptr3 = 0; len3 = 0;
|
|
39
|
+
throw takeFromExternrefTable0(ret[2]);
|
|
40
|
+
}
|
|
41
|
+
deferred4_0 = ptr3;
|
|
42
|
+
deferred4_1 = len3;
|
|
43
|
+
return getStringFromWasm0(ptr3, len3);
|
|
44
|
+
} finally {
|
|
45
|
+
wasm.__wbindgen_free(deferred4_0, deferred4_1, 1);
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
/**
|
|
50
|
+
* Compatibility wrapper returning errors as text. Prefer `m_bus_render`.
|
|
2
51
|
* @param {string} data
|
|
3
52
|
* @param {string} format
|
|
4
53
|
* @returns {string}
|
|
@@ -21,6 +70,7 @@ export function m_bus_parse(data, format) {
|
|
|
21
70
|
}
|
|
22
71
|
|
|
23
72
|
/**
|
|
73
|
+
* Compatibility wrapper returning errors as text. Prefer `m_bus_render`.
|
|
24
74
|
* @param {string} data
|
|
25
75
|
* @param {string} format
|
|
26
76
|
* @param {string} key_hex
|
|
@@ -45,6 +95,40 @@ export function m_bus_parse_with_key(data, format, key_hex) {
|
|
|
45
95
|
}
|
|
46
96
|
}
|
|
47
97
|
|
|
98
|
+
/**
|
|
99
|
+
* Render with the shared Rust/Python/CLI output contract.
|
|
100
|
+
* @param {string} data
|
|
101
|
+
* @param {string} format
|
|
102
|
+
* @param {string | null} [key_hex]
|
|
103
|
+
* @param {number | null} [width]
|
|
104
|
+
* @param {boolean | null} [include_enrichment]
|
|
105
|
+
* @returns {string}
|
|
106
|
+
*/
|
|
107
|
+
export function m_bus_render(data, format, key_hex, width, include_enrichment) {
|
|
108
|
+
let deferred5_0;
|
|
109
|
+
let deferred5_1;
|
|
110
|
+
try {
|
|
111
|
+
const ptr0 = passStringToWasm0(data, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
|
|
112
|
+
const len0 = WASM_VECTOR_LEN;
|
|
113
|
+
const ptr1 = passStringToWasm0(format, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
|
|
114
|
+
const len1 = WASM_VECTOR_LEN;
|
|
115
|
+
var ptr2 = isLikeNone(key_hex) ? 0 : passStringToWasm0(key_hex, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
|
|
116
|
+
var len2 = WASM_VECTOR_LEN;
|
|
117
|
+
const ret = wasm.m_bus_render(ptr0, len0, ptr1, len1, ptr2, len2, isLikeNone(width) ? Number.MAX_SAFE_INTEGER : (width) >>> 0, isLikeNone(include_enrichment) ? 0xFFFFFF : include_enrichment ? 1 : 0);
|
|
118
|
+
var ptr4 = ret[0];
|
|
119
|
+
var len4 = ret[1];
|
|
120
|
+
if (ret[3]) {
|
|
121
|
+
ptr4 = 0; len4 = 0;
|
|
122
|
+
throw takeFromExternrefTable0(ret[2]);
|
|
123
|
+
}
|
|
124
|
+
deferred5_0 = ptr4;
|
|
125
|
+
deferred5_1 = len4;
|
|
126
|
+
return getStringFromWasm0(ptr4, len4);
|
|
127
|
+
} finally {
|
|
128
|
+
wasm.__wbindgen_free(deferred5_0, deferred5_1, 1);
|
|
129
|
+
}
|
|
130
|
+
}
|
|
131
|
+
|
|
48
132
|
/**
|
|
49
133
|
* @returns {string}
|
|
50
134
|
*/
|
|
@@ -60,6 +144,89 @@ export function version() {
|
|
|
60
144
|
wasm.__wbindgen_free(deferred1_0, deferred1_1, 1);
|
|
61
145
|
}
|
|
62
146
|
}
|
|
147
|
+
export function __wbg_Error_92b29b0548f8b746(arg0, arg1) {
|
|
148
|
+
const ret = Error(getStringFromWasm0(arg0, arg1));
|
|
149
|
+
return ret;
|
|
150
|
+
}
|
|
151
|
+
export function __wbg_String_8564e559799eccda(arg0, arg1) {
|
|
152
|
+
const ret = String(arg1);
|
|
153
|
+
const ptr1 = passStringToWasm0(ret, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
|
|
154
|
+
const len1 = WASM_VECTOR_LEN;
|
|
155
|
+
getDataViewMemory0().setInt32(arg0 + 4 * 1, len1, true);
|
|
156
|
+
getDataViewMemory0().setInt32(arg0 + 4 * 0, ptr1, true);
|
|
157
|
+
}
|
|
158
|
+
export function __wbg___wbindgen_is_string_ea5e6cc2e4141dfe(arg0) {
|
|
159
|
+
const ret = typeof(arg0) === 'string';
|
|
160
|
+
return ret;
|
|
161
|
+
}
|
|
162
|
+
export function __wbg___wbindgen_string_get_b0ca35b86a603356(arg0, arg1) {
|
|
163
|
+
const obj = arg1;
|
|
164
|
+
const ret = typeof(obj) === 'string' ? obj : undefined;
|
|
165
|
+
var ptr1 = isLikeNone(ret) ? 0 : passStringToWasm0(ret, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
|
|
166
|
+
var len1 = WASM_VECTOR_LEN;
|
|
167
|
+
getDataViewMemory0().setInt32(arg0 + 4 * 1, len1, true);
|
|
168
|
+
getDataViewMemory0().setInt32(arg0 + 4 * 0, ptr1, true);
|
|
169
|
+
}
|
|
170
|
+
export function __wbg___wbindgen_throw_344f42d3211c4765(arg0, arg1) {
|
|
171
|
+
throw new Error(getStringFromWasm0(arg0, arg1));
|
|
172
|
+
}
|
|
173
|
+
export function __wbg_new_32b398fb48b6d94a() {
|
|
174
|
+
const ret = new Array();
|
|
175
|
+
return ret;
|
|
176
|
+
}
|
|
177
|
+
export function __wbg_new_7796ffc7ed656783() {
|
|
178
|
+
const ret = new Map();
|
|
179
|
+
return ret;
|
|
180
|
+
}
|
|
181
|
+
export function __wbg_new_b667d279fd5aa943(arg0, arg1) {
|
|
182
|
+
const ret = new Error(getStringFromWasm0(arg0, arg1));
|
|
183
|
+
return ret;
|
|
184
|
+
}
|
|
185
|
+
export function __wbg_new_da52cf8fe3429cb2() {
|
|
186
|
+
const ret = new Object();
|
|
187
|
+
return ret;
|
|
188
|
+
}
|
|
189
|
+
export function __wbg_set_575dd786d51585f8(arg0, arg1, arg2) {
|
|
190
|
+
const ret = arg0.set(arg1, arg2);
|
|
191
|
+
return ret;
|
|
192
|
+
}
|
|
193
|
+
export function __wbg_set_6be42768c690e380(arg0, arg1, arg2) {
|
|
194
|
+
arg0[arg1] = arg2;
|
|
195
|
+
}
|
|
196
|
+
export function __wbg_set_8535240470bf2500() { return handleError(function (arg0, arg1, arg2) {
|
|
197
|
+
const ret = Reflect.set(arg0, arg1, arg2);
|
|
198
|
+
return ret;
|
|
199
|
+
}, arguments); }
|
|
200
|
+
export function __wbg_set_8a16b38e4805b298(arg0, arg1, arg2) {
|
|
201
|
+
arg0[arg1 >>> 0] = arg2;
|
|
202
|
+
}
|
|
203
|
+
export function __wbg_set_name_3bbc583faefa4193(arg0, arg1, arg2) {
|
|
204
|
+
arg0.name = getStringFromWasm0(arg1, arg2);
|
|
205
|
+
}
|
|
206
|
+
export function __wbg_stringify_b54333f60f1e4dad() { return handleError(function (arg0) {
|
|
207
|
+
const ret = JSON.stringify(arg0);
|
|
208
|
+
return ret;
|
|
209
|
+
}, arguments); }
|
|
210
|
+
export function __wbindgen_cast_0000000000000001(arg0) {
|
|
211
|
+
// Cast intrinsic for `F64 -> Externref`.
|
|
212
|
+
const ret = arg0;
|
|
213
|
+
return ret;
|
|
214
|
+
}
|
|
215
|
+
export function __wbindgen_cast_0000000000000002(arg0) {
|
|
216
|
+
// Cast intrinsic for `I64 -> Externref`.
|
|
217
|
+
const ret = arg0;
|
|
218
|
+
return ret;
|
|
219
|
+
}
|
|
220
|
+
export function __wbindgen_cast_0000000000000003(arg0, arg1) {
|
|
221
|
+
// Cast intrinsic for `Ref(String) -> Externref`.
|
|
222
|
+
const ret = getStringFromWasm0(arg0, arg1);
|
|
223
|
+
return ret;
|
|
224
|
+
}
|
|
225
|
+
export function __wbindgen_cast_0000000000000004(arg0) {
|
|
226
|
+
// Cast intrinsic for `U64 -> Externref`.
|
|
227
|
+
const ret = BigInt.asUintN(64, arg0);
|
|
228
|
+
return ret;
|
|
229
|
+
}
|
|
63
230
|
export function __wbindgen_init_externref_table() {
|
|
64
231
|
const table = wasm.__wbindgen_externrefs;
|
|
65
232
|
const offset = table.grow(4);
|
|
@@ -69,6 +236,20 @@ export function __wbindgen_init_externref_table() {
|
|
|
69
236
|
table.set(offset + 2, true);
|
|
70
237
|
table.set(offset + 3, false);
|
|
71
238
|
}
|
|
239
|
+
function addToExternrefTable0(obj) {
|
|
240
|
+
const idx = wasm.__externref_table_alloc();
|
|
241
|
+
wasm.__wbindgen_externrefs.set(idx, obj);
|
|
242
|
+
return idx;
|
|
243
|
+
}
|
|
244
|
+
|
|
245
|
+
let cachedDataViewMemory0 = null;
|
|
246
|
+
function getDataViewMemory0() {
|
|
247
|
+
if (cachedDataViewMemory0 === null || cachedDataViewMemory0.buffer.detached === true || (cachedDataViewMemory0.buffer.detached === undefined && cachedDataViewMemory0.buffer !== wasm.memory.buffer)) {
|
|
248
|
+
cachedDataViewMemory0 = new DataView(wasm.memory.buffer);
|
|
249
|
+
}
|
|
250
|
+
return cachedDataViewMemory0;
|
|
251
|
+
}
|
|
252
|
+
|
|
72
253
|
function getStringFromWasm0(ptr, len) {
|
|
73
254
|
return decodeText(ptr >>> 0, len);
|
|
74
255
|
}
|
|
@@ -81,6 +262,19 @@ function getUint8ArrayMemory0() {
|
|
|
81
262
|
return cachedUint8ArrayMemory0;
|
|
82
263
|
}
|
|
83
264
|
|
|
265
|
+
function handleError(f, args) {
|
|
266
|
+
try {
|
|
267
|
+
return f.apply(this, args);
|
|
268
|
+
} catch (e) {
|
|
269
|
+
const idx = addToExternrefTable0(e);
|
|
270
|
+
wasm.__wbindgen_exn_store(idx);
|
|
271
|
+
}
|
|
272
|
+
}
|
|
273
|
+
|
|
274
|
+
function isLikeNone(x) {
|
|
275
|
+
return x === undefined || x === null;
|
|
276
|
+
}
|
|
277
|
+
|
|
84
278
|
function passStringToWasm0(arg, malloc, realloc) {
|
|
85
279
|
if (realloc === undefined) {
|
|
86
280
|
const buf = cachedTextEncoder.encode(arg);
|
|
@@ -118,6 +312,12 @@ function passStringToWasm0(arg, malloc, realloc) {
|
|
|
118
312
|
return ptr;
|
|
119
313
|
}
|
|
120
314
|
|
|
315
|
+
function takeFromExternrefTable0(idx) {
|
|
316
|
+
const value = wasm.__wbindgen_externrefs.get(idx);
|
|
317
|
+
wasm.__externref_table_dealloc(idx);
|
|
318
|
+
return value;
|
|
319
|
+
}
|
|
320
|
+
|
|
121
321
|
let cachedTextDecoder = new TextDecoder('utf-8', { ignoreBOM: true, fatal: true });
|
|
122
322
|
cachedTextDecoder.decode();
|
|
123
323
|
const MAX_SAFARI_DECODE_BYTES = 2146435072;
|
|
Binary file
|