Method: Rex::Encoder::XDR.encode
- Defined in:
- lib/rex/encoder/xdr.rb
.encode(*data) ⇒ Object
encode(0, [0, 1], “foo”, [“bar”, 4]) does:
encode_int(0) +
encode_varray([0, 1]) { |i| XDR.encode_int(i) } +
encode_string("foo") +
encode_string("bar", 4)
63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 |
# File 'lib/rex/encoder/xdr.rb', line 63 def XDR.encode(*data) data.collect do |var| if var.kind_of?(String) encode_string(var) elsif var.kind_of?(Integer) encode_int(var) elsif var.kind_of?(Array) && var[0].kind_of?(String) raise ArgumentError, 'XDR: Incorrect string array arguments' if var.length != 2 encode_string(var[0], var[1]) elsif var.kind_of?(Array) && var[0].kind_of?(Integer) encode_varray(var) { |i| XDR.encode_int(i) } # 0 means an empty array index in the case of Integer and an empty string in # the case of String so we get the best of both worlds elsif var.kind_of?(Array) && var[0].nil? encode_int(0) else type = var.class type = var[0].class if var.kind_of?(Array) raise TypeError, "XDR: encode does not support #{type}" end end.join(nil) end |