QGrpcSerializationFormat Class
QGrpcSerializationFormat 类包含 Protobuf 消息序列化器及其关联的内容类型后缀。更多内容...
| 头文件: | #include <QGrpcSerializationFormat> |
| CMake: | find_package(Qt6 REQUIRED COMPONENTS Grpc) target_link_libraries(mytarget PRIVATE Qt6::Grpc) |
| 自: | Qt 6.8 |
QGrpcSerializationFormat 比较
| 类别 | 可比较类型 |
|---|---|
| 相等性 | QGrpcSerializationFormat |
公共函数
| QGrpcSerializationFormat(QtGrpc::SerializationFormat format = {}) | |
| QGrpcSerializationFormat(QByteArrayView suffix, std::shared_ptr<QAbstractProtobufSerializer> serializer) | |
| QGrpcSerializationFormat(const QGrpcSerializationFormat &other) | |
| QGrpcSerializationFormat(QGrpcSerializationFormat &&other) | |
| ~QGrpcSerializationFormat() | |
| std::shared_ptr<QAbstractProtobufSerializer> | serializer() const |
| QByteArrayView | suffix() const |
(since 6.8) void | swap(QGrpcSerializationFormat &other) |
(since 6.8) | operator QVariant() const |
| QGrpcSerializationFormat & | operator=(QGrpcSerializationFormat &&other) |
| QGrpcSerializationFormat & | operator=(const QGrpcSerializationFormat &other) |
相关的非成员
(since 6.8) size_t | qHash(const QGrpcSerializationFormat &key) |
(since 6.8) size_t | qHash(const QGrpcSerializationFormat &key, size_t seed) |
(since 6.8) bool | operator!=(const QGrpcSerializationFormat &lhs, const QGrpcSerializationFormat &rhs) |
(since 6.8) QDebug | operator<<(QDebug debug, const QGrpcSerializationFormat &sfmt) |
(since 6.8) bool | operator==(const QGrpcSerializationFormat &lhs, const QGrpcSerializationFormat &rhs) |
详细说明
QGrpcSerializationFormat 类包含用于对 protobuf 消息进行序列化和反序列化的serializer ,以及相关的内容类型suffix ,该内容类型指示传输中的消息编码方式。有关 HTTP/2 的具体细节,请参阅Content-Type 部分。
注意:内容类型 属于传输层,因此取决于具体实现。
该类可通过使用SerializationFormat 中的预设之一,或自定义后缀和序列化器来构造:
QGrpcSerializationFormat jsonFormat(QtGrpc::SerializationFormat::Json);这将创建一个带有json 后缀的QProtobufJsonSerializer 。对于 HTTP/2 传输,这将生成application/grpc+json 内容类型。
class DummySerializer : public QAbstractProtobufSerializer
{
...
};
QGrpcSerializationFormat dummyFormat("dummy", std::make_shared<DummySerializer>());此方法使用DummySerializer 对带有dummy 后缀的消息进行编码和解码。对于HTTP/2传输,这将生成application/grpc+dummy 内容类型。
注意:自定义 序列化器需要服务器支持指定的格式。
另请参阅 QGrpcChannelOptions::serializationFormat 。
成员函数文档
QGrpcSerializationFormat::QGrpcSerializationFormat(QtGrpc::SerializationFormat format = {})
使用指定的预设format 构建一个新的QGrpcSerializationFormat。
默认使用的格式为SerializationFormat::Default 。
[explicit] QGrpcSerializationFormat::QGrpcSerializationFormat(QByteArrayView suffix, std::shared_ptr<QAbstractProtobufSerializer> serializer)
创建一个新的 QGrpcSerializationFormat,其自定义内容类型由suffix 指定,并包含 protobuf 消息serializer 。
QGrpcSerializationFormat::QGrpcSerializationFormat(const QGrpcSerializationFormat &other)
创建other 的副本。
[constexpr noexcept default] QGrpcSerializationFormat::QGrpcSerializationFormat(QGrpcSerializationFormat &&other)
从 `other` 创建一个新的 `QGrpcSerializationFormat` 对象。
注意: 被移动的对象 other 将处于一种部分构建状态,在此状态下,唯一有效的操作是销毁和赋予新值。
[noexcept] QGrpcSerializationFormat::~QGrpcSerializationFormat()
std::shared_ptr<QAbstractProtobufSerializer> QGrpcSerializationFormat::serializer() const
返回此序列化格式的序列化器。
/saQAbstractProtobufSerializer
[noexcept] QByteArrayView QGrpcSerializationFormat::suffix() const
返回此序列化格式的内容类型后缀。
[noexcept, since 6.8] void QGrpcSerializationFormat::swap(QGrpcSerializationFormat &other)
将other 与该对象互换。此操作速度极快,且绝不会失败。
该函数于 Qt 6.8 中引入。
[since 6.8] QGrpcSerializationFormat::operator QVariant() const
根据该对象构建一个新的QVariant 。
该函数于 Qt 6.8 中引入。
[noexcept] QGrpcSerializationFormat &QGrpcSerializationFormat::operator=(QGrpcSerializationFormat &&other)
将other 按值赋值给此QGrpcSerializationFormat 实例,并返回对其的引用。
注意: 被移动的对象 other 处于部分构状态,在此状态下,唯一有效的操作是销毁和赋值。
QGrpcSerializationFormat &QGrpcSerializationFormat::operator=(const QGrpcSerializationFormat &other)
将other QGrpcSerializationFormat 对象分配给此对象。
相关的非成员
[noexcept, since 6.8] size_t qHash(const QGrpcSerializationFormat &key)
返回key 的哈希值,并使用0 作为计算的种子。
该函数于 Qt 6.8 版本中引入。
[noexcept, since 6.8] size_t qHash(const QGrpcSerializationFormat &key, size_t seed)
返回key 的哈希值,并使用seed 作为计算的种子。
该函数在 Qt 6.8 中引入。
[noexcept, since 6.8] bool operator!=(const QGrpcSerializationFormat &lhs, const QGrpcSerializationFormat &rhs)
如果lhs 和rhs 中的suffix 与serializer 不相等,则返回true 。
该函数在 Qt 6.8 中引入。
[since 6.8] QDebug operator<<(QDebug debug, const QGrpcSerializationFormat &sfmt)
将sfmt 写入指定的流debug 。
该函数于 Qt 6.8 中引入。
[noexcept, since 6.8] bool operator==(const QGrpcSerializationFormat &lhs, const QGrpcSerializationFormat &rhs)
如果suffix 和serializer (位于lhs 和rhs 中)相等,则返回true 。
该函数在 Qt 6.8 中引入。
© 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.