QGrpcSerializationFormat Class

The QGrpcSerializationFormat class holds the protobuf message serializer and the associated content-type suffix. 更多...

头: #include <QGrpcSerializationFormat>
CMake: find_package(Qt6 REQUIRED COMPONENTS Grpc)
target_link_libraries(mytarget PRIVATE Qt6::Grpc)
Since: Qt 6.8

此类 equality-comparable .

公共函数

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
(从 6.8 起) void swap (QGrpcSerializationFormat & other )
(从 6.8 起) QVariant operator QVariant () const
QGrpcSerializationFormat & operator= (QGrpcSerializationFormat && other )
QGrpcSerializationFormat & operator= (const QGrpcSerializationFormat & other )
(从 6.8 起) QDebug operator<< (QDebug debug , const QGrpcSerializationFormat & sfmt )

详细描述

The QGrpcSerializationFormat class contains the serializer used for serializing and deserializing protobuf messages, as well as the associated content-type suffix , which indicates the message encoding in transport. For HTTP/2 specific details see the Content-Type 章节。

注意: The content-type is transport, and therefore implementation specific.

The class can be constructed using one of the SerializationFormat presets or a custom suffix and serializer:

QGrpcSerializationFormat jsonFormat(QtGrpc::SerializationFormat::Json);
					

This creates a QProtobufJsonSerializer 采用 json suffix. For HTTP/2 transportation this results in the application/grpc+json content-type.

class DummySerializer : public QAbstractProtobufSerializer
{
    ...
};
QGrpcSerializationFormat dummyFormat("dummy", std::make_shared<DummySerializer>());
					

This uses DummySerializer for encoding and decoding messages with the dummy suffix. For HTTP/2 transportation this results in the application/grpc+dummy content-type.

注意: Custom serializers require server support for the specified format.

另请参阅 QGrpcChannelOptions::serializationFormat .

成员函数文档编制

QGrpcSerializationFormat:: QGrpcSerializationFormat ( QtGrpc::SerializationFormat format = {})

Constructs a new QGrpcSerializationFormat with the specified preset format .

The default format used is SerializationFormat::Default .

[explicit] QGrpcSerializationFormat:: QGrpcSerializationFormat ( QByteArrayView suffix , std::shared_ptr < QAbstractProtobufSerializer > serializer )

Constructs a new QGrpcSerializationFormat with a custom content type specified by suffix and a protobuf message serializer .

QGrpcSerializationFormat:: QGrpcSerializationFormat (const QGrpcSerializationFormat & other )

构造副本为 other .

[noexcept] QGrpcSerializationFormat:: QGrpcSerializationFormat ( QGrpcSerializationFormat && other )

Move-constructs a new QGrpcSerializationFormat from other .

注意: The moved-from object other is placed in a partially-formed state, in which the only valid operations are destruction and assignment of a new value.

[noexcept] QGrpcSerializationFormat:: ~QGrpcSerializationFormat ()

销毁 QGrpcSerializationFormat .

std::shared_ptr < QAbstractProtobufSerializer > QGrpcSerializationFormat:: serializer () const

Returns the serializer for this serialization format.

/sa QAbstractProtobufSerializer

[noexcept] QByteArrayView QGrpcSerializationFormat:: suffix () const

Returns the content type suffix for this serialization format.

[noexcept, since 6.8] void QGrpcSerializationFormat:: swap ( QGrpcSerializationFormat & other )

交换 other 与此对象。此操作非常快且从不失败。

该函数在 Qt 6.8 引入。

[since 6.8] QVariant QGrpcSerializationFormat:: operator QVariant () const

构造新的 QVariant from this object.

该函数在 Qt 6.8 引入。

[noexcept] QGrpcSerializationFormat &QGrpcSerializationFormat:: operator= ( QGrpcSerializationFormat && other )

移动赋值 other 到此 QGrpcSerializationFormat instance and returns a reference to it.

注意: The moved-from object other is placed in a partially-formed state, in which the only valid operations are destruction and assignment of a new value.

QGrpcSerializationFormat &QGrpcSerializationFormat:: operator= (const QGrpcSerializationFormat & other )

赋值 other QGrpcSerializationFormat object to this one.

相关非成员

[since 6.8] QDebug operator<< ( QDebug debug , const QGrpcSerializationFormat & sfmt )

写入 sfmt to the specified stream debug .

该函数在 Qt 6.8 引入。