class

Candiru::StructScaffolding

Inherits Candiru::ValueClass < Candiru::IValueClassType < Reference < Object

Struct scaffolding helps to describe the scaffolding of structs.

This implementation treats structs as arrays with (possibly) different type for each element.

point = StructScaffolding[Int32, Int32]

instance = point.new do |b|
  b << 123
  b << 456
end

instance.pointer # Pointer(Void)

Constructors

new

Initializes an empty struct scaffolding.

Source

Instance methods

<<(type : T.class) forall T

Appends a struct field of the given type.

Source
<<(scaffolding : StructScaffolding)

Appends a pointer to another struct (could be itself, e.g. in a linked list), as described by scaffolding.

Source
[](*args, **options)

Redirected to fields.

Source
[](*args, **options, &)

Redirected to fields.

Source
bytesize

Returns the padded size of this struct, in bytes.

Source
each(*args, **options)

Redirected to fields.

Source
each(*args, **options, &)

Redirected to fields.

Source
fields

Returns the array of typed fields in this struct scaffolding.

Source
from_ffi_return_pointer(pointer : Pointer(Void))

Casts pointer, a return value hole from FFI, to this type, and returns its value.

Source
matches?(other : StructInstance)
Source
new

Yields a StructBuilder which facilitates the creation of an instance of this struct. Returns the resulting struct instance.

Source
new(pointer : Pointer(Void))

Makes a struct instance from pointer. Unsafe: does not verify whether the contents of pointer are valid for use under this struct scaffolding.

Source
new

Blockless new.

Source
size(*args, **options)

Redirected to fields.

Source
size(*args, **options, &)

Redirected to fields.

Source
to_ffi

Returns the FFI type corresponding to this value class.

Int32.to_ffi # FFI::Type.sint32
Source

Macros

[](*types)

A shorthand for initializing struct scaffolding.

StructScaffolding[Int64, Int64]

# Is the same as writing:

scaffolding = StructScaffolding.new
scaffolding << Int64
scaffolding << Int64
Source