From eee38b0c018b3279f77d03dff796f440f40d3516 Mon Sep 17 00:00:00 2001 From: Feng Xiao Date: Sat, 22 Aug 2015 18:25:48 -0700 Subject: Down-integrate from google3. --- src/google/protobuf/map_type_handler.h | 729 +++++++++++++++++++++------------ 1 file changed, 470 insertions(+), 259 deletions(-) (limited to 'src/google/protobuf/map_type_handler.h') diff --git a/src/google/protobuf/map_type_handler.h b/src/google/protobuf/map_type_handler.h index ffdb6dfb..5040e605 100644 --- a/src/google/protobuf/map_type_handler.h +++ b/src/google/protobuf/map_type_handler.h @@ -54,22 +54,6 @@ struct MapIf { typedef FalseType type; }; -// In MapField, string and message are stored as pointer while others are stored -// as object. However, google::protobuf::Map has unified api. Functions in this class -// convert key/value to type wanted in api regardless how it's stored -// internally. -template -class MapCommonTypeHandler { - public: - static inline Type& Reference(Type* x) { return *x; } - static inline Type& Reference(Type& x) { return x; } - static inline const Type& Reference(const Type& x) { return x; } - static inline Type* Pointer(Type* x) { return x; } - static inline Type* Pointer(Type& x) { return &x; } - static inline const Type* Pointer(const Type* x) { return x; } - static inline const Type* Pointer(const Type& x) { return &x; } -}; - // In proto2 Map, enum needs to be initialized to given default value, while // other types' default value can be inferred from the type. template @@ -110,174 +94,29 @@ template class MapArenaMessageCreator { public: static inline Type* CreateMessage(Arena* arena) { - return new Type; - } -}; - -// Handlers for key/value stored type in MapField. ================== - -// Handler for message -template -class MapCppTypeHandler : public MapCommonTypeHandler { - public: - static const bool kIsStringOrMessage = true; - // SpaceUsedInMapEntry: Return bytes used by value in MapEntry, excluding - // those already calculate in sizeof(MapField). - static int SpaceUsedInMapEntry(const Type* value) { - return value->SpaceUsed(); - } - // Return bytes used by value in Map. - static int SpaceUsedInMap(const Type& value) { return value.SpaceUsed(); } - static inline void Clear(Type** value) { - if (*value != NULL) (*value)->Clear(); - } - static inline void ClearMaybeByDefaultEnum(Type** value, - int default_enum_value) { - if (*value != NULL) (*value)->Clear(); - } - static inline void Merge(const Type& from, Type** to) { - (*to)->MergeFrom(from); - } - - static void Delete(const Type* ptr) { delete ptr; } - - // Assign default value to given instance. - static inline void AssignDefaultValue(Type** value) { - *value = const_cast(&Type::default_instance()); - } - // Initialize value when constructing MapEntry - static inline void Initialize(Type** x, Arena* arena) { *x = NULL; } - // Same as above, but use default_enum_value to initialize enum type value. - static inline void InitializeMaybeByDefaultEnum( - Type** x, int default_enum_value, Arena* arena) { - *x = NULL; - } - // Initialize value for the first time mutable accessor is called. - static inline void EnsureMutable(Type** value, Arena* arena) { - if (*value == NULL) { - *value = - MapArenaMessageCreator:: - type::value>::CreateMessage(arena); - } - } - // Return default instance if value is not initialized when calling const - // reference accessor. - static inline const Type& DefaultIfNotInitialized(const Type* value, - const Type* default_value) { - return value != NULL ? *value : *default_value; - } - // Check if all required fields have values set. - static inline bool IsInitialized(Type* value) { - return value->IsInitialized(); - } -}; - -// Handler for string. -template <> -class MapCppTypeHandler : public MapCommonTypeHandler { - public: - static const bool kIsStringOrMessage = true; - static inline void Merge(const string& from, string** to) { **to = from; } - static inline void Clear(string** value) { (*value)->clear(); } - static inline void ClearMaybeByDefaultEnum(string** value, int default_enum) { - (*value)->clear(); - } - static inline int SpaceUsedInMapEntry(const string* value) { - return sizeof(*value) + StringSpaceUsedExcludingSelf(*value); - } - static inline int SpaceUsedInMap(const string& value) { - return sizeof(value) + StringSpaceUsedExcludingSelf(value); - } - static void Delete(const string* ptr) { - if (ptr != &::google::protobuf::internal::GetEmptyString()) delete ptr; - } - static inline void AssignDefaultValue(string** value) {} - static inline void Initialize(string** value, Arena* arena) { - *value = const_cast< ::std::string*>(&::google::protobuf::internal::GetEmptyString()); - if (arena != NULL) arena->Own(*value); - } - static inline void InitializeMaybeByDefaultEnum( - string** value, int default_enum_value, Arena* arena) { - *value = const_cast< ::std::string*>(&::google::protobuf::internal::GetEmptyString()); - if (arena != NULL) arena->Own(*value); + return Arena::Create(arena); } - static inline void EnsureMutable(string** value, Arena* arena) { - if (*value == &::google::protobuf::internal::GetEmptyString()) { - *value = Arena::Create(arena); - } - } - static inline const string& DefaultIfNotInitialized( - const string* value, - const string* default_value) { - return value != default_value ? *value : *default_value; - } - static inline bool IsInitialized(string* value) { return true; } }; -// Base class for primitive type handlers. -template -class MapPrimitiveTypeHandler : public MapCommonTypeHandler { - public: - static const bool kIsStringOrMessage = false; - static inline void Delete(const Type& x) {} - static inline void Merge(const Type& from, Type* to) { *to = from; } - static inline int SpaceUsedInMapEntry(const Type& value) { return 0; } - static inline int SpaceUsedInMap(const Type& value) { return sizeof(Type); } - static inline void AssignDefaultValue(Type* value) {} - static inline const Type& DefaultIfNotInitialized( - const Type& value, const Type& default_value) { - return value; - } - static inline bool IsInitialized(const Type& value) { return true; } -}; - -// Handlers for primitive types. -#define PRIMITIVE_HANDLER(CType) \ - template <> \ - class MapCppTypeHandler : public MapPrimitiveTypeHandler { \ - public: \ - static inline void Clear(CType* value) { *value = 0; } \ - static inline void ClearMaybeByDefaultEnum(CType* value, \ - int default_enum_value) { \ - *value = static_cast(default_enum_value); \ - } \ - static inline void Initialize(CType* value, Arena* arena) { *value = 0; } \ - static inline void InitializeMaybeByDefaultEnum(CType* value, \ - int default_enum_value, \ - Arena* arena) { \ - *value = static_cast(default_enum_value); \ - } \ - static inline void EnsureMutable(CType* value, Arena* arena) {} \ - }; - -PRIMITIVE_HANDLER(int32 ) -PRIMITIVE_HANDLER(int64 ) -PRIMITIVE_HANDLER(uint32) -PRIMITIVE_HANDLER(uint64) -PRIMITIVE_HANDLER(double) -PRIMITIVE_HANDLER(float ) -PRIMITIVE_HANDLER(bool ) - -#undef PRIMITIVE_HANDLER - // Define constants for given wire field type -template +template class MapWireFieldTypeTraits {}; -#define TYPE_TRAITS(FieldType, CType, WireFormatType, IsMessage, IsEnum) \ - template <> \ - class MapWireFieldTypeTraits { \ - public: \ - typedef CType CppType; \ - static const bool kIsMessage = IsMessage; \ - static const bool kIsEnum = IsEnum; \ - static const WireFormatLite::WireType kWireType = \ - WireFormatLite::WIRETYPE_##WireFormatType; \ +#define TYPE_TRAITS(FieldType, CType, WireFormatType, IsMessage, IsEnum) \ + template \ + class MapWireFieldTypeTraits { \ + public: \ + static const bool kIsMessage = IsMessage; \ + static const bool kIsEnum = IsEnum; \ + typedef typename MapIf::type TypeOnMemory; \ + typedef typename MapIf::type MapEntryAccessorType; \ + static const WireFormatLite::WireType kWireType = \ + WireFormatLite::WIRETYPE_##WireFormatType; \ }; -TYPE_TRAITS(MESSAGE , MessageLite, LENGTH_DELIMITED, true, false) -TYPE_TRAITS(STRING , string , LENGTH_DELIMITED, false, false) -TYPE_TRAITS(BYTES , string , LENGTH_DELIMITED, false, false) +TYPE_TRAITS(MESSAGE , Type, LENGTH_DELIMITED, true, false) +TYPE_TRAITS(STRING , ArenaStringPtr, LENGTH_DELIMITED, false, false) +TYPE_TRAITS(BYTES , ArenaStringPtr , LENGTH_DELIMITED, false, false) TYPE_TRAITS(INT64 , int64 , VARINT , false, false) TYPE_TRAITS(UINT64 , uint64 , VARINT , false, false) TYPE_TRAITS(INT32 , int32 , VARINT , false, false) @@ -295,46 +134,149 @@ TYPE_TRAITS(BOOL , bool , VARINT , false, false) #undef TYPE_TRAITS -template -class MapWireFieldTypeHandler { +template +class MapTypeHandler {}; + +template +class MapTypeHandler { public: + // Enum type cannot be used for MapTypeHandler::Read. Define a type which will + // replace Enum with int. + typedef typename MapWireFieldTypeTraits::MapEntryAccessorType MapEntryAccessorType; // Internal stored type in MapEntryLite for given wire field type. - typedef typename MapWireFieldTypeTraits::CppType CppType; + typedef typename MapWireFieldTypeTraits::TypeOnMemory TypeOnMemory; // Corresponding wire type for field type. static const WireFormatLite::WireType kWireType = - MapWireFieldTypeTraits::kWireType; + MapWireFieldTypeTraits::kWireType; // Whether wire type is for message. - static const bool kIsMessage = MapWireFieldTypeTraits::kIsMessage; + static const bool kIsMessage = + MapWireFieldTypeTraits::kIsMessage; // Whether wire type is for enum. - static const bool kIsEnum = MapWireFieldTypeTraits::kIsEnum; + static const bool kIsEnum = + MapWireFieldTypeTraits::kIsEnum; // Functions used in parsing and serialization. =================== - template - static inline int ByteSize(const ValueType& value); - template - static inline int GetCachedSize(const ValueType& value); - template - static inline bool Read(io::CodedInputStream* input, ValueType* value); - static inline void Write(int field, const CppType& value, + static inline int ByteSize(const MapEntryAccessorType& value); + static inline int GetCachedSize(const MapEntryAccessorType& value); + static inline bool Read(io::CodedInputStream* input, + MapEntryAccessorType* value); + static inline void Write(int field, const MapEntryAccessorType& value, io::CodedOutputStream* output); - static inline uint8* WriteToArray(int field, const CppType& value, + static inline uint8* WriteToArray(int field, + const MapEntryAccessorType& value, uint8* output); + + // Functions to manipulate data on memory. ======================== + static inline const Type& GetExternalReference(const Type* value); + static inline void DeleteNoArena(const Type* x); + static inline void Merge(const Type& from, Type** to, Arena* arena); + static inline void Clear(Type** value, Arena* arena); + static inline void ClearMaybeByDefaultEnum(Type** value, Arena* arena, + int default_enum_value); + static inline void Initialize(Type** x, Arena* arena); + + static inline void InitializeMaybeByDefaultEnum(Type** x, + int default_enum_value, + Arena* arena); + static inline Type* EnsureMutable(Type** value, Arena* arena); + // SpaceUsedInMapEntry: Return bytes used by value in MapEntry, excluding + // those already calculate in sizeof(MapField). + static inline int SpaceUsedInMapEntry(const Type* value); + // Return bytes used by value in Map. + static inline int SpaceUsedInMap(const Type& value); + // Assign default value to given instance. + static inline void AssignDefaultValue(Type** value); + // Return default instance if value is not initialized when calling const + // reference accessor. + static inline const Type& DefaultIfNotInitialized( + const Type* value, const Type* default_value); + // Check if all required fields have values set. + static inline bool IsInitialized(Type* value); }; -template <> -template -inline int MapWireFieldTypeHandler::ByteSize( - const ValueType& value) { +#define MAP_HANDLER(FieldType) \ + template \ + class MapTypeHandler { \ + public: \ + typedef typename MapWireFieldTypeTraits::MapEntryAccessorType \ + MapEntryAccessorType; \ + typedef typename MapWireFieldTypeTraits::TypeOnMemory TypeOnMemory; \ + static const WireFormatLite::WireType kWireType = \ + MapWireFieldTypeTraits::kWireType; \ + static const bool kIsMessage = \ + MapWireFieldTypeTraits::kIsMessage; \ + static const bool kIsEnum = \ + MapWireFieldTypeTraits::kIsEnum; \ + static inline int ByteSize(const MapEntryAccessorType& value); \ + static inline int GetCachedSize(const MapEntryAccessorType& value); \ + static inline bool Read(io::CodedInputStream* input, \ + MapEntryAccessorType* value); \ + static inline void Write(int field, const MapEntryAccessorType& value, \ + io::CodedOutputStream* output); \ + static inline uint8* WriteToArray(int field, \ + const MapEntryAccessorType& value, \ + uint8* output); \ + static inline const MapEntryAccessorType& GetExternalReference( \ + const TypeOnMemory& value); \ + static inline void DeleteNoArena(const TypeOnMemory& x); \ + static inline void Merge(const MapEntryAccessorType& from, \ + TypeOnMemory* to, Arena* arena); \ + static inline void Clear(TypeOnMemory* value, Arena* arena); \ + static inline void ClearMaybeByDefaultEnum(TypeOnMemory* value, \ + Arena* arena, \ + int default_enum); \ + static inline int SpaceUsedInMapEntry(const TypeOnMemory& value); \ + static inline int SpaceUsedInMap(const TypeOnMemory& value); \ + static inline int SpaceUsedInMap(const string& value); \ + static inline void AssignDefaultValue(TypeOnMemory* value); \ + static inline const MapEntryAccessorType& DefaultIfNotInitialized( \ + const TypeOnMemory& value, const TypeOnMemory& default_value); \ + static inline bool IsInitialized(const TypeOnMemory& value); \ + static void DeleteNoArena(TypeOnMemory& value); \ + static inline void Initialize(TypeOnMemory* value, Arena* arena); \ + static inline void InitializeMaybeByDefaultEnum(TypeOnMemory* value, \ + int default_enum_value, \ + Arena* arena); \ + static inline MapEntryAccessorType* EnsureMutable(TypeOnMemory* value, \ + Arena* arena); \ + }; +MAP_HANDLER(STRING) +MAP_HANDLER(BYTES) +MAP_HANDLER(INT64) +MAP_HANDLER(UINT64) +MAP_HANDLER(INT32) +MAP_HANDLER(UINT32) +MAP_HANDLER(SINT64) +MAP_HANDLER(SINT32) +MAP_HANDLER(ENUM) +MAP_HANDLER(DOUBLE) +MAP_HANDLER(FLOAT) +MAP_HANDLER(FIXED64) +MAP_HANDLER(FIXED32) +MAP_HANDLER(SFIXED64) +MAP_HANDLER(SFIXED32) +MAP_HANDLER(BOOL) +#undef MAP_HANDLER + +template +inline int +MapTypeHandler::ByteSize( + const MapEntryAccessorType& value) { return WireFormatLite::MessageSizeNoVirtual(value); } -#define BYTE_SIZE(FieldType, DeclaredType) \ - template <> \ - template \ - inline int \ - MapWireFieldTypeHandler::ByteSize( \ - const ValueType& value) { \ - return WireFormatLite::DeclaredType##Size(value); \ +#define BYTE_SIZE(FieldType, DeclaredType) \ + template \ + inline int MapTypeHandler::ByteSize( \ + const MapEntryAccessorType& value) { \ + return WireFormatLite::DeclaredType##Size(value); \ } BYTE_SIZE(STRING, String) @@ -349,13 +291,11 @@ BYTE_SIZE(ENUM , Enum) #undef BYTE_SIZE -#define FIXED_BYTE_SIZE(FieldType, DeclaredType) \ - template <> \ - template \ - inline int \ - MapWireFieldTypeHandler::ByteSize( \ - const ValueType& value) { \ - return WireFormatLite::k##DeclaredType##Size; \ +#define FIXED_BYTE_SIZE(FieldType, DeclaredType) \ + template \ + inline int MapTypeHandler::ByteSize( \ + const MapEntryAccessorType& value) { \ + return WireFormatLite::k##DeclaredType##Size; \ } FIXED_BYTE_SIZE(DOUBLE , Double) @@ -368,20 +308,19 @@ FIXED_BYTE_SIZE(BOOL , Bool) #undef FIXED_BYTE_SIZE -template <> -template -inline int MapWireFieldTypeHandler< - WireFormatLite::TYPE_MESSAGE>::GetCachedSize(const ValueType& value) { +template +inline int +MapTypeHandler::GetCachedSize( + const MapEntryAccessorType& value) { return WireFormatLite::LengthDelimitedSize(value.GetCachedSize()); } -#define GET_CACHED_SIZE(FieldType, DeclaredType) \ - template <> \ - template \ - inline int \ - MapWireFieldTypeHandler::GetCachedSize( \ - const ValueType& value) { \ - return WireFormatLite::DeclaredType##Size(value); \ +#define GET_CACHED_SIZE(FieldType, DeclaredType) \ + template \ + inline int \ + MapTypeHandler::GetCachedSize( \ + const MapEntryAccessorType& value) { \ + return WireFormatLite::DeclaredType##Size(value); \ } GET_CACHED_SIZE(STRING, String) @@ -396,13 +335,12 @@ GET_CACHED_SIZE(ENUM , Enum) #undef GET_CACHED_SIZE -#define GET_FIXED_CACHED_SIZE(FieldType, DeclaredType) \ - template <> \ - template \ - inline int \ - MapWireFieldTypeHandler::GetCachedSize( \ - const ValueType& value) { \ - return WireFormatLite::k##DeclaredType##Size; \ +#define GET_FIXED_CACHED_SIZE(FieldType, DeclaredType) \ + template \ + inline int \ + MapTypeHandler::GetCachedSize( \ + const MapEntryAccessorType& value) { \ + return WireFormatLite::k##DeclaredType##Size; \ } GET_FIXED_CACHED_SIZE(DOUBLE , Double) @@ -415,30 +353,31 @@ GET_FIXED_CACHED_SIZE(BOOL , Bool) #undef GET_FIXED_CACHED_SIZE -template <> -inline void MapWireFieldTypeHandler::Write( - int field, const MessageLite& value, io::CodedOutputStream* output) { +template +inline void MapTypeHandler::Write( + int field, const MapEntryAccessorType& value, + io::CodedOutputStream* output) { WireFormatLite::WriteMessageMaybeToArray(field, value, output); } -template <> +template inline uint8* -MapWireFieldTypeHandler::WriteToArray( - int field, const MessageLite& value, uint8* output) { +MapTypeHandler::WriteToArray( + int field, const MapEntryAccessorType& value, uint8* output) { return WireFormatLite::WriteMessageToArray(field, value, output); } #define WRITE_METHOD(FieldType, DeclaredType) \ - template <> \ - inline void \ - MapWireFieldTypeHandler::Write( \ - int field, const CppType& value, io::CodedOutputStream* output) { \ + template \ + inline void MapTypeHandler::Write( \ + int field, const MapEntryAccessorType& value, \ + io::CodedOutputStream* output) { \ return WireFormatLite::Write##DeclaredType(field, value, output); \ } \ - template <> \ + template \ inline uint8* \ - MapWireFieldTypeHandler::WriteToArray( \ - int field, const CppType& value, uint8* output) { \ + MapTypeHandler::WriteToArray( \ + int field, const MapEntryAccessorType& value, uint8* output) { \ return WireFormatLite::Write##DeclaredType##ToArray(field, value, output); \ } @@ -461,35 +400,31 @@ WRITE_METHOD(BOOL , Bool) #undef WRITE_METHOD -template <> -template -inline bool MapWireFieldTypeHandler::Read( - io::CodedInputStream* input, ValueType* value) { +template +inline bool MapTypeHandler::Read( + io::CodedInputStream* input, MapEntryAccessorType* value) { return WireFormatLite::ReadMessageNoVirtual(input, value); } -template <> -template -inline bool MapWireFieldTypeHandler::Read( - io::CodedInputStream* input, ValueType* value) { +template +inline bool MapTypeHandler::Read( + io::CodedInputStream* input, MapEntryAccessorType* value) { return WireFormatLite::ReadString(input, value); } -template <> -template -inline bool MapWireFieldTypeHandler::Read( - io::CodedInputStream* input, ValueType* value) { +template +inline bool MapTypeHandler::Read( + io::CodedInputStream* input, MapEntryAccessorType* value) { return WireFormatLite::ReadBytes(input, value); } -#define READ_METHOD(FieldType) \ - template <> \ - template \ - inline bool MapWireFieldTypeHandler::Read( \ - io::CodedInputStream* input, ValueType* value) { \ - return WireFormatLite::ReadPrimitive( \ - input, value); \ +#define READ_METHOD(FieldType) \ + template \ + inline bool MapTypeHandler::Read( \ + io::CodedInputStream* input, MapEntryAccessorType* value) { \ + return WireFormatLite::ReadPrimitive( \ + input, value); \ } READ_METHOD(INT64) @@ -509,6 +444,282 @@ READ_METHOD(BOOL) #undef READ_METHOD +// Definition for message handler + +template +inline const Type& +MapTypeHandler::GetExternalReference(const Type* value) { + return *value; +} + +template +inline int +MapTypeHandler::SpaceUsedInMapEntry(const Type* value) { + return value->SpaceUsed(); +} + +template +int MapTypeHandler::SpaceUsedInMap( + const Type& value) { + return value.SpaceUsed(); +} + +template +inline void MapTypeHandler::Clear( + Type** value, Arena* arena) { + if (*value != NULL) (*value)->Clear(); +} +template +inline void +MapTypeHandler::ClearMaybeByDefaultEnum(Type** value, + Arena* arena, + int default_enum_value) { + if (*value != NULL) (*value)->Clear(); +} +template +inline void MapTypeHandler::Merge( + const Type& from, Type** to, Arena* arena) { + (*to)->MergeFrom(from); +} + +template +void MapTypeHandler::DeleteNoArena( + const Type* ptr) { + delete ptr; +} + +template +inline void MapTypeHandler::AssignDefaultValue(Type** value) { + *value = const_cast(&Type::default_instance()); +} + +template +inline void MapTypeHandler::Initialize(Type** x, + Arena* arena) { + *x = NULL; +} + +template +inline void MapTypeHandler:: + InitializeMaybeByDefaultEnum(Type** x, int default_enum_value, + Arena* arena) { + *x = NULL; +} + +template +inline Type* MapTypeHandler::EnsureMutable(Type** value, + Arena* arena) { + if (*value == NULL) { + *value = + MapArenaMessageCreator:: + type::value>::CreateMessage(arena); + } + return *value; +} + +template +inline const Type& MapTypeHandler:: + DefaultIfNotInitialized(const Type* value, const Type* default_value) { + return value != NULL ? *value : *default_value; +} + +template +inline bool MapTypeHandler::IsInitialized(Type* value) { + return value->IsInitialized(); +} + +// Definition for string/bytes handler + +#define STRING_OR_BYTES_HANDLER_FUNCTIONS(FieldType) \ + template \ + inline const typename MapTypeHandler::MapEntryAccessorType& \ + MapTypeHandler::GetExternalReference(const TypeOnMemory& value) { \ + return value.Get(&::google::protobuf::internal::GetEmptyString()); \ + } \ + template \ + inline int \ + MapTypeHandler::SpaceUsedInMapEntry( \ + const TypeOnMemory& value) { \ + return sizeof(value); \ + } \ + template \ + inline int MapTypeHandler::SpaceUsedInMap(const TypeOnMemory& value) { \ + return sizeof(value); \ + } \ + template \ + inline int MapTypeHandler::SpaceUsedInMap(const string& value) { \ + return sizeof(value); \ + } \ + template \ + inline void MapTypeHandler::Clear( \ + TypeOnMemory* value, Arena* arena) { \ + value->ClearToEmpty(&::google::protobuf::internal::GetEmptyString(), arena); \ + } \ + template \ + inline void \ + MapTypeHandler::ClearMaybeByDefaultEnum(TypeOnMemory* value, \ + Arena* arena, \ + int default_enum) { \ + Clear(value, arena); \ + } \ + template \ + inline void MapTypeHandler::Merge( \ + const MapEntryAccessorType& from, TypeOnMemory* to, Arena* arena) { \ + to->Set(&::google::protobuf::internal::GetEmptyString(), from, arena); \ + } \ + template \ + void MapTypeHandler::DeleteNoArena( \ + TypeOnMemory& value) { \ + value.DestroyNoArena(&::google::protobuf::internal::GetEmptyString()); \ + } \ + template \ + inline void MapTypeHandler::AssignDefaultValue(TypeOnMemory* value) {} \ + template \ + inline void \ + MapTypeHandler::Initialize( \ + TypeOnMemory* value, Arena* arena) { \ + value->UnsafeSetDefault(&::google::protobuf::internal::GetEmptyString()); \ + } \ + template \ + inline void \ + MapTypeHandler::InitializeMaybeByDefaultEnum(TypeOnMemory* value, \ + int default_enum_value, \ + Arena* arena) { \ + Initialize(value, arena); \ + } \ + template \ + inline typename MapTypeHandler::MapEntryAccessorType* \ + MapTypeHandler::EnsureMutable( \ + TypeOnMemory* value, Arena* arena) { \ + return value->Mutable(&::google::protobuf::internal::GetEmptyString(), arena); \ + } \ + template \ + inline const typename MapTypeHandler::MapEntryAccessorType& \ + MapTypeHandler::DefaultIfNotInitialized(const TypeOnMemory& value, \ + const TypeOnMemory& \ + default_value) { \ + return value.Get(&::google::protobuf::internal::GetEmptyString()); \ + } \ + template \ + inline bool MapTypeHandler::IsInitialized(const TypeOnMemory& value) { \ + return true; \ + } +STRING_OR_BYTES_HANDLER_FUNCTIONS(STRING) +STRING_OR_BYTES_HANDLER_FUNCTIONS(BYTES) +#undef STRING_OR_BYTES_HANDLER_FUNCTIONS + +#define PRIMITIVE_HANDLER_FUNCTIONS(FieldType) \ + template \ + inline const typename MapTypeHandler::MapEntryAccessorType& \ + MapTypeHandler::GetExternalReference(const TypeOnMemory& value) { \ + return value; \ + } \ + template \ + inline int \ + MapTypeHandler::SpaceUsedInMapEntry( \ + const TypeOnMemory& value) { \ + return 0; \ + } \ + template \ + inline int MapTypeHandler::SpaceUsedInMap(const TypeOnMemory& value) { \ + return sizeof(Type); \ + } \ + template \ + inline void MapTypeHandler::Clear( \ + TypeOnMemory* value, Arena* arena) { \ + *value = 0; \ + } \ + template \ + inline void \ + MapTypeHandler::ClearMaybeByDefaultEnum(TypeOnMemory* value, \ + Arena* arena, \ + int default_enum_value) { \ + *value = static_cast(default_enum_value); \ + } \ + template \ + inline void MapTypeHandler::Merge( \ + const MapEntryAccessorType& from, TypeOnMemory* to, Arena* arena) { \ + *to = from; \ + } \ + template \ + inline void MapTypeHandler::DeleteNoArena(TypeOnMemory& x) {} \ + template \ + inline void MapTypeHandler::AssignDefaultValue(TypeOnMemory* value) {} \ + template \ + inline void \ + MapTypeHandler::Initialize( \ + TypeOnMemory* value, Arena* arena) { \ + *value = 0; \ + } \ + template \ + inline void \ + MapTypeHandler::InitializeMaybeByDefaultEnum(TypeOnMemory* value, \ + int default_enum_value, \ + Arena* arena) { \ + *value = static_cast(default_enum_value); \ + } \ + template \ + inline typename MapTypeHandler::MapEntryAccessorType* \ + MapTypeHandler::EnsureMutable( \ + TypeOnMemory* value, Arena* arena) { \ + return value; \ + } \ + template \ + inline const typename MapTypeHandler::MapEntryAccessorType& \ + MapTypeHandler::DefaultIfNotInitialized(const TypeOnMemory& value, \ + const TypeOnMemory& \ + default_value) { \ + return value; \ + } \ + template \ + inline bool MapTypeHandler::IsInitialized(const TypeOnMemory& value) { \ + return true; \ + } +PRIMITIVE_HANDLER_FUNCTIONS(INT64) +PRIMITIVE_HANDLER_FUNCTIONS(UINT64) +PRIMITIVE_HANDLER_FUNCTIONS(INT32) +PRIMITIVE_HANDLER_FUNCTIONS(UINT32) +PRIMITIVE_HANDLER_FUNCTIONS(SINT64) +PRIMITIVE_HANDLER_FUNCTIONS(SINT32) +PRIMITIVE_HANDLER_FUNCTIONS(ENUM) +PRIMITIVE_HANDLER_FUNCTIONS(DOUBLE) +PRIMITIVE_HANDLER_FUNCTIONS(FLOAT) +PRIMITIVE_HANDLER_FUNCTIONS(FIXED64) +PRIMITIVE_HANDLER_FUNCTIONS(FIXED32) +PRIMITIVE_HANDLER_FUNCTIONS(SFIXED64) +PRIMITIVE_HANDLER_FUNCTIONS(SFIXED32) +PRIMITIVE_HANDLER_FUNCTIONS(BOOL) +#undef PRIMITIVE_HANDLER_FUNCTIONS + } // namespace internal } // namespace protobuf -- cgit v1.2.3