class XDR::Opaque

Public Class Methods

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

Public Instance Methods

read(io) click to toggle source
# File lib/xdr/opaque.rb, line 12
def read(io)
  # read and return @length bytes
  # throw away @padding bytes
  read_bytes(io, @length).tap{ read_bytes(io, @padding) }
end
write(val,io) click to toggle source
# File lib/xdr/opaque.rb, line 18
def write(val,io)
  length = val.bytesize
  
  if val.length != @length
    raise XDR::WriteError, "Value length is #{length}, must be #{@length}" 
  end

  io.write val
  io.write "\x00" * @padding
end