Class CanonicalABI
java.lang.Object
ai.tegmentum.webassembly4j.runtime.marshal.CanonicalABI
Static utilities for Component Model Canonical ABI layout calculations.
-
Method Summary
Modifier and TypeMethodDescriptionstatic intalignTo(int offset, int alignment) Aligns an offset up to the given alignment boundary.static int[]fieldOffsets(TypeLayout... fields) Computes the byte offset of each field in a record.static intrecordAlignment(TypeLayout... fields) Computes the alignment of a record, which is the maximum alignment of its fields.static intrecordSize(TypeLayout... fields) Computes the total size of a record with the given field layouts, including padding for alignment.
-
Method Details
-
alignTo
public static int alignTo(int offset, int alignment) Aligns an offset up to the given alignment boundary.- Parameters:
offset- the current offsetalignment- the required alignment (must be a power of 2)- Returns:
- the aligned offset
-
recordSize
Computes the total size of a record with the given field layouts, including padding for alignment.- Parameters:
fields- the field layouts in order- Returns:
- the total record size in bytes (padded to record alignment)
-
fieldOffsets
Computes the byte offset of each field in a record.- Parameters:
fields- the field layouts in order- Returns:
- an array of byte offsets, one per field
-
recordAlignment
Computes the alignment of a record, which is the maximum alignment of its fields.- Parameters:
fields- the field layouts- Returns:
- the record alignment in bytes
-