Supported major Marshal version
Supported minor Marshal version
An Array
A Bignum
A class (reference, not content)
A wrapped C pointer
An object that has been extended with a module
false type prefix
Fixnum type prefix
A Float
A Hash
A Hash with a default value (not proc)
Instance variables for a following object
A reference to a previously-stored Object
A module (reference, not content)
An old-style Module (reference, not content)
I'm not sure what makes this old. The byte stream is identical to TYPE_MODULE
nil type prefix
A ruby Object
A Regexp
A String
A Struct
A Symbol
A reference to a previously Symbol
true type prefix
A subclass of a built-in type
An object saved with _dump
An object saved with marshal_dump
Consumes one byte from the marshal stream
# File lib/marshal/structure/tokenizer.rb, line 185 def byte raise Marshal::Structure::EndOfMarshal.new(@consumed, 1) if @consumed >= @byte_array.size data = @byte_array[@consumed] @consumed += 1 data end
Consumes count
bytes from the marshal stream as an Array of
bytes
# File lib/marshal/structure/tokenizer.rb, line 198 def byte_array count bytes(count).bytes.to_a end
Consumes a sequence of bytes from the marshal stream based on the next integer
# File lib/marshal/structure/tokenizer.rb, line 206 def byte_sequence size = long bytes size end
Consumes count
from the marshal stream
# File lib/marshal/structure/tokenizer.rb, line 214 def bytes count raise Marshal::Structure::EndOfMarshal.new(@consumed, count) if @consumed + count > @stream.size data = @stream[@consumed, count] @consumed += count data end
Consumes one byte from the marshal stream and returns a character
# File lib/marshal/structure/tokenizer.rb, line 226 def character byte.chr end
Checks if the stream starts with a compatible marshal version
# File lib/marshal/structure/tokenizer.rb, line 233 def check_version major = @stream[0].ord minor = @stream[1].ord return if major == MAJOR_VERSION and minor <= MINOR_VERSION raise TypeError, "incompatible marshal file format (can't be read)\n\tformat version #{MAJOR_VERSION}.#{MINOR_VERSION} required; #{major}.#{minor} given" end
Decodes a stored C long
# File lib/marshal/structure/tokenizer.rb, line 245 def long c = byte return 0 if c == 0 # convert to signed integer c = (c ^ 0x80) - 0x80 if c > 0 then return c - 5 if 4 < c x = 0 c.times do |i| x |= byte << (8 * i) end x else return c + 5 if c < -4 x = -1 (-c).times do |i| factor = 8 * i x &= ~(0xff << factor) x |= byte << factor end x end end
Returns an Enumerator that will tokenize the Marshal stream.
# File lib/marshal/structure/tokenizer.rb, line 316 def tokens check_version Enumerator.new do |yielder| until @state.empty? do token = next_token yielder << token if token end end end