![]() |
TrinityCore
|
#include <BinaryInput.h>
Static Public Attributes | |
| static const bool | NO_COPY = false |
Private Member Functions | |
| void | loadIntoMemory (int64 startPosition, int64 minLength=0) |
| void | prepareToRead (int64 nbytes) |
| BinaryInput (const BinaryInput &) | |
| BinaryInput & | operator= (const BinaryInput &) |
| bool | operator== (const BinaryInput &) |
| void | decompress () |
Private Attributes | |
| G3DEndian | m_fileEndian |
| std::string | m_filename |
| bool | m_swapBytes |
| int | m_bitPos |
| uint32 | m_bitString |
| int | m_beginEndBits |
| int64 | m_alreadyRead |
| int64 | m_length |
| int64 | m_bufferLength |
| uint8 * | m_buffer |
| int64 | m_pos |
| bool | m_freeBuffer |
Static Private Attributes | |
| static const int64 | INITIAL_BUFFER_LENGTH |
Sequential or random access byte-order independent binary file access. Files compressed with zlib and beginning with an unsigned 32-bit int size are transparently decompressed when the compressed = true flag is specified to the constructor.
For every readX method there are also versions that operate on a whole Array, std::vector, or C-array. e.g. readFloat32(Array<float32>& array, n) These methods resize the array or std::vector to the appropriate size before reading. For a C-array, they require the pointer to reference a memory block at least large enough to hold n elements.
Most classes define serialize/deserialize methods that use BinaryInput, BinaryOutput, TextInput, and TextOutput. There are text serializer functions for primitive types (e.g. int, std::string, float, double) but not binary serializers– you must call the BinaryInput::readInt32 or other appropriate function. This is because it would be very hard to debug the error sequence: serialize(1.0, bo); ... float f; deserialize(f, bi); in which a double is serialized and then deserialized as a float.
|
private |
| G3D::BinaryInput::BinaryInput | ( | const std::string & | filename, |
| G3DEndian | fileEndian, | ||
| bool | compressed = false |
||
| ) |
If the file cannot be opened, a zero length buffer is presented. Automatically opens files that are inside zipfiles.
| compressed | Set to true if and only if the file was compressed using BinaryOutput's zlib compression. This has nothing to do with whether the input is in a zipfile. |
Here is the call graph for this function:| G3D::BinaryInput::BinaryInput | ( | const uint8 * | data, |
| int64 | dataLen, | ||
| G3DEndian | dataEndian, | ||
| bool | compressed = false, |
||
| bool | copyMemory = true |
||
| ) |
Creates input stream from an in memory source. Unless you specify copyMemory = false, the data is copied from the pointer, so you may deallocate it as soon as the object is constructed. It is an error to specify copyMemory = false and compressed = true.
To decompress part of a file, you can follow the following paradigm:
BinaryInput master(...);
// read from master to point where compressed data exists.
BinaryInput subset(master.getCArray() + master.getPosition(),
master.length() - master.getPosition(),
master.endian(), true, true);
// Now read from subset (it is ok for master to go out of scope)
Here is the call graph for this function:
|
virtual |
Here is the call graph for this function:| void G3D::BinaryInput::beginBits | ( | ) |
Prepares for bit reading via readBits. Only readBits can be called between beginBits and endBits without corrupting the data stream.
Here is the call graph for this function:
|
private |
Buffer is compressed; replace it with a decompressed version
Here is the call graph for this function:| void G3D::BinaryInput::endBits | ( | ) |
Ends bit-reading.
|
inline |
Returns a pointer to the internal memory buffer. May throw an exception for huge files.
Here is the caller graph for this function:
|
inline |
|
inline |
Returns the length of the file in bytes.
Here is the caller graph for this function:
|
inline |
Returns the current byte position in the file, where 0 is the beginning and getLength() - 1 is the end.
|
inline |
Returns true if the position is not at the end of the file
Here is the caller graph for this function:Ensures that we are able to read at least minLength from startPosition (relative to start of file).
Here is the call graph for this function:
Here is the caller graph for this function:
|
private |
|
private |
Performs bounds checks in debug mode. [] are relative to the start of the file, not the current position. Seeks to the new position before reading (and leaves that as the current position)
Here is the call graph for this function:
|
private |
Verifies that at least this number of bytes can be read.
Here is the call graph for this function:
Here is the caller graph for this function:| uint32 G3D::BinaryInput::readBits | ( | int | numBits | ) |
Can only be called between beginBits and endBits
Here is the call graph for this function:
|
inline |
Here is the call graph for this function:
Here is the caller graph for this function:| void G3D::BinaryInput::readBytes | ( | void * | bytes, |
| int64 | n | ||
| ) |
Here is the call graph for this function:
Here is the caller graph for this function:| Color3 G3D::BinaryInput::readColor3 | ( | ) |
Here is the call graph for this function:| Color4 G3D::BinaryInput::readColor4 | ( | ) |
Here is the call graph for this function:| std::string G3D::BinaryInput::readFixedLengthString | ( | int | numBytes | ) |
Read a string (which may contain NULLs) of exactly numBytes bytes, including the final terminator if there is one. If there is a NULL in the string before the end, then only the part up to the first NULL is returned although all bytes are read.
Here is the call graph for this function:
|
inline |
Here is the call graph for this function:
Here is the caller graph for this function:
|
inline |
Here is the call graph for this function:
Here is the caller graph for this function:
|
inline |
Here is the call graph for this function:
|
inline |
Here is the call graph for this function:
Here is the caller graph for this function:
|
inline |
Here is the call graph for this function:
|
inline |
Here is the call graph for this function:
Here is the caller graph for this function:| std::string G3D::BinaryInput::readString | ( | int64 | maxLength | ) |
Always consumes maxLength characters. Reads a string until NULL or maxLength characters. Does not require NULL termination.
Here is the call graph for this function:| std::string G3D::BinaryInput::readString | ( | ) |
Reads a string until NULL or end of file.
Here is the call graph for this function:
Here is the caller graph for this function:| std::string G3D::BinaryInput::readString32 | ( | ) |
Reads a uint32 and then calls readString(maxLength) with that value as the length.
Here is the call graph for this function:
Here is the caller graph for this function:| std::string G3D::BinaryInput::readStringEven | ( | ) |
Reads until NULL or the end of the file is encountered. If the string has odd length (including NULL), reads another byte. This is a common format for 16-bit alignment in files.
Here is the call graph for this function:| std::string G3D::BinaryInput::readStringNewline | ( | ) |
Reads a string until NULL, newline ("\r", "\n", "\r\n", "\n\r") or the end of the file is encountered. Consumes the newline.
Here is the call graph for this function:
|
inline |
Here is the call graph for this function:
Here is the caller graph for this function:
|
inline |
Here is the call graph for this function:
Here is the caller graph for this function:| uint64 G3D::BinaryInput::readUInt64 | ( | ) |
Here is the call graph for this function:
Here is the caller graph for this function:
|
inline |
Here is the call graph for this function:
Here is the caller graph for this function:
|
inline |
Here is the call graph for this function:| Vector2 G3D::BinaryInput::readVector2 | ( | ) |
Here is the call graph for this function:| Vector3 G3D::BinaryInput::readVector3 | ( | ) |
Here is the call graph for this function:
Here is the caller graph for this function:| Vector4 G3D::BinaryInput::readVector4 | ( | ) |
Here is the call graph for this function:
|
inline |
Goes back to the beginning of the file.
Here is the call graph for this function:| void G3D::BinaryInput::setEndian | ( | G3DEndian | endian | ) |
Change the endian-ness of the file. This only changes the interpretation of the file for future read calls; the underlying data is unmodified.
Here is the call graph for this function:
Here is the caller graph for this function:
|
inline |
Sets the position. Cannot set past length. May throw a char* when seeking backwards more than 10 MB on a huge file.
Here is the call graph for this function:
Here is the caller graph for this function:
|
inline |
Here is the call graph for this function:
Here is the caller graph for this function:
|
inline |
Skips ahead n bytes.
Here is the call graph for this function:
Here is the caller graph for this function:
|
private |
When operating on huge files, we cannot load the whole file into memory. This is the file position to which buffer[0] corresponds. Even 32-bit code can load 64-bit files in chunks, so this is not size_t
|
private |
1 when between beginBits and endBits, 0 otherwise.
|
private |
Next position to read from in bitString during readBits.
|
private |
Bits currently being read by readBits. Contains at most 8 (low) bits. Note that beginBits/readBits actually consumes one extra byte, which will be restored by writeBits.
|
private |
|
private |
Length of the array referenced by buffer. May go past the end of the file!
|
private |
is the file big or little endian
|
private |
|
private |
When true, the buffer is freed in the destructor.
|
private |
Length of the entire file, in bytes. For the length of the buffer, see bufferLength
|
private |
Next byte in file, relative to buffer.
|
private |
false, constant to use with the copyMemory option
1.8.8