forked from msgpack/msgpack-ruby
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathpacker.rb
More file actions
37 lines (31 loc) · 1013 Bytes
/
packer.rb
File metadata and controls
37 lines (31 loc) · 1013 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
module MessagePack
class Packer
# see ext for other methods
# The semantic of duping a packer is just too weird.
undef_method :dup
undef_method :clone
def register_type(type, klass, method_name = nil, &block)
raise ArgumentError, "expected Module/Class got: #{klass.inspect}" unless klass.is_a?(Module)
register_type_internal(type, klass, block || method_name.to_proc)
end
def registered_types
list = []
registered_types_internal.each_pair do |klass, ary|
list << {type: ary[0], class: klass, packer: ary[1]}
end
list.sort{|a, b| a[:type] <=> b[:type] }
end
def type_registered?(klass_or_type)
case klass_or_type
when Class
klass = klass_or_type
registered_types.any?{|entry| klass <= entry[:class] }
when Integer
type = klass_or_type
registered_types.any?{|entry| type == entry[:type] }
else
raise ArgumentError, "class or type id"
end
end
end
end