Class: LibBin::Structure::Bitfield Abstract
- Inherits:
-
Object
- Object
- LibBin::Structure::Bitfield
- Defined in:
- lib/libbin/data_types.rb
Overview
A parent class that represent a bitfield that is
loading integers as an instance of itself. User should inherit this base class.
Scalars collapse
-
.map ⇒ Object
Bitfield’s field names and number of bits.
-
.signed ⇒ Object
readonly
Signedness of the underlying type.
-
.type ⇒ Object
Underlying type.
-
#__remainder ⇒ Object
Unused bits of underlying value.
Scalars collapse
-
.align ⇒ Object
Returns the underlying type
align
property. -
.always_align ⇒ Object
Returns the underlying type
always_align
property. -
.convert(input, output, input_big = LibBin::default_big?, output_big = !input_big,, parent = nil, index = nil, length = nil) ⇒ Bitfield+
Convert a Bitfield by loading it from
input
and dumping it tooutput
. -
.dump(value, output, output_big = LibBin::default_big?, parent = nil, index = nil, length = nil) ⇒ nil
Dump a Bitfield to
output
. -
.load(input, input_big = LibBin::default_big?, parent = nil, index = nil, length = nil) ⇒ Bitfield+
Load a Bitfield from
input
, and return it. -
.set_type_size(sz, signed = false) ⇒ Object
Set the size and signedness of the underlying type.
-
.shape(value = nil, previous_offset = 0, parent = nil, index = nil, kind = DataShape, length = nil) ⇒ Object
Forwards the call to the underlying type.
-
.size(value = nil, previous_offset = 0, parent = nil, index = nil, length = nil) ⇒ Object
Forwards the call to the underlying type.
Class Attribute Details
.map ⇒ Object
Bitfield’s field names and number of bits
505 506 507 |
# File 'lib/libbin/data_types.rb', line 505 def map @map end |
.signed ⇒ Object (readonly)
Signedness of the underlying type
507 508 509 |
# File 'lib/libbin/data_types.rb', line 507 def signed @signed end |
.type ⇒ Object
Underlying type
509 510 511 |
# File 'lib/libbin/data_types.rb', line 509 def type @type end |
Instance Attribute Details
#__remainder ⇒ Object
Unused bits of underlying value
548 549 550 |
# File 'lib/libbin/data_types.rb', line 548 def __remainder @__remainder end |
Class Method Details
.align ⇒ Object
Returns the underlying type align
property
601 602 603 |
# File 'lib/libbin/data_types.rb', line 601 def self.align @type.align end |
.always_align ⇒ Object
Returns the underlying type always_align
property
596 597 598 |
# File 'lib/libbin/data_types.rb', line 596 def self.always_align @type.always_align end |
.convert(input, output, input_big = LibBin::default_big?, output_big = !input_big,, parent = nil, index = nil, length = nil) ⇒ Bitfield+
Convert a LibBin::Structure::Bitfield by loading it from input
and dumping it to output
. Returns the loaded field.
651 652 653 654 655 656 657 658 659 660 661 662 663 664 |
# File 'lib/libbin/data_types.rb', line 651 def self.convert(input, output, input_big = LibBin::default_big?, output_big = !input_big, parent = nil, index = nil, length = nil) v = @type.convert(input, output, input_big, output_big, parent, index, length) if length v.collect { |val| bf = self.new bf.__set_value(val) bf } else bf = self.new bf.__set_value(v) bf end end |
.dump(value, output, output_big = LibBin::default_big?, parent = nil, index = nil, length = nil) ⇒ nil
Dump a LibBin::Structure::Bitfield to output
.
677 678 679 680 681 682 683 684 685 686 687 |
# File 'lib/libbin/data_types.rb', line 677 def self.dump(value, output, output_big = LibBin::default_big?, parent = nil, index = nil, length = nil) v = if length length.times.collect { |i| value[i].__get_value } else value.__get_value end @type.dump(v, output, output_big, parent, index, length) end |
.load(input, input_big = LibBin::default_big?, parent = nil, index = nil, length = nil) ⇒ Bitfield+
Load a LibBin::Structure::Bitfield from input
, and return it.
624 625 626 627 628 629 630 631 632 633 634 635 636 637 |
# File 'lib/libbin/data_types.rb', line 624 def self.load(input, input_big = LibBin::default_big?, parent = nil, index = nil, length = nil) v = @type.load(input, input_big, parent, index, length) if length v.collect { |val| bf = self.new bf.__set_value(val) bf } else bf = self.new bf.__set_value(v) bf end end |
.set_type_size(sz, signed = false) ⇒ Object
Set the size and signedness of the underlying type
512 513 514 515 516 517 518 519 |
# File 'lib/libbin/data_types.rb', line 512 def set_type_size(sz, signed = false) tname = "#{signed ? "" : "U"}Int#{sz}" t = eval tname raise "unsupported bitfield type #{tname}" unless t @type = t @signed = signed return sz end |
.shape(value = nil, previous_offset = 0, parent = nil, index = nil, kind = DataShape, length = nil) ⇒ Object
Forwards the call to the underlying type
611 612 613 |
# File 'lib/libbin/data_types.rb', line 611 def self.shape(value = nil, previous_offset = 0, parent = nil, index = nil, kind = DataShape, length = nil) @type.shape(value, previous_offset, parent, index, kind, length) end |
.size(value = nil, previous_offset = 0, parent = nil, index = nil, length = nil) ⇒ Object
Forwards the call to the underlying type
606 607 608 |
# File 'lib/libbin/data_types.rb', line 606 def self.size(value = nil, previous_offset = 0, parent = nil, index = nil, length = nil) @type.size(value, previous_offset, parent, index, length) end |