serialization
serialization
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..
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..
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 :(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"...
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.Jim wrote:Just use fread/fwrite on the whole data structures. Way easier than writing out all the elements by hand.
Jim
You will fail epically if your classes have virtual functions (and hence a pointer to vtbl) or you keep pointers to some other stuff.Jim wrote:Just use fread/fwrite on the whole data structures. Way easier than writing out all the elements by hand.
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]
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 :)
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.Jim wrote:Your high score tables have pointers in to other data structures?!
Come on, .net style serialization isn't necessary here.
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 :)
Thanks guys, that will be helpful.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).
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?serialization can be useful for other things like data transfer between 2 PSPs for multiplayer and whatnot
I suspect not. This is embedded programming you're doing here, not business.
Jim
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 ;)
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 ;)