Re: [Pyobjc-dev] NSCoding support for python list & dict
Brought to you by:
ronaldoussoren
|
From: Ronald O. <ron...@ma...> - 2007-11-27 09:30:47
|
On Tuesday, November 27, 2007, at 08:56AM, "Bill Bumgarner" <bb...@ma...> wrote: >On Nov 26, 2007, at 9:59 PM, Ronald Oussoren wrote: >> NSCoding support for other objects should also be doable, but is >> more work and requires a lot of testing. Pickling Objective-C >> objects on the other hand has the outlooks of being a very hard >> problem. > >NSArchiver and NSKeyedArchiver support arbitrary archival of objects. >That is, you can create an archiving session and then archive the sub- >graphs of objects of objects in arbitrary order and with arbitrary >references between the subgraphs. > >Pickling of a graph containing a mix of Python and Objective-C objects >could be done by creating a UUID for each object in the graph at the >pickle/archiver boundary. The UUID could be stored in the pickle, >could be used to archive the sub-graph of Objective-C objects and >store 'em away via -encodeObject:forKey:, and then the resulting BLOB >of archived Objective-C data could be stored in the pickle as a ><string>. > >Completely trivial, right? At first glance that doesn't quite fit into the pickle interface, but could be made to work using a class/function on top of pickle that does the work. Dealing with cycles and object-identity will be interesting though (e.g. pickle.dumps([O, NSArray.arrayWithArray_([O])]), where O is a pure Python object (or even (O=[]; A=NSArray.arrayWithArray_([O]); O.append(A); pickle.dumps([O,A]). The other way around (adding NSCoding support to Python objects) is easy: just call __getstate__/__reduce__ to get object state, then use encodeObject:forKey: to write that, more basic, object to the stream. > >Only because of my ignorance. There is a definite chicken-and-egg >problem in that archival will produce the archived obj-c objects >*last* whereas unarchival will need them to be decoded *first*. And >that is just scratching the surface. What might work: implement __reduce__ for objc.objc_object using a custom NSCoder subclass that builds a python datastructure containing the object state, then let the pickle machinery serialize that. That is, encodeObject:forKey: would add the object to a dictionary. At some point the object state must be some basic object, such as C integers, which pickle can encode without further recursion. I know this is a bit vague, I made this up while typing this e-mail. It does look like something that can be made to work though. Volunteers? Ronald > >b.bum > >------------------------------------------------------------------------- >This SF.net email is sponsored by: Microsoft >Defy all challenges. Microsoft(R) Visual Studio 2005. >http://clk.atdmt.com/MRT/go/vse0120000070mrt/direct/01/ >_______________________________________________ >Pyobjc-dev mailing list >Pyo...@li... >https://lists.sourceforge.net/lists/listinfo/pyobjc-dev > > |