Any Class

class QtProtobuf ::Any

A helper class to simplify working with the protobuf Any type. 更多...

头: #include <Any>
CMake: find_package(Qt6 REQUIRED COMPONENTS ProtobufWellKnownTypes)
target_link_libraries(mytarget PRIVATE Qt6::ProtobufWellKnownTypes)
qmake: QT += protobufwellknowntypes
Since: Qt 6.6
继承: QProtobufMessage
状态: 技术预览

公共函数

Any ()
Any (const QtProtobuf::Any & other )
~Any ()
std::optional<T> as (QAbstractProtobufSerializer * serializer ) const
void setTypeUrl (const QString & typeUrl )
void setValue (const QByteArray & value )
QString typeUrl () const
QByteArray value () const
QtProtobuf::Any & operator= (const QtProtobuf::Any & other )

静态公共成员

QtProtobuf::Any fromMessage (QAbstractProtobufSerializer * serializer , const T & message , QAnyStringView typeUrlPrefix = defaultUrlPrefix())
bool operator!= (const QtProtobuf::Any & lhs , const QtProtobuf::Any & rhs )
bool operator== (const QtProtobuf::Any & lhs , const QtProtobuf::Any & rhs )

详细描述

The Any class enables easy casting to and from other types using as () 和 fromMessage ().

It is the type used in code generated by qtprotobufgen when a message contains a field of the google.protobuf.Any 类型。

成员函数文档编制

Any:: 任何 ()

Constructs a defaulted, empty, instance of Any.

Any:: 任何 (const QtProtobuf::Any & other )

构造副本为 other .

[noexcept] Any:: ~Any ()

Destroys this instance of Any

template <typename T> std::optional < T > Any:: as ( QAbstractProtobufSerializer * serializer ) const

This function compares the message name of T with the value of typeUrl () before deserializing the data using serializer .

If the verification or deserialization fails it will return std::nullopt .

注意: T must be a class derived from QProtobufMessage 采用 Q_PROTOBUF_OBJECT macro or (for a nested Any message) be Any itself.

[static] template <typename T> QtProtobuf::Any Any:: fromMessage ( QAbstractProtobufSerializer * serializer , const T & message , QAnyStringView typeUrlPrefix = defaultUrlPrefix())

This function serializes the given message as the value of the returned Any instance. This instance's typeUrl () is constructed from a prefix, a forward slash and the message name obtained from T::propertyOrdering.getMessageFullName() 使用 serializer 。若 typeUrlPrefix is supplied, it is used as prefix, otherwise "type.googleapis.com" 被使用。

注意: T must be a class derived from QProtobufMessage 采用 Q_PROTOBUF_OBJECT macro or (for a nested Any message) be Any itself.

void Any:: setTypeUrl (const QString & typeUrl )

Sets the type URL for the data contained to typeUrl .

注意: No verification is performed on the input to test if it's correct or in a valid format.

注意: setter 函数对于特性 typeUrl .

另请参阅 typeUrl () 和 fromMessage ().

void Any:: setValue (const QByteArray & value )

Sets the raw bytes of the value stored to value .

value must be the output of serializing a message.

注意: setter 函数对于特性 value .

另请参阅 value () 和 fromMessage ().

QString Any:: typeUrl () const

Returns the type URL of the Any object. The URL is meant as a hint for what the contained data really is.

注意: Qt has no support for dynamically obtaining any potential recipes for deconstructing types and simply uses the type URL to verify that types passed as T to as<T>() are of the correct type.

注意: Getter function for property typeUrl.

另请参阅 setTypeUrl () 和 value ().

QByteArray Any:: value () const

Returns the raw bytes that make up the value stored.

Consult typeUrl () to determine how to interpret these bytes.

注意: Getter function for property value.

另请参阅 setValue () 和 typeUrl ().

QtProtobuf::Any &Any:: operator= (const QtProtobuf::Any & other )

Copies the data of other into this instance.

相关非成员

[noexcept] bool operator!= (const QtProtobuf::Any & lhs , const QtProtobuf::Any & rhs )

Returns true if the two instances of Any, lhs and rhs , are distinct.

[noexcept] bool operator== (const QtProtobuf::Any & lhs , const QtProtobuf::Any & rhs )

Returns true if the two instances of Any, lhs and rhs , compare equal.