Class: Rex::Proto::Rmi::Model::Element

Inherits:
Object
  • Object
show all
Includes:
Rex::Proto::Rmi::Model
Defined in:
lib/rex/proto/rmi/model/element.rb

Constant Summary

Constants included from Rex::Proto::Rmi::Model

CALL_MESSAGE, DGC_ACK_MESSAGE, MULTIPLEX_PROTOCOL, PING_ACK, PING_MESSAGE, PROTOCOL_ACK, PROTOCOL_NOT_SUPPORTED, RETURN_DATA, RETURN_EXCEPTION, RETURN_VALUE, SIGNATURE, SINGLE_OP_PROTOCOL, STREAM_PROTOCOL

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(options = {}) ⇒ Element

Returns a new instance of Element.


35
36
37
38
39
40
41
42
# File 'lib/rex/proto/rmi/model/element.rb', line 35

def initialize(options = {})
  self.class.attributes.each do |attr|
    if options.has_key?(attr)
      m = (attr.to_s + '=').to_sym
      self.send(m, options[attr])
    end
  end
end

Class Method Details

.attr_accessor(*vars) ⇒ Object


11
12
13
14
15
# File 'lib/rex/proto/rmi/model/element.rb', line 11

def self.attr_accessor(*vars)
  @attributes ||= []
  @attributes.concat vars
  super(*vars)
end

.attributesArray

Retrieves the element class fields

Returns:

  • (Array)

20
21
22
# File 'lib/rex/proto/rmi/model/element.rb', line 20

def self.attributes
  @attributes
end

.decode(io) ⇒ Rex::Proto::Rmi::Model::Element

Creates a Rex::Proto::Rmi::Model::Element with data from the IO.

Parameters:

  • io (IO)

    the IO to read data from

Returns:


28
29
30
31
32
33
# File 'lib/rex/proto/rmi/model/element.rb', line 28

def self.decode(io)
  elem = self.new
  elem.decode(io)

  elem
end

Instance Method Details

#attributesArray

Retrieves the element instance fields

Returns:

  • (Array)

47
48
49
# File 'lib/rex/proto/rmi/model/element.rb', line 47

def attributes
  self.class.attributes
end

#decode(io) ⇒ Rex::Proto::Rmi::Model::Element

Decodes the Rex::Proto::Rmi::Model::Element from the input.

Returns:

Raises:

  • (NoMethodError)

55
56
57
58
59
60
61
62
63
64
# File 'lib/rex/proto/rmi/model/element.rb', line 55

def decode(io)
  self.class.attributes.each do |attr|
    dec_method = ("decode_#{attr}").to_sym
    decoded = self.send(dec_method, io)
    assign_method = (attr.to_s + '=').to_sym
    self.send(assign_method, decoded)
  end

  self
end

#encodeString

Encodes the Rex::Proto::Rmi::Model::Element into an String.

Returns:

  • (String)

Raises:

  • (NoMethodError)

70
71
72
73
74
75
76
77
78
# File 'lib/rex/proto/rmi/model/element.rb', line 70

def encode
  encoded = ''
  self.class.attributes.each do |attr|
    m = ("encode_#{attr}").to_sym
    encoded << self.send(m) if self.send(attr)
  end

  encoded
end