marshal_load, marshal_dump

T

Tim Hunter

Currently RMagick uses the old _dump and _load methods to
marshal/unmarshal images. I'd like to start using the new marshal_load
and marshal_dump methods. What is the impact of switching? Can I just
replace _dump and _load with marshal_dump and marshal_load? Suppose I
have an image that was dumped using an old version of RMagick. How do I
support loading it?
 
E

Eric Hodel

Currently RMagick uses the old _dump and _load methods to marshal/
unmarshal images. I'd like to start using the new marshal_load and
marshal_dump methods. What is the impact of switching? Can I just
replace _dump and _load with marshal_dump and marshal_load? Suppose
I have an image that was dumped using an old version of RMagick. How
do I support loading it?

Note that _dump/_load occurs before allocate and marshal_dump/
marshal_load occurs after. In some instances this is an important
distinction.
 
T

Tim Hunter

Eric said:
Note that _dump/_load occurs before allocate and
marshal_dump/marshal_load occurs after. In some instances this is an
important distinction.

Absolutely. I wish I could find some examples of custom
marshal_dump/marshal_load implementations. Searching thru the
1.8.7/1.9.1 sources didn't turn up anything illuminating.
 
E

Eric Hodel

Absolutely. I wish I could find some examples of custom marshal_dump/
marshal_load implementations. Searching thru the 1.8.7/1.9.1 sources
didn't turn up anything illuminating.

Look in RubyGems. Gem::Specification, Gem::Version and
Gem::Requirement have custom marshal methods.
 
J

Joel VanderWerf

Tim said:
Absolutely. I wish I could find some examples of custom
marshal_dump/marshal_load implementations. Searching thru the
1.8.7/1.9.1 sources didn't turn up anything illuminating.

A very simple one:

class C
attr_accessor :x, :y

def marshal_dump
[x, y]
end

def marshal_load(ary)
@x, @y = ary
end
end

c = C.new
c.x = "foo"
c.y = "bar"

s = Marshal.dump(c)
p Marshal.load(s)
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,764
Messages
2,569,564
Members
45,040
Latest member
papereejit

Latest Threads

Top