Class: NFS::XDR::Structure
- Inherits:
-
Object
- Object
- NFS::XDR::Structure
- Defined in:
- lib/nfs/xdr.rb
Instance Method Summary collapse
- #component(name, type) ⇒ Object
- #decode(string) ⇒ Object
- #encode(value) ⇒ Object
-
#initialize(&block) ⇒ Structure
constructor
A new instance of Structure.
Constructor Details
#initialize(&block) ⇒ Structure
Returns a new instance of Structure.
209 210 211 212 213 |
# File 'lib/nfs/xdr.rb', line 209 def initialize(&block) @components = [] @names = [] instance_eval(&block) if block_given? end |
Instance Method Details
#component(name, type) ⇒ Object
215 216 217 218 |
# File 'lib/nfs/xdr.rb', line 215 def component(name, type) @components << [name, type] @names << name end |
#decode(string) ⇒ Object
232 233 234 235 236 |
# File 'lib/nfs/xdr.rb', line 232 def decode(string) @components.each_with_object({}) do |component, result| result[component[0]] = component[1].decode(string) end end |
#encode(value) ⇒ Object
220 221 222 223 224 225 226 227 228 229 230 |
# File 'lib/nfs/xdr.rb', line 220 def encode(value) ''.tap do |result| @components.each do |component| unless value.include?(component[0]) raise 'missing structure component ' + component[0].to_s end result << component[1].encode(value[component[0]]) end end end |