class XDR::Array

Public Class Methods

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

Public Instance Methods

read(io) click to toggle source
# File lib/xdr/array.rb, line 21
def read(io)
  @length.times.map{ @child_type.read(io) }
end
valid?(val) click to toggle source
Calls superclass method XDR::Concerns::ArrayConverter#valid?
# File lib/xdr/array.rb, line 25
def valid?(val)
  super(val) && val.length == @length
end
write(val, io) click to toggle source
# File lib/xdr/array.rb, line 12
def write(val, io)
  raise XDR::WriteError, "val is not array" unless val.is_a?(Array)
  raise XDR::WriteError, "array must be #{@length} long, was #{val.length}" if val.length != @length

  @length.times do |i|
    @child_type.write val[i], io
  end
end