ya-struct 0.0.4 → 0.0.5
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/lib/marshaller.js +8 -0
- package/lib/types/basic.js +9 -9
- package/package.json +1 -1
package/lib/marshaller.js
CHANGED
|
@@ -30,6 +30,10 @@ const createInterpretingMarshaller = ({ fieldDefinitions, size }) => {
|
|
|
30
30
|
? BigInt(data[fieldName])
|
|
31
31
|
: Number(data[fieldName]);
|
|
32
32
|
|
|
33
|
+
if (!result[writeFuncName]) {
|
|
34
|
+
throw Error(`can't marshal "${fieldName}" ${JSON.stringify(fieldDefinitions[fieldName])}`);
|
|
35
|
+
}
|
|
36
|
+
|
|
33
37
|
result[writeFuncName](valueToWrite, offset);
|
|
34
38
|
});
|
|
35
39
|
|
|
@@ -54,6 +58,10 @@ const createInterpretingMarshaller = ({ fieldDefinitions, size }) => {
|
|
|
54
58
|
endianness,
|
|
55
59
|
})}`;
|
|
56
60
|
|
|
61
|
+
if (!buffer[readFuncName]) {
|
|
62
|
+
throw Error(`can't unmarshal "${fieldName}" ${JSON.stringify(fieldDefinitions[fieldName])}`);
|
|
63
|
+
}
|
|
64
|
+
|
|
57
65
|
const val = buffer[readFuncName](offset);
|
|
58
66
|
|
|
59
67
|
result = {
|
package/lib/types/basic.js
CHANGED
|
@@ -146,7 +146,7 @@ const dataAndAlignmentModels = {
|
|
|
146
146
|
},
|
|
147
147
|
};
|
|
148
148
|
|
|
149
|
-
const abi = ({ dataModel, compiler, endianness }) => {
|
|
149
|
+
const abi = ({ dataModel, compiler, endianness: defaultEndianess }) => {
|
|
150
150
|
const model =
|
|
151
151
|
dataAndAlignmentModels[dataModel]?.[compiler] ||
|
|
152
152
|
dataAndAlignmentModels.default;
|
|
@@ -155,7 +155,7 @@ const abi = ({ dataModel, compiler, endianness }) => {
|
|
|
155
155
|
return Math.floor((offset + align - 1) / align) * align;
|
|
156
156
|
};
|
|
157
157
|
|
|
158
|
-
const type = ({ signed, align, size }) => {
|
|
158
|
+
const type = ({ signed, align, size, endianness }) => {
|
|
159
159
|
return ({ offset }) => {
|
|
160
160
|
const alignedOffset = findAlignedOffset({ offset, align });
|
|
161
161
|
|
|
@@ -170,28 +170,28 @@ const abi = ({ dataModel, compiler, endianness }) => {
|
|
|
170
170
|
|
|
171
171
|
return {
|
|
172
172
|
Int8: type({ ...model.Int8, endianness: undefined }),
|
|
173
|
-
Int16: type({ ...model.Int16, endianness }),
|
|
173
|
+
Int16: type({ ...model.Int16, endianness: defaultEndianess }),
|
|
174
174
|
Int16LE: type({ ...model.Int16, endianness: "LE" }),
|
|
175
175
|
Int16BE: type({ ...model.Int16, endianness: "BE" }),
|
|
176
|
-
Int32: type({ ...model.Int32, endianness }),
|
|
176
|
+
Int32: type({ ...model.Int32, endianness: defaultEndianess }),
|
|
177
177
|
Int32LE: type({ ...model.Int32, endianness: "LE" }),
|
|
178
178
|
Int32BE: type({ ...model.Int32, endianness: "BE" }),
|
|
179
|
-
Int64: type({ ...model.Int64, endianness }),
|
|
179
|
+
Int64: type({ ...model.Int64, endianness: defaultEndianess }),
|
|
180
180
|
Int64LE: type({ ...model.Int64, endianness: "LE" }),
|
|
181
181
|
Int64BE: type({ ...model.Int64, endianness: "BE" }),
|
|
182
182
|
|
|
183
183
|
UInt8: type({ ...model.UInt8, endianness: undefined }),
|
|
184
|
-
UInt16: type({ ...model.UInt16, endianness }),
|
|
184
|
+
UInt16: type({ ...model.UInt16, endianness: defaultEndianess }),
|
|
185
185
|
UInt16LE: type({ ...model.UInt16, endianness: "LE" }),
|
|
186
186
|
UInt16BE: type({ ...model.UInt16, endianness: "BE" }),
|
|
187
|
-
UInt32: type({ ...model.UInt32, endianness }),
|
|
187
|
+
UInt32: type({ ...model.UInt32, endianness: defaultEndianess }),
|
|
188
188
|
UInt32LE: type({ ...model.UInt32, endianness: "LE" }),
|
|
189
189
|
UInt32BE: type({ ...model.UInt32, endianness: "BE" }),
|
|
190
|
-
UInt64: type({ ...model.UInt64, endianness }),
|
|
190
|
+
UInt64: type({ ...model.UInt64, endianness: defaultEndianess }),
|
|
191
191
|
UInt64LE: type({ ...model.UInt64, endianness: "LE" }),
|
|
192
192
|
UInt64BE: type({ ...model.UInt64, endianness: "BE" }),
|
|
193
193
|
|
|
194
|
-
Pointer: type({ ...model.Pointer, endianness }),
|
|
194
|
+
Pointer: type({ ...model.Pointer, endianness: defaultEndianess }),
|
|
195
195
|
};
|
|
196
196
|
};
|
|
197
197
|
|