class XDR::VarArray

Public Class Methods

new(child_type, length=XDR::MAX_SIZE) click to toggle source
# File lib/xdr/var_array.rb, line 7
def initialize(child_type, length=XDR::MAX_SIZE)
  @child_type   = child_type
  @length = length
end

Public Instance Methods

read(io) click to toggle source
# 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) click to toggle source
Calls superclass method XDR::Concerns::ArrayConverter#valid?
# File lib/xdr/var_array.rb, line 35
def valid?(val)
  super(val) && val.length <= @length
end
write(val, io) click to toggle source
# 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