Class: NFS::XDR::DynamicString
- Inherits:
-
Object
- Object
- NFS::XDR::DynamicString
- Defined in:
- lib/nfs/xdr.rb
Direct Known Subclasses
Instance Method Summary collapse
- #decode(string) ⇒ Object
- #encode(value) ⇒ Object
-
#initialize(n = nil) ⇒ DynamicString
constructor
A new instance of DynamicString.
Constructor Details
permalink #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
permalink #decode(string) ⇒ Object
[View source]
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 |
permalink #encode(value) ⇒ Object
[View source]
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 |