110 #ifndef GOOGLE_PROTOBUF_MESSAGE_H__
111 #define GOOGLE_PROTOBUF_MESSAGE_H__
115 #include <type_traits>
121 #include <google/protobuf/stubs/common.h>
122 #include <google/protobuf/descriptor.h>
125 #define GOOGLE_PROTOBUF_HAS_ONEOF
126 #define GOOGLE_PROTOBUF_HAS_ARENAS
134 class MessageFactory;
140 class MapReflectionTester;
145 class UnknownFieldSet;
147 class ZeroCopyInputStream;
148 class ZeroCopyOutputStream;
149 class CodedInputStream;
150 class CodedOutputStream;
153 class MapReflectionFriend;
156 class CelMapReflectionFriend;
164 class MapFieldReflectionTest;
199 virtual Message* New()
const = 0;
215 virtual void CopyFrom(
const Message& from);
222 virtual void MergeFrom(
const Message& from);
226 void CheckInitialized()
const;
232 void FindInitializationErrors(std::vector<string>* errors)
const;
236 string InitializationErrorString()
const;
248 virtual void DiscardUnknownFields();
258 virtual size_t SpaceUsedLong()
const;
260 PROTOBUF_RUNTIME_DEPRECATED(
"Please use SpaceUsedLong() instead")
267 string DebugString()
const;
269 string ShortDebugString()
const;
271 string Utf8DebugString()
const;
273 void PrintDebugString()
const;
281 bool ParseFromFileDescriptor(
int file_descriptor);
284 bool ParsePartialFromFileDescriptor(
int file_descriptor);
287 bool ParseFromIstream(std::istream* input);
290 bool ParsePartialFromIstream(std::istream* input);
294 bool SerializeToFileDescriptor(
int file_descriptor)
const;
296 bool SerializePartialToFileDescriptor(
int file_descriptor)
const;
299 bool SerializeToOstream(std::ostream* output)
const;
301 bool SerializePartialToOstream(std::ostream* output)
const;
308 virtual string GetTypeName()
const;
309 virtual void Clear();
310 virtual bool IsInitialized()
const;
311 virtual void CheckTypeAndMergeFrom(
const MessageLite& other);
312 virtual bool MergePartialFromCodedStream(io::CodedInputStream* input);
314 virtual void SerializeWithCachedSizes(io::CodedOutputStream* output)
const;
324 virtual void SetCachedSize(
int size)
const;
336 const Descriptor*
GetDescriptor()
const {
return GetMetadata().descriptor; }
346 return GetMetadata().reflection;
353 virtual Metadata GetMetadata()
const = 0;
357 GOOGLE_DISALLOW_EVIL_CONSTRUCTORS(
Message);
363 class RepeatedFieldAccessor;
368 template<
typename T,
typename Enable =
void>
371 template<
typename T,
typename Enable =
void>
421 virtual const UnknownFieldSet& GetUnknownFields(
422 const Message& message)
const = 0;
428 virtual UnknownFieldSet* MutableUnknownFields(
Message* message)
const = 0;
431 virtual size_t SpaceUsedLong(
const Message& message)
const = 0;
433 PROTOBUF_RUNTIME_DEPRECATED(
"Please use SpaceUsedLong() instead")
439 virtual bool HasField(
const Message& message,
440 const FieldDescriptor*
field)
const = 0;
443 virtual int FieldSize(
const Message& message,
444 const FieldDescriptor*
field)
const = 0;
448 virtual void ClearField(
Message* message,
449 const FieldDescriptor*
field)
const = 0;
456 const OneofDescriptor* )
const {
461 const OneofDescriptor* )
const {}
467 const OneofDescriptor* )
const {
478 virtual void RemoveLast(
Message* message,
479 const FieldDescriptor*
field)
const = 0;
483 const FieldDescriptor*
field)
const = 0;
486 virtual void Swap(
Message* message1,
Message* message2)
const = 0;
489 virtual void SwapFields(
Message* message1,
491 const std::vector<const FieldDescriptor*>& fields)
495 virtual void SwapElements(
Message* message,
496 const FieldDescriptor*
field,
498 int index2)
const = 0;
508 virtual void ListFields(
510 std::vector<const FieldDescriptor*>* output)
const = 0;
517 const FieldDescriptor*
field)
const = 0;
519 const FieldDescriptor*
field)
const = 0;
521 const FieldDescriptor*
field)
const = 0;
523 const FieldDescriptor*
field)
const = 0;
524 virtual float GetFloat (
const Message& message,
525 const FieldDescriptor*
field)
const = 0;
526 virtual double GetDouble(
const Message& message,
527 const FieldDescriptor*
field)
const = 0;
528 virtual bool GetBool (
const Message& message,
529 const FieldDescriptor*
field)
const = 0;
530 virtual string GetString(
const Message& message,
531 const FieldDescriptor*
field)
const = 0;
532 virtual const EnumValueDescriptor* GetEnum(
533 const Message& message,
const FieldDescriptor*
field)
const = 0;
540 virtual int GetEnumValue(
541 const Message& message,
const FieldDescriptor*
field)
const = 0;
545 const FieldDescriptor*
field,
563 virtual const string& GetStringReference(
const Message& message,
564 const FieldDescriptor*
field,
565 string* scratch)
const = 0;
571 virtual void SetInt32 (
Message* message,
572 const FieldDescriptor*
field,
int32 value)
const = 0;
573 virtual void SetInt64 (
Message* message,
574 const FieldDescriptor*
field,
int64 value)
const = 0;
575 virtual void SetUInt32(
Message* message,
576 const FieldDescriptor*
field,
uint32 value)
const = 0;
577 virtual void SetUInt64(
Message* message,
578 const FieldDescriptor*
field,
uint64 value)
const = 0;
579 virtual void SetFloat (
Message* message,
580 const FieldDescriptor*
field,
float value)
const = 0;
581 virtual void SetDouble(
Message* message,
582 const FieldDescriptor*
field,
double value)
const = 0;
583 virtual void SetBool (
Message* message,
584 const FieldDescriptor*
field,
bool value)
const = 0;
585 virtual void SetString(
Message* message,
586 const FieldDescriptor*
field,
587 const string& value)
const = 0;
588 virtual void SetEnum (
Message* message,
589 const FieldDescriptor*
field,
590 const EnumValueDescriptor* value)
const = 0;
595 virtual void SetEnumValue(
Message* message,
596 const FieldDescriptor*
field,
597 int value)
const = 0;
610 const FieldDescriptor*
field,
616 virtual void SetAllocatedMessage(
Message* message,
618 const FieldDescriptor*
field)
const = 0;
627 const FieldDescriptor*
field,
635 const FieldDescriptor*
field,
636 int index)
const = 0;
638 const FieldDescriptor*
field,
639 int index)
const = 0;
641 const FieldDescriptor*
field,
642 int index)
const = 0;
644 const FieldDescriptor*
field,
645 int index)
const = 0;
646 virtual float GetRepeatedFloat (
const Message& message,
647 const FieldDescriptor*
field,
648 int index)
const = 0;
649 virtual double GetRepeatedDouble(
const Message& message,
650 const FieldDescriptor*
field,
651 int index)
const = 0;
652 virtual bool GetRepeatedBool (
const Message& message,
653 const FieldDescriptor*
field,
654 int index)
const = 0;
655 virtual string GetRepeatedString(
const Message& message,
656 const FieldDescriptor*
field,
657 int index)
const = 0;
658 virtual const EnumValueDescriptor* GetRepeatedEnum(
660 const FieldDescriptor*
field,
int index)
const = 0;
666 virtual int GetRepeatedEnumValue(
668 const FieldDescriptor*
field,
int index)
const = 0;
669 virtual const Message& GetRepeatedMessage(
671 const FieldDescriptor*
field,
int index)
const = 0;
674 virtual const string& GetRepeatedStringReference(
676 int index,
string* scratch)
const = 0;
682 virtual void SetRepeatedInt32 (
Message* message,
683 const FieldDescriptor*
field,
684 int index,
int32 value)
const = 0;
685 virtual void SetRepeatedInt64 (
Message* message,
686 const FieldDescriptor*
field,
687 int index,
int64 value)
const = 0;
688 virtual void SetRepeatedUInt32(
Message* message,
689 const FieldDescriptor*
field,
690 int index,
uint32 value)
const = 0;
691 virtual void SetRepeatedUInt64(
Message* message,
692 const FieldDescriptor*
field,
693 int index,
uint64 value)
const = 0;
694 virtual void SetRepeatedFloat (
Message* message,
695 const FieldDescriptor*
field,
696 int index,
float value)
const = 0;
697 virtual void SetRepeatedDouble(
Message* message,
698 const FieldDescriptor*
field,
699 int index,
double value)
const = 0;
700 virtual void SetRepeatedBool (
Message* message,
701 const FieldDescriptor*
field,
702 int index,
bool value)
const = 0;
703 virtual void SetRepeatedString(
Message* message,
704 const FieldDescriptor*
field,
705 int index,
const string& value)
const = 0;
706 virtual void SetRepeatedEnum(
Message* message,
707 const FieldDescriptor*
field,
int index,
708 const EnumValueDescriptor* value)
const = 0;
713 virtual void SetRepeatedEnumValue(
Message* message,
714 const FieldDescriptor*
field,
int index,
715 int value)
const = 0;
718 virtual Message* MutableRepeatedMessage(
719 Message* message,
const FieldDescriptor*
field,
int index)
const = 0;
725 virtual void AddInt32 (
Message* message,
726 const FieldDescriptor*
field,
int32 value)
const = 0;
727 virtual void AddInt64 (
Message* message,
728 const FieldDescriptor*
field,
int64 value)
const = 0;
729 virtual void AddUInt32(
Message* message,
730 const FieldDescriptor*
field,
uint32 value)
const = 0;
731 virtual void AddUInt64(
Message* message,
732 const FieldDescriptor*
field,
uint64 value)
const = 0;
733 virtual void AddFloat (
Message* message,
734 const FieldDescriptor*
field,
float value)
const = 0;
735 virtual void AddDouble(
Message* message,
736 const FieldDescriptor*
field,
double value)
const = 0;
737 virtual void AddBool (
Message* message,
738 const FieldDescriptor*
field,
bool value)
const = 0;
739 virtual void AddString(
Message* message,
740 const FieldDescriptor*
field,
741 const string& value)
const = 0;
742 virtual void AddEnum (
Message* message,
743 const FieldDescriptor*
field,
744 const EnumValueDescriptor* value)
const = 0;
749 virtual void AddEnumValue(
Message* message,
750 const FieldDescriptor*
field,
751 int value)
const = 0;
754 const FieldDescriptor*
field,
761 virtual void AddAllocatedMessage(
Message* message,
762 const FieldDescriptor*
field,
792 const Message& message,
const FieldDescriptor*
field)
const;
818 PROTOBUF_RUNTIME_DEPRECATED(
"Please use GetRepeatedFieldRef() instead")
820 const
Message&, const FieldDescriptor*) const;
826 PROTOBUF_RUNTIME_DEPRECATED("Please use GetMutableRepeatedFieldRef() instead")
828 Message*, const FieldDescriptor*) const;
835 PROTOBUF_RUNTIME_DEPRECATED("Please use GetRepeatedFieldRef() instead")
837 const
Message&, const FieldDescriptor*) const;
844 PROTOBUF_RUNTIME_DEPRECATED("Please use GetMutableRepeatedFieldRef() instead")
846 Message*, const FieldDescriptor*) const;
852 virtual const FieldDescriptor* FindKnownExtensionByName(
853 const
string& name) const = 0;
857 virtual const FieldDescriptor* FindKnownExtensionByNumber(
858 int number) const = 0;
890 virtual
bool SupportsUnknownEnumValues()
const {
return false; }
911 virtual void* MutableRawRepeatedField(
912 Message* message,
const FieldDescriptor*
field, FieldDescriptor::CppType,
913 int ctype,
const Descriptor* message_type)
const = 0;
918 FieldDescriptor::CppType cpptype,
int ctype,
919 const Descriptor* message_type)
const {
920 return MutableRawRepeatedField(
921 const_cast<Message*
>(&message),
field, cpptype, ctype, message_type);
940 virtual void* RepeatedFieldData(
942 FieldDescriptor::CppType cpp_type,
943 const Descriptor* message_type)
const;
947 virtual const internal::RepeatedFieldAccessor* RepeatedFieldAccessor(
948 const FieldDescriptor*
field)
const;
951 template<
typename T,
typename Enable>
953 template<
typename T,
typename Enable>
955 friend class ::google::protobuf::python::MapReflectionFriend;
956 #define GOOGLE_PROTOBUF_HAS_CEL_MAP_REFLECTION_FRIEND
957 friend class ::google::protobuf::expr::CelMapReflectionFriend;
958 friend class internal::MapFieldReflectionTest;
959 friend class internal::MapKeySorter;
960 friend class internal::WireFormat;
961 friend class internal::ReflectionOps;
969 void* MutableRawRepeatedString(
970 Message* message,
const FieldDescriptor*
field,
bool is_string)
const;
972 friend class MapReflectionTester;
976 virtual bool ContainsMapKey(
const Message& ,
977 const FieldDescriptor* ,
978 const MapKey& )
const {
985 virtual bool InsertOrLookupMapValue(
Message* ,
986 const FieldDescriptor* ,
988 MapValueRef* )
const {
994 virtual bool DeleteMapValue(Message* ,
995 const FieldDescriptor* ,
996 const MapKey& )
const {
1003 virtual MapIterator MapBegin(
1005 const FieldDescriptor*
field)
const;
1010 virtual MapIterator MapEnd(
1012 const FieldDescriptor*
field)
const;
1016 virtual int MapSize(
const Message& ,
1017 const FieldDescriptor* )
const {
1022 friend class MapIterator;
1023 virtual internal::MapFieldBase* MapData(
1024 Message* ,
const FieldDescriptor* )
const {
1028 GOOGLE_DISALLOW_EVIL_CONSTRUCTORS(
Reflection);
1055 virtual const Message* GetPrototype(
const Descriptor*
type) = 0;
1081 static void InternalRegisterGeneratedFile(
1082 const char* filename,
void (*register_messages)(
const string&));
1087 static void InternalRegisterGeneratedMessage(
const Descriptor* descriptor,
1095 #define DECLARE_GET_REPEATED_FIELD(TYPE) \
1097 LIBPROTOBUF_EXPORT \
1098 const RepeatedField<TYPE>& Reflection::GetRepeatedField<TYPE>( \
1099 const Message& message, const FieldDescriptor* field) const; \
1102 LIBPROTOBUF_EXPORT \
1103 RepeatedField<TYPE>* Reflection::MutableRepeatedField<TYPE>( \
1104 Message* message, const FieldDescriptor* field) const;
1114 #undef DECLARE_GET_REPEATED_FIELD
1125 const Message& message,
const FieldDescriptor*
field)
const {
1127 MutableRawRepeatedString(
const_cast<Message*
>(&message),
field,
true));
1132 Message* message,
const FieldDescriptor*
field)
const {
1134 MutableRawRepeatedString(message,
field,
true));
1142 const Message& message,
const FieldDescriptor*
field)
const {
1150 Message* message,
const FieldDescriptor*
field)
const {
1151 return static_cast<RepeatedPtrField<Message>*
>(
1153 FieldDescriptor::CPPTYPE_MESSAGE, -1,
1157 template<
typename PB>
1159 const Message& message,
const FieldDescriptor*
field)
const {
1160 return *
static_cast<const RepeatedPtrField<PB>*
>(
1162 -1, PB::default_instance().GetDescriptor()));
1165 template<
typename PB>
1167 Message* message,
const FieldDescriptor*
field)
const {
1168 return static_cast<RepeatedPtrField<PB>*
>(
1170 FieldDescriptor::CPPTYPE_MESSAGE, -1,
1171 PB::default_instance().GetDescriptor()));
1176 #endif // GOOGLE_PROTOBUF_MESSAGE_H__