ya-struct 0.0.10 → 0.0.11
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/dist/lib/layout.js +44 -44
- package/dist/lib/parser.d.ts +6 -1
- package/dist/lib/parser.js +2 -0
- package/dist/lib/types/array.js +1 -0
- package/dist/lib/types/string.js +1 -0
- package/dist/lib/types/struct.js +1 -0
- package/package.json +12 -7
- package/.editorconfig +0 -8
- package/.github/workflows/ci.yml +0 -23
- package/.github/workflows/npm-publish.yml +0 -28
- package/eslint.config.js +0 -127
- package/lib/bit-buffer.ts +0 -70
- package/lib/common.ts +0 -30
- package/lib/index.ts +0 -21
- package/lib/layout.ts +0 -286
- package/lib/parser.ts +0 -88
- package/lib/types/array.ts +0 -90
- package/lib/types/c-types.ts +0 -222
- package/lib/types/index.ts +0 -122
- package/lib/types/integer.ts +0 -160
- package/lib/types/pointer.ts +0 -27
- package/lib/types/string.ts +0 -56
- package/lib/types/struct.ts +0 -146
- package/lib/types/value.ts +0 -8
- package/package.npm.json +0 -25
- package/samples/basic.ts +0 -40
- package/test/c-structs.ts +0 -399
- package/test/compile-util.ts +0 -92
- package/test/nested-structs.ts +0 -78
- package/tsconfig.json +0 -11
package/dist/lib/layout.js
CHANGED
|
@@ -42,12 +42,12 @@ import nodeUtil from "node:util";
|
|
|
42
42
|
|
|
43
43
|
const pointerSizeInBitsByDataModel = ({ dataModel }/*: { dataModel: TAbi["dataModel"] }*/)/*: number*/ => {
|
|
44
44
|
switch (dataModel) {
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
45
|
+
case "LP64":
|
|
46
|
+
return 64;
|
|
47
|
+
case "ILP32":
|
|
48
|
+
return 32;
|
|
49
|
+
default:
|
|
50
|
+
throw Error(`unsupported data model "${dataModel}" for pointer size determination`);
|
|
51
51
|
}
|
|
52
52
|
};
|
|
53
53
|
|
|
@@ -82,53 +82,53 @@ const layoutStruct = ({
|
|
|
82
82
|
|
|
83
83
|
if (!definition.packed) {
|
|
84
84
|
switch (normalizedField.type) {
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
}
|
|
95
|
-
|
|
96
|
-
break;
|
|
85
|
+
case "integer":
|
|
86
|
+
case "float": {
|
|
87
|
+
const sizeInBits = normalizedField.sizeInBits;
|
|
88
|
+
|
|
89
|
+
if (abi.compiler === "gcc" && abi.dataModel === "ILP32" && sizeInBits === 64) {
|
|
90
|
+
// special handling for gcc 64-bit integers on ILP32 data model (alignment to 32 bits)
|
|
91
|
+
currentOffsetInBits = align({ offset: currentOffsetInBits, alignment: 32 });
|
|
92
|
+
} else {
|
|
93
|
+
currentOffsetInBits = align({ offset: currentOffsetInBits, alignment: sizeInBits });
|
|
97
94
|
}
|
|
98
|
-
case "array": {
|
|
99
95
|
|
|
100
|
-
|
|
96
|
+
break;
|
|
97
|
+
}
|
|
98
|
+
case "array": {
|
|
101
99
|
|
|
102
|
-
|
|
103
|
-
const { sizeInBits } = layout({ definition: normalizedField.elementType, abi, currentOffsetInBits: 0 });
|
|
100
|
+
// TODO: this is probably not sufficient for all cases
|
|
104
101
|
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
currentOffsetInBits = align({ offset: currentOffsetInBits, alignment: 32 });
|
|
108
|
-
} else {
|
|
109
|
-
currentOffsetInBits = align({ offset: currentOffsetInBits, alignment: sizeInBits });
|
|
110
|
-
}
|
|
102
|
+
// eslint-disable-next-line no-use-before-define
|
|
103
|
+
const { sizeInBits } = layout({ definition: normalizedField.elementType, abi, currentOffsetInBits: 0 });
|
|
111
104
|
|
|
112
|
-
|
|
105
|
+
if (abi.compiler === "gcc" && abi.dataModel === "ILP32" && sizeInBits === 64) {
|
|
106
|
+
// special handling for gcc 64-bit integers on ILP32 data model (alignment to 32 bits)
|
|
107
|
+
currentOffsetInBits = align({ offset: currentOffsetInBits, alignment: 32 });
|
|
108
|
+
} else {
|
|
109
|
+
currentOffsetInBits = align({ offset: currentOffsetInBits, alignment: sizeInBits });
|
|
113
110
|
}
|
|
114
|
-
case "struct": {
|
|
115
111
|
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
112
|
+
break;
|
|
113
|
+
}
|
|
114
|
+
case "struct": {
|
|
119
115
|
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
case "string": {
|
|
123
|
-
// no special alignment needed
|
|
124
|
-
break;
|
|
125
|
-
}
|
|
126
|
-
case "pointer": {
|
|
127
|
-
currentOffsetInBits = align({ offset: currentOffsetInBits, alignment: pointerSizeInBits });
|
|
128
|
-
break;
|
|
116
|
+
if (currentOffsetInBits % 64 !== 0) {
|
|
117
|
+
throw Error("nested struct alignment handling not implemented yet");
|
|
129
118
|
}
|
|
130
|
-
|
|
131
|
-
|
|
119
|
+
|
|
120
|
+
break;
|
|
121
|
+
}
|
|
122
|
+
case "string": {
|
|
123
|
+
// no special alignment needed
|
|
124
|
+
break;
|
|
125
|
+
}
|
|
126
|
+
case "pointer": {
|
|
127
|
+
currentOffsetInBits = align({ offset: currentOffsetInBits, alignment: pointerSizeInBits });
|
|
128
|
+
break;
|
|
129
|
+
}
|
|
130
|
+
default:
|
|
131
|
+
throw Error(`unsupported field type for struct layout: ${nodeUtil.inspect(field.definition)}`);
|
|
132
132
|
}
|
|
133
133
|
}
|
|
134
134
|
|
package/dist/lib/parser.d.ts
CHANGED
|
@@ -19,7 +19,12 @@ type FieldValue<T extends TFieldType> = T extends {
|
|
|
19
19
|
} ? StructValue<F & readonly {
|
|
20
20
|
name: string;
|
|
21
21
|
definition: TFieldType;
|
|
22
|
-
}[]> :
|
|
22
|
+
}[]> : T extends {
|
|
23
|
+
type: "c-type";
|
|
24
|
+
cType: "float" | "double" | "long double";
|
|
25
|
+
} ? number : T extends {
|
|
26
|
+
type: "c-type";
|
|
27
|
+
} ? bigint : never;
|
|
23
28
|
type StructValue<F extends readonly {
|
|
24
29
|
name: string;
|
|
25
30
|
definition: TFieldType;
|
package/dist/lib/parser.js
CHANGED
|
@@ -13,6 +13,8 @@ import { createStructParser } from "./types/struct.js";
|
|
|
13
13
|
? FieldValue<E & TFieldType>[] :
|
|
14
14
|
T extends { type: "struct"; fields: infer F }
|
|
15
15
|
? StructValue<F & readonly { name: string; definition: TFieldType }[]> :
|
|
16
|
+
T extends { type: "c-type"; cType: "float" | "double" | "long double" } ? number :
|
|
17
|
+
T extends { type: "c-type" } ? bigint :
|
|
16
18
|
never;*/
|
|
17
19
|
|
|
18
20
|
/*type StructValue<
|
package/dist/lib/types/array.js
CHANGED
|
@@ -43,6 +43,7 @@ const createArrayParser = ({
|
|
|
43
43
|
for (let i = 0; i < length; i += 1) {
|
|
44
44
|
const fieldData = data.subarray(i * elementSizeInBytes, (i + 1) * elementSizeInBytes);
|
|
45
45
|
const fieldValue = fieldParser.parse({ data: fieldData, offsetInBits: 0 });
|
|
46
|
+
// eslint-disable-next-line fp/no-mutating-methods -- performance
|
|
46
47
|
result.push(fieldValue);
|
|
47
48
|
}
|
|
48
49
|
|
package/dist/lib/types/string.js
CHANGED
package/dist/lib/types/struct.js
CHANGED
|
@@ -98,6 +98,7 @@ const createStructParser = ({
|
|
|
98
98
|
sizeInBits: field.definition.sizeInBits
|
|
99
99
|
});
|
|
100
100
|
|
|
101
|
+
// eslint-disable-next-line immutable/no-mutation -- performance
|
|
101
102
|
result[field.name] = fieldParser.parse({ data: fieldData, offsetInBits: fieldOffsetInBits });
|
|
102
103
|
});
|
|
103
104
|
|
package/package.json
CHANGED
|
@@ -1,26 +1,31 @@
|
|
|
1
1
|
{
|
|
2
|
-
"version": "0.0.
|
|
2
|
+
"version": "0.0.11",
|
|
3
3
|
"name": "ya-struct",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"description": "Yet Another Node.js Structure API",
|
|
6
|
+
"files": [
|
|
7
|
+
"dist"
|
|
8
|
+
],
|
|
6
9
|
"main": "dist/lib/index.js",
|
|
7
10
|
"scripts": {
|
|
8
11
|
"build": "rm -rf dist/ && deno-node-build --root . --out dist/ --entry lib/index.ts",
|
|
9
12
|
"test": "c8 --reporter lcov --reporter html --reporter text --all --src lib/ mocha test/**/*.ts",
|
|
10
|
-
"lint": "eslint ."
|
|
13
|
+
"lint": "eslint .",
|
|
14
|
+
"type-check": "tsc --noEmit",
|
|
15
|
+
"update-deps": "npm-check-updates -u"
|
|
11
16
|
},
|
|
12
17
|
"dependencies": {},
|
|
13
18
|
"devDependencies": {
|
|
14
|
-
"@eslint/js": "^
|
|
19
|
+
"@eslint/js": "^10.0.1",
|
|
20
|
+
"@k13engineering/eslint-rules": "^0.0.5",
|
|
15
21
|
"@k13engineering/releasetool": "^0.0.5",
|
|
16
22
|
"@types/mocha": "^10.0.10",
|
|
17
|
-
"@types/node": "^25.0
|
|
18
|
-
"c8": "^
|
|
23
|
+
"@types/node": "^25.6.0",
|
|
24
|
+
"c8": "^11.0.0",
|
|
19
25
|
"deno-node": "^0.0.12",
|
|
20
|
-
"eslint": "^9.39.2",
|
|
21
26
|
"mocha": "^11.7.5",
|
|
22
27
|
"tmp-promise": "^3.0.3",
|
|
23
|
-
"typescript
|
|
28
|
+
"typescript": "^6.0.3"
|
|
24
29
|
},
|
|
25
30
|
"repository": {
|
|
26
31
|
"type": "git",
|
package/.editorconfig
DELETED
package/.github/workflows/ci.yml
DELETED
|
@@ -1,23 +0,0 @@
|
|
|
1
|
-
name: CI
|
|
2
|
-
|
|
3
|
-
on: [push, pull_request]
|
|
4
|
-
|
|
5
|
-
jobs:
|
|
6
|
-
ci:
|
|
7
|
-
runs-on: ubuntu-latest
|
|
8
|
-
name: Continous integration tests
|
|
9
|
-
steps:
|
|
10
|
-
- uses: actions/checkout@v4
|
|
11
|
-
- uses: actions/setup-node@v4
|
|
12
|
-
with:
|
|
13
|
-
node-version: '24'
|
|
14
|
-
- name: Install libc6-dev-i386
|
|
15
|
-
run: sudo apt-get update && sudo apt-get install -y libc6-dev-i386
|
|
16
|
-
- name: Install dependencies
|
|
17
|
-
run: npm ci
|
|
18
|
-
- name: Build
|
|
19
|
-
run: npm run build
|
|
20
|
-
- name: Run tests
|
|
21
|
-
run: npm run test
|
|
22
|
-
- name: Verify code with linter
|
|
23
|
-
run: npm run lint
|
|
@@ -1,28 +0,0 @@
|
|
|
1
|
-
name: Publish Package to npmjs
|
|
2
|
-
on:
|
|
3
|
-
push:
|
|
4
|
-
tags:
|
|
5
|
-
- '*'
|
|
6
|
-
|
|
7
|
-
permissions:
|
|
8
|
-
id-token: write # Required for OIDC
|
|
9
|
-
contents: read
|
|
10
|
-
|
|
11
|
-
jobs:
|
|
12
|
-
publish:
|
|
13
|
-
runs-on: ubuntu-latest
|
|
14
|
-
permissions:
|
|
15
|
-
contents: read
|
|
16
|
-
id-token: write
|
|
17
|
-
steps:
|
|
18
|
-
- uses: actions/checkout@v4
|
|
19
|
-
# Setup .npmrc file to publish to npm
|
|
20
|
-
- uses: actions/setup-node@v4
|
|
21
|
-
with:
|
|
22
|
-
node-version: '24'
|
|
23
|
-
registry-url: 'https://registry.npmjs.org'
|
|
24
|
-
- run: npm ci
|
|
25
|
-
- run: npm run build
|
|
26
|
-
- run: node node_modules/.bin/releasetool merge --local-package-json package.json --npm-package-json package.npm.json --output package.json
|
|
27
|
-
- run: node node_modules/.bin/releasetool patch-version --package-json package.json --package-version ${{ github.ref_name }}
|
|
28
|
-
- run: npm publish
|
package/eslint.config.js
DELETED
|
@@ -1,127 +0,0 @@
|
|
|
1
|
-
/* c8 ignore start */
|
|
2
|
-
import eslint from "@eslint/js";
|
|
3
|
-
import tseslint from "typescript-eslint";
|
|
4
|
-
|
|
5
|
-
export default tseslint.config(
|
|
6
|
-
{
|
|
7
|
-
ignores: [
|
|
8
|
-
"dist/**/*"
|
|
9
|
-
]
|
|
10
|
-
},
|
|
11
|
-
eslint.configs.recommended,
|
|
12
|
-
...tseslint.configs.recommended,
|
|
13
|
-
{
|
|
14
|
-
rules: {
|
|
15
|
-
"global-require": "off",
|
|
16
|
-
"quote-props": ["warn", "consistent-as-needed"],
|
|
17
|
-
|
|
18
|
-
"quotes": ["error", "double", {
|
|
19
|
-
allowTemplateLiterals: true,
|
|
20
|
-
}],
|
|
21
|
-
|
|
22
|
-
"no-plusplus": "error",
|
|
23
|
-
"no-nested-ternary": "error",
|
|
24
|
-
"no-multiple-empty-lines": "error",
|
|
25
|
-
"no-inline-comments": "error",
|
|
26
|
-
"no-lonely-if": "error",
|
|
27
|
-
"no-array-constructor": "error",
|
|
28
|
-
"no-delete-var": "error",
|
|
29
|
-
"no-param-reassign": "error",
|
|
30
|
-
"no-return-assign": "error",
|
|
31
|
-
"no-import-assign": "error",
|
|
32
|
-
"no-multi-assign": "error",
|
|
33
|
-
"keyword-spacing": "error",
|
|
34
|
-
|
|
35
|
-
"max-len": ["warn", {
|
|
36
|
-
code: 140,
|
|
37
|
-
}],
|
|
38
|
-
|
|
39
|
-
"max-params": ["error", 4],
|
|
40
|
-
"max-statements": ["error", 15],
|
|
41
|
-
"no-loss-of-precision": "error",
|
|
42
|
-
"no-unreachable-loop": "error",
|
|
43
|
-
"require-atomic-updates": "error",
|
|
44
|
-
"complexity": ["error", 4],
|
|
45
|
-
|
|
46
|
-
"max-statements-per-line": ["error", {
|
|
47
|
-
max: 1,
|
|
48
|
-
}],
|
|
49
|
-
|
|
50
|
-
"no-tabs": "error",
|
|
51
|
-
"no-underscore-dangle": "error",
|
|
52
|
-
"no-negated-condition": "error",
|
|
53
|
-
"no-use-before-define": "error",
|
|
54
|
-
|
|
55
|
-
"no-shadow": "off",
|
|
56
|
-
"@typescript-eslint/no-shadow": "error",
|
|
57
|
-
|
|
58
|
-
"no-labels": "error",
|
|
59
|
-
"no-throw-literal": "error",
|
|
60
|
-
"default-case": "error",
|
|
61
|
-
"default-case-last": "error",
|
|
62
|
-
"no-caller": "error",
|
|
63
|
-
"no-eval": "error",
|
|
64
|
-
"no-implied-eval": "error",
|
|
65
|
-
"no-new": "error",
|
|
66
|
-
"no-new-func": "error",
|
|
67
|
-
"no-new-object": "error",
|
|
68
|
-
"no-new-wrappers": "error",
|
|
69
|
-
"no-useless-concat": "error",
|
|
70
|
-
|
|
71
|
-
"no-unused-vars": "off",
|
|
72
|
-
"@typescript-eslint/no-unused-vars": ["error", {
|
|
73
|
-
ignoreRestSiblings: true,
|
|
74
|
-
}],
|
|
75
|
-
|
|
76
|
-
"array-bracket-newline": ["error", "consistent"],
|
|
77
|
-
"func-names": ["error", "never"],
|
|
78
|
-
|
|
79
|
-
"func-style": ["error", "expression", {
|
|
80
|
-
allowArrowFunctions: true,
|
|
81
|
-
}],
|
|
82
|
-
|
|
83
|
-
"max-depth": ["error", 4],
|
|
84
|
-
"arrow-parens": "error",
|
|
85
|
-
"no-confusing-arrow": "error",
|
|
86
|
-
"prefer-const": "error",
|
|
87
|
-
"rest-spread-spacing": ["error", "never"],
|
|
88
|
-
"template-curly-spacing": ["error", "never"],
|
|
89
|
-
"prefer-rest-params": "error",
|
|
90
|
-
"prefer-spread": "error",
|
|
91
|
-
"prefer-template": "error",
|
|
92
|
-
"object-shorthand": ["error", "properties"],
|
|
93
|
-
"no-var": "error",
|
|
94
|
-
"no-useless-computed-key": "error",
|
|
95
|
-
"array-callback-return": "error",
|
|
96
|
-
"consistent-return": "error",
|
|
97
|
-
"dot-notation": "error",
|
|
98
|
-
"eqeqeq": "error",
|
|
99
|
-
"no-eq-null": "error",
|
|
100
|
-
"no-implicit-coercion": "error",
|
|
101
|
-
"no-multi-spaces": "error",
|
|
102
|
-
"no-proto": "error",
|
|
103
|
-
"yoda": "error",
|
|
104
|
-
"indent": ["error", 2, { SwitchCase: 1 }],
|
|
105
|
-
"object-curly-spacing": ["error", "always"],
|
|
106
|
-
|
|
107
|
-
"object-curly-newline": ["error", {
|
|
108
|
-
consistent: true,
|
|
109
|
-
multiline: true,
|
|
110
|
-
}],
|
|
111
|
-
|
|
112
|
-
"space-before-blocks": "error",
|
|
113
|
-
"space-before-function-paren": ["error", "always"],
|
|
114
|
-
"spaced-comment": "error",
|
|
115
|
-
"no-whitespace-before-property": "error",
|
|
116
|
-
|
|
117
|
-
"brace-style": ["error", "1tbs", {
|
|
118
|
-
allowSingleLine: false,
|
|
119
|
-
}],
|
|
120
|
-
|
|
121
|
-
"eol-last": ["error", "always"],
|
|
122
|
-
"func-call-spacing": ["error", "never"],
|
|
123
|
-
"semi": ["error", "always"],
|
|
124
|
-
}
|
|
125
|
-
}
|
|
126
|
-
);
|
|
127
|
-
/* c8 ignore stop */
|
package/lib/bit-buffer.ts
DELETED
|
@@ -1,70 +0,0 @@
|
|
|
1
|
-
type TBitBuffer = {
|
|
2
|
-
sizeInBits: number;
|
|
3
|
-
slice: (args: { startOffsetInBits: number, endOffsetInBits: number }) => TBitBuffer;
|
|
4
|
-
readBits: (args: { offsetInBits: number, lengthInBits: number }) => { data: Uint8Array, offsetInBits: number };
|
|
5
|
-
}
|
|
6
|
-
|
|
7
|
-
const bitBufferFromUint8Array = ({
|
|
8
|
-
data,
|
|
9
|
-
offsetInBits: dataOffsetInBits,
|
|
10
|
-
sizeInBits
|
|
11
|
-
}: {
|
|
12
|
-
data: Uint8Array,
|
|
13
|
-
offsetInBits: number,
|
|
14
|
-
sizeInBits: number
|
|
15
|
-
}): TBitBuffer => {
|
|
16
|
-
|
|
17
|
-
const slice: TBitBuffer["slice"] = ({ startOffsetInBits, endOffsetInBits }) => {
|
|
18
|
-
const totalStartOffsetInBits = dataOffsetInBits + startOffsetInBits;
|
|
19
|
-
const totalEndOffsetInBits = dataOffsetInBits + endOffsetInBits;
|
|
20
|
-
|
|
21
|
-
const byteStartOffset = (totalStartOffsetInBits) / 8;
|
|
22
|
-
const byteEndOffset = (totalEndOffsetInBits) / 8;
|
|
23
|
-
|
|
24
|
-
const newData = data.slice(byteStartOffset, byteEndOffset);
|
|
25
|
-
const newOffsetInBits = totalStartOffsetInBits % 8;
|
|
26
|
-
|
|
27
|
-
return bitBufferFromUint8Array({
|
|
28
|
-
data: newData,
|
|
29
|
-
offsetInBits: newOffsetInBits,
|
|
30
|
-
sizeInBits: endOffsetInBits - startOffsetInBits
|
|
31
|
-
});
|
|
32
|
-
};
|
|
33
|
-
|
|
34
|
-
const readBits: TBitBuffer["readBits"] = ({ offsetInBits: readOffsetInBits, lengthInBits }) => {
|
|
35
|
-
const totalOffsetInBits = dataOffsetInBits + readOffsetInBits;
|
|
36
|
-
const totalEndOffsetInBits = totalOffsetInBits + lengthInBits;
|
|
37
|
-
|
|
38
|
-
const byteOffset = (totalOffsetInBits) / 8;
|
|
39
|
-
const byteEndOffset = (totalEndOffsetInBits) / 8;
|
|
40
|
-
|
|
41
|
-
const bitData = data.slice(byteOffset, byteEndOffset);
|
|
42
|
-
const bitOffset = totalOffsetInBits % 8;
|
|
43
|
-
|
|
44
|
-
return {
|
|
45
|
-
offsetInBits: bitOffset,
|
|
46
|
-
data: bitData
|
|
47
|
-
};
|
|
48
|
-
};
|
|
49
|
-
|
|
50
|
-
return {
|
|
51
|
-
sizeInBits,
|
|
52
|
-
readBits,
|
|
53
|
-
slice,
|
|
54
|
-
};
|
|
55
|
-
};
|
|
56
|
-
|
|
57
|
-
const createBitBuffer = ({ sizeInBits, offsetInBits }: { sizeInBits: number, offsetInBits: number }) => {
|
|
58
|
-
const byteLength = Math.ceil(sizeInBits / 8);
|
|
59
|
-
const buffer = new Uint8Array(byteLength);
|
|
60
|
-
return bitBufferFromUint8Array({ data: buffer, offsetInBits, sizeInBits });
|
|
61
|
-
};
|
|
62
|
-
|
|
63
|
-
export {
|
|
64
|
-
createBitBuffer,
|
|
65
|
-
bitBufferFromUint8Array
|
|
66
|
-
};
|
|
67
|
-
|
|
68
|
-
export type {
|
|
69
|
-
TBitBuffer
|
|
70
|
-
};
|
package/lib/common.ts
DELETED
|
@@ -1,30 +0,0 @@
|
|
|
1
|
-
type TDataModel = "LP64" | "ILP32";
|
|
2
|
-
type TCompiler = "gcc";
|
|
3
|
-
type TEndianness = "little" | "big";
|
|
4
|
-
|
|
5
|
-
type TAbi = {
|
|
6
|
-
endianness: TEndianness;
|
|
7
|
-
compiler: TCompiler;
|
|
8
|
-
dataModel: TDataModel;
|
|
9
|
-
};
|
|
10
|
-
|
|
11
|
-
const align = ({ offset, alignment }: { offset: number; alignment: number }): number => {
|
|
12
|
-
const remainder = offset % alignment;
|
|
13
|
-
if (remainder === 0) {
|
|
14
|
-
return offset;
|
|
15
|
-
}
|
|
16
|
-
|
|
17
|
-
return offset + (alignment - remainder);
|
|
18
|
-
};
|
|
19
|
-
|
|
20
|
-
export type {
|
|
21
|
-
TDataModel,
|
|
22
|
-
TCompiler,
|
|
23
|
-
TEndianness,
|
|
24
|
-
|
|
25
|
-
TAbi
|
|
26
|
-
};
|
|
27
|
-
|
|
28
|
-
export {
|
|
29
|
-
align
|
|
30
|
-
};
|
package/lib/index.ts
DELETED
|
@@ -1,21 +0,0 @@
|
|
|
1
|
-
import { define } from "./parser.ts";
|
|
2
|
-
import { types } from "./types/index.ts";
|
|
3
|
-
|
|
4
|
-
import type {
|
|
5
|
-
TAbi,
|
|
6
|
-
TCompiler,
|
|
7
|
-
TDataModel,
|
|
8
|
-
TEndianness,
|
|
9
|
-
} from "./common.ts";
|
|
10
|
-
|
|
11
|
-
export {
|
|
12
|
-
define,
|
|
13
|
-
types
|
|
14
|
-
};
|
|
15
|
-
|
|
16
|
-
export type {
|
|
17
|
-
TAbi,
|
|
18
|
-
TEndianness,
|
|
19
|
-
TCompiler,
|
|
20
|
-
TDataModel
|
|
21
|
-
};
|