serialization

Discuss the development of new homebrew software, tools and libraries.

Moderators: cheriff, TyRaNiD

Post Reply
daaa57150
Posts: 28
Joined: Fri Nov 17, 2006 10:35 pm

serialization

Post by daaa57150 »

Hi,

is there a library somewhere I can use for serializing my objects?
I found that but it's not usable on cygwin.
did someone already do serialization on his own?
I need it for saving profiles (scores etc) into binary files for a beginning but I think I'll need it if I implement multiplayer one day..
User avatar
jean
Posts: 489
Joined: Sat Jan 05, 2008 2:44 am

Post by jean »

As long as C++ does support polymorphism, inheritance and the other nice things we are used to, generic serialization through so called "reflection" is something commonly done only by managed code (java,.net,mono). With this i'm not teling this cannot be done (if code has to be polymorphic, all naming data and method signatures are to be stored) but i'm telling that even use this (if you have not to implement yourself) would be a pain in the a**. Don't know of any specific library, but a quick search on google will show many. However, my suggestion remains: "implement specific serializeMe() and deSerializeMe() methods in your class"...
daaa57150
Posts: 28
Joined: Fri Nov 17, 2006 10:35 pm

Post by daaa57150 »

jean wrote:As long as C++ does support polymorphism, inheritance and the other nice things we are used to, generic serialization through so called "reflection" is something commonly done only by managed code (java,.net,mono). With this i'm not teling this cannot be done (if code has to be polymorphic, all naming data and method signatures are to be stored) but i'm telling that even use this (if you have not to implement yourself) would be a pain in the a**. Don't know of any specific library, but a quick search on google will show many. However, my suggestion remains: "implement specific serializeMe() and deSerializeMe() methods in your class"...
I'm thinking the same thing: much easier to implement serialization/deserialization functions myself :(
User avatar
Jim
Posts: 476
Joined: Sat Jul 02, 2005 10:06 pm
Location: Sydney
Contact:

Post by Jim »

Just use fread/fwrite on the whole data structures. Way easier than writing out all the elements by hand.

Jim
daaa57150
Posts: 28
Joined: Fri Nov 17, 2006 10:35 pm

Post by daaa57150 »

Jim wrote:Just use fread/fwrite on the whole data structures. Way easier than writing out all the elements by hand.

Jim
this may work with simple structures, but with pointers or members containing pointers (std containers for example) only the memory address will be written and not the data pointed.
gauri
Posts: 35
Joined: Sun Jan 20, 2008 11:17 pm
Location: Belarus

Post by gauri »

Jim wrote:Just use fread/fwrite on the whole data structures. Way easier than writing out all the elements by hand.
You will fail epically if your classes have virtual functions (and hence a pointer to vtbl) or you keep pointers to some other stuff.
One way to fix vtable issue is to really write the whole object at a time and then when reading it back call placement new on it, which will restore vtable ptrs.
Freelance game industry veteran. 8]
User avatar
jean
Posts: 489
Joined: Sat Jan 05, 2008 2:44 am

Post by jean »

No need to end up to complex things. Just derive all serialilzable classes from an ancestor IMySerializable that exports virtual doSerializeTo(stream) and unSerializeFrom(stream) methods. Then, in your method implementations (un)serialize all primitive types as you wish, and then recurr calling serialization methods on class fields. This is just how java implements this :)
pspZorba
Posts: 156
Joined: Sat Sep 22, 2007 11:45 am
Location: NY

Post by pspZorba »

You will need to save the object type too, in order to be able to re-instranciate it when you re-read it (use a Param factory for the instanciation).
--pspZorba--
NO to K1.5 !
User avatar
Jim
Posts: 476
Joined: Sat Jul 02, 2005 10:06 pm
Location: Sydney
Contact:

Post by Jim »

Your high score tables have pointers in to other data structures?!
Come on, .net style serialization isn't necessary here.

Jim
daaa57150
Posts: 28
Joined: Fri Nov 17, 2006 10:35 pm

Post by daaa57150 »

Jim wrote:Your high score tables have pointers in to other data structures?!
Come on, .net style serialization isn't necessary here.
True, score tables can be done like you said, it's just that I want to do things properly if I can, and serialization can be useful for other things like data transfer between 2 PSPs for multiplayer and whatnot. And by the way, it's in fact "profiles" that I want to save, which have pointers to score tables for each levels alongside primitive types.
jean wrote:No need to end up to complex things. Just derive all serialilzable classes from an ancestor IMySerializable that exports virtual doSerializeTo(stream) and unSerializeFrom(stream) methods. Then, in your method implementations (un)serialize all primitive types as you wish, and then recurr calling serialization methods on class fields. This is just how java implements this :)
pspZorba wrote:You will need to save the object type too, in order to be able to re-instranciate it when you re-read it (use a Param factory for the instanciation).
Thanks guys, that will be helpful.
User avatar
Jim
Posts: 476
Joined: Sat Jul 02, 2005 10:06 pm
Location: Sydney
Contact:

Post by Jim »

serialization can be useful for other things like data transfer between 2 PSPs for multiplayer and whatnot
I don't grok this either. Are you expecting the PSP on the other end of the connection to be running different-endian, different-ieee754, different CPU, different OS, different vendor, different anything?
I suspect not. This is embedded programming you're doing here, not business.

Jim
miniJB
Posts: 5
Joined: Sun Apr 06, 2008 8:54 pm

Post by miniJB »

Boost.Serialization could be an option (using the boost4psp jamfiles to build it)...

Boost.Build doesnt detect the pspsdk cygwin environment as supporting wide chars (it IS missing a few functions...) but the non-wide serialisation part of the library compiles fine.

I havent tested it yet though, so if it works let me know ;)
Post Reply