Basically _encode nees to take the entire object state and serialize it into something using only the basic data types (i.e. no objects, programs, funtions or types). _decode needs to decode this serialized format and set the object state accoringly.
class A (string foo, int bar) { array _encode() { return ({ foo, bar }); }
array _decode(array in) { [ foo, bar ] = in; } }
void main() { A a=A("hello",18); write("%O\n", encode_value(a)); write("%O\n", decode_value(encode_value(a))->foo); }