1. c array serialization and deserialization API
// Serialize and serialize the C array apibool parsefromarray (const void * data, int size); bool serializetoarray (void * data, int size) const; // use void set_people () {WP. set_name ("sealyao"); WP. set_id (123456); WP. set_email ("sealyaog@gmail.com"); WP. serializetoarray (parray, 256);} void get_people () {rap. parsefromarray (parray, 256); cout <"get people from array:" <Endl; cout <"\ t name:" <rap. name () <Endl; cout <"\ t ID:" <rap. ID () <Endl; cout <"\ t Email:" <rap. email () <Endl ;}
2. c ++ string serialization and deserialization API
// C ++ string serialize and serialize apibool serializetostring (string * output) const; bool parsefromstring (const string & data); // use: void set_people () {WP. set_name ("sealyao"); WP. set_id (123456); WP. set_email ("sealyaog@gmail.com"); WP. serializetostring (& pstring);} void get_people () {RSP. parsefromstring (pstring); cout <"get people from string:" <Endl; cout <"\ t name:" <RSP. name () <Endl; cout <"\ t ID:" <RSP. ID () <Endl; cout <"\ t Email:" <RSP. email () <Endl ;}
3. file descriptor serialization and deserialization APIs
// File descriptor serialization and serialization API bool serializetofiledescriptor (INT file_descriptor) const; bool parsefromfiledescriptor (INT file_descriptor); // use: void set_people () {FD = open (path, o_creat | o_trunc | o_rdwr, 0644); If (FD <= 0) {perror ("open"); exit (0);} WP. set_name ("sealyaog"); WP. set_id (123456); WP. set_email ("sealyaog@gmail.com"); WP. serializetofiledescriptor (FD); close (FD);} void get_people () {FD = open (path, o_rdonly); If (FD <= 0) {perror ("open "); exit (0);} Rp. parsefromfiledescriptor (FD); STD: cout <"get people from Fd:" <Endl; STD: cout <"\ t name:" <Rp. name () <Endl; STD: cout <"\ t ID:" <Rp. ID () <Endl; STD: cout <"\ t Email:" <Rp. email () <Endl; close (FD );}
4. c ++ streamSerialization and deserialization APIs
// C ++ stream serialization/deserialization apibool serializetoostream (ostream * output) const; bool parsefromistream (istream * input); // use: void set_people () {fstream FS (path, IOS: Out | IOs: trunc | IOs: Binary); WP. set_name ("sealyaog"); WP. set_id (123456); WP. set_email ("sealyaog@gmail.com"); WP. serializreceivstream (& FS); FS. close (); FS. clear ();} void get_people () {fstream FS (path, IOS: In | IOs: Binary); RP. parsefromistream (& FS); STD: cout <"\ t name:" <Rp. name () <Endl; STD: cout <"\ t ID:" <Rp. ID () <Endl; STD: cout <"\ t Email:" <Rp. email () <Endl; FS. close (); FS. clear ();}