From 3abd1e103ff26a86db428f1e47224e6910aa6327 Mon Sep 17 00:00:00 2001 From: Anton Thomasson Date: Sat, 13 Aug 2022 12:12:09 +0200 Subject: [PATCH] Enable encoding 1-set-of --- src/ippmsg.cpp | 34 ++++++++++++++++++++++------------ src/ippmsg.h | 1 + 2 files changed, 23 insertions(+), 12 deletions(-) diff --git a/src/ippmsg.cpp b/src/ippmsg.cpp index 19a5320..8ff6bfb 100644 --- a/src/ippmsg.cpp +++ b/src/ippmsg.cpp @@ -361,7 +361,25 @@ void IppMsg::encode_attr(Bytestream& msg, quint8 tag, QString name, QJsonValue v name = ""; } msg << tag << quint16(name.length()) << name.toStdString(); + if(value.isArray()) + { + QJsonArray array = value.toArray(); + value = array.takeAt(0); + encode_value(msg, tag, value); + for(QJsonValue v : array) + { + msg << tag << quint16(0); + encode_value(msg, tag, v); + } + } + else + { + encode_value(msg, tag, value); + } +} +void IppMsg::encode_value(Bytestream& msg, quint8 tag, QJsonValue value) +{ switch (tag) { case OpAttrs: @@ -405,19 +423,11 @@ void IppMsg::encode_attr(Bytestream& msg, quint8 tag, QString name, QJsonValue v case BeginCollection: { msg << (quint16)0; // length of value - if(value.isObject()) + QJsonObject collection = value.toObject(); + for(QString key : collection.keys()) { - QJsonObject collection = value.toObject(); - for(QString key : collection.keys()) - { - encode_attr(msg, collection[key].toObject()["tag"].toInt(), key, - collection[key].toObject()["value"], true); - } - } - else - { - // TODO add support for 1-setOf in collections - Q_ASSERT("FIXME-array"); + encode_attr(msg, collection[key].toObject()["tag"].toInt(), key, + collection[key].toObject()["value"], true); } msg << (quint8)EndCollection << (quint16)0 << (quint16)0; break; diff --git a/src/ippmsg.h b/src/ippmsg.h index ba389a2..b99e73f 100644 --- a/src/ippmsg.h +++ b/src/ippmsg.h @@ -88,6 +88,7 @@ private: QJsonValue collect_attributes(QJsonArray& attrs); QString consume_attribute(QJsonObject& attrs, Bytestream& data); void encode_attr(Bytestream& msg, quint8 tag, QString name, QJsonValue value, bool subCollection=false); + void encode_value(Bytestream& msg, quint8 tag, QJsonValue value); Operation _operation;