Enable encoding 1-set-of

This commit is contained in:
Anton Thomasson 2022-08-13 12:12:09 +02:00
parent 8712ee6eea
commit 3abd1e103f
2 changed files with 23 additions and 12 deletions

View file

@ -361,7 +361,25 @@ void IppMsg::encode_attr(Bytestream& msg, quint8 tag, QString name, QJsonValue v
name = ""; name = "";
} }
msg << tag << quint16(name.length()) << name.toStdString(); 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) { switch (tag) {
case OpAttrs: case OpAttrs:
@ -405,19 +423,11 @@ void IppMsg::encode_attr(Bytestream& msg, quint8 tag, QString name, QJsonValue v
case BeginCollection: case BeginCollection:
{ {
msg << (quint16)0; // length of value msg << (quint16)0; // length of value
if(value.isObject()) QJsonObject collection = value.toObject();
for(QString key : collection.keys())
{ {
QJsonObject collection = value.toObject(); encode_attr(msg, collection[key].toObject()["tag"].toInt(), key,
for(QString key : collection.keys()) collection[key].toObject()["value"], true);
{
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");
} }
msg << (quint8)EndCollection << (quint16)0 << (quint16)0; msg << (quint8)EndCollection << (quint16)0 << (quint16)0;
break; break;

View file

@ -88,6 +88,7 @@ private:
QJsonValue collect_attributes(QJsonArray& attrs); QJsonValue collect_attributes(QJsonArray& attrs);
QString consume_attribute(QJsonObject& attrs, Bytestream& data); QString consume_attribute(QJsonObject& attrs, Bytestream& data);
void encode_attr(Bytestream& msg, quint8 tag, QString name, QJsonValue value, bool subCollection=false); 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; Operation _operation;