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 |
五进制32 | uint32 |
qint32 | int32 |
quint64 | uint64 |
qint64 | int64 |
浮点数 | 浮点数 |
double | 双 |
QString | 字符串 |
QOpcUaQualifiedName | 限定名称 |
QOpcUaLocalizedText | 本地化文本 |
QOpcUaEUInformation | 欧盟信息 |
QOpcUaRange | 范围 |
QOpcUaComplexNumber | 复数 |
QOpcUaDoubleComplexNumber | 双复数 |
QOpcUaAxisInformation | 轴信息 |
QOpcUaXValue | XV |
QUuid | GUID |
QString 节点 ID | 节点 ID |
QByteArray | 字节字符串 |
QDateTime | 日期时间 |
QOpcUa::UaStatusCode | 状态代码 |
QOpcUaExpandedNodeId | 扩展节点 ID |
QOpcUaExtensionObject | 扩展对象 |
QOpcUaArgument | 参数 |
QOpcUaDiagnosticInfo (自 Qt 6.7 起) | 诊断信息 |
QOpcUaApplicationRecordDataType | 应用程序记录数据类型 |
QOpcUaStructureDefinition (自 Qt 6.7 起) | 结构定义 |
QOpcUaStructureField (自 Qt 6.7 起) | 结构字段 |
QOpcUaEnumDefinition (自 Qt 6.7 起) | 枚举定义 |
QOpcUaEnumField (自 Qt 6.7 起) | 枚举字段 |
QOpcUaVariant (自 Qt 6.7 起) | 变量 |
QOpcUaDataValue (自 Qt 6.7 起) | 数据值 |
成员函数文档
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)
从数据缓冲区解码 T 类型的标量值。如果解码成功,success 设置为true
;如果解码失败,false
。
解码后的值将被返回。如果success 为 false,则返回值无效。
另请参阅 decodeArray() 。
template <typename T, QOpcUa::Types OVERLAY = QOpcUa::Types::Undefined> QList<T> QOpcUaBinaryDataEncoding::decodeArray(bool &success)
从数据缓冲区解码 T 类型数组。如果解码成功,success 设置为true
;如果解码失败,false
。
解码后的值将被返回。如果success 为 false,则返回值无效。
另请参阅 decode() 。
template <typename T, QOpcUa::Types OVERLAY = QOpcUa::Types::Undefined> bool QOpcUaBinaryDataEncoding::encode(const T &src)
对src 的 T 类型进行编码,并将编码值追加到数据缓冲区。如果值已成功编码,则返回true
。
另请参见 encodeArray()。
template <typename T, QOpcUa::Types OVERLAY = QOpcUa::Types::Undefined> bool QOpcUaBinaryDataEncoding::encodeArray(const QList<T> &src)
在src 中编码 T 类型的所有元素,并将编码值追加到数据缓冲区。
如果值已成功编码,则返回true
。
另请参见 encode().
int QOpcUaBinaryDataEncoding::offset() const
返回数据缓冲区中的当前偏移量。
另请参见 setOffset()。
void QOpcUaBinaryDataEncoding::setOffset(int offset)
将数据缓冲区中的当前偏移量设置为offset 。缓冲区中的第一个字节偏移量为 0。
另请参阅 offset() 。
void QOpcUaBinaryDataEncoding::truncateBufferToOffset()
将数据缓冲区截断到当前offset() 的位置。如果偏移量小于当前缓冲区大小,该方法将不起作用。
该方法可用于在编码失败后进行回滚,方法是设置旧偏移量并调用 truncateBufferToOffset()。
© 2025 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.