Class: NFS::XDR::Optional

Inherits:
DynamicArray show all
Defined in:
lib/nfs/xdr.rb

Instance Method Summary collapse

Constructor Details

#initialize(type) ⇒ Optional

Returns a new instance of Optional.



185
186
187
# File 'lib/nfs/xdr.rb', line 185

def initialize(type)
  super(type, 1)
end

Instance Method Details

#decode(string) ⇒ Object



197
198
199
200
201
202
203
204
205
# File 'lib/nfs/xdr.rb', line 197

def decode(string)
  result = super(string)

  if result.empty?
    nil
  else
    result[0]
  end
end

#encode(value) ⇒ Object



189
190
191
192
193
194
195
# File 'lib/nfs/xdr.rb', line 189

def encode(value)
  if value.nil?
    super([])
  else
    super([value])
  end
end