File indexing completed on 2025-01-31 10:12:05
0001
0002
0003
0004
0005
0006
0007
0008 #ifndef GOOGLE_PROTOBUF_ANY_H__
0009 #define GOOGLE_PROTOBUF_ANY_H__
0010
0011 #include <string>
0012
0013 #include "google/protobuf/port.h"
0014 #include "google/protobuf/arenastring.h"
0015 #include "google/protobuf/message_lite.h"
0016
0017
0018 #include "google/protobuf/port_def.inc"
0019
0020 namespace google {
0021 namespace protobuf {
0022
0023 class FieldDescriptor;
0024 class Message;
0025
0026 namespace internal {
0027
0028
0029 PROTOBUF_EXPORT extern const char kAnyFullTypeName[];
0030
0031 PROTOBUF_EXPORT extern const char kTypeGoogleApisComPrefix[];
0032
0033 PROTOBUF_EXPORT extern const char kTypeGoogleProdComPrefix[];
0034
0035 std::string GetTypeUrl(absl::string_view message_name,
0036 absl::string_view type_url_prefix);
0037
0038
0039 class PROTOBUF_EXPORT AnyMetadata {
0040 typedef ArenaStringPtr UrlType;
0041 typedef ArenaStringPtr ValueType;
0042 public:
0043
0044 constexpr AnyMetadata(UrlType* type_url, ValueType* value)
0045 : type_url_(type_url), value_(value) {}
0046 AnyMetadata(const AnyMetadata&) = delete;
0047 AnyMetadata& operator=(const AnyMetadata&) = delete;
0048
0049
0050
0051
0052 template <typename T>
0053 bool PackFrom(Arena* arena, const T& message) {
0054 return InternalPackFrom(arena, message, kTypeGoogleApisComPrefix,
0055 T::FullMessageName());
0056 }
0057
0058 bool PackFrom(Arena* arena, const Message& message);
0059
0060
0061
0062
0063
0064
0065
0066
0067 template <typename T>
0068 bool PackFrom(Arena* arena, const T& message,
0069 absl::string_view type_url_prefix) {
0070 return InternalPackFrom(arena, message, type_url_prefix,
0071 T::FullMessageName());
0072 }
0073
0074 bool PackFrom(Arena* arena, const Message& message,
0075 absl::string_view type_url_prefix);
0076
0077
0078
0079
0080
0081 template <typename T>
0082 bool UnpackTo(T* message) const {
0083 return InternalUnpackTo(T::FullMessageName(), message);
0084 }
0085
0086 bool UnpackTo(Message* message) const;
0087
0088
0089
0090
0091 template <typename T>
0092 bool Is() const {
0093 return InternalIs(T::FullMessageName());
0094 }
0095
0096 private:
0097 bool InternalPackFrom(Arena* arena, const MessageLite& message,
0098 absl::string_view type_url_prefix,
0099 absl::string_view type_name);
0100 bool InternalUnpackTo(absl::string_view type_name,
0101 MessageLite* message) const;
0102 bool InternalIs(absl::string_view type_name) const;
0103
0104 UrlType* type_url_;
0105 ValueType* value_;
0106 };
0107
0108
0109
0110
0111
0112
0113
0114
0115 bool ParseAnyTypeUrl(absl::string_view type_url, std::string* full_type_name);
0116
0117
0118
0119
0120
0121
0122 bool ParseAnyTypeUrl(absl::string_view type_url, std::string* url_prefix,
0123 std::string* full_type_name);
0124
0125
0126
0127 bool GetAnyFieldDescriptors(const Message& message,
0128 const FieldDescriptor** type_url_field,
0129 const FieldDescriptor** value_field);
0130
0131 }
0132 }
0133 }
0134
0135 #include "google/protobuf/port_undef.inc"
0136
0137 #endif