QGrpcSerializationFormat Class

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

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

This class is equality-comparable.

Public Functions

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

Detailed Description

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 section.

Note: 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 with the 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.

Note: Custom serializers require server support for the specified format.

See also QGrpcChannelOptions::serializationFormat.

Member Function Documentation

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)

Constructs a copy of other.

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

Move-constructs a new QGrpcSerializationFormat from other.

Note: 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()

Destroys the 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)

Swaps other with this object. This operation is very fast and never fails.

This function was introduced in Qt 6.8.

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

Constructs a new QVariant from this object.

This function was introduced in Qt 6.8.

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

Move-assigns other to this QGrpcSerializationFormat instance and returns a reference to it.

Note: 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)

Assigns the other QGrpcSerializationFormat object to this one.

Related Non-Members

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

Writes sfmt to the specified stream debug.

This function was introduced in Qt 6.8.