Class: XDR::VarArray
- Inherits:
-
Object
- Object
- XDR::VarArray
- Includes:
- Concerns::ArrayConverter, Concerns::ConvertsToXDR
- Defined in:
- lib/xdr/var_array.rb
Instance Method Summary collapse
-
#initialize(child_type, length = XDR::MAX_SIZE) ⇒ VarArray
constructor
A new instance of VarArray.
- #read(io) ⇒ Object
- #valid?(val) ⇒ Boolean
- #write(val, io) ⇒ Object
Methods included from Concerns::ConvertsToXDR
Constructor Details
Instance Method Details
#read(io) ⇒ Object
25 26 27 28 29 30 31 32 33 |
# File 'lib/xdr/var_array.rb', line 25 def read(io) length = XDR::Int.read(io) if length > @length raise XDR::ReadError, "VarArray length #{length} is greater than max #{@length}" end length.times.map { @child_type.read(io) } end |
#valid?(val) ⇒ Boolean
35 36 37 |
# File 'lib/xdr/var_array.rb', line 35 def valid?(val) super(val) && val.length <= @length end |
#write(val, io) ⇒ Object
12 13 14 15 16 17 18 19 20 21 22 23 |
# File 'lib/xdr/var_array.rb', line 12 def write(val, io) length = val.length if length > @length raise XDR::WriteError, "Value length #{length} exceeds max #{@length}" end XDR::Int.write(length, io) val.each do |member| @child_type.write member, io end end |