@sie-js/wbxml 1.0.0

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.
Binary file
@@ -0,0 +1,19 @@
1
+ export type WBXMLVersion = "1.0" | "1.1" | "1.2" | "1.3";
2
+ export type WBXMLLang = "WML10" | "WML11" | "WML12" | "WML13" | "WTA10" | "WTAWML12" | "CHANNEL11" | "CHANNEL12" | "SI10" | "SL10" | "CO10" | "PROV10" | "EMN10" | "DRMREL10" | "OTA" | "SYNCML10" | "DEVINF10" | "SYNCML11" | "DEVINF11" | "METINF11" | "SYNCML12" | "DEVINF12" | "METINF12" | "DMDDF12" | "CSP11" | "CSP12" | "AIRSYNC" | "ACTIVESYNC" | "CONML";
3
+ export type WBXMLCharset = "ASCII" | "ISO-8859-1" | "ISO-8859-2" | "ISO-8859-3" | "ISO-8859-4" | "ISO-8859-5" | "ISO-8859-6" | "ISO-8859-7" | "ISO-8859-8" | "ISO-8859-9" | "ISO-10646-UCS-2" | "SHIFT_JIS" | "BIG5" | "UTF-8" | "UTF-16";
4
+ interface OptionsToWBXML {
5
+ version?: WBXMLVersion;
6
+ preserveWhitespace?: boolean;
7
+ noStringTable?: boolean;
8
+ noPublicId?: boolean;
9
+ }
10
+ interface OptionsFromWBXML {
11
+ mode?: "compact" | "indent" | "canonical";
12
+ indent?: number;
13
+ preserveWhitespace?: boolean;
14
+ lang?: WBXMLLang;
15
+ charset?: WBXMLCharset;
16
+ }
17
+ export declare function xml2wbxml(xml: string, opts?: OptionsToWBXML): Buffer;
18
+ export declare function wbxml2xml(wbxml: Buffer, opts?: OptionsFromWBXML): string;
19
+ export {};
@@ -0,0 +1,69 @@
1
+ import Module from "#build/wbxml.js";
2
+ const WBXML = await Module();
3
+ const _xml2wbxml = WBXML.cwrap('xml2wbxml', 'number', [
4
+ 'number', // xml_in
5
+ 'number', // xml_in_len
6
+ 'number', // out**
7
+ 'number', // out_len*
8
+ 'string', // wbxml_version
9
+ 'number', // preserve_whitespace
10
+ 'number', // no_string_table
11
+ 'number', // no_public_id
12
+ ]);
13
+ const _wbxml2xml = WBXML.cwrap("wbxml2xml", "number", [
14
+ "number", // wbxml_in
15
+ "number", // wbxml_in_len
16
+ "number", // out
17
+ "number", // out_len
18
+ "number", // gen_type
19
+ "number", // indent
20
+ "number", // preserve_whitespace
21
+ "string", // force_lang
22
+ "string", // force_charset
23
+ ]);
24
+ export function xml2wbxml(xml, opts = {}) {
25
+ const { version = "1.3", preserveWhitespace = false, noStringTable = false, noPublicId = false, } = opts;
26
+ const xmlBytes = Buffer.from(xml);
27
+ const xmlPtr = WBXML._malloc(xmlBytes.length || 1);
28
+ WBXML.HEAPU8.set(xmlBytes, xmlPtr);
29
+ const outPtrPtr = WBXML._malloc(4);
30
+ const outLenPtr = WBXML._malloc(4);
31
+ WBXML.HEAPU32[outPtrPtr >> 2] = 0;
32
+ WBXML.HEAPU32[outLenPtr >> 2] = 0;
33
+ const rc = _xml2wbxml(xmlPtr, xmlBytes.length, outPtrPtr, outLenPtr, version, preserveWhitespace ? 1 : 0, noStringTable ? 1 : 0, noPublicId ? 1 : 0);
34
+ const outPtr = WBXML.HEAPU32[outPtrPtr >> 2] >>> 0;
35
+ const outLen = WBXML.HEAPU32[outLenPtr >> 2] >>> 0;
36
+ const result = Buffer.from(WBXML.HEAPU8.slice(outPtr, outPtr + outLen));
37
+ WBXML._free(xmlPtr);
38
+ WBXML._free(outPtrPtr);
39
+ WBXML._free(outLenPtr);
40
+ WBXML._free(outPtr);
41
+ if (rc !== 0)
42
+ throw new Error(result.toString());
43
+ return result;
44
+ }
45
+ export function wbxml2xml(wbxml, opts = {}) {
46
+ const { mode = "indent", indent = -1, preserveWhitespace = false, lang = undefined, charset = undefined, } = opts;
47
+ const inPtr = WBXML._malloc(wbxml.length);
48
+ WBXML.HEAPU8.set(wbxml, inPtr);
49
+ const outPtrPtr = WBXML._malloc(4);
50
+ const outLenPtr = WBXML._malloc(4);
51
+ const modeToNumber = {
52
+ compact: 0,
53
+ indent: 1,
54
+ canonical: 2,
55
+ };
56
+ if (!(mode in modeToNumber))
57
+ throw new Error(`Unknown mode: ${mode}`);
58
+ const rc = _wbxml2xml(inPtr, wbxml.length, outPtrPtr, outLenPtr, modeToNumber[mode], indent, preserveWhitespace ? 1 : 0, lang, charset);
59
+ const outPtr = WBXML.HEAPU32[outPtrPtr >> 2] >>> 0;
60
+ const outLen = WBXML.HEAPU32[outLenPtr >> 2] >>> 0;
61
+ const result = Buffer.from(WBXML.HEAPU8.slice(outPtr, outPtr + outLen));
62
+ WBXML._free(inPtr);
63
+ WBXML._free(outPtrPtr);
64
+ WBXML._free(outLenPtr);
65
+ WBXML._free(outPtr);
66
+ if (rc !== 0)
67
+ throw new Error(result.toString());
68
+ return result.toString();
69
+ }
package/package.json ADDED
@@ -0,0 +1,31 @@
1
+ {
2
+ "name": "@sie-js/wbxml",
3
+ "version": "1.0.0",
4
+ "type": "module",
5
+ "main": "dist/src/index.js",
6
+ "types": "dist/src/index.d.ts",
7
+ "description": "WBXML converter library",
8
+ "files": [
9
+ "./dist/src/*",
10
+ "./build/*.wasm",
11
+ "./build/*.js"
12
+ ],
13
+ "imports": {
14
+ "#build/*": "./build/*"
15
+ },
16
+ "keywords": [],
17
+ "author": "kirill.zhumarin@gmail.com",
18
+ "license": "LGPL-2.1-or-later",
19
+ "repository": {
20
+ "url": "git+https://github.com/siemens-mobile-hacks/node-sie-wbxml.git"
21
+ },
22
+ "devDependencies": {
23
+ "@types/node": "^24.10.0",
24
+ "tsx": "^4.20.6",
25
+ "typescript": "^5.9.3"
26
+ },
27
+ "scripts": {
28
+ "build": "tsc",
29
+ "watch": "tsc -w"
30
+ }
31
+ }