Method: MessagePack::Factory#registered_types

Defined in:
lib/msgpack/factory.rb

#registered_types(selector = :both) ⇒ Object

id, class: Class(or nil), packer: arg, unpacker: arg, …


41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
# File 'lib/msgpack/factory.rb', line 41

def registered_types(selector=:both)
  packer, unpacker = registered_types_internal
  # packer: Class -> [tid, proc, _flags]
  # unpacker: tid -> [klass, proc, _flags]

  list = []

  case selector
  when :both
    packer.each_pair do |klass, ary|
      type = ary[0]
      packer_proc = ary[1]
      unpacker_proc = nil
      if unpacker.has_key?(type)
        unpacker_proc = unpacker.delete(type)[1]
      end
      list << {type: type, class: klass, packer: packer_proc, unpacker: unpacker_proc}
    end

    # unpacker definition only
    unpacker.each_pair do |type, ary|
      list << {type: type, class: ary[0], packer: nil, unpacker: ary[1]}
    end

  when :packer
    packer.each_pair do |klass, ary|
      if ary[1]
        list << {type: ary[0], class: klass, packer: ary[1]}
      end
    end

  when :unpacker
    unpacker.each_pair do |type, ary|
      if ary[1]
        list << {type: type, class: ary[0], unpacker: ary[1]}
      end
    end

  else
    raise ArgumentError, "invalid selector #{selector}"
  end

  list.sort{|a, b| a[:type] <=> b[:type] }
end