ya-struct 0.0.6 → 0.0.8

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.
@@ -95,6 +95,22 @@ const layoutStruct = ({
95
95
 
96
96
  break;
97
97
  }
98
+ case "array": {
99
+
100
+ // TODO: this is probably not sufficient for all cases
101
+
102
+ // eslint-disable-next-line no-use-before-define
103
+ const { sizeInBits } = layout({ definition: normalizedField.elementType, abi, currentOffsetInBits: 0 });
104
+
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 });
110
+ }
111
+
112
+ break;
113
+ }
98
114
  case "string": {
99
115
  // no special alignment needed
100
116
  break;
@@ -224,7 +240,7 @@ const layout = ({
224
240
  definition: TFieldType,
225
241
  abi: TAbi,
226
242
  currentOffsetInBits: number
227
- // eslint-disable-next-line complexity
243
+ // eslint-disable-next-line complexity
228
244
  }*/)/*: TLayoutedField*/ => {
229
245
 
230
246
  if (definition.type === "struct") {
@@ -84,7 +84,12 @@ declare const types: {
84
84
  };
85
85
  readonly ascii: ({ length }: {
86
86
  length: number;
87
- }) => TFieldType;
87
+ }) => {
88
+ readonly type: "string";
89
+ readonly charSizeInBits: 8;
90
+ readonly nullTerminatorMandatory: true;
91
+ readonly length: number;
92
+ };
88
93
  readonly pointer: {
89
94
  readonly type: "pointer";
90
95
  readonly fixedAbi: Partial<TAbi>;
@@ -85,7 +85,7 @@ const UInt64/*: TFieldType*/ = {
85
85
  fixedAbi: {}
86
86
  } /*as const*/;
87
87
 
88
- const ascii = ({ length }/*: { length: number }*/)/*: TFieldType*/ => {
88
+ const ascii = ({ length }/*: { length: number }*/) => {
89
89
  return {
90
90
  type: "string",
91
91
  charSizeInBits: 8,
package/lib/layout.ts CHANGED
@@ -95,6 +95,22 @@ const layoutStruct = ({
95
95
 
96
96
  break;
97
97
  }
98
+ case "array": {
99
+
100
+ // TODO: this is probably not sufficient for all cases
101
+
102
+ // eslint-disable-next-line no-use-before-define
103
+ const { sizeInBits } = layout({ definition: normalizedField.elementType, abi, currentOffsetInBits: 0 });
104
+
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 });
110
+ }
111
+
112
+ break;
113
+ }
98
114
  case "string": {
99
115
  // no special alignment needed
100
116
  break;
@@ -224,7 +240,7 @@ const layout = ({
224
240
  definition: TFieldType,
225
241
  abi: TAbi,
226
242
  currentOffsetInBits: number
227
- // eslint-disable-next-line complexity
243
+ // eslint-disable-next-line complexity
228
244
  }): TLayoutedField => {
229
245
 
230
246
  if (definition.type === "struct") {
@@ -85,7 +85,7 @@ const UInt64: TFieldType = {
85
85
  fixedAbi: {}
86
86
  } as const;
87
87
 
88
- const ascii = ({ length }: { length: number }): TFieldType => {
88
+ const ascii = ({ length }: { length: number }) => {
89
89
  return {
90
90
  type: "string",
91
91
  charSizeInBits: 8,
package/package.json CHANGED
@@ -1,5 +1,5 @@
1
1
  {
2
- "version": "0.0.6",
2
+ "version": "0.0.8",
3
3
  "name": "ya-struct",
4
4
  "type": "module",
5
5
  "description": "Yet Another Node.js Structure API",