QtlMovie 1.12 (A specialized FFmpeg front-end)
QtlByteBlock Class Reference

Definitions of a generic block of bytes. More...

Inheritance diagram for QtlByteBlock:

Public Types

enum  ByteOrder {
  BigEndian = QSysInfo::BigEndian,
  LittleEndian = QSysInfo::LittleEndian
}
 Byte order for integer serializing and deserializing. More...
 
typedef QVector< quint8 > ByteVector
 Type definition for the superclass, a Qt vector of bytes. More...
 

Public Member Functions

 QtlByteBlock (int size=0, quint8 value=0)
 Default constructor. More...
 
 QtlByteBlock (const ByteVector &other)
 Copy constructor. More...
 
 QtlByteBlock (const void *addr, int size)
 Constructor from a data block. More...
 
 QtlByteBlock (const QByteArray &ba)
 Constructor from a QByteArray. More...
 
 QtlByteBlock (const char *str)
 Constructor from a C string. More...
 
void append (const void *addr, int size)
 Append raw data to a byte block. More...
 
void append (const QtlByteBlock &bb)
 Append a byte block to a byte block. More...
 
void append (const QByteArray &ba)
 Append a QByteArray to a byte block. More...
 
void append (int count, quint8 value)
 Append n bytes with value i. More...
 
void appendInt16 (qint16 i)
 Add an integer in big endian representation at the end. More...
 
void appendInt16LittleEndian (qint16 i)
 Add an integer in little endian representation at the end. More...
 
void appendInt32 (qint32 i)
 Add an integer in big endian representation at the end. More...
 
void appendInt32LittleEndian (qint32 i)
 Add an integer in little endian representation at the end. More...
 
void appendInt64 (qint64 i)
 Add an integer in big endian representation at the end. More...
 
void appendInt64LittleEndian (qint64 i)
 Add an integer in little endian representation at the end. More...
 
void appendInt8 (qint8 i)
 Add an integer in big endian representation at the end. More...
 
void appendString (const char *str)
 Append a C-string to a byte block. More...
 
template<typename INT >
void appendToBigEndian (INT i)
 Add an integer in big endian representation at the end. More...
 
template<>
void appendToBigEndian (quint8 i)
 Add an integer in big endian representation at the end. More...
 
template<>
void appendToBigEndian (qint8 i)
 Add an integer in big endian representation at the end. More...
 
template<typename INT >
void appendToByteOrder (INT i, ByteOrder order)
 Add an integer in a given byte order at the end. More...
 
template<typename INT >
void appendToLittleEndian (INT i)
 Add an integer in little endian representation at the end. More...
 
template<>
void appendToLittleEndian (quint8 i)
 Add an integer in little endian representation at the end. More...
 
template<>
void appendToLittleEndian (qint8 i)
 Add an integer in little endian representation at the end. More...
 
void appendUInt16 (quint16 i)
 Add an integer in big endian representation at the end. More...
 
void appendUInt16LittleEndian (quint16 i)
 Add an integer in little endian representation at the end. More...
 
void appendUInt32 (quint32 i)
 Add an integer in big endian representation at the end. More...
 
void appendUInt32LittleEndian (quint32 i)
 Add an integer in little endian representation at the end. More...
 
void appendUInt64 (quint64 i)
 Add an integer in big endian representation at the end. More...
 
void appendUInt64LittleEndian (quint64 i)
 Add an integer in little endian representation at the end. More...
 
void appendUInt8 (quint8 i)
 Add an integer in big endian representation at the end. More...
 
void copy (const void *addr, int size)
 Replace the content with a data block. More...
 
void * enlarge (int n)
 Increase size by n and return pointer to new n-byte area at end of block. More...
 
void * enlargeFrom (int index, int n)
 Make sure there are at
bytes available at the specified index. More...
 
template<typename INT >
bool fromBigEndian (int &index, INT &i) const
 Get an integer in big endian representation at a given position. More...
 
template<typename INT >
INT fromBigEndian (int index) const
 Get an integer in big endian representation at a given position. More...
 
template<typename INT >
bool fromByteOrder (int &index, INT &i, ByteOrder order) const
 Get an integer in a given byte order at a given position. More...
 
template<typename INT >
INT fromByteOrder (int index, ByteOrder order) const
 Get an integer in a given byte order at a given position. More...
 
template<typename INT >
bool fromLittleEndian (int &index, INT &i) const
 Get an integer in little endian representation at a given position. More...
 
template<typename INT >
INT fromLittleEndian (int index) const
 Get an integer in little endian representation at a given position. More...
 
bool getLatin1 (int &index, int stringSize, QString &s) const
 Get a Latin-1 string at a given position. More...
 
QString getLatin1 (int index, int stringSize) const
 Get a Latin1 string at a given position. More...
 
bool getUtf8 (int &index, int stringSize, QString &s) const
 Get an UTF-8 string at a given position. More...
 
QString getUtf8 (int index, int stringSize) const
 Get an UTF-8 string at a given position. More...
 
void storeInt16 (int index, qint16 i)
 Store an integer in big endian representation at a given index. More...
 
void storeInt16LittleEndian (int index, qint16 i)
 Store an integer in little endian representation at a given index. More...
 
void storeInt32 (int index, qint32 i)
 Store an integer in big endian representation at a given index. More...
 
void storeInt32LittleEndian (int index, qint32 i)
 Store an integer in little endian representation at a given index. More...
 
void storeInt64 (int index, qint64 i)
 Store an integer in big endian representation at a given index. More...
 
void storeInt64LittleEndian (int index, qint64 i)
 Store an integer in little endian representation at a given index. More...
 
void storeInt8 (int index, qint8 i)
 Store an integer in big endian representation at a given index. More...
 
template<typename INT >
void storeToBigEndian (int index, INT i)
 Store an integer in big endian representation at a given index. More...
 
template<typename INT >
void storeToByteOrder (int index, INT i, ByteOrder order)
 Store an integer in a given byte order at a given index. More...
 
template<typename INT >
void storeToLittleEndian (int index, INT i)
 Store an integer in little endian representation at a given index. More...
 
void storeUInt16 (int index, quint16 i)
 Store an integer in big endian representation at a given index. More...
 
void storeUInt16LittleEndian (int index, quint16 i)
 Store an integer in little endian representation at a given index. More...
 
void storeUInt32 (int index, quint32 i)
 Store an integer in big endian representation at a given index. More...
 
void storeUInt32LittleEndian (int index, quint32 i)
 Store an integer in little endian representation at a given index. More...
 
void storeUInt64 (int index, quint64 i)
 Store an integer in big endian representation at a given index. More...
 
void storeUInt64LittleEndian (int index, quint64 i)
 Store an integer in little endian representation at a given index. More...
 
void storeUInt8 (int index, quint8 i)
 Store an integer in big endian representation at a given index. More...
 
QByteArray toByteArray () const
 Convert a QtlByteBlock into a QByteArray. More...
 

Detailed Description

Definitions of a generic block of bytes.

Member Typedef Documentation

◆ ByteVector

typedef QVector<quint8> QtlByteBlock::ByteVector

Type definition for the superclass, a Qt vector of bytes.

Member Enumeration Documentation

◆ ByteOrder

Byte order for integer serializing and deserializing.

Enumerator
BigEndian 

Most significant byte first.

LittleEndian 

Least significant byte first.

Constructor & Destructor Documentation

◆ QtlByteBlock() [1/5]

QtlByteBlock::QtlByteBlock ( int  size = 0,
quint8  value = 0 
)
inlineexplicit

Default constructor.

Parameters
[in]sizeSize of the byte block.
[in]valueValue to assign to each byte.

◆ QtlByteBlock() [2/5]

QtlByteBlock::QtlByteBlock ( const ByteVector other)
inline

Copy constructor.

Parameters
[in]otherOther instance to copy.

◆ QtlByteBlock() [3/5]

QtlByteBlock::QtlByteBlock ( const void *  addr,
int  size 
)
inline

Constructor from a data block.

Parameters
[in]addrAddress of the data block.
[in]sizeSize of the data block.

◆ QtlByteBlock() [4/5]

QtlByteBlock::QtlByteBlock ( const QByteArray &  ba)
inline

Constructor from a QByteArray.

Parameters
[in]baByte array to copy.

◆ QtlByteBlock() [5/5]

QtlByteBlock::QtlByteBlock ( const char *  str)
inline

Constructor from a C string.

Parameters
[in]strA nul-terminated string.

Member Function Documentation

◆ toByteArray()

QByteArray QtlByteBlock::toByteArray ( ) const
inline

Convert a QtlByteBlock into a QByteArray.

Returns
A byte array with the same content as this object.

◆ copy()

void QtlByteBlock::copy ( const void *  addr,
int  size 
)

Replace the content with a data block.

Parameters
[in]addrAddress of the data block.
[in]sizeSize of the data block.

◆ enlarge()

void * QtlByteBlock::enlarge ( int  n)

Increase size by n and return pointer to new n-byte area at end of block.

Parameters
[in]nNumber of bytes to add.
Returns
Starting address of enlarged area.

◆ enlargeFrom()

void * QtlByteBlock::enlargeFrom ( int  index,
int  n 
)

Make sure there are at
bytes available at the specified index.

The byte block is enlarged if necessary.

Parameters
[in]indexIndex of area. If negative, append at end of data block.
[in]nNumber of bytes to make available.
Returns
Starting address at index or a null pointer if index is negative.

◆ append() [1/4]

void QtlByteBlock::append ( const void *  addr,
int  size 
)

Append raw data to a byte block.

Parameters
[in]addrAddress of the data block.
[in]sizeSize of the data block.

◆ append() [2/4]

void QtlByteBlock::append ( const QtlByteBlock bb)
inline

Append a byte block to a byte block.

Parameters
[in]bbByte block to append.

◆ appendString()

void QtlByteBlock::appendString ( const char *  str)
inline

Append a C-string to a byte block.

Parameters
[in]strA nul-terminated string.

◆ append() [3/4]

void QtlByteBlock::append ( const QByteArray &  ba)
inline

Append a QByteArray to a byte block.

Parameters
[in]baByte array to append.

◆ append() [4/4]

void QtlByteBlock::append ( int  count,
quint8  value 
)
inline

Append n bytes with value i.

Parameters
[in]countNumber of bytes to add.
[in]valueValue to assign to each byte.

◆ appendUInt8()

void QtlByteBlock::appendUInt8 ( quint8  i)
inline

Add an integer in big endian representation at the end.

Parameters
[in]iInteger value to append.

◆ appendUInt16()

void QtlByteBlock::appendUInt16 ( quint16  i)
inline

Add an integer in big endian representation at the end.

Parameters
[in]iInteger value to append.

◆ appendUInt32()

void QtlByteBlock::appendUInt32 ( quint32  i)
inline

Add an integer in big endian representation at the end.

Parameters
[in]iInteger value to append.

◆ appendUInt64()

void QtlByteBlock::appendUInt64 ( quint64  i)
inline

Add an integer in big endian representation at the end.

Parameters
[in]iInteger value to append.

◆ appendInt8()

void QtlByteBlock::appendInt8 ( qint8  i)
inline

Add an integer in big endian representation at the end.

Parameters
[in]iInteger value to append.

◆ appendInt16()

void QtlByteBlock::appendInt16 ( qint16  i)
inline

Add an integer in big endian representation at the end.

Parameters
[in]iInteger value to append.

◆ appendInt32()

void QtlByteBlock::appendInt32 ( qint32  i)
inline

Add an integer in big endian representation at the end.

Parameters
[in]iInteger value to append.

◆ appendInt64()

void QtlByteBlock::appendInt64 ( qint64  i)
inline

Add an integer in big endian representation at the end.

Parameters
[in]iInteger value to append.

◆ appendToBigEndian() [1/3]

template<typename INT >
void QtlByteBlock::appendToBigEndian ( INT  i)
inline

Add an integer in big endian representation at the end.

Template variant

Template Parameters
INTAn integer type.
Parameters
[in]iInteger value to append.

◆ storeUInt8()

void QtlByteBlock::storeUInt8 ( int  index,
quint8  i 
)
inline

Store an integer in big endian representation at a given index.

The byte block is enlarged if necessary.

Parameters
[in]indexIndex where to store the integer. If negative, append at end of data block.
[in]iInteger value to append.

◆ storeUInt16()

void QtlByteBlock::storeUInt16 ( int  index,
quint16  i 
)
inline

Store an integer in big endian representation at a given index.

The byte block is enlarged if necessary.

Parameters
[in]indexIndex where to store the integer. If negative, append at end of data block.
[in]iInteger value to append.

◆ storeUInt32()

void QtlByteBlock::storeUInt32 ( int  index,
quint32  i 
)
inline

Store an integer in big endian representation at a given index.

The byte block is enlarged if necessary.

Parameters
[in]indexIndex where to store the integer. If negative, append at end of data block.
[in]iInteger value to append.

◆ storeUInt64()

void QtlByteBlock::storeUInt64 ( int  index,
quint64  i 
)
inline

Store an integer in big endian representation at a given index.

The byte block is enlarged if necessary.

Parameters
[in]indexIndex where to store the integer. If negative, append at end of data block.
[in]iInteger value to append.

◆ storeInt8()

void QtlByteBlock::storeInt8 ( int  index,
qint8  i 
)
inline

Store an integer in big endian representation at a given index.

The byte block is enlarged if necessary.

Parameters
[in]indexIndex where to store the integer. If negative, append at end of data block.
[in]iInteger value to append.

◆ storeInt16()

void QtlByteBlock::storeInt16 ( int  index,
qint16  i 
)
inline

Store an integer in big endian representation at a given index.

The byte block is enlarged if necessary.

Parameters
[in]indexIndex where to store the integer. If negative, append at end of data block.
[in]iInteger value to append.

◆ storeInt32()

void QtlByteBlock::storeInt32 ( int  index,
qint32  i 
)
inline

Store an integer in big endian representation at a given index.

The byte block is enlarged if necessary.

Parameters
[in]indexIndex where to store the integer. If negative, append at end of data block.
[in]iInteger value to append.

◆ storeInt64()

void QtlByteBlock::storeInt64 ( int  index,
qint64  i 
)
inline

Store an integer in big endian representation at a given index.

The byte block is enlarged if necessary.

Parameters
[in]indexIndex where to store the integer. If negative, append at end of data block.
[in]iInteger value to append.

◆ storeToBigEndian()

template<typename INT >
void QtlByteBlock::storeToBigEndian ( int  index,
INT  i 
)
inline

Store an integer in big endian representation at a given index.

The byte block is enlarged if necessary. Template variant

Template Parameters
INTAn integer type.
Parameters
[in]indexIndex where to store the integer. If negative, append at end of data block.
[in]iInteger value to append.

◆ appendUInt16LittleEndian()

void QtlByteBlock::appendUInt16LittleEndian ( quint16  i)
inline

Add an integer in little endian representation at the end.

Parameters
[in]iInteger value to append.

◆ appendUInt32LittleEndian()

void QtlByteBlock::appendUInt32LittleEndian ( quint32  i)
inline

Add an integer in little endian representation at the end.

Parameters
[in]iInteger value to append.

◆ appendUInt64LittleEndian()

void QtlByteBlock::appendUInt64LittleEndian ( quint64  i)
inline

Add an integer in little endian representation at the end.

Parameters
[in]iInteger value to append.

◆ appendInt16LittleEndian()

void QtlByteBlock::appendInt16LittleEndian ( qint16  i)
inline

Add an integer in little endian representation at the end.

Parameters
[in]iInteger value to append.

◆ appendInt32LittleEndian()

void QtlByteBlock::appendInt32LittleEndian ( qint32  i)
inline

Add an integer in little endian representation at the end.

Parameters
[in]iInteger value to append.

◆ appendInt64LittleEndian()

void QtlByteBlock::appendInt64LittleEndian ( qint64  i)
inline

Add an integer in little endian representation at the end.

Parameters
[in]iInteger value to append.

◆ appendToLittleEndian() [1/3]

template<typename INT >
void QtlByteBlock::appendToLittleEndian ( INT  i)
inline

Add an integer in little endian representation at the end.

Template variant

Template Parameters
INTAn integer type.
Parameters
[in]iInteger value to append.

◆ storeUInt16LittleEndian()

void QtlByteBlock::storeUInt16LittleEndian ( int  index,
quint16  i 
)
inline

Store an integer in little endian representation at a given index.

The byte block is enlarged if necessary.

Parameters
[in]indexIndex where to store the integer. If negative, append at end of data block.
[in]iInteger value to append.

◆ storeUInt32LittleEndian()

void QtlByteBlock::storeUInt32LittleEndian ( int  index,
quint32  i 
)
inline

Store an integer in little endian representation at a given index.

The byte block is enlarged if necessary.

Parameters
[in]indexIndex where to store the integer. If negative, append at end of data block.
[in]iInteger value to append.

◆ storeUInt64LittleEndian()

void QtlByteBlock::storeUInt64LittleEndian ( int  index,
quint64  i 
)
inline

Store an integer in little endian representation at a given index.

The byte block is enlarged if necessary.

Parameters
[in]indexIndex where to store the integer. If negative, append at end of data block.
[in]iInteger value to append.

◆ storeInt16LittleEndian()

void QtlByteBlock::storeInt16LittleEndian ( int  index,
qint16  i 
)
inline

Store an integer in little endian representation at a given index.

The byte block is enlarged if necessary.

Parameters
[in]indexIndex where to store the integer. If negative, append at end of data block.
[in]iInteger value to append.

◆ storeInt32LittleEndian()

void QtlByteBlock::storeInt32LittleEndian ( int  index,
qint32  i 
)
inline

Store an integer in little endian representation at a given index.

The byte block is enlarged if necessary.

Parameters
[in]indexIndex where to store the integer. If negative, append at end of data block.
[in]iInteger value to append.

◆ storeInt64LittleEndian()

void QtlByteBlock::storeInt64LittleEndian ( int  index,
qint64  i 
)
inline

Store an integer in little endian representation at a given index.

The byte block is enlarged if necessary.

Parameters
[in]indexIndex where to store the integer. If negative, append at end of data block.
[in]iInteger value to append.

◆ storeToLittleEndian()

template<typename INT >
void QtlByteBlock::storeToLittleEndian ( int  index,
INT  i 
)
inline

Store an integer in little endian representation at a given index.

The byte block is enlarged if necessary. Template variant

Template Parameters
INTAn integer type.
Parameters
[in]indexIndex where to store the integer. If negative, append at end of data block.
[in]iInteger value to append.

◆ appendToByteOrder()

template<typename INT >
void QtlByteBlock::appendToByteOrder ( INT  i,
ByteOrder  order 
)
inline

Add an integer in a given byte order at the end.

Template Parameters
INTAn integer type.
Parameters
[in]iInteger value to append.
[in]orderThe byte order to serialize i.

◆ storeToByteOrder()

template<typename INT >
void QtlByteBlock::storeToByteOrder ( int  index,
INT  i,
ByteOrder  order 
)
inline

Store an integer in a given byte order at a given index.

The byte block is enlarged if necessary.

Template Parameters
INTAn integer type.
Parameters
[in]indexIndex where to store the integer. If negative, append at end of data block.
[in]iInteger value to append.
[in]orderThe byte order to serialize i.

◆ getUtf8() [1/2]

bool QtlByteBlock::getUtf8 ( int &  index,
int  stringSize,
QString &  s 
) const

Get an UTF-8 string at a given position.

Parameters
[in,out]indexIndex in the byte block where to read the data. If the data is correctly read, index is updated to point after the read data.
[in]stringSizeRequested string size in bytes.
[out]sReturned string.
Returns
True on success, false on error.

◆ getUtf8() [2/2]

QString QtlByteBlock::getUtf8 ( int  index,
int  stringSize 
) const

Get an UTF-8 string at a given position.

Parameters
[in]indexIndex in the byte block where to read the data.
[in]stringSizeRequested string size in bytes.
Returns
The string, possibly truncated to stay within the block.

◆ getLatin1() [1/2]

bool QtlByteBlock::getLatin1 ( int &  index,
int  stringSize,
QString &  s 
) const

Get a Latin-1 string at a given position.

Parameters
[in,out]indexIndex in the byte block where to read the data. If the data is correctly read, index is updated to point after the read data.
[in]stringSizeRequested string size in bytes.
[out]sReturned string.
Returns
True on success, false on error.

◆ getLatin1() [2/2]

QString QtlByteBlock::getLatin1 ( int  index,
int  stringSize 
) const

Get a Latin1 string at a given position.

Parameters
[in]indexIndex in the byte block where to read the data.
[in]stringSizeRequested string size in bytes.
Returns
The string, possibly truncated to stay within the block.

◆ fromBigEndian() [1/2]

template<typename INT >
bool QtlByteBlock::fromBigEndian ( int &  index,
INT &  i 
) const
inline

Get an integer in big endian representation at a given position.

Parameters
[in,out]indexIndex in the byte block where to read the data. If the data is correctly read, index is updated to point after the read data.
[out]iReturned integer value.
Returns
True on success, false on error.

◆ fromBigEndian() [2/2]

template<typename INT >
INT QtlByteBlock::fromBigEndian ( int  index) const
inline

Get an integer in big endian representation at a given position.

Parameters
[in]indexIndex in the byte block where to read the data.
Returns
The decoded integer value or zero if no space in byte block.

◆ fromLittleEndian() [1/2]

template<typename INT >
bool QtlByteBlock::fromLittleEndian ( int &  index,
INT &  i 
) const
inline

Get an integer in little endian representation at a given position.

Parameters
[in,out]indexIndex in the byte block where to read the data. If the data is correctly read, index is updated to point after the read data.
[out]iReturned integer value.
Returns
True on success, false on error.

◆ fromLittleEndian() [2/2]

template<typename INT >
INT QtlByteBlock::fromLittleEndian ( int  index) const
inline

Get an integer in little endian representation at a given position.

Parameters
[in]indexIndex in the byte block where to read the data.
Returns
The decoded integer value or zero if no space in byte block.

◆ fromByteOrder() [1/2]

template<typename INT >
bool QtlByteBlock::fromByteOrder ( int &  index,
INT &  i,
ByteOrder  order 
) const
inline

Get an integer in a given byte order at a given position.

Parameters
[in,out]indexIndex in the byte block where to read the data. If the data is correctly read, index is updated to point after the read data.
[out]iReturned integer value.
[in]orderThe byte order to deserialize i.
Returns
True on success, false on error.

◆ fromByteOrder() [2/2]

template<typename INT >
INT QtlByteBlock::fromByteOrder ( int  index,
ByteOrder  order 
) const
inline

Get an integer in a given byte order at a given position.

Parameters
[in]indexIndex in the byte block where to read the data.
[in]orderThe byte order to deserialize the integer.
Returns
The decoded integer value or zero if no space in byte block.

◆ appendToBigEndian() [2/3]

template<>
void QtlByteBlock::appendToBigEndian ( quint8  i)
inline

Add an integer in big endian representation at the end.

Template specializations for performance

Parameters
[in]iInteger value to append.

◆ appendToBigEndian() [3/3]

template<>
void QtlByteBlock::appendToBigEndian ( qint8  i)
inline

Add an integer in big endian representation at the end.

Template specializations for performance

Parameters
[in]iInteger value to append.

◆ appendToLittleEndian() [2/3]

template<>
void QtlByteBlock::appendToLittleEndian ( quint8  i)
inline

Add an integer in little endian representation at the end.

Template specializations for performance

Parameters
[in]iInteger value to append.

◆ appendToLittleEndian() [3/3]

template<>
void QtlByteBlock::appendToLittleEndian ( qint8  i)
inline

Add an integer in little endian representation at the end.

Template specializations for performance

Parameters
[in]iInteger value to append.

The documentation for this class was generated from the following files: