Class: Etherlite::Types::ArrayFixed
- Defined in:
- lib/etherlite/types/array_fixed.rb
Instance Attribute Summary collapse
-
#length ⇒ Object
readonly
Returns the value of attribute length.
-
#subtype ⇒ Object
readonly
Returns the value of attribute subtype.
Instance Method Summary collapse
- #decode(_connection, _data) ⇒ Object
- #encode(_values) ⇒ Object
-
#initialize(_subtype, _length) ⇒ ArrayFixed
constructor
A new instance of ArrayFixed.
- #signature ⇒ Object
- #size ⇒ Object
Methods inherited from Base
Constructor Details
#initialize(_subtype, _length) ⇒ ArrayFixed
Returns a new instance of ArrayFixed.
5 6 7 8 9 10 |
# File 'lib/etherlite/types/array_fixed.rb', line 5 def initialize(_subtype, _length) raise ArgumentError, 'An array can not contain a dynamic type' if _subtype.dynamic? @subtype = _subtype @length = _length end |
Instance Attribute Details
#length ⇒ Object (readonly)
Returns the value of attribute length.
3 4 5 |
# File 'lib/etherlite/types/array_fixed.rb', line 3 def length @length end |
#subtype ⇒ Object (readonly)
Returns the value of attribute subtype.
3 4 5 |
# File 'lib/etherlite/types/array_fixed.rb', line 3 def subtype @subtype end |
Instance Method Details
#decode(_connection, _data) ⇒ Object
28 29 30 |
# File 'lib/etherlite/types/array_fixed.rb', line 28 def decode(_connection, _data) Etherlite::Support::Array.decode(_connection, [@subtype] * @length, _data) end |
#encode(_values) ⇒ Object
21 22 23 24 25 26 |
# File 'lib/etherlite/types/array_fixed.rb', line 21 def encode(_values) raise ArgumentError, "expected an array for #{signature}" unless _values.is_a? Array raise ArgumentError, "expected array of length #{@length}" unless _values.length == @length Etherlite::Support::Array.encode([@subtype] * @length, _values) end |
#signature ⇒ Object
12 13 14 |
# File 'lib/etherlite/types/array_fixed.rb', line 12 def signature "#{@subtype.signature}[#{@length}]" end |
#size ⇒ Object
16 17 18 19 |
# File 'lib/etherlite/types/array_fixed.rb', line 16 def size return nil if @subtype.dynamic? @subtype.size * @length end |