Sha256: 25135817916680dbce418e001779e524e3eb135dd2367292ffd0a638eb134832

Contents?: true

Size: 650 Bytes

Versions: 11

Compression:

Stored size: 650 Bytes

Contents

class XDR::Array
  include XDR::Concerns::ConvertsToXDR
  include XDR::Concerns::ArrayConverter

  singleton_class.send(:alias_method, :[], :new)

  def initialize(child_type, length)
    @child_type = child_type
    @length     = length
  end

  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

  def read(io)
    @length.times.map{ @child_type.read(io) }
  end

  def valid?(val)
    super(val) && val.length == @length
  end
end

Version data entries

11 entries across 11 versions & 2 rubygems

Version Path
payshares-xdr-0.0.2 lib/xdr/array.rb
xdr-3.0.2 lib/xdr/array.rb
xdr-3.0.1 lib/xdr/array.rb
xdr-3.0.0 lib/xdr/array.rb
xdr-2.0.0 lib/xdr/array.rb
xdr-1.0.0 lib/xdr/array.rb
xdr-0.1.0 lib/xdr/array.rb
xdr-0.0.4 lib/xdr/array.rb
xdr-0.0.3 lib/xdr/array.rb
xdr-0.0.2 lib/xdr/array.rb
xdr-0.0.1 lib/xdr/array.rb