module Rstruct::ClassMethods
Public Instance Methods
default_registry()
click to toggle source
Returns the default Rstruct
registry
# File lib/rstruct.rb, line 58 def default_registry Registry::DEFAULT_REGISTRY end
get_type(typ, reg=Registry::DEFAULT_REGISTRY)
click to toggle source
# File lib/rstruct.rb, line 62 def get_type(typ, reg=Registry::DEFAULT_REGISTRY) reg[typ] end
sizeof(typ, reg=nil)
click to toggle source
# File lib/rstruct.rb, line 48 def sizeof(typ, reg=nil) reg ||= default_registry if t=reg[typ] t.sizeof else raise(InvalidTypeError, "unknown type: #{typ}") end end
struct(name, opts={},&block)
click to toggle source
Take the following C struct for example:
struct mach_header { uint32_t magic; /* mach magic number identifier */ cpu_type_t cputype; /* cpu specifier */ cpu_subtype_t cpusubtype; /* machine specifier */ uint32_t filetype; /* type of file */ uint32_t ncmds; /* number of load commands */ uint32_t sizeofcmds; /* the size of all the load commands */ uint32_t flags; /* flags */ }
Which might be defined with rstruct as follows:
extend(Rstruct::ClassMethods) typedef :uint32_t, :cpu_type_t typedef :uint32_t, :cpu_subtype_t struct(:mach_header) { uint32_t :magic # mach magic number identifier cpu_type_t :cputype # cpu specifier cpu_subtype_t :cpusubtype # machine specifier uint32_t :filetype # type of file uint32_t :ncmds # number of load commands uint32_t :sizeofcmds # the size of all the load commands uint32_t :flags # flags }
# File lib/rstruct.rb, line 39 def struct(name, opts={},&block) Rstruct::Structure.new(name, opts, &block) end
typedef(p, t, opts={})
click to toggle source
# File lib/rstruct.rb, line 43 def typedef(p, t, opts={}) reg = opts[:register] || default_registry reg.typedef(p,t,opts) end