diff --git a/src/property.ts b/src/property.ts index 4b58cfc..12a3796 100644 --- a/src/property.ts +++ b/src/property.ts @@ -58,7 +58,7 @@ export class SimpleProperty implements Property { } else { // Structure const structure = getStructure(this.#type); - return structure.getSize(); + return structure.getSize(true); } } diff --git a/src/struct.ts b/src/struct.ts index ff2cc92..55a319b 100644 --- a/src/struct.ts +++ b/src/struct.ts @@ -48,7 +48,7 @@ export class Struct { const alignment = this.getAlignment(); return Math.ceil(size / alignment) * alignment; } - getSize() { + getSize(round: boolean) { let size; if (this.#size !== null) { size = this.#size; @@ -61,7 +61,9 @@ export class Struct { } } } - size = this.#roundSize(size); + if (round) { + size = this.#roundSize(size); + } return size; } getName() { @@ -120,7 +122,7 @@ export class Struct { this.#properties.sort((a, b) => a.propertyOffset() - b.propertyOffset()); // Check Size - const size = this.getSize(); + const size = this.getSize(true); if (this.#size !== null) { // Check Alignment if (size !== this.#size) { @@ -188,7 +190,7 @@ export class Struct { } else if (i === this.#properties.length) { // End Of Structure Padding if (this.#size !== null && lastProperty) { - const realSize = lastProperty.propertyOffset() + lastProperty.propertySize(); + const realSize = this.#roundSize(lastProperty.propertyOffset() + lastProperty.propertySize()); neededPadding = this.#size - realSize; } } else { @@ -229,7 +231,7 @@ export class Struct { } // Sanity Check Size - const size = this.getSize(); + const size = this.getSize(true); const isSizeDefined = this.#size !== null; out += assertSize(this.#name, size, isSizeDefined);