Encode ipp attrs into a Bytestream-ref
This commit is contained in:
parent
011c897e76
commit
ac2b76a0f0
2 changed files with 13 additions and 20 deletions
|
@ -308,12 +308,12 @@ QByteArray IppMsg::encode(Operation op)
|
||||||
foreach(QString key, InitialAttrs)
|
foreach(QString key, InitialAttrs)
|
||||||
{
|
{
|
||||||
QJsonObject val = _opAttrs.take(key).toObject();
|
QJsonObject val = _opAttrs.take(key).toObject();
|
||||||
ipp << encode_attr(val["tag"].toInt(), key, val["value"]);
|
encode_attr(ipp, val["tag"].toInt(), key, val["value"]);
|
||||||
}
|
}
|
||||||
for(QJsonObject::iterator it = _opAttrs.begin(); it != _opAttrs.end(); it++)
|
for(QJsonObject::iterator it = _opAttrs.begin(); it != _opAttrs.end(); it++)
|
||||||
{ // encode any remaining op-attrs
|
{ // encode any remaining op-attrs
|
||||||
QJsonObject val = it.value().toObject();
|
QJsonObject val = it.value().toObject();
|
||||||
ipp << encode_attr(val["tag"].toInt(), it.key(), val["value"]);
|
encode_attr(ipp, val["tag"].toInt(), it.key(), val["value"]);
|
||||||
}
|
}
|
||||||
for(QJsonArray::iterator ait = _jobAttrs.begin(); ait != _jobAttrs.end(); ait++)
|
for(QJsonArray::iterator ait = _jobAttrs.begin(); ait != _jobAttrs.end(); ait++)
|
||||||
{
|
{
|
||||||
|
@ -323,7 +323,7 @@ QByteArray IppMsg::encode(Operation op)
|
||||||
for(QJsonObject::iterator it = tmpObj.begin(); it != tmpObj.end(); it++)
|
for(QJsonObject::iterator it = tmpObj.begin(); it != tmpObj.end(); it++)
|
||||||
{
|
{
|
||||||
QJsonObject val = it.value().toObject();
|
QJsonObject val = it.value().toObject();
|
||||||
ipp << encode_attr(val["tag"].toInt(), it.key(), val["value"]);
|
encode_attr(ipp, val["tag"].toInt(), it.key(), val["value"]);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -333,9 +333,10 @@ QByteArray IppMsg::encode(Operation op)
|
||||||
return QByteArray((char*)(ipp.raw()), ipp.size());
|
return QByteArray((char*)(ipp.raw()), ipp.size());
|
||||||
}
|
}
|
||||||
|
|
||||||
Bytestream IppMsg::encode_attr(quint8 tag, QString name, QJsonValueRef value)
|
void IppMsg::encode_attr(Bytestream& msg, quint8 tag, QString name, QJsonValueRef value)
|
||||||
{
|
{
|
||||||
Bytestream req;
|
|
||||||
|
msg << tag << quint16(name.length()) << name.toStdString();
|
||||||
|
|
||||||
switch (tag) {
|
switch (tag) {
|
||||||
case OpAttrs:
|
case OpAttrs:
|
||||||
|
@ -347,13 +348,13 @@ Bytestream IppMsg::encode_attr(quint8 tag, QString name, QJsonValueRef value)
|
||||||
case Enum:
|
case Enum:
|
||||||
{
|
{
|
||||||
quint32 tmp_u32 = value.toInt();
|
quint32 tmp_u32 = value.toInt();
|
||||||
req << (quint16)4 << tmp_u32;
|
msg << (quint16)4 << tmp_u32;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case Boolean:
|
case Boolean:
|
||||||
{
|
{
|
||||||
quint32 tmp_u8 = value.toBool();
|
quint32 tmp_u8 = value.toBool();
|
||||||
req << (quint16)1 << tmp_u8;
|
msg << (quint16)1 << tmp_u8;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case DateTime:
|
case DateTime:
|
||||||
|
@ -366,14 +367,14 @@ Bytestream IppMsg::encode_attr(quint8 tag, QString name, QJsonValueRef value)
|
||||||
qint32 x = value.toObject()["x"].toInt();
|
qint32 x = value.toObject()["x"].toInt();
|
||||||
qint32 y = value.toObject()["y"].toInt();
|
qint32 y = value.toObject()["y"].toInt();
|
||||||
qint8 units = value.toObject()["units"].toInt();
|
qint8 units = value.toObject()["units"].toInt();
|
||||||
req << (quint16)9 << x << y << units;
|
msg << (quint16)9 << x << y << units;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case IntegerRange:
|
case IntegerRange:
|
||||||
{
|
{
|
||||||
qint32 low = value.toObject()["low"].toInt();
|
qint32 low = value.toObject()["low"].toInt();
|
||||||
qint32 high = value.toObject()["high"].toInt();
|
qint32 high = value.toObject()["high"].toInt();
|
||||||
req << (quint16)8 << low << high;
|
msg << (quint16)8 << low << high;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case OctetStringUnknown:
|
case OctetStringUnknown:
|
||||||
|
@ -389,8 +390,8 @@ Bytestream IppMsg::encode_attr(quint8 tag, QString name, QJsonValueRef value)
|
||||||
case MimeMediaType:
|
case MimeMediaType:
|
||||||
{
|
{
|
||||||
QByteArray tmpstr = value.toString().toUtf8();
|
QByteArray tmpstr = value.toString().toUtf8();
|
||||||
req << quint16(tmpstr.length());
|
msg << quint16(tmpstr.length());
|
||||||
req.putBytes(tmpstr.data(), tmpstr.length());
|
msg.putBytes(tmpstr.data(), tmpstr.length());
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
default:
|
default:
|
||||||
|
@ -398,12 +399,4 @@ Bytestream IppMsg::encode_attr(quint8 tag, QString name, QJsonValueRef value)
|
||||||
Q_ASSERT(false);
|
Q_ASSERT(false);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
Bytestream actual;
|
|
||||||
if(req.size() != 0)
|
|
||||||
{
|
|
||||||
actual << tag << quint16(name.length()) << name.toStdString() << req;
|
|
||||||
}
|
|
||||||
|
|
||||||
return actual;
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -85,7 +85,7 @@ private:
|
||||||
QJsonArray get_unnamed_attributes(Bytestream& data);
|
QJsonArray get_unnamed_attributes(Bytestream& data);
|
||||||
QJsonValue collect_attributes(QJsonArray& attrs);
|
QJsonValue collect_attributes(QJsonArray& attrs);
|
||||||
QString consume_attribute(QJsonObject& attrs, Bytestream& data);
|
QString consume_attribute(QJsonObject& attrs, Bytestream& data);
|
||||||
Bytestream encode_attr(quint8 tag, QString name, QJsonValueRef value);
|
void encode_attr(Bytestream& msg, quint8 tag, QString name, QJsonValueRef value);
|
||||||
|
|
||||||
quint8 _majVsn;
|
quint8 _majVsn;
|
||||||
quint8 _minVsn;
|
quint8 _minVsn;
|
||||||
|
|
Loading…
Reference in a new issue