Forum: Ruby marshal_load, marshal_dump

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
3afd3e5e05dc9310c89aa5762cc8dd1d?d=identicon&s=25 Tim Hunter (Guest)
on 2008-12-13 23:48
(Received via mailing list)
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?
0ec4920185b657a03edf01fff96b4e9b?d=identicon&s=25 Yukihiro Matsumoto (Guest)
on 2008-12-15 10:59
(Received via mailing list)
Hi,

In message "Re: marshal_load, marshal_dump"
    on Sun, 14 Dec 2008 07:36:18 +0900, Tim Hunter <TimHunter@nc.rr.com>
writes:

|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?

marshal_dump has high priority over _dump, so you can keep _load as
long as you want backward compatibility.

              matz.
58479f76374a3ba3c69b9804163f39f4?d=identicon&s=25 Eric Hodel (Guest)
on 2008-12-16 00:14
(Received via mailing list)
On Dec 13, 2008, at 14:36 PM, Tim Hunter wrote:
> 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.
3afd3e5e05dc9310c89aa5762cc8dd1d?d=identicon&s=25 Tim Hunter (Guest)
on 2008-12-16 02:28
(Received via mailing list)
Eric Hodel wrote:
> 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.
58479f76374a3ba3c69b9804163f39f4?d=identicon&s=25 Eric Hodel (Guest)
on 2008-12-16 07:31
(Received via mailing list)
On Dec 15, 2008, at 17:20 PM, Tim Hunter wrote:
>> 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.

Look in RubyGems.  Gem::Specification, Gem::Version and
Gem::Requirement have custom marshal methods.
3afd3e5e05dc9310c89aa5762cc8dd1d?d=identicon&s=25 Tim Hunter (Guest)
on 2008-12-16 13:22
(Received via mailing list)
Eric Hodel wrote:
>>> 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.
>
> Look in RubyGems.  Gem::Specification, Gem::Version and Gem::Requirement
> have custom marshal methods.
>
>

Excellent! Thanks for the pointer.
47b1910084592eb77a032bc7d8d1a84e?d=identicon&s=25 Joel VanderWerf (Guest)
on 2008-12-16 20:04
(Received via mailing list)
Tim Hunter wrote:
> 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)
This topic is locked and can not be replied to.