class Candiru::StructScaffolding

Overview

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)

Included Modules

Defined in:

candiru.cr

Constructors

Instance Method Summary

Macro Summary

Instance methods inherited from module Candiru::ValueClass(UInt64)

adopt_as_field_value(field : ITypedField, pointer : Pointer(Void)) : FieldValue(T) adopt_as_field_value, from_ffi_return_pointer(pointer : Pointer(Void)) from_ffi_return_pointer, matches?(other : T) matches?

Instance methods inherited from module Candiru::IValueClassType

adopt_as_field_value(field : ITypedField, pointer : Pointer(Void)) adopt_as_field_value, from_ffi_return_pointer(pointer : Pointer(Void)) from_ffi_return_pointer, matches?(other) matches?, to_ffi : FFI::Type to_ffi

Constructor Detail

def self.new #

Initializes an empty struct scaffolding.


[View source]

Instance Method Detail

def <<(type : T.class) forall T #

Appends a struct field of the given type.


[View source]
def <<(scaffolding : StructScaffolding) #

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


[View source]
def [](*args, **options) #

Redirected to #fields.


[View source]
def [](*args, **options, &) #

Redirected to #fields.


[View source]
def bytesize : UInt64 #

Returns the padded size of this struct, in bytes.


[View source]
def each(*args, **options) #

Redirected to #fields.


[View source]
def each(*args, **options, &) #

Redirected to #fields.


[View source]
def fields : Array(ITypedField) #

Returns the array of typed fields in this struct scaffolding.


[View source]
def from_ffi_return_pointer(pointer : Pointer(Void)) #
Description copied from module Candiru::IValueClassType

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


[View source]
def matches?(other : StructInstance) #

[View source]
def new(&) : StructInstance #

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


[View source]
def 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.


[View source]
def new #

Blockless #new.


[View source]
def size(*args, **options) #

Redirected to #fields.


[View source]
def size(*args, **options, &) #

Redirected to #fields.


[View source]
def to_ffi : FFI::Type #
Description copied from module Candiru::IValueClassType

Returns the FFI type corresponding to this value class.

Int32.to_ffi # FFI::Type.sint32

[View source]

Macro Detail

macro [](*types) #

A shorthand for initializing struct scaffolding.

StructScaffolding[Int64, Int64]

# Is the same as writing:

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

[View source]