Class: Rex::Proto::Thrift::ThriftStruct

Inherits:
BinData::Array
  • Object
show all
Defined in:
lib/rex/proto/thrift.rb

Class Method Summary collapse

Class Method Details

.flatten(struct) ⇒ Object

Recursively flatten struct’s members into to a hash, keyed by field ID. This is a one way operation because the width of numbers is lost.



67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
# File 'lib/rex/proto/thrift.rb', line 67

def self.flatten(struct)
  struct = struct.snapshot if struct.is_a?(ThriftStruct)
  flattened = {}
  struct.each do |member|
    case member[:data_type]
    when ThriftDataType::T_STOP
      break
    when ThriftDataType::T_STRUCT
      field_value = flatten(member[:data_value])
    else
      field_value = member[:data_value]
    end

    flattened[member[:field_id]] = field_value
  end

  flattened
end