ya-struct 0.0.4 → 0.0.6
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/.editorconfig +8 -0
- package/.github/workflows/ci.yml +23 -0
- package/.github/workflows/npm-publish.yml +28 -0
- package/README.md +150 -18
- package/dist/lib/common.d.ts +14 -0
- package/dist/lib/common.js +30 -0
- package/dist/lib/index.d.ts +5 -0
- package/dist/lib/index.js +21 -0
- package/dist/lib/layout.d.ts +48 -0
- package/dist/lib/layout.js +262 -0
- package/dist/lib/parser.d.ts +51 -0
- package/dist/lib/parser.js +87 -0
- package/dist/lib/types/array.d.ts +10 -0
- package/dist/lib/types/array.js +90 -0
- package/dist/lib/types/c-types.d.ts +13 -0
- package/dist/lib/types/c-types.js +222 -0
- package/dist/lib/types/index.d.ts +93 -0
- package/dist/lib/types/index.js +122 -0
- package/dist/lib/types/integer.d.ts +9 -0
- package/dist/lib/types/integer.js +160 -0
- package/dist/lib/types/pointer.d.ts +8 -0
- package/dist/lib/types/pointer.js +27 -0
- package/dist/lib/types/string.d.ts +6 -0
- package/dist/lib/types/string.js +56 -0
- package/dist/lib/types/struct.d.ts +11 -0
- package/dist/lib/types/struct.js +113 -0
- package/dist/lib/types/value.d.ts +12 -0
- package/dist/lib/types/value.js +8 -0
- package/eslint.config.js +127 -0
- package/lib/bit-buffer.ts +70 -0
- package/lib/common.ts +30 -0
- package/lib/index.ts +21 -0
- package/lib/layout.ts +262 -0
- package/lib/parser.ts +87 -0
- package/lib/types/array.ts +90 -0
- package/lib/types/c-types.ts +222 -0
- package/lib/types/index.ts +122 -0
- package/lib/types/integer.ts +160 -0
- package/lib/types/pointer.ts +27 -0
- package/lib/types/string.ts +56 -0
- package/lib/types/struct.ts +113 -0
- package/lib/types/value.ts +8 -0
- package/package.json +19 -15
- package/package.npm.json +25 -0
- package/samples/basic.ts +40 -0
- package/test/c-structs.ts +399 -0
- package/test/compile-util.ts +92 -0
- package/tsconfig.json +10 -0
- package/.eslintrc +0 -92
- package/.github/workflows/CI.yml +0 -39
- package/.prettierrc +0 -5
- package/lib/builder.js +0 -62
- package/lib/index.js +0 -159
- package/lib/marshaller.js +0 -80
- package/lib/refbuf.js +0 -11
- package/lib/types/basic.js +0 -200
- package/lib/types/ctypes.js +0 -160
- package/test/abi.js +0 -203
- package/test/basic.js +0 -92
- package/test/ctypes.js +0 -166
- package/test/ref.js +0 -35
|
@@ -0,0 +1,87 @@
|
|
|
1
|
+
/*import type { TAbi } from "./common.ts";*/
|
|
2
|
+
import { layout, /*type TLayoutedField */} from "./layout.js";
|
|
3
|
+
/*import type { TFieldType } from "./types/index.ts";*/
|
|
4
|
+
import { createStructParser } from "./types/struct.js";
|
|
5
|
+
/*import type { TValueParser } from "./types/value.ts";*/
|
|
6
|
+
|
|
7
|
+
/*type FieldValue<T extends TFieldType> =
|
|
8
|
+
T extends { type: "integer" } ? bigint :
|
|
9
|
+
T extends { type: "float" } ? number :
|
|
10
|
+
T extends { type: "pointer" } ? bigint :
|
|
11
|
+
T extends { type: "string" } ? string :
|
|
12
|
+
T extends { type: "array"; elementType: infer E; length: number }
|
|
13
|
+
? FieldValue<E & TFieldType>[] :
|
|
14
|
+
T extends { type: "struct"; fields: infer F }
|
|
15
|
+
? StructValue<F & readonly { name: string; definition: TFieldType }[]> :
|
|
16
|
+
never;*/
|
|
17
|
+
|
|
18
|
+
/*type StructValue<
|
|
19
|
+
F extends readonly { name: string; definition: TFieldType }[]
|
|
20
|
+
> = {
|
|
21
|
+
[K in F[number]as K["name"]]: FieldValue<K["definition"]>;
|
|
22
|
+
};*/
|
|
23
|
+
|
|
24
|
+
/*type Simplify<T> = {
|
|
25
|
+
[K in keyof T]: T[K]
|
|
26
|
+
} & {};*/
|
|
27
|
+
|
|
28
|
+
/*type TParsedValueOfDefinition<T extends TFieldType> = Simplify<FieldValue<T>>;*/
|
|
29
|
+
|
|
30
|
+
/*type TParser<T extends TFieldType> = {
|
|
31
|
+
size: number;
|
|
32
|
+
parse: ({ data }: { data: Uint8Array }) => TParsedValueOfDefinition<T>;
|
|
33
|
+
format: ({ value }: { value: TParsedValueOfDefinition<T> }) => Uint8Array;
|
|
34
|
+
layout: TLayoutedField;
|
|
35
|
+
};*/
|
|
36
|
+
|
|
37
|
+
const define = /*<const T extends TFieldType>*/({ definition }/*: { definition: T }*/) => {
|
|
38
|
+
|
|
39
|
+
const parser = ({ abi }/*: { abi: TAbi }*/)/*: TParser<T>*/ => {
|
|
40
|
+
|
|
41
|
+
/*type P = TParser<T>;*/
|
|
42
|
+
|
|
43
|
+
const l = layout({ definition, abi, currentOffsetInBits: 0 });
|
|
44
|
+
|
|
45
|
+
const size = Math.ceil(l.sizeInBits / 8);
|
|
46
|
+
|
|
47
|
+
// console.log(l);
|
|
48
|
+
|
|
49
|
+
let valueParser/*: TValueParser<TParsedValueOfDefinition<T>>*/;
|
|
50
|
+
|
|
51
|
+
if (l.type === "struct") {
|
|
52
|
+
valueParser = createStructParser({
|
|
53
|
+
layoutedFields: l.fields,
|
|
54
|
+
endianness: abi.endianness
|
|
55
|
+
}) /*as unknown*/ /*as TValueParser<TParsedValueOfDefinition<T>>*/;
|
|
56
|
+
} else {
|
|
57
|
+
throw Error("only struct root definitions are supported currently");
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
const parse/*: P["parse"]*/ = ({ data }) => {
|
|
61
|
+
return valueParser.parse({ data, offsetInBits: 0 });
|
|
62
|
+
};
|
|
63
|
+
|
|
64
|
+
const format/*: P["format"]*/ = ({ value }) => {
|
|
65
|
+
const data = new Uint8Array(l.sizeInBits / 8);
|
|
66
|
+
valueParser.format({ value, target: data, offsetInBits: 0 });
|
|
67
|
+
|
|
68
|
+
return data;
|
|
69
|
+
};
|
|
70
|
+
|
|
71
|
+
return {
|
|
72
|
+
size,
|
|
73
|
+
parse,
|
|
74
|
+
format,
|
|
75
|
+
layout: l
|
|
76
|
+
};
|
|
77
|
+
};
|
|
78
|
+
|
|
79
|
+
return {
|
|
80
|
+
definition,
|
|
81
|
+
parser
|
|
82
|
+
};
|
|
83
|
+
};
|
|
84
|
+
|
|
85
|
+
export {
|
|
86
|
+
define
|
|
87
|
+
};
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import type { TEndianness } from "../common.js";
|
|
2
|
+
import type { TFieldType } from "./index.js";
|
|
3
|
+
import type { TValueParser } from "./value.js";
|
|
4
|
+
type TArrayParser = TValueParser<unknown[]>;
|
|
5
|
+
declare const createArrayParser: ({ elementType, length, endianness }: {
|
|
6
|
+
elementType: TFieldType;
|
|
7
|
+
length: number;
|
|
8
|
+
endianness: TEndianness;
|
|
9
|
+
}) => TArrayParser;
|
|
10
|
+
export { createArrayParser };
|
|
@@ -0,0 +1,90 @@
|
|
|
1
|
+
/*import type { TEndianness } from "../common.ts";*/
|
|
2
|
+
/*import type { TFieldType } from "./index.ts";*/
|
|
3
|
+
import { createIntegerParser } from "./integer.js";
|
|
4
|
+
/*import type { TValueParser } from "./value.ts";*/
|
|
5
|
+
|
|
6
|
+
/*type TArrayParser = TValueParser<unknown[]>;*/
|
|
7
|
+
|
|
8
|
+
const createArrayParser = ({
|
|
9
|
+
elementType,
|
|
10
|
+
length,
|
|
11
|
+
endianness
|
|
12
|
+
}/*: {
|
|
13
|
+
elementType: TFieldType,
|
|
14
|
+
length: number,
|
|
15
|
+
endianness: TEndianness
|
|
16
|
+
}*/)/*: TArrayParser*/ => {
|
|
17
|
+
|
|
18
|
+
let fieldParser/*: TValueParser<unknown>*/;
|
|
19
|
+
|
|
20
|
+
if (elementType.type === "integer") {
|
|
21
|
+
fieldParser = createIntegerParser({
|
|
22
|
+
sizeInBits: elementType.sizeInBits,
|
|
23
|
+
signed: elementType.signed,
|
|
24
|
+
endianness
|
|
25
|
+
}) /*as TValueParser<unknown>*/;
|
|
26
|
+
} else {
|
|
27
|
+
throw Error("only integer array elements are supported currently");
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
const elementSizeInBytes = elementType.sizeInBits / 8;
|
|
31
|
+
if (!Number.isInteger(elementSizeInBytes)) {
|
|
32
|
+
throw Error("BUG: non byte-aligned array element size");
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
const parse/*: TArrayParser["parse"]*/ = ({ data, offsetInBits }) => {
|
|
36
|
+
if (offsetInBits !== 0) {
|
|
37
|
+
throw Error("unaligned array parsing not supported yet");
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
// eslint-disable-next-line prefer-const
|
|
41
|
+
let result/*: unknown[]*/ = [];
|
|
42
|
+
|
|
43
|
+
for (let i = 0; i < length; i += 1) {
|
|
44
|
+
const fieldData = data.subarray(i * elementSizeInBytes, (i + 1) * elementSizeInBytes);
|
|
45
|
+
const fieldValue = fieldParser.parse({ data: fieldData, offsetInBits: 0 });
|
|
46
|
+
result.push(fieldValue);
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
return result;
|
|
50
|
+
};
|
|
51
|
+
|
|
52
|
+
// eslint-disable-next-line complexity
|
|
53
|
+
const format/*: TArrayParser["format"]*/ = ({ value, target, offsetInBits }) => {
|
|
54
|
+
if (offsetInBits !== 0) {
|
|
55
|
+
throw Error("unaligned array formatting not supported yet");
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
if (value.length !== length) {
|
|
59
|
+
throw Error(`array length mismatch: field length is ${length}, value length is ${value.length}`);
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
if (target.length < length * elementSizeInBytes) {
|
|
63
|
+
throw Error("not enough space in target for array formatting");
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
for (let i = 0; i < length; i += 1) {
|
|
67
|
+
const fieldTarget = target.subarray(i * elementSizeInBytes, (i + 1) * elementSizeInBytes);
|
|
68
|
+
|
|
69
|
+
try {
|
|
70
|
+
fieldParser.format({
|
|
71
|
+
value: value[i],
|
|
72
|
+
target: fieldTarget,
|
|
73
|
+
offsetInBits: 0
|
|
74
|
+
});
|
|
75
|
+
} catch (ex) {
|
|
76
|
+
throw Error(`failed to format array element at index ${i}`, { cause: ex });
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
}
|
|
80
|
+
};
|
|
81
|
+
|
|
82
|
+
return {
|
|
83
|
+
parse,
|
|
84
|
+
format
|
|
85
|
+
};
|
|
86
|
+
};
|
|
87
|
+
|
|
88
|
+
export {
|
|
89
|
+
createArrayParser
|
|
90
|
+
};
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { type TAbi } from "../common.js";
|
|
2
|
+
import { type TFieldType, type TPrimitiveBasicFieldType } from "./index.js";
|
|
3
|
+
type TCField = TFieldType & {
|
|
4
|
+
type: "c-type";
|
|
5
|
+
};
|
|
6
|
+
declare const createCTypeNormalizer: ({ abi }: {
|
|
7
|
+
abi: TAbi;
|
|
8
|
+
}) => {
|
|
9
|
+
normalize: ({ cField }: {
|
|
10
|
+
cField: TCField;
|
|
11
|
+
}) => TPrimitiveBasicFieldType;
|
|
12
|
+
};
|
|
13
|
+
export { createCTypeNormalizer };
|
|
@@ -0,0 +1,222 @@
|
|
|
1
|
+
import { /*type TCompiler, *//*type TDataModel, *//*type TAbi */} from "../common.js";
|
|
2
|
+
import { /*type TFieldType, *//*type TCFieldType, *//*type TPrimitiveBasicFieldType */} from "./index.js";
|
|
3
|
+
|
|
4
|
+
/*type TCField = TFieldType & { type: "c-type" };*/
|
|
5
|
+
|
|
6
|
+
/*type TPartialCTypeMappings = {
|
|
7
|
+
[dataModel in TDataModel]?: {
|
|
8
|
+
[compiler in TCompiler]?: {
|
|
9
|
+
[field in TCFieldType]?: TPrimitiveBasicFieldType
|
|
10
|
+
}
|
|
11
|
+
}
|
|
12
|
+
};*/
|
|
13
|
+
|
|
14
|
+
const cTypeMappings/*: TPartialCTypeMappings*/ = {
|
|
15
|
+
LP64: {
|
|
16
|
+
gcc: {
|
|
17
|
+
"char": {
|
|
18
|
+
type: "integer",
|
|
19
|
+
sizeInBits: 8,
|
|
20
|
+
fixedAbi: {},
|
|
21
|
+
signed: true
|
|
22
|
+
},
|
|
23
|
+
"unsigned char": {
|
|
24
|
+
type: "integer",
|
|
25
|
+
sizeInBits: 8,
|
|
26
|
+
fixedAbi: {},
|
|
27
|
+
signed: false
|
|
28
|
+
},
|
|
29
|
+
"short": {
|
|
30
|
+
type: "integer",
|
|
31
|
+
sizeInBits: 16,
|
|
32
|
+
fixedAbi: {},
|
|
33
|
+
signed: true
|
|
34
|
+
},
|
|
35
|
+
"unsigned short": {
|
|
36
|
+
type: "integer",
|
|
37
|
+
sizeInBits: 16,
|
|
38
|
+
fixedAbi: {},
|
|
39
|
+
signed: false
|
|
40
|
+
},
|
|
41
|
+
"int": {
|
|
42
|
+
type: "integer",
|
|
43
|
+
sizeInBits: 32,
|
|
44
|
+
fixedAbi: {},
|
|
45
|
+
signed: true
|
|
46
|
+
},
|
|
47
|
+
"unsigned int": {
|
|
48
|
+
type: "integer",
|
|
49
|
+
sizeInBits: 32,
|
|
50
|
+
fixedAbi: {},
|
|
51
|
+
signed: false
|
|
52
|
+
},
|
|
53
|
+
"long": {
|
|
54
|
+
type: "integer",
|
|
55
|
+
sizeInBits: 64,
|
|
56
|
+
fixedAbi: {},
|
|
57
|
+
signed: true
|
|
58
|
+
},
|
|
59
|
+
"unsigned long": {
|
|
60
|
+
type: "integer",
|
|
61
|
+
sizeInBits: 64,
|
|
62
|
+
fixedAbi: {},
|
|
63
|
+
signed: false
|
|
64
|
+
},
|
|
65
|
+
"long long": {
|
|
66
|
+
type: "integer",
|
|
67
|
+
sizeInBits: 64,
|
|
68
|
+
fixedAbi: {},
|
|
69
|
+
signed: true
|
|
70
|
+
},
|
|
71
|
+
"unsigned long long": {
|
|
72
|
+
type: "integer",
|
|
73
|
+
sizeInBits: 64,
|
|
74
|
+
fixedAbi: {},
|
|
75
|
+
signed: false
|
|
76
|
+
},
|
|
77
|
+
"float": {
|
|
78
|
+
type: "float",
|
|
79
|
+
sizeInBits: 32,
|
|
80
|
+
fixedAbi: {}
|
|
81
|
+
},
|
|
82
|
+
"double": {
|
|
83
|
+
type: "float",
|
|
84
|
+
sizeInBits: 64,
|
|
85
|
+
fixedAbi: {}
|
|
86
|
+
},
|
|
87
|
+
"long double": {
|
|
88
|
+
type: "float",
|
|
89
|
+
sizeInBits: 128,
|
|
90
|
+
fixedAbi: {}
|
|
91
|
+
},
|
|
92
|
+
}
|
|
93
|
+
},
|
|
94
|
+
|
|
95
|
+
ILP32: {
|
|
96
|
+
gcc: {
|
|
97
|
+
"char": {
|
|
98
|
+
type: "integer",
|
|
99
|
+
sizeInBits: 8,
|
|
100
|
+
fixedAbi: {},
|
|
101
|
+
signed: true
|
|
102
|
+
},
|
|
103
|
+
"unsigned char": {
|
|
104
|
+
type: "integer",
|
|
105
|
+
sizeInBits: 8,
|
|
106
|
+
fixedAbi: {},
|
|
107
|
+
signed: false
|
|
108
|
+
},
|
|
109
|
+
"short": {
|
|
110
|
+
type: "integer",
|
|
111
|
+
sizeInBits: 16,
|
|
112
|
+
fixedAbi: {},
|
|
113
|
+
signed: true
|
|
114
|
+
},
|
|
115
|
+
"unsigned short": {
|
|
116
|
+
type: "integer",
|
|
117
|
+
sizeInBits: 16,
|
|
118
|
+
fixedAbi: {},
|
|
119
|
+
signed: false
|
|
120
|
+
},
|
|
121
|
+
"int": {
|
|
122
|
+
type: "integer",
|
|
123
|
+
sizeInBits: 32,
|
|
124
|
+
fixedAbi: {},
|
|
125
|
+
signed: true
|
|
126
|
+
},
|
|
127
|
+
"unsigned int": {
|
|
128
|
+
type: "integer",
|
|
129
|
+
sizeInBits: 32,
|
|
130
|
+
fixedAbi: {},
|
|
131
|
+
signed: false
|
|
132
|
+
},
|
|
133
|
+
"long": {
|
|
134
|
+
type: "integer",
|
|
135
|
+
sizeInBits: 32,
|
|
136
|
+
fixedAbi: {},
|
|
137
|
+
signed: true
|
|
138
|
+
},
|
|
139
|
+
"unsigned long": {
|
|
140
|
+
type: "integer",
|
|
141
|
+
sizeInBits: 32,
|
|
142
|
+
fixedAbi: {},
|
|
143
|
+
signed: false
|
|
144
|
+
},
|
|
145
|
+
"long long": {
|
|
146
|
+
type: "integer",
|
|
147
|
+
sizeInBits: 64,
|
|
148
|
+
fixedAbi: {},
|
|
149
|
+
signed: true
|
|
150
|
+
},
|
|
151
|
+
"unsigned long long": {
|
|
152
|
+
type: "integer",
|
|
153
|
+
sizeInBits: 64,
|
|
154
|
+
fixedAbi: {},
|
|
155
|
+
signed: false
|
|
156
|
+
},
|
|
157
|
+
"float": {
|
|
158
|
+
type: "float",
|
|
159
|
+
sizeInBits: 32,
|
|
160
|
+
fixedAbi: {}
|
|
161
|
+
},
|
|
162
|
+
"double": {
|
|
163
|
+
type: "float",
|
|
164
|
+
sizeInBits: 64,
|
|
165
|
+
fixedAbi: {}
|
|
166
|
+
},
|
|
167
|
+
"long double": {
|
|
168
|
+
type: "float",
|
|
169
|
+
sizeInBits: 128,
|
|
170
|
+
fixedAbi: {}
|
|
171
|
+
},
|
|
172
|
+
}
|
|
173
|
+
}
|
|
174
|
+
};
|
|
175
|
+
|
|
176
|
+
const createCTypeNormalizer = ({
|
|
177
|
+
abi
|
|
178
|
+
}/*: {
|
|
179
|
+
abi: TAbi
|
|
180
|
+
}*/) => {
|
|
181
|
+
|
|
182
|
+
const fieldMappings = cTypeMappings[abi.dataModel]?.[abi.compiler];
|
|
183
|
+
if (!fieldMappings) {
|
|
184
|
+
throw Error(`no c-type mappings for data model ${abi.dataModel} and compiler ${abi.compiler}`);
|
|
185
|
+
}
|
|
186
|
+
|
|
187
|
+
const normalize = ({ cField }/*: { cField: TCField }*/)/*: TPrimitiveBasicFieldType*/ => {
|
|
188
|
+
|
|
189
|
+
const mapping = fieldMappings[cField.cType];
|
|
190
|
+
if (mapping === undefined) {
|
|
191
|
+
throw Error(`no c-type mapping for c-type "${cField.cType}" for data model ${abi.dataModel} and compiler ${abi.compiler}`);
|
|
192
|
+
}
|
|
193
|
+
|
|
194
|
+
const mappingFixedAbi = mapping.fixedAbi;
|
|
195
|
+
const fieldFixedAbi = cField.fixedAbi;
|
|
196
|
+
|
|
197
|
+
const fixedAbi = {
|
|
198
|
+
...mappingFixedAbi,
|
|
199
|
+
...fieldFixedAbi
|
|
200
|
+
};
|
|
201
|
+
|
|
202
|
+
Object.keys(fixedAbi).forEach((keyAsString) => {
|
|
203
|
+
const key = keyAsString /*as keyof TAbi*/;
|
|
204
|
+
if (mappingFixedAbi[key] !== undefined && fieldFixedAbi[key] !== undefined) {
|
|
205
|
+
throw Error(`conflicting fixed ABI property for key ${key} between c-type mapping and c-field`);
|
|
206
|
+
}
|
|
207
|
+
});
|
|
208
|
+
|
|
209
|
+
return {
|
|
210
|
+
...mapping,
|
|
211
|
+
fixedAbi
|
|
212
|
+
};
|
|
213
|
+
};
|
|
214
|
+
|
|
215
|
+
return {
|
|
216
|
+
normalize
|
|
217
|
+
};
|
|
218
|
+
};
|
|
219
|
+
|
|
220
|
+
export {
|
|
221
|
+
createCTypeNormalizer
|
|
222
|
+
};
|
|
@@ -0,0 +1,93 @@
|
|
|
1
|
+
import type { TAbi } from "../common.js";
|
|
2
|
+
type TCFieldType = "char" | "unsigned char" | "short" | "unsigned short" | "int" | "unsigned int" | "long" | "unsigned long" | "long long" | "unsigned long long" | "float" | "double" | "long double";
|
|
3
|
+
type TFieldType = {
|
|
4
|
+
readonly type: "integer";
|
|
5
|
+
readonly sizeInBits: number;
|
|
6
|
+
readonly signed: boolean;
|
|
7
|
+
readonly fixedAbi: Partial<TAbi>;
|
|
8
|
+
} | {
|
|
9
|
+
readonly type: "float";
|
|
10
|
+
readonly sizeInBits: number;
|
|
11
|
+
readonly fixedAbi: Partial<TAbi>;
|
|
12
|
+
} | {
|
|
13
|
+
readonly type: "pointer";
|
|
14
|
+
readonly fixedAbi: Partial<TAbi>;
|
|
15
|
+
} | {
|
|
16
|
+
readonly type: "array";
|
|
17
|
+
readonly elementType: TFieldType;
|
|
18
|
+
readonly length: number;
|
|
19
|
+
} | {
|
|
20
|
+
readonly type: "struct";
|
|
21
|
+
readonly fields: readonly {
|
|
22
|
+
readonly name: string;
|
|
23
|
+
readonly definition: TFieldType;
|
|
24
|
+
}[];
|
|
25
|
+
readonly packed: boolean;
|
|
26
|
+
readonly fixedAbi: Partial<TAbi>;
|
|
27
|
+
} | {
|
|
28
|
+
readonly type: "string";
|
|
29
|
+
readonly charSizeInBits: number;
|
|
30
|
+
readonly nullTerminatorMandatory: boolean;
|
|
31
|
+
readonly length: number;
|
|
32
|
+
} | {
|
|
33
|
+
readonly type: "c-type";
|
|
34
|
+
readonly cType: TCFieldType;
|
|
35
|
+
readonly fixedAbi: Partial<TAbi>;
|
|
36
|
+
};
|
|
37
|
+
type TBasicFieldType = Exclude<TFieldType, {
|
|
38
|
+
type: "c-type";
|
|
39
|
+
}>;
|
|
40
|
+
type TPrimitiveBasicFieldType = Exclude<TBasicFieldType, {
|
|
41
|
+
type: "array";
|
|
42
|
+
} | {
|
|
43
|
+
type: "struct";
|
|
44
|
+
} | {
|
|
45
|
+
type: "string";
|
|
46
|
+
}>;
|
|
47
|
+
export type { TBasicFieldType, TFieldType, TCFieldType, TPrimitiveBasicFieldType };
|
|
48
|
+
declare const types: {
|
|
49
|
+
readonly Int16: {
|
|
50
|
+
readonly type: "integer";
|
|
51
|
+
readonly sizeInBits: number;
|
|
52
|
+
readonly signed: boolean;
|
|
53
|
+
readonly fixedAbi: Partial<TAbi>;
|
|
54
|
+
};
|
|
55
|
+
readonly UInt16: {
|
|
56
|
+
readonly type: "integer";
|
|
57
|
+
readonly sizeInBits: number;
|
|
58
|
+
readonly signed: boolean;
|
|
59
|
+
readonly fixedAbi: Partial<TAbi>;
|
|
60
|
+
};
|
|
61
|
+
readonly Int32: {
|
|
62
|
+
readonly type: "integer";
|
|
63
|
+
readonly sizeInBits: number;
|
|
64
|
+
readonly signed: boolean;
|
|
65
|
+
readonly fixedAbi: Partial<TAbi>;
|
|
66
|
+
};
|
|
67
|
+
readonly Int64: {
|
|
68
|
+
readonly type: "integer";
|
|
69
|
+
readonly sizeInBits: number;
|
|
70
|
+
readonly signed: boolean;
|
|
71
|
+
readonly fixedAbi: Partial<TAbi>;
|
|
72
|
+
};
|
|
73
|
+
readonly UInt32: {
|
|
74
|
+
readonly type: "integer";
|
|
75
|
+
readonly sizeInBits: number;
|
|
76
|
+
readonly signed: boolean;
|
|
77
|
+
readonly fixedAbi: Partial<TAbi>;
|
|
78
|
+
};
|
|
79
|
+
readonly UInt64: {
|
|
80
|
+
readonly type: "integer";
|
|
81
|
+
readonly sizeInBits: number;
|
|
82
|
+
readonly signed: boolean;
|
|
83
|
+
readonly fixedAbi: Partial<TAbi>;
|
|
84
|
+
};
|
|
85
|
+
readonly ascii: ({ length }: {
|
|
86
|
+
length: number;
|
|
87
|
+
}) => TFieldType;
|
|
88
|
+
readonly pointer: {
|
|
89
|
+
readonly type: "pointer";
|
|
90
|
+
readonly fixedAbi: Partial<TAbi>;
|
|
91
|
+
};
|
|
92
|
+
};
|
|
93
|
+
export { types };
|
|
@@ -0,0 +1,122 @@
|
|
|
1
|
+
/*import type { TAbi } from "../common.ts";*/
|
|
2
|
+
|
|
3
|
+
/*type TCFieldType =
|
|
4
|
+
"char" | "unsigned char" |
|
|
5
|
+
"short" | "unsigned short" |
|
|
6
|
+
"int" | "unsigned int" |
|
|
7
|
+
"long" | "unsigned long" |
|
|
8
|
+
"long long" | "unsigned long long" |
|
|
9
|
+
"float" | "double" | "long double";*/
|
|
10
|
+
|
|
11
|
+
/*type TFieldType = {
|
|
12
|
+
readonly type: "integer";
|
|
13
|
+
readonly sizeInBits: number;
|
|
14
|
+
readonly signed: boolean;
|
|
15
|
+
readonly fixedAbi: Partial<TAbi>;
|
|
16
|
+
} | {
|
|
17
|
+
readonly type: "float";
|
|
18
|
+
readonly sizeInBits: number;
|
|
19
|
+
readonly fixedAbi: Partial<TAbi>;
|
|
20
|
+
} | {
|
|
21
|
+
readonly type: "pointer";
|
|
22
|
+
readonly fixedAbi: Partial<TAbi>;
|
|
23
|
+
} | {
|
|
24
|
+
readonly type: "array";
|
|
25
|
+
readonly elementType: TFieldType;
|
|
26
|
+
readonly length: number;
|
|
27
|
+
} | {
|
|
28
|
+
readonly type: "struct";
|
|
29
|
+
readonly fields: readonly { readonly name: string; readonly definition: TFieldType }[];
|
|
30
|
+
readonly packed: boolean;
|
|
31
|
+
readonly fixedAbi: Partial<TAbi>;
|
|
32
|
+
} | {
|
|
33
|
+
readonly type: "string";
|
|
34
|
+
readonly charSizeInBits: number;
|
|
35
|
+
readonly nullTerminatorMandatory: boolean;
|
|
36
|
+
readonly length: number;
|
|
37
|
+
} | {
|
|
38
|
+
readonly type: "c-type";
|
|
39
|
+
readonly cType: TCFieldType;
|
|
40
|
+
readonly fixedAbi: Partial<TAbi>;
|
|
41
|
+
};*/
|
|
42
|
+
|
|
43
|
+
/*type TBasicFieldType = Exclude<TFieldType, { type: "c-type" }>;*/
|
|
44
|
+
/*type TPrimitiveBasicFieldType = Exclude<TBasicFieldType, { type: "array" } | { type: "struct" } | { type: "string" }>;*/
|
|
45
|
+
|
|
46
|
+
const Int16/*: TFieldType*/ = {
|
|
47
|
+
type: "integer",
|
|
48
|
+
sizeInBits: 16,
|
|
49
|
+
signed: true,
|
|
50
|
+
fixedAbi: {}
|
|
51
|
+
} /*as const*/;
|
|
52
|
+
|
|
53
|
+
const UInt16/*: TFieldType*/ = {
|
|
54
|
+
type: "integer",
|
|
55
|
+
sizeInBits: 16,
|
|
56
|
+
signed: false,
|
|
57
|
+
fixedAbi: {}
|
|
58
|
+
} /*as const*/;
|
|
59
|
+
|
|
60
|
+
const Int32/*: TFieldType*/ = {
|
|
61
|
+
type: "integer",
|
|
62
|
+
sizeInBits: 32,
|
|
63
|
+
signed: true,
|
|
64
|
+
fixedAbi: {}
|
|
65
|
+
} /*as const*/;
|
|
66
|
+
|
|
67
|
+
const Int64/*: TFieldType*/ = {
|
|
68
|
+
type: "integer",
|
|
69
|
+
sizeInBits: 64,
|
|
70
|
+
signed: true,
|
|
71
|
+
fixedAbi: {}
|
|
72
|
+
} /*as const*/;
|
|
73
|
+
|
|
74
|
+
const UInt32/*: TFieldType*/ = {
|
|
75
|
+
type: "integer",
|
|
76
|
+
sizeInBits: 32,
|
|
77
|
+
signed: false,
|
|
78
|
+
fixedAbi: {}
|
|
79
|
+
} /*as const*/;
|
|
80
|
+
|
|
81
|
+
const UInt64/*: TFieldType*/ = {
|
|
82
|
+
type: "integer",
|
|
83
|
+
sizeInBits: 64,
|
|
84
|
+
signed: false,
|
|
85
|
+
fixedAbi: {}
|
|
86
|
+
} /*as const*/;
|
|
87
|
+
|
|
88
|
+
const ascii = ({ length }/*: { length: number }*/)/*: TFieldType*/ => {
|
|
89
|
+
return {
|
|
90
|
+
type: "string",
|
|
91
|
+
charSizeInBits: 8,
|
|
92
|
+
nullTerminatorMandatory: true,
|
|
93
|
+
length
|
|
94
|
+
} /*as const*/;
|
|
95
|
+
};
|
|
96
|
+
|
|
97
|
+
const pointer/*: TFieldType*/ = {
|
|
98
|
+
type: "pointer",
|
|
99
|
+
fixedAbi: {}
|
|
100
|
+
} /*as const*/;
|
|
101
|
+
|
|
102
|
+
/*export type {
|
|
103
|
+
TBasicFieldType,
|
|
104
|
+
TFieldType,
|
|
105
|
+
TCFieldType,
|
|
106
|
+
TPrimitiveBasicFieldType
|
|
107
|
+
};*/
|
|
108
|
+
|
|
109
|
+
const types = {
|
|
110
|
+
Int16,
|
|
111
|
+
UInt16,
|
|
112
|
+
Int32,
|
|
113
|
+
Int64,
|
|
114
|
+
UInt32,
|
|
115
|
+
UInt64,
|
|
116
|
+
ascii,
|
|
117
|
+
pointer
|
|
118
|
+
} /*as const*/;
|
|
119
|
+
|
|
120
|
+
export {
|
|
121
|
+
types
|
|
122
|
+
};
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import type { TEndianness } from "../common.js";
|
|
2
|
+
import type { TValueParser } from "./value.js";
|
|
3
|
+
type TIntegerParser = TValueParser<bigint>;
|
|
4
|
+
declare const createIntegerParser: ({ sizeInBits, signed, endianness }: {
|
|
5
|
+
sizeInBits: number;
|
|
6
|
+
signed: boolean;
|
|
7
|
+
endianness: TEndianness;
|
|
8
|
+
}) => TIntegerParser;
|
|
9
|
+
export { createIntegerParser };
|