Class: LibBin::Structure::Field
- Inherits:
-
Object
- Object
- LibBin::Structure::Field
- Defined in:
- lib/libbin/data_types.rb,
ext/libbin/libbin_c.c
Overview
Field class that is instantiated to describe a structure field. Instances are immutable.
Instance Attribute Summary collapse
-
#align ⇒ Object
readonly
Returns the value of attribute align.
-
#condition ⇒ Object
readonly
Returns the value of attribute condition.
-
#count ⇒ Object
readonly
Returns the value of attribute count.
-
#expect ⇒ Object
readonly
Returns the value of attribute expect.
-
#length ⇒ Object
readonly
Returns the value of attribute length.
-
#name ⇒ Object
readonly
Returns the value of attribute name.
-
#offset ⇒ Object
readonly
Returns the value of attribute offset.
-
#type ⇒ Object
readonly
Returns the value of attribute type.
Instance Method Summary collapse
- #initialize(name, type, length, count, offset, sequence, condition, relative_offset, align, expect) ⇒ Field constructor
-
#relative_offset? ⇒ Boolean
Returns
true
if the field offset should be relative to its parent. -
#sequence? ⇒ Boolean
Returns
true
if the field is a sequence.
Constructor Details
#initialize(name, type, length, count, offset, sequence, condition, relative_offset, align, expect) ⇒ Field
68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 |
# File 'ext/libbin/libbin_c.c', line 68
static VALUE cField_initialize(
VALUE self,
VALUE name,
VALUE type,
VALUE length,
VALUE count,
VALUE offset,
VALUE sequence,
VALUE condition,
VALUE relative_offset,
VALUE align,
VALUE expect) {
VALUE tmp;
struct cField_data *data;
TypedData_Get_Struct(self, struct cField_data, &cField_type, data);
if (RTEST(align)) {
size_t a = NUM2LL(align);
if (a & (a-1))
rb_raise(rb_eRuntimeError, "alignment is not a power of 2: %zu", a);
}
data->name = name;
tmp = rb_str_dup(rb_obj_as_string(name));
data->getter = rb_intern_str(tmp);
data->setter = rb_intern_str(rb_str_cat(tmp, "=", 1));
data->type = cField_preprocess_expression(self, type);
data->length = cField_preprocess_expression(self, length);
data->count = cField_preprocess_expression(self, count);
data->offset = cField_preprocess_expression(self, offset);
data->sequence = sequence;
data->condition = cField_preprocess_expression(self, condition);
data->relative_offset = relative_offset;
data->align = align;
data->expect = expect;
return self;
}
|
Instance Attribute Details
#align ⇒ Object (readonly)
Returns the value of attribute align.
10 11 12 |
# File 'lib/libbin/data_types.rb', line 10 def align @align end |
#condition ⇒ Object (readonly)
Returns the value of attribute condition.
9 10 11 |
# File 'lib/libbin/data_types.rb', line 9 def condition @condition end |
#count ⇒ Object (readonly)
Returns the value of attribute count.
7 8 9 |
# File 'lib/libbin/data_types.rb', line 7 def count @count end |
#expect ⇒ Object (readonly)
Returns the value of attribute expect.
11 12 13 |
# File 'lib/libbin/data_types.rb', line 11 def expect @expect end |
#length ⇒ Object (readonly)
Returns the value of attribute length.
6 7 8 |
# File 'lib/libbin/data_types.rb', line 6 def length @length end |
#name ⇒ Object (readonly)
Returns the value of attribute name.
4 5 6 |
# File 'lib/libbin/data_types.rb', line 4 def name @name end |
#offset ⇒ Object (readonly)
Returns the value of attribute offset.
8 9 10 |
# File 'lib/libbin/data_types.rb', line 8 def offset @offset end |
#type ⇒ Object (readonly)
Returns the value of attribute type.
5 6 7 |
# File 'lib/libbin/data_types.rb', line 5 def type @type end |
Instance Method Details
#relative_offset? ⇒ Boolean
Returns true
if the field offset should be relative to its parent.
|
# File 'lib/libbin/data_types.rb', line 13
|
#sequence? ⇒ Boolean
Returns true
if the field is a sequence
|
# File 'lib/libbin/data_types.rb', line 17
|