That wouldn't take care of the reference to the program in all cases, and the codec in the master would only handle it if the program is a pike module or a nested class in a pike module.
If one added additional constraints on the program, like that it must not contain any methods (except perhaps an implicit create function), then it would be possible to encode and decode such objects without the original program - the decoder would simply create an identical one instead. That would allow struct-like classes to be encoded and decoded as simply as mappings.
/ Martin Stjernholm, Roxen IS
Previous text:
2003-02-28 01:05: Subject: Save_Object
This will work: string enc = encode_value(obj, master->Codec());
You need to implement the _encode/_decode methods for the object, for example using a generic implementation:
string _encode() { mapping enc = mkmapping(indices(this), values(this)); foreach(enc; string key; mixed value) { if(functionp(value)) { m_delete(enc, key); } } return encode_value( enc, master()->Codec() ); }
void _decode(string data) { mapping decoded = decode_value(data, master()->Codec()); foreach(decoded; string key; mixed value) { catch { this[key] = value; }; } }
There is no way to make it automatically save public variables to the best of my knowledge (unless you make your own Codec()), but I think that the above solution is easy enough.
That said, if it by default did do what the above does, that wouldn't be bad thing.
/ David Hedbor