Skip to main content
Struct defines the memory layout of a C struct, supporting serialization/deserialization. It works with ffi.ptr to pass data to C functions.

Example

Struct()

StructSchema

size

Total size of the struct in bytes, including padding.

create()

Serialize an object to an ArrayBuffer. Nested struct fields accept the ArrayBuffer from their own create().

fromPtr()

Read struct data from a raw pointer. Primitive fields return numbers; nested struct fields return a pointer (the absolute address of the sub-struct). Use the inner schema’s fromPtr to read further.

get() / set()

Only supported for primitive fields. Nested struct fields return 0 / no-op.

Nested Structs

Field values can be another StructSchema for recursive layout computation.

With dlopen (HFA register passing)

For small HFA structs passed in registers, pass StructSchema directly as args / returns to dlopen:
Struct args are expanded to their field values for register passing. Struct returns allocate a buffer and return its pointer. Read the result synchronously via fromPtr.

ARM64 Alignment Rules

Nested struct alignment is the maximum alignment of all its fields.

Working with C Functions