QOpcUaBinaryDataEncoding Class
QOpcUaBinaryDataEncoding 是 OPC UA 第 6 部分中所述的 OPC UA 二进制数据编码的部分实现。更多内容...
| 头文件: | #include <QOpcUaBinaryDataEncoding> |
| CMake: | find_package(Qt6 REQUIRED COMPONENTS OpcUa) target_link_libraries(mytarget PRIVATE Qt6::OpcUa) |
| qmake: | QT += opcua |
公共函数
| QOpcUaBinaryDataEncoding(QByteArray *buffer) | |
| QOpcUaBinaryDataEncoding(QOpcUaExtensionObject &object) | |
| T | decode(bool &success) |
| QList<T> | decodeArray(bool &success) |
| bool | encode(const T &src) |
| bool | encodeArray(const QList<T> &src) |
| int | offset() const |
| void | setOffset(int offset) |
| void | truncateBufferToOffset() |
详细说明
它提供了用于对数据进行编码和解码的模板函数,以便读写扩展对象。
支持以下类型:
| Qt 类型 | OPC UA 类型 |
|---|---|
| quint8 | uint8 |
| qint8 | int8 |
| quint16 | uint16 |
| qint16 | int16 |
| quint32 | uint32 |
| qint32 | int32 |
| quint64 | uint64 |
| qint64 | int64 |
| float | float |
| double | double |
| QString | 字符串 |
| QOpcUaQualifiedName | 限定名 |
| QOpcUaLocalizedText | 本地化文本 |
| QOpcUaEUInformation | 欧盟信息 |
| QOpcUaRange | 范围 |
| QOpcUaComplexNumber | 复数 |
| QOpcUaDoubleComplexNumber | 双精度复数 |
| QOpcUaAxisInformation | 轴信息 |
| QOpcUaXValue | XV |
| QUuid | GUID |
| QString 节点 ID | 节点ID |
| QByteArray | 字节字符串 |
| QDateTime | DateTime |
| QOpcUa::UaStatusCode | 状态码 |
| QOpcUaExpandedNodeId | 扩展节点ID |
| QOpcUaExtensionObject | 扩展对象 |
| QOpcUaArgument | 参数 |
| QOpcUaDiagnosticInfo (自 Qt 6.7 起) | 诊断信息 |
| QOpcUaApplicationRecordDataType | ApplicationRecordDataType |
| QOpcUaStructureDefinition (自 Qt 6.7 起) | 结构定义 |
| QOpcUaStructureField (自 Qt 6.7 起) | 结构字段 |
| QOpcUaEnumDefinition (自 Qt 6.7 起) | EnumDefinition |
| QOpcUaEnumField (自 Qt 6.7 起) | EnumField |
| QOpcUaVariant (自 Qt 6.7 起) | Variant |
| QOpcUaDataValue (自 Qt 6.7 起) | DataValue |
成员函数文档
QOpcUaBinaryDataEncoding::QOpcUaBinaryDataEncoding(QByteArray *buffer)
为数据缓冲区buffer 构建一个二进制数据编码对象。只要该二进制数据编码对象仍在使用,就不得删除buffer 。
QOpcUaBinaryDataEncoding::QOpcUaBinaryDataEncoding(QOpcUaExtensionObject &object)
使用object 的编码主体作为数据缓冲区,构建一个二进制数据编码对象。
object 只要该二进制数据编码对象仍在使用,就不得将其删除。
template <typename T, QOpcUa::Types OVERLAY = QOpcUa::Types::Undefined> T QOpcUaBinaryDataEncoding::decode(bool &success)
使用由OVERLAY 指定的OPC UA内置类型,从数据缓冲区解码类型为T的标量值。如果解码成功,success 将设置为true ;否则,将设置为false 。
返回解码后的值。若success 为false,则返回的值无效。
解码的最大递归深度限制为500 。若达到该限制,success 将被设置为 false,并返回一个无效值。
另请参阅 decodeArray()。
template <typename T, QOpcUa::Types OVERLAY = QOpcUa::Types::Undefined> QList<T> QOpcUaBinaryDataEncoding::decodeArray(bool &success)
使用由OVERLAY 指定的OPC UA内置类型,从数据缓冲区解码一个类型为T的数组。如果解码成功,success 将设置为true ;否则,将设置为false 。
返回解码后的值。如果success 为false,则返回的值无效。
解码的最大递归深度限制为500 。如果达到限制,success 将被设置为 false,并返回一个无效值。
另请参阅 decode()。
template <typename T, QOpcUa::Types OVERLAY = QOpcUa::Types::Undefined> bool QOpcUaBinaryDataEncoding::encode(const T &src)
使用由OVERLAY 指定的 OPC UA 内置类型对类型为 T 的src 进行编码,并将编码后的值追加到数据缓冲区中。如果值已成功编码,则返回true 。
另请参阅 encodeArray()。
template <typename T, QOpcUa::Types OVERLAY = QOpcUa::Types::Undefined> bool QOpcUaBinaryDataEncoding::encodeArray(const QList<T> &src)
使用由OVERLAY 指定的 OPC UA 内置类型,将src 中所有类型为 T 的元素进行编码,并将编码后的值追加到数据缓冲区中。
如果值已成功编码,则返回true 。
另请参阅 encode()。
int QOpcUaBinaryDataEncoding::offset() const
返回数据缓冲区中的当前偏移量。
另请参阅 setOffset()。
void QOpcUaBinaryDataEncoding::setOffset(int offset)
将数据缓冲区中的当前偏移量设置为offset 。缓冲区中的第一个字节的偏移量为0。
另请参阅 offset()。
void QOpcUaBinaryDataEncoding::truncateBufferToOffset()
将数据缓冲区截断至当前offset()处的偏移量。如果偏移量小于当前缓冲区大小,则此方法不执行任何操作。
此方法可用于在编码失败后进行回滚,具体操作是设置旧偏移量并调用 truncateBufferToOffset()。
© 2026 The Qt Company Ltd. Documentation contributions included herein are the copyrights of their respective owners. The documentation provided herein is licensed under the terms of the GNU Free Documentation License version 1.3 as published by the Free Software Foundation. Qt and respective logos are trademarks of The Qt Company Ltd. in Finland and/or other countries worldwide. All other trademarks are property of their respective owners.