[NAME] ALL.module.standard.serializer [TITLE] Serializer [DESCRIPTION] Serializer is the module to provide methods for serializing data structures into strings and deserializing from strings. It also provide methods to serialize and deserialize an e ntire namespace. These methods include: * serialize(value:any)=>string Serialize a value to string. Primitive types (such as int, string) and container typ es (such as array, list, map and tuple) are directly serialized. Objects of C data t ypes and Dao classes can be serialized if they define method named serialize() that return data that can be directly serialized. * deserialize(text:string)=>any Deserialize a string into a value. Serializations from primitive types (such as int, string) and container types (such as array, list, map and tuple) can be directly des erialized into values. Serializations from objects of C data types and Dao classes w ill be deserialized into primitive values or container values first. If the C data t ypes and Dao classes has defined constructors that can take these values as paramete rs, such constrcuts will be used to construct proper C data objects and Dao objects as the deserialized values. * backup(tofile='backup.sdo',limit=0) Backup the current namespace by serialization to a file. * restore(fromfile='backup.sdo') Restore a namespace from a backup file. Upon loading this module, these methods are imported to the std namespace. Examples, 1 load serializer; 2 3 list1 = { 1.3, 2.5, 3.6 } 4 list2 = { (any)(name=>'dao',year=>2006), (123+456C, 'abc'), [1.2, 3.4; 5.6, 7.8] } 5 6 s1 = std.serialize( list1 ); 7 s2 = std.serialize( list2 ); 8 9 io.writeln( s2 ) 10 io.writeln( s1, std.deserialize( s1 ) ) 11 io.writeln( s2, std.deserialize( s2 ) ) 12 13 map1 = { 'abc'->123, 'def'->{} } 14 s3 = std.serialize( map1 ); 15 io.writeln( s3, std.deserialize( s3 ) ) 16 17 class Klass 18 { 19 var index = 123; 20 var name = 'abc'; 21 22 routine Klass( ){ index = 789; } 23 routine Klass( i : int, s : string ){ index = i; name = s; } 24 routine Klass( tup : tuple<int,string> ){index = tup[0]; name = tup[1]; } 25 routine serialize(){ return index, name } 26 } 27 object = Klass( 456, 'def' ); 28 io.writeln( object.serialize() ); 29 30 ss = std.serialize( object ); 31 io.writeln( ss ); 32 object = (Klass)std.deserialize( ss ) 33 io.writeln( object, object.index, object.name );