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
类型。
Constructs a defaulted, empty, instance of Any.
构造副本为 other .
[noexcept]
Any::
~Any
()
Destroys this instance of Any
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.
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 ().
Sets the raw bytes of the value stored to value .
value must be the output of serializing a message.
注意: setter 函数对于特性 value .
另请参阅 value () 和 fromMessage ().
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 ().
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 ().
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.