class Gogyou::Model
構造体の構成情報などを保持するクラスです。
構造体の大きさや各フィールドの名前、バイト位置、型などを管理します。
Constants
- BasicCreator
- BasicStruct
- FIELDNAME_PATTERN
- TYPEMAP
Public Class Methods
check_typeinfo(obj)
click to toggle source
# File lib/gogyou/model.rb, line 210 def self.check_typeinfo(obj) if obj.kind_of?(Model) || (obj.kind_of?(Module) && obj < Accessor) || (obj.respond_to?(:bytesize) && obj.respond_to?(:bytealign) && obj.respond_to?(:extensible?) && obj.respond_to?(:aset) && obj.respond_to?(:aref)) true else false end end
define_container(typemap, packexp, model_type, &block)
click to toggle source
# File lib/gogyou/model.rb, line 202 def self.define_container(typemap, packexp, model_type, &block) creator = model_type::Creator.new(typemap, 0, []) proxy = model_type::Creator::Proxy.new(creator, packexp) proxy.instance_exec(&block) model = creator.to_model model end
initialize(bytesize, bytealign, fields, ...)
click to toggle source
- bytesize
-
This is total model size in bytes.
- bytealign
-
This is model alignment size in bytes.
- fields …
-
These are one or more field instance.
Calls superclass method
# File lib/gogyou/model.rb, line 29 def initialize(bytesize, bytealign, field1, *fields) if fields.empty? && field1.kind_of?(::Array) super else super bytesize.to_i, bytealign.to_i, [field1, *fields] end end
struct(typemap, packexp = Field::PACKSIZE_NOTDEFINE, &block)
click to toggle source
# File lib/gogyou/model.rb, line 169 def self.struct(typemap, packexp = Field::PACKSIZE_NOTDEFINE, &block) define_container(typemap, packexp, Model::Struct, &block) end
typedef(typemap, type, aliasname, *elements)
click to toggle source
# File lib/gogyou/model.rb, line 177 def self.typedef(typemap, type, aliasname, *elements) raise ArgumentError, "informal aliasname (#{aliasname.inspect})" unless aliasname =~ FIELDNAME_PATTERN aliasname = aliasname.intern case type when Symbol, String type0 = type type = typemap[type.intern] raise ArgumentError, "type not defined (#{type0})" unless type else # 型情報子を用いる方法 raise ArgumentError, "type is not typeinfo (#{type.inspect})" unless Model.check_typeinfo(type) end unless elements.empty? # 配列型 # TODO: Accessor::Array を構築するのではなく、Model::Array インスタンスを生成するようにする type = Accessor.define_subarray(Model::Field[0, nil, elements, type, 0]) end typemap[aliasname] = type nil end
union(typemap, packexp = Field::PACKSIZE_NOTDEFINE, &block)
click to toggle source
# File lib/gogyou/model.rb, line 173 def self.union(typemap, packexp = Field::PACKSIZE_NOTDEFINE, &block) define_container(typemap, packexp, Model::Union, &block) end
Public Instance Methods
aref(buffer, offset)
click to toggle source
# File lib/gogyou/model.rb, line 41 def aref(buffer, offset) raise NotImplementedError end
aset(buffer, offset, value)
click to toggle source
# File lib/gogyou/model.rb, line 37 def aset(buffer, offset, value) raise NotImplementedError end
extensible?()
click to toggle source
# File lib/gogyou/model.rb, line 45 def extensible? fields.any? { |f| f.extensible? } end
pretty_print(q)
click to toggle source
# File lib/gogyou/model.rb, line 55 def pretty_print(q) #bytesize, bytealign, fields q.group(1, "#{self.class}[") do #q.breakable q.text "bytesize=" q.pp bytesize q.text ", " #q.breakable q.text "bytealign=" q.pp bytealign q.text ", " #q.breakable(" ") q.text "fields=" q.breakable q.pp fields end q.text "]" end
to_s()
click to toggle source
# File lib/gogyou/model.rb, line 49 def to_s "#{self.class}[bytesize=#{bytesize.inspect}, bytealign=#{bytealign.inspect}, fields=#{fields.inspect}]" end
Also aliased as: inspect