03.01.2013 Views

Chapter 1

Chapter 1

Chapter 1

SHOW MORE
SHOW LESS

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

� Without the aLength parameter, the whole descriptor is written.<br />

� The const TUint8* variant writes aLength bytes from the pointer specified.<br />

� The const TDesC16 and const TUint16* variants write Unicode characters (with<br />

little-endian byte order) instead of bytes.<br />

RReadStream comes with similar (though not precisely symmetrical) functions:<br />

class RReadStream<br />

{<br />

public:<br />

//<br />

...<br />

IMPORT_C void ReadL(TDes8& aDes);<br />

IMPORT_C void ReadL(TDes8& aDes, TInt aLength);<br />

IMPORT_C void ReadL(TDes8& aDes, TChar aDelim);<br />

IMPORT_C void ReadL(TUint8* aPtr, TInt aLength);<br />

IMPORT_C void ReadL(TInt aLength);<br />

...<br />

IMPORT_C void ReadL(TDes16& aDes);<br />

IMPORT_C void ReadL(TDes16& aDes, TInt aLength);<br />

IMPORT_C void ReadL(TDes16& aDes, TChar aDelim);<br />

IMPORT_C void ReadL(TUint16* aPtr, TInt aLength);<br />

...<br />

The problem when reading is to know when to stop. When you're writing, the descriptor<br />

length (or the aLength parameter) specifies the data length. When you're reading, the rules<br />

work like this:<br />

� The TDes8& aDes format passes a descriptor whose MaxLength()bytes will be<br />

read.<br />

� If you specify aLength explicitly, then that number of bytes will be read.<br />

� If you specify a delimiter character, the stream will read up to and including that<br />

character. If the MaxLength() of the target descriptor is encountered before the<br />

delimiter character, reading stops after MaxLength() characters – nothing is read and<br />

thrown away.<br />

Like all other ReadXxxL() functions, these functions will leave with KErrEof (end of file) if<br />

the end of file is encountered during the read operation.<br />

You should use these raw data functions with great care. Any data that you externalize with<br />

WriteL() is effectively struct-dumped into the stream. This is fine provided that the data is<br />

already in external format. Be sure that it is!<br />

When you internalize with ReadL(), you must always have a strategy for dealing with the<br />

anticipated maximum length of data. For example, you could decide that it would be<br />

unreasonable to have more than 10 000 bytes in a particular string and so you check the<br />

length purportedly given and if you find it's more than 10 000 you leave with KErrCorrupt.<br />

That's what HBufC::AllocL(RReadStream&,TInt) does.<br />

Strings

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!