forums.ps2dev.org Forum Index forums.ps2dev.org
Homebrew PS2, PSP & PS3 Development Discussions
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

serialization

 
Post new topic   Reply to topic    forums.ps2dev.org Forum Index -> PSP Development
View previous topic :: View next topic  
Author Message
daaa57150



Joined: 17 Nov 2006
Posts: 28

PostPosted: Wed Apr 09, 2008 5:47 pm    Post subject: serialization Reply with quote

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..
Back to top
View user's profile Send private message
jean



Joined: 05 Jan 2008
Posts: 489

PostPosted: Wed Apr 09, 2008 6:05 pm    Post subject: Reply with quote

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"...
Back to top
View user's profile Send private message
daaa57150



Joined: 17 Nov 2006
Posts: 28

PostPosted: Wed Apr 09, 2008 6:08 pm    Post subject: Reply with quote

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 :(
Back to top
View user's profile Send private message
Jim



Joined: 02 Jul 2005
Posts: 487
Location: Sydney

PostPosted: Wed Apr 09, 2008 9:34 pm    Post subject: Reply with quote

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

Jim
_________________
http://www.dbfinteractive.com
Back to top
View user's profile Send private message Visit poster's website
daaa57150



Joined: 17 Nov 2006
Posts: 28

PostPosted: Wed Apr 09, 2008 9:38 pm    Post subject: Reply with quote

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.
Back to top
View user's profile Send private message
gauri



Joined: 20 Jan 2008
Posts: 35
Location: Belarus

PostPosted: Thu Apr 10, 2008 3:37 pm    Post subject: Reply with quote

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]
Back to top
View user's profile Send private message
jean



Joined: 05 Jan 2008
Posts: 489

PostPosted: Thu Apr 10, 2008 9:55 pm    Post subject: Reply with quote

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 :)
Back to top
View user's profile Send private message
pspZorba



Joined: 22 Sep 2007
Posts: 156
Location: NY

PostPosted: Thu Apr 10, 2008 10:21 pm    Post subject: Reply with quote

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 !
Back to top
View user's profile Send private message
Jim



Joined: 02 Jul 2005
Posts: 487
Location: Sydney

PostPosted: Thu Apr 10, 2008 11:16 pm    Post subject: Reply with quote

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

Jim
_________________
http://www.dbfinteractive.com
Back to top
View user's profile Send private message Visit poster's website
daaa57150



Joined: 17 Nov 2006
Posts: 28

PostPosted: Fri Apr 11, 2008 4:57 pm    Post subject: Reply with quote

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.
Back to top
View user's profile Send private message
Jim



Joined: 02 Jul 2005
Posts: 487
Location: Sydney

PostPosted: Fri Apr 11, 2008 11:14 pm    Post subject: Reply with quote

Quote:
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
_________________
http://www.dbfinteractive.com
Back to top
View user's profile Send private message Visit poster's website
miniJB



Joined: 06 Apr 2008
Posts: 5

PostPosted: Fri Apr 11, 2008 11:42 pm    Post subject: Reply with quote

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 ;)
Back to top
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic    forums.ps2dev.org Forum Index -> PSP Development All times are GMT + 10 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group