Marshal string format

Hello ALL!

Given a class (let’s take the Pickaxe example)

class Klass
def initialize(str)
@str=str
end
def sayHello
@str
end
end

o=Klass.new(“hello\n”)
data=Marshal.dump(o)

p data => “\004\006o:\nKlass\006:\t@str”\nhello"

What does all the meta-data in string “data” mean? I am thinking of placing
them into a different datastructure… I need to know what to expect from
such strings… :slight_smile:

[]s

Pablo

···


Pablo Lorenzzoni (Spectra) spectra@debian.org
GnuPG Key ID 268A084D at search.keyserver.net
Webpage: http://people.debian.org/~spectra/

Have a look through marshal.c, it’s very clearly written.

Marshal is intended to be an ‘opaque’ string that you can squirt into a file
or down a wire, and recreate a copy of the same object at the other end. If
you want it to be parseable, you might prefer to use a different marshaling
library (e.g. YAML or SOAP). Or you can extract the data about your object
directly:

p o.class
p o.instance_variables
o.instance_variables.each { |v| p o.instance_variable_get(v) } # 1.8 only

Marshal is very, very fast though. I would love to see a C library for Perl
which reads/writes in Ruby’s Marshal format :slight_smile:

Cheers,

Brian.

···

On Thu, May 15, 2003 at 09:32:54AM +0900, Pablo Lorenzzoni wrote:

Given a class (let’s take the Pickaxe example)

class Klass
def initialize(str)
@str=str
end
def sayHello
@str
end
end

o=Klass.new(“hello\n”)
data=Marshal.dump(o)

p data => “\004\006o:\nKlass\006:\t@str"\nhello”

What does all the meta-data in string “data” mean?