Qx v0.5.8
Qt Extensions Library
Loading...
Searching...
No Matches
Qx::ByteArray Class Reference

The ByteArray class is a collection of static functions pertaining to QByteArray.

#include <qx/core/qx-bytearray.h>

Public Member Functions

template<>
QByteArray fromPrimitive (bool primitive, QSysInfo::Endian endianness)
 

Static Public Member Functions

template<typename T >
requires arithmetic<T>
static QByteArray fromPrimitive (T primitive, QSysInfo::Endian endianness=QSysInfo::ByteOrder)
 
template<typename T >
requires arithmetic<T>
static T toPrimitive (QByteArray ba, QSysInfo::Endian endianness=QSysInfo::ByteOrder)
 

Member Function Documentation

◆ fromPrimitive() [1/2]

template<>
QByteArray Qx::ByteArray::fromPrimitive< bool > ( bool primitive,
QSysInfo::Endian endianness )
inline

This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.

Template specialization of the above for T == bool.

Returns a byte array consisting of the single byte 0x01 or 0x00 for true and false respectively.

endianness is ignored.

◆ fromPrimitive() [2/2]

template<typename T >
requires arithmetic<T>
QByteArray Qx::ByteArray::fromPrimitive ( T primitive,
QSysInfo::Endian endianness = QSysInfo::ByteOrder )
inlinestatic

Creates a byte array from the integer value primitive, using endianness byte-ordering if T requires multiple bytes to store, and returns it.

Note
The exact representation for floating-point types depends on the underlying system, but most often the IEEE-754 standard is used.

◆ toPrimitive()

template<typename T >
requires arithmetic<T>
T Qx::ByteArray::toPrimitive ( QByteArray ba,
QSysInfo::Endian endianness = QSysInfo::ByteOrder )
inlinestatic

Returns the raw binary data in ba reinterpreted as fundamental type T, according to the byte-order specified by endianness for multi-byte values.

If the requested type is not large enough to store the reinterpreted contents of ba, the conversion will be performed on the first n-bytes that will fit instead.

If the requested type is stored using more bytes than are present within ba, the conversion will be performed as if ba was padded with zeros to reach that size, in accordance with endianness,

Note
When T == bool, this function will return false if the first byte of ba is zero, or true if it is any other value.
The exact interpretation for floating-point types depends on the underlying system, but most often the IEEE-754 standard is used.

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