64 bool seenMessageBegin =
false;
65 bool seenMessageEnd =
false;
74 const bool messageBegin =
flags & 0x80;
75 const bool messageEnd =
flags & 0x40;
77 const bool cf =
flags & 0x20;
78 const bool sr =
flags & 0x10;
79 const bool il =
flags & 0x08;
82 if (messageBegin && seenMessageBegin) {
83 qWarning(
"Got message begin but already parsed some records");
85 }
else if (!messageBegin && !seenMessageBegin) {
86 qWarning(
"Haven't got message begin yet");
88 }
else if (messageBegin && !seenMessageBegin) {
89 seenMessageBegin =
true;
91 if (messageEnd && seenMessageEnd) {
92 qWarning(
"Got message end but already parsed final record");
94 }
else if (messageEnd && !seenMessageEnd) {
95 seenMessageEnd =
true;
98 if ((typeNameFormat != 0x06) && !partialChunk.
isEmpty()) {
99 qWarning(
"Partial chunk not empty, but TNF not 0x06 as expected");
103 int headerLength = 1;
104 headerLength += (sr) ? 1 : 4;
105 headerLength += (il) ? 1 : 0;
107 if (idx + headerLength >=
message.size()) {
108 qWarning(
"Unexpected end of message");
114 if ((typeNameFormat == 0x06) && (typeLength != 0)) {
115 qWarning(
"Invalid chunked data, TYPE_LENGTH != 0");
137 const qsizetype contentLength = convertedPayloadLength + typeLength + idLength;
143 if ((contentLength < 0) || (convertedPayloadLength < 0)
144 || ((std::numeric_limits<qsizetype>::max() - idx) < contentLength)) {
145 qWarning(
"Payload can't fit into QByteArray");
149 if (idx + contentLength >=
message.size()) {
150 qWarning(
"Unexpected end of message");
154 if ((typeNameFormat == 0x06) && il) {
155 qWarning(
"Invalid chunked data, IL != 0");
159 if (typeNameFormat != 0x06)
162 if (typeLength > 0) {
165 idx += typeLength - 1;
174 if (payloadLength > 0) {
179 partialChunk.
append(payload);
180 }
else if (typeNameFormat == 0x06) {
182 record.setPayload(partialChunk + payload);
183 partialChunk.
clear();
186 record.setPayload(payload);
189 idx += payloadLength - 1;
197 if (!cf && seenMessageEnd)
204 if (!seenMessageBegin || !seenMessageEnd) {
205 qWarning(
"Malformed NDEF Message, missing begin or end");
290 if (
record.payload().size() < 255)
293 if (!
record.id().isEmpty())
297 m.append(
record.type().size());
312 if (!
record.type().isEmpty())
315 if (!
record.id().isEmpty())
318 if (!
record.payload().isEmpty())
bool isEmpty() const noexcept
Returns true if the byte array has size 0; otherwise returns false.
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...
qsizetype size() const noexcept
bool isEmpty() const noexcept
The QNdefMessage class provides an NFC NDEF message.
Q_NFC_EXPORT_COMPAT QNdefMessage()=default
Constructs a new empty NDEF message.
Q_NFC_EXPORT QByteArray toByteArray() const
Returns the NDEF message as a byte array.
Q_NFC_EXPORT bool operator==(const QNdefMessage &other) const
Returns true if this NDEF message is equivalent to other; otherwise returns false.
The QNdefRecord class provides an NFC NDEF record.
TypeNameFormat
This enum describes the type name format of an NDEF record.
Combined button and popup list for selecting options.
GLenum GLuint GLintptr GLsizeiptr size
[1]
GLenum GLuint GLenum GLsizei length
GLuint GLsizei const GLchar * message