|
|
|
@ -84,10 +84,6 @@ class MapTypeHandler<WireFormatLite::TYPE_MESSAGE, Type> { |
|
|
|
|
// Functions used in parsing and serialization. ===================
|
|
|
|
|
static inline size_t ByteSize(const MapEntryAccessorType& value); |
|
|
|
|
static inline int GetCachedSize(const MapEntryAccessorType& value); |
|
|
|
|
static inline bool Read(io::CodedInputStream* input, |
|
|
|
|
MapEntryAccessorType* value); |
|
|
|
|
static inline const char* Read(const char* ptr, ParseContext* ctx, |
|
|
|
|
MapEntryAccessorType* value); |
|
|
|
|
|
|
|
|
|
static inline uint8_t* Write(int field, const MapEntryAccessorType& value, |
|
|
|
|
uint8_t* ptr, io::EpsCopyOutputStream* stream); |
|
|
|
@ -95,8 +91,6 @@ class MapTypeHandler<WireFormatLite::TYPE_MESSAGE, Type> { |
|
|
|
|
// Functions to manipulate data on memory. ========================
|
|
|
|
|
static inline void DeleteNoArena(const Type* x); |
|
|
|
|
static constexpr TypeOnMemory Constinit(); |
|
|
|
|
|
|
|
|
|
static inline Type* EnsureMutable(Type** value, Arena* arena); |
|
|
|
|
}; |
|
|
|
|
|
|
|
|
|
#define MAP_HANDLER(FieldType) \ |
|
|
|
@ -113,18 +107,12 @@ class MapTypeHandler<WireFormatLite::TYPE_MESSAGE, Type> { |
|
|
|
|
Type>::kWireType; \
|
|
|
|
|
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 const char* Read(const char* begin, ParseContext* ctx, \
|
|
|
|
|
MapEntryAccessorType* value); \
|
|
|
|
|
static inline uint8_t* Write(int field, const MapEntryAccessorType& value, \
|
|
|
|
|
uint8_t* ptr, \
|
|
|
|
|
io::EpsCopyOutputStream* stream); \
|
|
|
|
|
static inline void DeleteNoArena(const TypeOnMemory& x); \
|
|
|
|
|
static void DeleteNoArena(TypeOnMemory& value); \
|
|
|
|
|
static constexpr TypeOnMemory Constinit(); \
|
|
|
|
|
static inline MapEntryAccessorType* EnsureMutable(TypeOnMemory* value, \
|
|
|
|
|
Arena* arena); \
|
|
|
|
|
}; |
|
|
|
|
MAP_HANDLER(STRING) |
|
|
|
|
MAP_HANDLER(BYTES) |
|
|
|
@ -281,132 +269,6 @@ WRITE_METHOD(BOOL, Bool) |
|
|
|
|
|
|
|
|
|
#undef WRITE_METHOD |
|
|
|
|
|
|
|
|
|
template <typename Type> |
|
|
|
|
inline bool MapTypeHandler<WireFormatLite::TYPE_MESSAGE, Type>::Read( |
|
|
|
|
io::CodedInputStream* input, MapEntryAccessorType* value) { |
|
|
|
|
return WireFormatLite::ReadMessageNoVirtual(input, value); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
template <typename Type> |
|
|
|
|
inline bool MapTypeHandler<WireFormatLite::TYPE_STRING, Type>::Read( |
|
|
|
|
io::CodedInputStream* input, MapEntryAccessorType* value) { |
|
|
|
|
return WireFormatLite::ReadString(input, value); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
template <typename Type> |
|
|
|
|
inline bool MapTypeHandler<WireFormatLite::TYPE_BYTES, Type>::Read( |
|
|
|
|
io::CodedInputStream* input, MapEntryAccessorType* value) { |
|
|
|
|
return WireFormatLite::ReadBytes(input, value); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
template <typename Type> |
|
|
|
|
const char* MapTypeHandler<WireFormatLite::TYPE_MESSAGE, Type>::Read( |
|
|
|
|
const char* ptr, ParseContext* ctx, MapEntryAccessorType* value) { |
|
|
|
|
return ctx->ParseMessage(value, ptr); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
template <typename Type> |
|
|
|
|
const char* MapTypeHandler<WireFormatLite::TYPE_STRING, Type>::Read( |
|
|
|
|
const char* ptr, ParseContext* ctx, MapEntryAccessorType* value) { |
|
|
|
|
int size = ReadSize(&ptr); |
|
|
|
|
GOOGLE_PROTOBUF_PARSER_ASSERT(ptr); |
|
|
|
|
return ctx->ReadString(ptr, size, value); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
template <typename Type> |
|
|
|
|
const char* MapTypeHandler<WireFormatLite::TYPE_BYTES, Type>::Read( |
|
|
|
|
const char* ptr, ParseContext* ctx, MapEntryAccessorType* value) { |
|
|
|
|
int size = ReadSize(&ptr); |
|
|
|
|
GOOGLE_PROTOBUF_PARSER_ASSERT(ptr); |
|
|
|
|
return ctx->ReadString(ptr, size, value); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
inline const char* ReadINT64(const char* ptr, int64_t* value) { |
|
|
|
|
return VarintParse(ptr, reinterpret_cast<uint64_t*>(value)); |
|
|
|
|
} |
|
|
|
|
inline const char* ReadUINT64(const char* ptr, uint64_t* value) { |
|
|
|
|
return VarintParse(ptr, value); |
|
|
|
|
} |
|
|
|
|
inline const char* ReadINT32(const char* ptr, int32_t* value) { |
|
|
|
|
return VarintParse(ptr, reinterpret_cast<uint32_t*>(value)); |
|
|
|
|
} |
|
|
|
|
inline const char* ReadUINT32(const char* ptr, uint32_t* value) { |
|
|
|
|
return VarintParse(ptr, value); |
|
|
|
|
} |
|
|
|
|
inline const char* ReadSINT64(const char* ptr, int64_t* value) { |
|
|
|
|
*value = ReadVarintZigZag64(&ptr); |
|
|
|
|
return ptr; |
|
|
|
|
} |
|
|
|
|
inline const char* ReadSINT32(const char* ptr, int32_t* value) { |
|
|
|
|
*value = ReadVarintZigZag32(&ptr); |
|
|
|
|
return ptr; |
|
|
|
|
} |
|
|
|
|
template <typename E> |
|
|
|
|
inline const char* ReadENUM(const char* ptr, E* value) { |
|
|
|
|
*value = static_cast<E>(ReadVarint32(&ptr)); |
|
|
|
|
return ptr; |
|
|
|
|
} |
|
|
|
|
inline const char* ReadBOOL(const char* ptr, bool* value) { |
|
|
|
|
*value = static_cast<bool>(ReadVarint64(&ptr)); |
|
|
|
|
return ptr; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
template <typename F> |
|
|
|
|
inline const char* ReadUnaligned(const char* ptr, F* value) { |
|
|
|
|
*value = UnalignedLoad<F>(ptr); |
|
|
|
|
return ptr + sizeof(F); |
|
|
|
|
} |
|
|
|
|
inline const char* ReadFLOAT(const char* ptr, float* value) { |
|
|
|
|
return ReadUnaligned(ptr, value); |
|
|
|
|
} |
|
|
|
|
inline const char* ReadDOUBLE(const char* ptr, double* value) { |
|
|
|
|
return ReadUnaligned(ptr, value); |
|
|
|
|
} |
|
|
|
|
inline const char* ReadFIXED64(const char* ptr, uint64_t* value) { |
|
|
|
|
return ReadUnaligned(ptr, value); |
|
|
|
|
} |
|
|
|
|
inline const char* ReadFIXED32(const char* ptr, uint32_t* value) { |
|
|
|
|
return ReadUnaligned(ptr, value); |
|
|
|
|
} |
|
|
|
|
inline const char* ReadSFIXED64(const char* ptr, int64_t* value) { |
|
|
|
|
return ReadUnaligned(ptr, value); |
|
|
|
|
} |
|
|
|
|
inline const char* ReadSFIXED32(const char* ptr, int32_t* value) { |
|
|
|
|
return ReadUnaligned(ptr, value); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
#define READ_METHOD(FieldType) \ |
|
|
|
|
template <typename Type> \
|
|
|
|
|
inline bool MapTypeHandler<WireFormatLite::TYPE_##FieldType, Type>::Read( \
|
|
|
|
|
io::CodedInputStream* input, MapEntryAccessorType* value) { \
|
|
|
|
|
return WireFormatLite::ReadPrimitive<TypeOnMemory, \
|
|
|
|
|
WireFormatLite::TYPE_##FieldType>( \
|
|
|
|
|
input, value); \
|
|
|
|
|
} \
|
|
|
|
|
template <typename Type> \
|
|
|
|
|
const char* MapTypeHandler<WireFormatLite::TYPE_##FieldType, Type>::Read( \
|
|
|
|
|
const char* begin, ParseContext* ctx, MapEntryAccessorType* value) { \
|
|
|
|
|
(void)ctx; \
|
|
|
|
|
return Read##FieldType(begin, value); \
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
READ_METHOD(INT64) |
|
|
|
|
READ_METHOD(UINT64) |
|
|
|
|
READ_METHOD(INT32) |
|
|
|
|
READ_METHOD(UINT32) |
|
|
|
|
READ_METHOD(SINT64) |
|
|
|
|
READ_METHOD(SINT32) |
|
|
|
|
READ_METHOD(ENUM) |
|
|
|
|
READ_METHOD(DOUBLE) |
|
|
|
|
READ_METHOD(FLOAT) |
|
|
|
|
READ_METHOD(FIXED64) |
|
|
|
|
READ_METHOD(FIXED32) |
|
|
|
|
READ_METHOD(SFIXED64) |
|
|
|
|
READ_METHOD(SFIXED32) |
|
|
|
|
READ_METHOD(BOOL) |
|
|
|
|
|
|
|
|
|
#undef READ_METHOD |
|
|
|
|
|
|
|
|
|
// Definition for message handler
|
|
|
|
|
|
|
|
|
|
template <typename Type> |
|
|
|
@ -421,15 +283,6 @@ constexpr auto MapTypeHandler<WireFormatLite::TYPE_MESSAGE, Type>::Constinit() |
|
|
|
|
return nullptr; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
template <typename Type> |
|
|
|
|
inline Type* MapTypeHandler<WireFormatLite::TYPE_MESSAGE, Type>::EnsureMutable( |
|
|
|
|
Type** value, Arena* arena) { |
|
|
|
|
if (*value == nullptr) { |
|
|
|
|
*value = Arena::CreateMessage<Type>(arena); |
|
|
|
|
} |
|
|
|
|
return *value; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
// Definition for string/bytes handler
|
|
|
|
|
|
|
|
|
|
#define STRING_OR_BYTES_HANDLER_FUNCTIONS(FieldType) \ |
|
|
|
@ -444,13 +297,6 @@ inline Type* MapTypeHandler<WireFormatLite::TYPE_MESSAGE, Type>::EnsureMutable( |
|
|
|
|
-> TypeOnMemory { \
|
|
|
|
|
return TypeOnMemory(&internal::fixed_address_empty_string, \
|
|
|
|
|
ConstantInitialized{}); \
|
|
|
|
|
} \
|
|
|
|
|
template <typename Type> \
|
|
|
|
|
inline typename MapTypeHandler<WireFormatLite::TYPE_##FieldType, \
|
|
|
|
|
Type>::MapEntryAccessorType* \
|
|
|
|
|
MapTypeHandler<WireFormatLite::TYPE_##FieldType, Type>::EnsureMutable( \
|
|
|
|
|
TypeOnMemory* value, Arena* arena) { \
|
|
|
|
|
return value->Mutable(arena); \
|
|
|
|
|
} |
|
|
|
|
STRING_OR_BYTES_HANDLER_FUNCTIONS(STRING) |
|
|
|
|
STRING_OR_BYTES_HANDLER_FUNCTIONS(BYTES) |
|
|
|
@ -465,13 +311,6 @@ STRING_OR_BYTES_HANDLER_FUNCTIONS(BYTES) |
|
|
|
|
MapTypeHandler<WireFormatLite::TYPE_##FieldType, Type>::Constinit() \
|
|
|
|
|
->TypeOnMemory { \
|
|
|
|
|
return 0; \
|
|
|
|
|
} \
|
|
|
|
|
template <typename Type> \
|
|
|
|
|
inline typename MapTypeHandler<WireFormatLite::TYPE_##FieldType, \
|
|
|
|
|
Type>::MapEntryAccessorType* \
|
|
|
|
|
MapTypeHandler<WireFormatLite::TYPE_##FieldType, Type>::EnsureMutable( \
|
|
|
|
|
TypeOnMemory* value, Arena* /* arena */) { \
|
|
|
|
|
return value; \
|
|
|
|
|
} |
|
|
|
|
PRIMITIVE_HANDLER_FUNCTIONS(INT64) |
|
|
|
|
PRIMITIVE_HANDLER_FUNCTIONS(UINT64) |
|
|
|
|