6#define CBOR_NO_ENCODER_API
7#include <private/qcborcommon_p.h>
9#include <private/qnumeric_p.h>
10#include <private/qstringconverter_p.h>
23#define CBOR_PARSER_READER_CONTROL 1
24#define CBOR_PARSER_CAN_READ_BYTES_FUNCTION qt_cbor_decoder_can_read
25#define CBOR_PARSER_ADVANCE_BYTES_FUNCTION qt_cbor_decoder_advance
26#define CBOR_PARSER_TRANSFER_STRING_FUNCTION qt_cbor_decoder_transfer_string
27#define CBOR_PARSER_READ_BYTES_FUNCTION qt_cbor_decoder_read
33#include <cborparser.c>
39 Q_UNREACHABLE_RETURN(CborErrorInternalError);
43 Q_UNREACHABLE_RETURN(CborErrorInternalError);
586 if (avail ==
buffer.size())
609 if (err != CborErrorUnexpectedEOF)
644 d->handleError(CborError(
error.c));
652 qint64 avail = self->buffer.
size() - self->bufferStart;
662 self->bufferStart += int(
len);
682 static_assert(
sizeof(size_t) ==
sizeof(
qsizetype));
687 if (
len >
size_t(std::numeric_limits<QByteArray::size_type>::max())
688 || qAddOverflow<qsizetype>(
offset,
len, &total))
689 return CborErrorDataTooLarge;
692 *userptr =
reinterpret_cast<void *
>(
offset);
694 qint64 avail = (self->device ? self->device->bytesAvailable() : self->buffer.
size()) -
696 return total > avail ? CborErrorUnexpectedEOF : CborNoError;
701 if (
currentElement.flags & CborIteratorFlag_IteratingStringChunks)
704 CborError err = cbor_value_begin_string_iteration(&
currentElement);
714inline void QCborStreamReader::preparse()
719 if (type_ == CborInvalidType) {
732 if (type_ == CborBooleanType || type_ == CborNullType || type_ == CborUndefinedType) {
733 type_ = CborSimpleType;
871 qWarning(
"QCborStreamReader: addData() with device()");
1017 }
else if (maxRecursion < 0) {
1023 next(maxRecursion - 1);
1028 StringResult<qsizetype>
r;
1031 }
while (
r.status ==
Ok);
1034 StringResult<QString>
r;
1037 }
while (
r.status ==
Ok);
1091 err = CborErrorUnknownLength;
1095 err = CborErrorIllegalType;
1117bool QCborStreamReader::_enterContainer_helper()
1144 qWarning(
"QCborStreamReader::leaveContainer: trying to leave top-level element");
1151 CborError err = cbor_value_leave_container(&container, &d->
currentElement);
1410qsizetype QCborStreamReader::_currentStringChunkSize()
const
1417 if (err == CborErrorNoMoreStringChunks)
1479bool QCborStreamReader::_readAndAppendToString_helper(
QString &
dst)
1519bool QCborStreamReader::_readAndAppendToUtf8String_helper(
QByteArray &
dst)
1561bool QCborStreamReader::_readAndAppendToByteArray_helper(
QByteArray &
dst)
1615 auto status = reader.d->readStringChunk(
data).status;
1626 const void *content =
nullptr;
1653 err = cbor_value_get_byte_string_chunk(&
currentElement,
reinterpret_cast<const uint8_t **
>(&content),
1656 err = cbor_value_get_text_string_chunk(&
currentElement,
reinterpret_cast<const char **
>(&content),
1665 err = CborErrorDataTooLarge;
1668 if (err == CborErrorNoMoreStringChunks) {
1689 }
else if (
params.isUtf8String()) {
1704 if (remainingInBuffer <= 0) {
1711 buffer.truncate(remainingInBuffer);
1728 char *
ptr =
nullptr;
1730 if (
params.isPlainPointer()) {
1735 toRead =
params.maxlen_or_type;
1737 }
else if (!
params.isString()) {
1739 auto oldSize =
params.array->size();
1740 auto newSize = oldSize;
1741 if (
qAddOverflow<
decltype(newSize)>(oldSize, toRead, &newSize)) {
1746 params.array->resize(newSize);
1747 }
QT_CATCH (
const std::bad_alloc &) {
1755 ptr =
const_cast<char *
>(
params.array->constData()) + oldSize;
1761 if (actuallyRead != toRead) {
1765 if (skipped !=
left)
1769 if (actuallyRead < 0) {
1774 actuallyRead = toRead;
1778 return actuallyRead;
1789 size_t newSize = size_t(utf8len) + size_t(currentSize);
1796 }
QT_CATCH (
const std::bad_alloc &) {
1809 constexpr qsizetype StringChunkSize = 16384;
1811 QVarLengthArray<char> chunk(chunkSize);
1817 if (actuallyRead == toRead)
1820 if (actuallyRead != toRead) {
1835 return size - currentSize;
1857#include "moc_qcborstreamreader.cpp"
IOBluetoothDevice * device
constexpr QByteArrayView last(qsizetype n) const
static constexpr qsizetype max_size() noexcept
char at(qsizetype i) const
Returns the byte at index position i in the byte array.
void clear()
Clears the contents of the byte array and makes it null.
QByteArray & append(char c)
This is an overloaded member function, provided for convenience. It differs from the above function o...
bool ensureStringIteration()
QStack< CborValue > containerStack
void handleError(CborError err) noexcept
QCborStreamReaderPrivate(QIODevice *device)
QByteArray::size_type bufferStart
qsizetype readStringChunk_byte(ReadStringChunk params, qsizetype len)
bool readFullString(ReadStringChunk params)
qsizetype readStringChunk_unicode(ReadStringChunk params, qsizetype utf8len)
static QCborStreamReader::StringResultCode appendStringChunk(QCborStreamReader &reader, QByteArray *data)
QCborStreamReader::StringResult< qsizetype > readStringChunk(ReadStringChunk params)
~QCborStreamReaderPrivate()
qsizetype readStringChunk_utf8(ReadStringChunk params, qsizetype utf8len)
void setDevice(QIODevice *dev)
QCborStreamReaderPrivate(const QByteArray &data)
\inmodule QtCore\reentrant
void setDevice(QIODevice *device)
Sets the source of data to device, resetting the decoder to its initial state.
bool isLengthKnown() const noexcept Q_DECL_PURE_FUNCTION
Returns true if the length of the current array, map, byte array or string is known (explicit in the ...
QCborError lastError() const
Returns the last error in decoding the stream, if any.
QIODevice * device() const
Returns the QIODevice that was set with either setDevice() or the QCborStreamReader constructor.
void clear()
Clears the decoder state and resets the input source data to an empty byte array.
qint64 currentOffset() const
Returns the offset in the input stream of the item currently being decoded.
bool isByteArray() const
Returns true if the type of the current element is a byte array (that is, if type() returns QCborStre...
bool next(int maxRecursion=10000)
Advance the CBOR stream decoding one element.
void addData(const QByteArray &data)
Adds data to the CBOR stream and reparses the current element.
bool isString() const
Returns true if the type of the current element is a text string (that is, if type() returns QCborStr...
void reset()
Resets the source back to the beginning and clears the decoder state.
QCborStreamReader()
Creates a QCborStreamReader object with no source data.
QCborStreamReader::Type parentContainerType() const
Returns either QCborStreamReader::Array or QCborStreamReader::Map, indicating whether the container t...
bool enterContainer()
Enters the array or map that is the current item and prepares for iterating the elements contained in...
void reparse()
Reparses the current element.
quint64 length() const
Returns the length of the string or byte array, or the number of items in an array or the number,...
StringResult< QString > readString()
Decodes one string chunk from the CBOR string and returns it.
bool hasNext() const noexcept Q_DECL_PURE_FUNCTION
Returns true if there are more items to be decoded in the current container or false of we've reached...
StringResultCode
This enum is returned by readString() and readByteArray() and is used to indicate what the status of ...
StringResult< qsizetype > readStringChunk(char *ptr, qsizetype maxlen)
Reads the current string chunk into the buffer pointed to by ptr, whose size is maxlen.
Type
This enumeration contains all possible CBOR types as decoded by QCborStreamReader.
bool isContainer() const
Returns true if the current element is a container (that is, an array or a map), false if it is anyth...
~QCborStreamReader()
Destroys this QCborStreamReader object and frees any associated resources.
bool leaveContainer()
Leaves the array or map whose items were being processed and positions the decoder at the next item a...
int containerDepth() const
Returns the number of containers that this stream has entered with enterContainer() but not yet left.
\inmodule QtCore \reentrant
virtual qint64 size() const
For open random-access devices, this function returns the size of the device.
virtual qint64 pos() const
For random-access devices, this function returns the position that data is written to or read from.
qint64 peek(char *data, qint64 maxlen)
virtual qint64 bytesAvailable() const
Returns the number of bytes that are available for reading.
qint64 skip(qint64 maxSize)
virtual bool reset()
Seeks to the start of input for random-access devices.
qint64 read(char *data, qint64 maxlen)
Reads at most maxSize bytes from the device into data, and returns the number of bytes read.
qsizetype size() const noexcept
bool isEmpty() const noexcept
T & top()
Returns a reference to the stack's top item.
T pop()
Removes the top item from the stack and returns it.
void push(const T &t)
Adds element t to the top of the stack.
\macro QT_RESTRICTED_CAST_FROM_ASCII
const QChar * constData() const
Returns a pointer to the data stored in the QString.
static constexpr qsizetype max_size() noexcept
qsizetype size() const noexcept
Returns the number of characters in this string.
Combined button and popup list for selecting options.
Q_CORE_EXPORT Q_DECL_PURE_FUNCTION bool isValidUtf8(QByteArrayView s) noexcept
QT_WARNING_PUSH static QT_WARNING_POP CborError _cbor_value_dup_string(const CborValue *, void **, size_t *, CborValue *)
static CborError qt_cbor_decoder_transfer_string(void *token, const void **userptr, size_t offset, size_t len)
QCborStreamReader::StringResultCode qt_cbor_append_string_chunk(QCborStreamReader &reader, QByteArray *data)
static QT_BEGIN_NAMESPACE bool qt_cbor_decoder_can_read(void *token, size_t len)
void qt_cbor_stream_set_error(QCborStreamReaderPrivate *d, QCborError error)
static void qt_cbor_decoder_advance(void *token, size_t len)
static void * qt_cbor_decoder_read(void *token, void *userptr, size_t offset, size_t len)
static CborError cbor_value_get_half_float_as_float(const CborValue *, float *)
#define QT_WARNING_DISABLE_MSVC(number)
#define QT_WARNING_DISABLE_GCC(text)
DBusConnection const char DBusError * error
static ControlElement< T > * ptr(QWidget *widget)
constexpr const T & qMin(const T &a, const T &b)
std::enable_if_t< std::is_unsigned_v< T >, bool > qAddOverflow(T v1, T v2, T *r)
GLenum GLuint GLintptr GLsizeiptr size
[1]
GLint GLsizei GLsizei GLenum GLenum GLsizei void * data
GLenum GLuint GLintptr offset
GLsizei const GLchar *const * string
[0]
QtPrivate::QRegularExpressionMatchIteratorRangeBasedForIterator begin(const QRegularExpressionMatchIterator &iterator)
unsigned long long quint64
ReturnedValue read(const char *data)
\inmodule QtCore \inheaderfile QtCborCommon \reentrant
Code
This enum contains the possible error condition codes.
ReadStringChunk(char *ptr, qsizetype maxlen)
bool isPlainPointer() const
ReadStringChunk(QByteArray *array, Type type=ByteArray)
bool isUtf8String() const
ReadStringChunk(QString *str)
static QChar * convertToUnicode(QChar *buffer, QByteArrayView in) noexcept