38
39
40
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
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
|
# File 'lib/rmarshal/unmarshal.rb', line 38
def unmarshal
type = byte
case type
when '.' then :Ellipsis
when '0' then :null when 'N' then nil
when 'T' then true
when 'F' then false
when 'c'
argcount, nlocals, stacksize, flags = long, long, long, long
code_, consts, names, varnames, freevars = unmarshal, unmarshal, unmarshal, unmarshal, unmarshal
cellvars, filename, name = unmarshal, unmarshal, unmarshal
firstlineno, lnotab = long, unmarshal
Code.new(
argcount, nlocals, stacksize, flags,
code_, consts, names, varnames, freevars,
cellvars, filename, name, firstlineno, lnotab
)
when 'f' then @fp.read(byte).to_f
when 'g' then double
when 'i' then long
when 'I' then @fp.read(8).unpack('q')[0]
when 'R'
@interned[long]
when 's' then @fp.read long
when 'S' then :StopIteration
when 't'
str = @fp.read long
@interned[@interned.size] = str
str
when 'u' then @fp.read(long).force_encoding 'utf-8'
when 'x'
Complex @fp.read(byte).to_f(), @fp.read(byte).to_f()
when 'y'
Complex double, double
when '(', '['
(0...long).map { unmarshal }
when '{'
val = {}
while true
key = unmarshal
break if key == :null
val[key] = unmarshal
end
val
when '<', '>'
Set.new((0...long).map { unmarshal })
when '?'
raise 'TYPE_UNKNOWN encountered. Incomplete marshal.'
else
raise "Unknown type '#{type}'"
end
end
|