OGRE 14.3
Object-Oriented Graphics Rendering Engine
|
Utility class providing helper methods for reading / writing structured data held in a DataStream. More...
#include <OgreStreamSerialiser.h>
Classes | |
struct | Chunk |
Definition of a chunk of data in a file. More... | |
Public Types | |
enum | Endian { ENDIAN_AUTO , ENDIAN_BIG , ENDIAN_LITTLE } |
The endianness of files. More... | |
enum | RealStorageFormat { REAL_FLOAT , REAL_DOUBLE } |
The storage format of Real values. More... | |
Static Public Member Functions | |
static uint32 | makeIdentifier (const char(&code)[5]) |
Pack a 4-character code into a 32-bit identifier. | |
Utility class providing helper methods for reading / writing structured data held in a DataStream.
The structure of a file read / written by this class is a series of 'chunks'. A chunk-based format has the advantage of being extensible later, and it's robust, in that a reader can skip chunks that they are not able (or willing) to process.
Ogre::StreamSerialiser::StreamSerialiser | ( | const DataStreamPtr & | stream, |
Endian | endianMode = ENDIAN_AUTO , |
||
bool | autoHeader = true , |
||
RealStorageFormat | realFormat = REAL_FLOAT |
||
) |
Constructor.
stream | The stream on which you will read / write data. |
endianMode | The endian mode in which to read / writedata. If left at the default, when writing the endian mode will be the native platform mode, and when reading it's expected that the first chunk encountered will be the header chunk, which will determine the endian mode. |
autoHeader | If true, the first write or read to this stream will automatically read / write the header too. This is required if you set endianMode to ENDIAN_AUTO, but if you manually set the endian mode, then you can skip writing / reading the header if you wish, if for example this stream is midway through a file which has already included header information. |
realFormat | Set the format you want to write reals in. Only useful for files that you're writing (since when reading this is picked up from the file), and can only be changed if autoHeader is true, since real format is stored in the header. Defaults to float unless you're using OGRE_DOUBLE_PRECISION. |
|
virtual |
Get the endian mode.
If the result is ENDIAN_AUTO, this mode will change when the first piece of data is read / written.
Pack a 4-character code into a 32-bit identifier.
You can use this to generate id's for your chunks based on friendlier 4-character codes rather than assigning numerical IDs, if you like.
code | String to pack - must be 4 characters and '\0' |
|
inline |
Report the current depth of the chunk nesting, whether reading or writing.
Returns how many levels of nested chunks are currently being processed, either writing or reading. In order to tidily finish, you must call read/writeChunkEnd this many times.
uint32 Ogre::StreamSerialiser::getCurrentChunkID | ( | ) | const |
Get the ID of the chunk that's currently being read/written, if any.
size_t Ogre::StreamSerialiser::getOffsetFromChunkStart | ( | ) | const |
Get the current byte position relative to the start of the data section of the last chunk that was read or written.
Reads the start of the next chunk in the file.
Files are serialised in a chunk-based manner, meaning that each section of data is prepended by a chunk header. After reading this chunk header, the next set of data is available directly afterwards.
|
virtual |
Reads the start of the next chunk so long as it's of a given ID and version.
This method operates like readChunkBegin, except it checks the ID and version.
id | The ID you're expecting. If the next chunk isn't of this ID, then the chunk read is undone and the method returns null. |
maxVersion | The maximum version you're able to process. If the ID is correct but the version exceeds what is passed in here, the chunk is skipped over, the problem logged and null is returned. |
msg | Descriptive text added to the log if versions are not compatible |
Call this to 'rewind' the stream to just before the start of the current chunk.
The most common case of wanting to use this is if you'd calledReadChunkBegin(), but the chunk you read wasn't one you wanted to process, and rather than skipping over it (which readChunkEnd() would do), you want to backtrack and give something else an opportunity to read it.
id | The id of the chunk that you were reading (for validation purposes) |
Call this to 'peek' at the next chunk ID without permanently moving the stream pointer.
Finish the reading of a chunk.
You can call this method at any point after calling readChunkBegin, even if you didn't read all the rest of the data in the chunk. If you did not read to the end of a chunk, this method will automatically skip over the remainder of the chunk and position the stream just after it.
id | The id of the chunk that you were reading (for validation purposes) |
Return whether the current data pointer is at the end of the current chunk.
id | The id of the chunk that you were reading (for validation purposes) |
Reports whether the stream is at the end of file.
Get the definition of the current chunk being read (if any).
Begin writing a new chunk.
This starts the process of writing a new chunk to the stream. This will write the chunk header for you, and store a pointer so that the class can automatically go back and fill in the size for you later should you need it to. If you have already begun a chunk without ending it, then this method will start a nested chunk within it. Once written, you can then start writing chunk-specific data into your stream.
id | The identifier of the new chunk. Any value that's unique in the file context is valid, except for the numbers 0x0001 and 0x1000 which are reserved for internal header identification use. |
version | The version of the chunk you're writing |
End writing a chunk.
id | The identifier of the chunk - this is really just a safety check, since you can only end the chunk you most recently started. |
|
virtual |
Write arbitrary data to a stream.
buf | Pointer to bytes |
size | The size of each element to write; each will be endian-flipped if necessary |
count | The number of elements to write |
Catch-all method to write primitive types.
|
virtual |
|
virtual |
Read arbitrary data from a stream.
buf | Pointer to bytes |
size | The size of each element to read; each will be endian-flipped if necessary |
count | The number of elements to read |
Catch-all method to read primitive types.
read a Vector3
|
virtual |
|
virtual |
Start (un)compressing data.
avail_in | Available bytes for uncompressing |