Class: NFS::XDR::DynamicString

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

Direct Known Subclasses

Opaque

Instance Method Summary collapse

Constructor Details

#initialize(n = nil) ⇒ DynamicString

Returns a new instance of DynamicString.



110
111
112
113
# File 'lib/nfs/xdr.rb', line 110

def initialize(n = nil)
  @n = n
  @length = UnsignedInteger.new
end

Instance Method Details

#decode(string) ⇒ Object



122
123
124
125
126
# File 'lib/nfs/xdr.rb', line 122

def decode(string)
  length = @length.decode(string)
  superstring = string.slice!(0, XDR.pad(length, 4))
  superstring.nil? ? '' : superstring[0, length]
end

#encode(value) ⇒ Object



115
116
117
118
119
120
# File 'lib/nfs/xdr.rb', line 115

def encode(value)
  value = value.to_s
  n = value.size
  n = @n if !@n.nil? && @n < n
  @length.encode(n) + [value].pack('a' + XDR::pad(n, 4).to_s)
end