|
From: Dave B. <dav...@3d...> - 2007-06-27 10:27:21
|
I am trying to NSArchive and NSUnarchive some objects by first
marshaling them (these are pure Ruby objects) and it looks like only
part of the object tree is being archived. Marshal.dump returns a
Ruby string (really a byte array) and some byte value (probably 0) is
causing an early termination when the string is converted to NSData
automatically by NSArchive.
The section of code that demonstrates this is:
a = NSArchiver.archivedDataWithRootObject("a simple string".to_s)
u = NSUnarchiver.unarchiveObjectWithData(a)
pp a.to_s
pp u.to_s
puts "---"
dumped_data = Marshal.dump(@elementsOnPath)
pp dumped_data
a = NSArchiver.archivedDataWithRootObject(dumped_data.to_s)
u = NSUnarchiver.unarchiveObjectWithData(a)
pp a.to_s
pp u.to_s
puts "---"
a1 = NSData.alloc.initWithBytes_length(dumped_data,
dumped_data.length)
b1 = NSArchiver.archivedDataWithRootObject(a1)
u1 = NSUnarchiver.unarchiveObjectWithData(b1)
pp a1.to_s
pp b1.to_s
pp u1.to_s
and the results are (I have spaced these out and given some
explanation):
"<040b7479 70656473 74726561 6d8103e8 84014084 8484084e 53537472
696e6701 8484084e 534f626a 65637400 8584012b 0f612073 696d706c
65207374 72696e67 86>"
"a simple string"
The final result as expected.
"\004\010[\010U:\tPath[\n\"\vPath 0U:\016Inspector[\010@\010i\002,
\001i\001\310f\010100i\031i\006U;\000[\n\"\vPath 0U;\006[\010@\016i
\002,\001i\001\310@\vi\031i\006U;\000[\n\"\vPath 0U;\006[\010@\023i
\002,\001i\001\310@\vi\031i\006"
The object hierarchy given out by marshal
"<040b7479 70656473 74726561 6d8103e8 84014085 >"
Truncated by NSArchive
""
Converted to a null string by NSUnarchive
---
"<04085b08 553a0950 6174685b 0a220b50 61746820 30553a0e 496e7370
6563746f 725b0840 0869022c 016901c8 66083130 30691969 06553b00
5b0a220b 50617468 2030553b 065b0840 0e69022c 016901c8 400b6919
6906553b 005b0a22 0b506174 68203055 3b065b08 40136902 2c016901
c8400b69 196906>"
"<040b7479 70656473 74726561 6d8103e8 84014084 8484064e 53446174
61008484 084e534f 626a6563 74008584 01697784 065b3131 39635d04
085b0855 3a095061 74685b0a 220b5061 74682030 553a0e49 6e737065
63746f72 5b084008 69022c01 6901c866 08313030 69196906 553b005b
0a220b50 61746820 30553b06 5b08400e 69022c01 6901c840 0b691969
06553b00 5b0a220b 50617468 2030553b 065b0840 1369022c 016901c8
400b6919 690686>"
"<04085b08 553a0950 6174685b 0a220b50 61746820 30553a0e 496e7370
6563746f 725b0840 0869022c 016901c8 66083130 30691969 06553b00
5b0a220b 50617468 2030553b 065b0840 0e69022c 016901c8 400b6919
6906553b 005b0a22 0b506174 68203055 3b065b08 40136902 2c016901
c8400b69 196906>"
Converting the dumped string to NSData before NSArchiving and
NSUnarchiving returns the same data.
Using built in Ruby (1.8.2) and binary distribution of RubyCocoa
0.11.1 on a G4.
Dave.
|