6#define CBOR_NO_ENCODER_API
7#include <private/qcborcommon_p.h>
9#include <private/qbytearray_p.h>
10#include <private/qnumeric_p.h>
11#include <private/qstringconverter_p.h>
24#define CBOR_PARSER_READER_CONTROL 1
25#define CBOR_PARSER_CAN_READ_BYTES_FUNCTION qt_cbor_decoder_can_read
26#define CBOR_PARSER_ADVANCE_BYTES_FUNCTION qt_cbor_decoder_advance
27#define CBOR_PARSER_TRANSFER_STRING_FUNCTION qt_cbor_decoder_transfer_string
28#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)
641 d->handleError(CborError(
error.c));
649 qint64 avail = self->buffer.
size() - self->bufferStart;
659 self->bufferStart += int(
len);
679 static_assert(
sizeof(size_t) ==
sizeof(
qsizetype));
684 if (
len >
size_t(std::numeric_limits<QByteArray::size_type>::max())
685 || qAddOverflow<qsizetype>(
offset,
len, &total))
686 return CborErrorDataTooLarge;
689 *userptr =
reinterpret_cast<void *
>(
offset);
691 qint64 avail = (self->device ? self->device->bytesAvailable() : self->buffer.
size()) -
693 return total > avail ? CborErrorUnexpectedEOF : CborNoError;
698 if (
currentElement.flags & CborIteratorFlag_IteratingStringChunks)
701 CborError err = cbor_value_begin_string_iteration(&
currentElement);
711inline void QCborStreamReader::preparse()
716 if (type_ == CborInvalidType) {
729 if (type_ == CborBooleanType || type_ == CborNullType || type_ == CborUndefinedType) {
730 type_ = CborSimpleType;
868 qWarning(
"QCborStreamReader: addData() with device()");
1014 }
else if (maxRecursion < 0) {
1020 next(maxRecursion - 1);
1028 }
while (
r.status ==
Ok);
1034 }
while (
r.status ==
Ok);
1088 err = CborErrorUnknownLength;
1092 err = CborErrorIllegalType;
1114bool QCborStreamReader::_enterContainer_helper()
1141 qWarning(
"QCborStreamReader::leaveContainer: trying to leave top-level element");
1148 CborError err = cbor_value_leave_container(&container, &d->
currentElement);
1365qsizetype QCborStreamReader::_currentStringChunkSize()
const
1372 if (err == CborErrorNoMoreStringChunks)
1429 auto status = reader.d->readStringChunk(
data).status;
1440 const void *content =
nullptr;
1461 err = cbor_value_get_byte_string_chunk(&
currentElement,
reinterpret_cast<const uint8_t **
>(&content),
1464 err = cbor_value_get_text_string_chunk(&
currentElement,
reinterpret_cast<const char **
>(&content),
1473 err = CborErrorDataTooLarge;
1476 if (err == CborErrorNoMoreStringChunks) {
1510 if (remainingInBuffer <= 0) {
1517 buffer.truncate(remainingInBuffer);
1534 char *
ptr =
nullptr;
1536 if (
params.isPlainPointer()) {
1541 toRead =
params.maxlen_or_type;
1543 }
else if (
params.isByteArray()) {
1545 auto oldSize =
params.array->size();
1546 auto newSize = oldSize;
1547 if (
qAddOverflow<
decltype(newSize)>(oldSize, toRead, &newSize)) {
1552 params.array->resize(newSize);
1553 }
QT_CATCH (
const std::bad_alloc &) {
1561 ptr =
const_cast<char *
>(
params.array->constData()) + oldSize;
1567 if (actuallyRead != toRead) {
1571 if (skipped !=
left)
1575 if (actuallyRead < 0) {
1580 actuallyRead = toRead;
1584 return actuallyRead;
1595 params.string->resize(utf8len);
1596 }
QT_CATCH (
const std::bad_alloc &) {
1614 constexpr qsizetype StringChunkSize = 16384;
1622 if (actuallyRead == toRead)
1625 if (actuallyRead != toRead) {
1646#include "moc_qcborstreamreader.cpp"
IOBluetoothDevice * device
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)
qsizetype readStringChunk_unicode(ReadStringChunk params, qsizetype utf8len)
static QCborStreamReader::StringResultCode appendStringChunk(QCborStreamReader &reader, QByteArray *data)
QCborStreamReader::StringResult< qsizetype > readStringChunk(ReadStringChunk params)
~QCborStreamReaderPrivate()
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 ...
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.
QCborError lastError()
Returns the last error in decoding the stream, if any.
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.
qsizetype size() const
Returns the number of characters in this string.
Combined button and popup list for selecting options.
constexpr qsizetype MaxStringSize
QT_BEGIN_NAMESPACE constexpr qsizetype MaxByteArraySize
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)
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)
ReadStringChunk(QByteArray *array)
bool isPlainPointer() const
ReadStringChunk(QString *str)
static QChar * convertToUnicode(QChar *buffer, QByteArrayView in) noexcept