You Are Here:

Community: Blogs

Paul Todd's Forum Nokia Blog

Serialize data

Paul.Todd | 24 May, 2007 00:21

I saw an intersting post today about what is the quickest way to serialize a structure.

To do this the proper way there are three alternatives:

Write out the structure member by member using the RWriteStream classes specialized for files - RFileWriteStream
Read them back with the relevant RReadStream classes - RFileReadStream

Write InternalizeL and ExternalizeL functions to serialize the data.

Thirdly there is actually however a much simpler solution which generates much less problems, using the TPckgC/TPckg classes.

These class wrap a struct into a TPtr8 which make make it much easier to read and write

Structure:
struct TTestStruct
    {
    TInt         iInt;
    TBuf<32>    iString;
    };

To write:
const TPckgC<TTestStruct> pkgOut(tmp);
User::LeaveIfError(file.Write(pkgOut));

To read:

TTestStruct nw;
TPckg<TTestStruct> pkgIn(nw);
User::LeaveIfError(file.Read(0, pkgIn));

OR

TPckgBuf<TTestStruct> pkgIn;
User::LeaveIfError(file.Read(0, pkgIn));
.... do something with pkgIn().iString etc.

I was going to point you folks to the descriptors blog on blogspot but strangly enough I could'nt find anything there about it.

Maybe Jo will add a section for these useful classes (TPckg, TPckgC and TPckgBuf)?
 
 

Rate This

 
 
Bookmark this page: DeliciousDiggFacebookGoogleYahooStumbleUponRedditDiigoTechnocratiTwitter  Share this page Share this page Print this Page Print this page Invite a friend Invite a friend
京ICP备05048969号    Email Newsletters Press Terms & Conditions Privacy Policy Sitemap Contact Us © 2009 Nokia 
RDF Facets: qdcZidentifierQSxhttpE3aE2fE2fblogsE2eforumE2enokiaE2ecomE2fblogE2fpaulE2dcoultonsE2dforumE2dnokiaE2dblogE2farchivesE2f2009E2f04E2fX qdcZtypeQUqfnZE45E78cludedFromGeneralE4cistingsQ qdcZtypeQUqfntypeZBlogContentQ qdcZtypeQUqfntypeZCommunityContentQ qdcZtypeQUqfntypeZE52esourceQ qdcZtypeQUqfntypeZWebpageQ qdcZtypeQUqmarsZManagedE52esourceQ qdcZtypeQUqwebZInformationE52esourceQ qdcZtypeQUqwebZPageQ qdcZtypeQUqwebZE52esourceQ qdcZtypeQUqrdfsZE52esourceQ qfnZtypeQUqfntypeZBlogContentQ qfnZtypeQUqfntypeZCommunityContentQ qfnZtypeQUqfntypeZE52esourceQ qfnZtypeQUqfntypeZWebpageQ qmarsZlanguageQUxhttpE3aE2fE2fswE2enokiaE2ecomE2flanguageE2d1E2fenX qrdfZtypeQUqfnZE45E78cludedFromGeneralE4cistingsQ qrdfZtypeQUqfntypeZBlogContentQ qrdfZtypeQUqfntypeZCommunityContentQ qrdfZtypeQUqfntypeZE52esourceQ qrdfZtypeQUqfntypeZWebpageQ qrdfZtypeQUqmarsZManagedE52esourceQ qrdfZtypeQUqwebZInformationE52esourceQ qrdfZtypeQUqwebZPageQ qrdfZtypeQUqwebZE52esourceQ qrdfZtypeQUqrdfsZE52esourceQ