lib/scrimp/thrift_util.rb
# Converts a Thrift value to a primitive, list, or hash (suitable for conversion to json).
# The value is interpreted using a type info hash of the format returned by #type_info.
Converts a Thrift value to a primitive, list, or hash (suitable for conversion to json).
The value is interpreted using a type info hash of the format returned by #type_info.
Converts a Thrift value to a primitive list or hash ( suitable for conversion to json ) . The value is interpreted using a type info hash of the format returned by #type_info .
def thrift_type_to_json_type(value, field)
        type = Thrift.type_name(field[:type])
        raise Thrift::TypeError.new("Type for #{field.inspect} not found.") unless type
        case type.sub('Types::', '')
        when 'STRUCT'
          if field[:class] < Thrift::Union
            thrift_union_to_json_map(value, field[:class])
          else
            thrift_struct_to_json_map(value, field[:class])
          end
        when 'LIST', 'SET'
          value.map { |e| thrift_type_to_json_type(e, field[:element]) }
        when 'MAP'
          value.map do |key, val|
            [thrift_type_to_json_type(key, field[:key]), thrift_type_to_json_type(val, field[:value])]
          end
        else
          (field[:enum_class] && field[:enum_class]::VALUE_MAP[value]) || value
        end
      end
def thrift_type_to_json_type ( value , field ) type = Thrift . type_name ( field [ :type ] ) raise Thrift :: TypeError . new ( "Type for #{field.inspect} not found." ) unless type case type . sub ( 'Types::' , '' ) when 'STRUCT' if field [ :class ] < Thrift :: Union thrift_union_to_json_map ( value , field [ :class ] ) else thrift_struct_to_json_map ( value , field [ :class ] ) end when 'LIST' , 'SET' value . map { | e | thrift_type_to_json_type ( e , field [ :element ] ) } when 'MAP' value . map do | key , val | [ thrift_type_to_json_type ( key , field [ :key ] ) , thrift_type_to_json_type ( val , field [ :value ] ) ] end else ( field [ :enum_class ] && field [ :enum_class ] :: VALUE_MAP [ value ] ) || value end end
Converts a Thrift value to a primitive, list, or hash (suitable for conversion to json).
Converts a Thrift value to a primitive list or hash ( suitable for conversion to json ) .
value
field