Any Class
class QtProtobuf::Any프로토부프 애니 타입 작업을 간소화하는 헬퍼 클래스입니다. 더 보기...
헤더: | #include <Any> |
CMake: | find_package(Qt6 REQUIRED COMPONENTS ProtobufWellKnownTypes) target_link_libraries(mytarget PRIVATE Qt6::ProtobufWellKnownTypes) |
qmake: | QT += protobufwellknowntypes |
이후: | Qt 6.6 |
상속합니다: | QProtobufMessage |
이 클래스는 동등 비교 가능합니다.
공용 함수
Any() | |
Any(const QtProtobuf::Any &other) | |
~Any() | |
void | setTypeUrl(const QString &typeUrl) |
void | setValue(const QByteArray &value) |
QString | typeUrl() const |
std::optional<T> | unpack(QAbstractProtobufSerializer *serializer) const |
QByteArray | value() const |
QtProtobuf::Any & | operator=(const QtProtobuf::Any &other) |
정적 공용 멤버
QtProtobuf::Any | fromMessage(QAbstractProtobufSerializer *serializer, const T &message, QAnyStringView typeUrlPrefix) |
관련 비회원
bool | operator!=(const QtProtobuf::Any &lhs, const QtProtobuf::Any &rhs) |
bool | operator==(const QtProtobuf::Any &lhs, const QtProtobuf::Any &rhs) |
상세 설명
Any 클래스는 as() 및 fromMessage()를 사용하여 다른 유형으로 쉽게 형 변환할 수 있습니다.
메시지에 google.protobuf.Any
유형의 필드가 포함될 때 qtprotobufgen에서 생성된 코드에서 사용되는 유형입니다.
멤버 함수 문서
Any::Any()
기본값으로 비어있는 Any 인스턴스를 생성합니다.
Any::Any(const QtProtobuf::Any &other)
other 의 복사본을 생성합니다.
[noexcept]
Any::~Any()
이 Any 인스턴스를 삭제합니다.
[static]
template <typename T> QtProtobuf::Any Any::fromMessage(QAbstractProtobufSerializer *serializer, const T &message, QAnyStringView typeUrlPrefix)
이 함수는 주어진 message 을 반환된 Any 인스턴스의 값으로 직렬화합니다. 이 인스턴스의 typeUrl()는 접두사, 슬래시, QProtobufMessage::propertyOrdering 에서 serializer 을 사용하여 얻은 메시지 이름으로 구성됩니다. typeUrlPrefix 가 제공되면 접두사로 사용되며, 그렇지 않으면 "type.googleapis.com"
이 사용됩니다.
참고: T는 Q_PROTOBUF_OBJECT
매크로를 사용하여 QProtobufMessage 에서 파생된 클래스이거나 (중첩된 Any 메시지의 경우) Any 자체여야 합니다.
void Any::setTypeUrl(const QString &typeUrl)
포함된 데이터의 유형 URL을 typeUrl 으로 설정합니다.
참고: 입력이 올바른지 또는 유효한 형식인지 테스트하기 위해 입력에 대한 검증은 수행되지 않습니다.
참고: 속성에 대한 설정자 함수 typeUrl.
typeUrl() 및 fromMessage()도 참조하세요 .
void Any::setValue(const QByteArray &value)
저장된 값의 원시 바이트를 value 으로 설정합니다.
value 는 메시지를 직렬화할 때의 출력이어야 합니다.
참고: value 속성에 대한 설정자 함수.
value() 및 fromMessage()도 참조하세요 .
QString Any::typeUrl() const
Any 객체의 유형 URL을 반환합니다. URL은 포함된 데이터가 실제로 무엇인지에 대한 힌트로 사용됩니다.
참고: Qt는 타입 해체를 위한 잠재적 레시피를 동적으로 얻는 것을 지원하지 않으며, 단순히 타입 URL을 사용하여 as<T>()
에 T 로 전달된 타입이 올바른 타입인지 확인합니다.
참고: typeUrl 프로퍼티에 대한 게터 함수.
setTypeUrl() 및 value()도 참조하세요 .
template <typename T> std::optional<T> Any::unpack(QAbstractProtobufSerializer *serializer) const
이 함수는 serializer 을 사용하여 데이터를 역직렬화하기 전에 T 의 메시지 이름과 typeUrl() 의 값을 비교합니다.
확인 또는 역직렬화에 실패하면 std::nullopt
을 반환합니다.
참고: T는 Q_PROTOBUF_OBJECT
매크로를 사용하여 QProtobufMessage 에서 파생된 클래스이거나 (중첩된 Any 메시지의 경우) Any 자체여야 합니다.
QByteArray Any::value() const
저장된 값을 구성하는 원시 바이트를 반환합니다.
이 바이트를 해석하는 방법은 typeUrl()를 참조하세요.
참고: 속성 값에 대한 게터 함수입니다.
setValue() 및 typeUrl()도 참조하세요 .
QtProtobuf::Any &Any::operator=(const QtProtobuf::Any &other)
other 의 데이터를 이 인스턴스에 복사합니다.
관련 비회원
[noexcept]
bool operator!=(const QtProtobuf::Any &lhs, const QtProtobuf::Any &rhs)
lhs 와 rhs, 두 개의 Any 인스턴스가 구별되는 경우 true를 반환합니다.
[noexcept]
bool operator==(const QtProtobuf::Any &lhs, const QtProtobuf::Any &rhs)
lhs 와 rhs, 두 개의 Any 인스턴스가 같으면 true를 반환합니다.
© 2025 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.