OLD | NEW |
1 // Protocol Buffers - Google's data interchange format | 1 // Protocol Buffers - Google's data interchange format |
2 // Copyright 2008 Google Inc. All rights reserved. | 2 // Copyright 2008 Google Inc. All rights reserved. |
3 // https://developers.google.com/protocol-buffers/ | 3 // https://developers.google.com/protocol-buffers/ |
4 // | 4 // |
5 // Redistribution and use in source and binary forms, with or without | 5 // Redistribution and use in source and binary forms, with or without |
6 // modification, are permitted provided that the following conditions are | 6 // modification, are permitted provided that the following conditions are |
7 // met: | 7 // met: |
8 // | 8 // |
9 // * Redistributions of source code must retain the above copyright | 9 // * Redistributions of source code must retain the above copyright |
10 // notice, this list of conditions and the following disclaimer. | 10 // notice, this list of conditions and the following disclaimer. |
(...skipping 140 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
151 static const WireFormatLite::WireType kWireType = | 151 static const WireFormatLite::WireType kWireType = |
152 MapWireFieldTypeTraits<WireFormatLite::TYPE_MESSAGE, Type>::kWireType; | 152 MapWireFieldTypeTraits<WireFormatLite::TYPE_MESSAGE, Type>::kWireType; |
153 // Whether wire type is for message. | 153 // Whether wire type is for message. |
154 static const bool kIsMessage = | 154 static const bool kIsMessage = |
155 MapWireFieldTypeTraits<WireFormatLite::TYPE_MESSAGE, Type>::kIsMessage; | 155 MapWireFieldTypeTraits<WireFormatLite::TYPE_MESSAGE, Type>::kIsMessage; |
156 // Whether wire type is for enum. | 156 // Whether wire type is for enum. |
157 static const bool kIsEnum = | 157 static const bool kIsEnum = |
158 MapWireFieldTypeTraits<WireFormatLite::TYPE_MESSAGE, Type>::kIsEnum; | 158 MapWireFieldTypeTraits<WireFormatLite::TYPE_MESSAGE, Type>::kIsEnum; |
159 | 159 |
160 // Functions used in parsing and serialization. =================== | 160 // Functions used in parsing and serialization. =================== |
161 static inline size_t ByteSize(const MapEntryAccessorType& value); | 161 static inline int ByteSize(const MapEntryAccessorType& value); |
162 static inline int GetCachedSize(const MapEntryAccessorType& value); | 162 static inline int GetCachedSize(const MapEntryAccessorType& value); |
163 static inline bool Read(io::CodedInputStream* input, | 163 static inline bool Read(io::CodedInputStream* input, |
164 MapEntryAccessorType* value); | 164 MapEntryAccessorType* value); |
165 static inline void Write(int field, const MapEntryAccessorType& value, | 165 static inline void Write(int field, const MapEntryAccessorType& value, |
166 io::CodedOutputStream* output); | 166 io::CodedOutputStream* output); |
167 static inline uint8* InternalWriteToArray(int field, | |
168 const MapEntryAccessorType& value, | |
169 bool deterministic, uint8* target); | |
170 static inline uint8* WriteToArray(int field, | 167 static inline uint8* WriteToArray(int field, |
171 const MapEntryAccessorType& value, | 168 const MapEntryAccessorType& value, |
172 uint8* target); | 169 uint8* output); |
173 | 170 |
174 // Functions to manipulate data on memory. ======================== | 171 // Functions to manipulate data on memory. ======================== |
175 static inline const Type& GetExternalReference(const Type* value); | 172 static inline const Type& GetExternalReference(const Type* value); |
176 static inline void DeleteNoArena(const Type* x); | 173 static inline void DeleteNoArena(const Type* x); |
177 static inline void Merge(const Type& from, Type** to, Arena* arena); | 174 static inline void Merge(const Type& from, Type** to, Arena* arena); |
178 static inline void Clear(Type** value, Arena* arena); | 175 static inline void Clear(Type** value, Arena* arena); |
179 static inline void ClearMaybeByDefaultEnum(Type** value, Arena* arena, | 176 static inline void ClearMaybeByDefaultEnum(Type** value, Arena* arena, |
180 int default_enum_value); | 177 int default_enum_value); |
181 static inline void Initialize(Type** x, Arena* arena); | 178 static inline void Initialize(Type** x, Arena* arena); |
182 | 179 |
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
216 Type>::kIsMessage; \ | 213 Type>::kIsMessage; \ |
217 static const bool kIsEnum = \ | 214 static const bool kIsEnum = \ |
218 MapWireFieldTypeTraits<WireFormatLite::TYPE_##FieldType, \ | 215 MapWireFieldTypeTraits<WireFormatLite::TYPE_##FieldType, \ |
219 Type>::kIsEnum; \ | 216 Type>::kIsEnum; \ |
220 static inline int ByteSize(const MapEntryAccessorType& value); \ | 217 static inline int ByteSize(const MapEntryAccessorType& value); \ |
221 static inline int GetCachedSize(const MapEntryAccessorType& value); \ | 218 static inline int GetCachedSize(const MapEntryAccessorType& value); \ |
222 static inline bool Read(io::CodedInputStream* input, \ | 219 static inline bool Read(io::CodedInputStream* input, \ |
223 MapEntryAccessorType* value); \ | 220 MapEntryAccessorType* value); \ |
224 static inline void Write(int field, const MapEntryAccessorType& value, \ | 221 static inline void Write(int field, const MapEntryAccessorType& value, \ |
225 io::CodedOutputStream* output); \ | 222 io::CodedOutputStream* output); \ |
226 static inline uint8* InternalWriteToArray( \ | |
227 int field, \ | |
228 const MapEntryAccessorType& value, \ | |
229 bool deterministic, \ | |
230 uint8* target); \ | |
231 static inline uint8* WriteToArray(int field, \ | 223 static inline uint8* WriteToArray(int field, \ |
232 const MapEntryAccessorType& value, \ | 224 const MapEntryAccessorType& value, \ |
233 uint8* target) { \ | 225 uint8* output); \ |
234 return InternalWriteToArray(field, value, false, target); \ | |
235 } \ | |
236 static inline const MapEntryAccessorType& GetExternalReference( \ | 226 static inline const MapEntryAccessorType& GetExternalReference( \ |
237 const TypeOnMemory& value); \ | 227 const TypeOnMemory& value); \ |
238 static inline void DeleteNoArena(const TypeOnMemory& x); \ | 228 static inline void DeleteNoArena(const TypeOnMemory& x); \ |
239 static inline void Merge(const MapEntryAccessorType& from, \ | 229 static inline void Merge(const MapEntryAccessorType& from, \ |
240 TypeOnMemory* to, Arena* arena); \ | 230 TypeOnMemory* to, Arena* arena); \ |
241 static inline void Clear(TypeOnMemory* value, Arena* arena); \ | 231 static inline void Clear(TypeOnMemory* value, Arena* arena); \ |
242 static inline void ClearMaybeByDefaultEnum(TypeOnMemory* value, \ | 232 static inline void ClearMaybeByDefaultEnum(TypeOnMemory* value, \ |
243 Arena* arena, \ | 233 Arena* arena, \ |
244 int default_enum); \ | 234 int default_enum); \ |
245 static inline int SpaceUsedInMapEntry(const TypeOnMemory& value); \ | 235 static inline int SpaceUsedInMapEntry(const TypeOnMemory& value); \ |
(...skipping 23 matching lines...) Expand all Loading... |
269 MAP_HANDLER(DOUBLE) | 259 MAP_HANDLER(DOUBLE) |
270 MAP_HANDLER(FLOAT) | 260 MAP_HANDLER(FLOAT) |
271 MAP_HANDLER(FIXED64) | 261 MAP_HANDLER(FIXED64) |
272 MAP_HANDLER(FIXED32) | 262 MAP_HANDLER(FIXED32) |
273 MAP_HANDLER(SFIXED64) | 263 MAP_HANDLER(SFIXED64) |
274 MAP_HANDLER(SFIXED32) | 264 MAP_HANDLER(SFIXED32) |
275 MAP_HANDLER(BOOL) | 265 MAP_HANDLER(BOOL) |
276 #undef MAP_HANDLER | 266 #undef MAP_HANDLER |
277 | 267 |
278 template <typename Type> | 268 template <typename Type> |
279 inline size_t | 269 inline int |
280 MapTypeHandler<WireFormatLite::TYPE_MESSAGE, Type>::ByteSize( | 270 MapTypeHandler<WireFormatLite::TYPE_MESSAGE, Type>::ByteSize( |
281 const MapEntryAccessorType& value) { | 271 const MapEntryAccessorType& value) { |
282 return WireFormatLite::MessageSizeNoVirtual(value); | 272 return WireFormatLite::MessageSizeNoVirtual(value); |
283 } | 273 } |
284 | 274 |
285 #define GOOGLE_PROTOBUF_BYTE_SIZE(FieldType, DeclaredType) \ | 275 #define GOOGLE_PROTOBUF_BYTE_SIZE(FieldType, DeclaredType) \ |
286 template <typename Type> \ | 276 template <typename Type> \ |
287 inline int MapTypeHandler<WireFormatLite::TYPE_##FieldType, Type>::ByteSize( \ | 277 inline int MapTypeHandler<WireFormatLite::TYPE_##FieldType, Type>::ByteSize( \ |
288 const MapEntryAccessorType& value) { \ | 278 const MapEntryAccessorType& value) { \ |
289 return WireFormatLite::DeclaredType##Size(value); \ | 279 return WireFormatLite::DeclaredType##Size(value); \ |
(...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
365 | 355 |
366 template <typename Type> | 356 template <typename Type> |
367 inline void MapTypeHandler<WireFormatLite::TYPE_MESSAGE, Type>::Write( | 357 inline void MapTypeHandler<WireFormatLite::TYPE_MESSAGE, Type>::Write( |
368 int field, const MapEntryAccessorType& value, | 358 int field, const MapEntryAccessorType& value, |
369 io::CodedOutputStream* output) { | 359 io::CodedOutputStream* output) { |
370 WireFormatLite::WriteMessageMaybeToArray(field, value, output); | 360 WireFormatLite::WriteMessageMaybeToArray(field, value, output); |
371 } | 361 } |
372 | 362 |
373 template <typename Type> | 363 template <typename Type> |
374 inline uint8* | 364 inline uint8* |
375 MapTypeHandler<WireFormatLite::TYPE_MESSAGE, Type>::InternalWriteToArray( | 365 MapTypeHandler<WireFormatLite::TYPE_MESSAGE, Type>::WriteToArray( |
376 int field, const MapEntryAccessorType& value, bool deterministic, | 366 int field, const MapEntryAccessorType& value, uint8* output) { |
377 uint8* target) { | 367 return WireFormatLite::WriteMessageToArray(field, value, output); |
378 return WireFormatLite::InternalWriteMessageToArray(field, value, | |
379 deterministic, target); | |
380 } | 368 } |
381 | 369 |
382 #define WRITE_METHOD(FieldType, DeclaredType) \ | 370 #define WRITE_METHOD(FieldType, DeclaredType) \ |
383 template <typename Type> \ | 371 template <typename Type> \ |
384 inline void MapTypeHandler<WireFormatLite::TYPE_##FieldType, Type>::Write( \ | 372 inline void MapTypeHandler<WireFormatLite::TYPE_##FieldType, Type>::Write( \ |
385 int field, const MapEntryAccessorType& value, \ | 373 int field, const MapEntryAccessorType& value, \ |
386 io::CodedOutputStream* output) { \ | 374 io::CodedOutputStream* output) { \ |
387 return WireFormatLite::Write##DeclaredType(field, value, output); \ | 375 return WireFormatLite::Write##DeclaredType(field, value, output); \ |
388 } \ | 376 } \ |
389 template <typename Type> \ | 377 template <typename Type> \ |
390 inline uint8* \ | 378 inline uint8* \ |
391 MapTypeHandler<WireFormatLite::TYPE_##FieldType, \ | 379 MapTypeHandler<WireFormatLite::TYPE_##FieldType, Type>::WriteToArray( \ |
392 Type>::InternalWriteToArray( \ | 380 int field, const MapEntryAccessorType& value, uint8* output) { \ |
393 int field, const MapEntryAccessorType& value, bool, uint8* target) { \ | 381 return WireFormatLite::Write##DeclaredType##ToArray(field, value, output); \ |
394 return WireFormatLite::Write##DeclaredType##ToArray(field, value, target); \ | |
395 } | 382 } |
396 | 383 |
397 WRITE_METHOD(STRING , String) | 384 WRITE_METHOD(STRING , String) |
398 WRITE_METHOD(BYTES , Bytes) | 385 WRITE_METHOD(BYTES , Bytes) |
399 WRITE_METHOD(INT64 , Int64) | 386 WRITE_METHOD(INT64 , Int64) |
400 WRITE_METHOD(UINT64 , UInt64) | 387 WRITE_METHOD(UINT64 , UInt64) |
401 WRITE_METHOD(INT32 , Int32) | 388 WRITE_METHOD(INT32 , Int32) |
402 WRITE_METHOD(UINT32 , UInt32) | 389 WRITE_METHOD(UINT32 , UInt32) |
403 WRITE_METHOD(SINT64 , SInt64) | 390 WRITE_METHOD(SINT64 , SInt64) |
404 WRITE_METHOD(SINT32 , SInt32) | 391 WRITE_METHOD(SINT32 , SInt32) |
(...skipping 144 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
549 } | 536 } |
550 | 537 |
551 // Definition for string/bytes handler | 538 // Definition for string/bytes handler |
552 | 539 |
553 #define STRING_OR_BYTES_HANDLER_FUNCTIONS(FieldType) \ | 540 #define STRING_OR_BYTES_HANDLER_FUNCTIONS(FieldType) \ |
554 template <typename Type> \ | 541 template <typename Type> \ |
555 inline const typename MapTypeHandler<WireFormatLite::TYPE_##FieldType, \ | 542 inline const typename MapTypeHandler<WireFormatLite::TYPE_##FieldType, \ |
556 Type>::MapEntryAccessorType& \ | 543 Type>::MapEntryAccessorType& \ |
557 MapTypeHandler<WireFormatLite::TYPE_##FieldType, \ | 544 MapTypeHandler<WireFormatLite::TYPE_##FieldType, \ |
558 Type>::GetExternalReference(const TypeOnMemory& value) { \ | 545 Type>::GetExternalReference(const TypeOnMemory& value) { \ |
559 return value.Get(); \ | 546 return value.Get(&::google::protobuf::internal::GetEmptyString());
\ |
560 } \ | 547 } \ |
561 template <typename Type> \ | 548 template <typename Type> \ |
562 inline int \ | 549 inline int \ |
563 MapTypeHandler<WireFormatLite::TYPE_##FieldType, Type>::SpaceUsedInMapEntry( \ | 550 MapTypeHandler<WireFormatLite::TYPE_##FieldType, Type>::SpaceUsedInMapEntry( \ |
564 const TypeOnMemory& value) { \ | 551 const TypeOnMemory& value) { \ |
565 return sizeof(value); \ | 552 return sizeof(value); \ |
566 } \ | 553 } \ |
567 template <typename Type> \ | 554 template <typename Type> \ |
568 inline int MapTypeHandler<WireFormatLite::TYPE_##FieldType, \ | 555 inline int MapTypeHandler<WireFormatLite::TYPE_##FieldType, \ |
569 Type>::SpaceUsedInMap(const TypeOnMemory& value) { \ | 556 Type>::SpaceUsedInMap(const TypeOnMemory& value) { \ |
570 return sizeof(value); \ | 557 return sizeof(value); \ |
571 } \ | 558 } \ |
572 template <typename Type> \ | 559 template <typename Type> \ |
573 inline int MapTypeHandler<WireFormatLite::TYPE_##FieldType, \ | 560 inline int MapTypeHandler<WireFormatLite::TYPE_##FieldType, \ |
574 Type>::SpaceUsedInMap(const string& value) { \ | 561 Type>::SpaceUsedInMap(const string& value) { \ |
575 return sizeof(value); \ | 562 return sizeof(value); \ |
576 } \ | 563 } \ |
577 template <typename Type> \ | 564 template <typename Type> \ |
578 inline void MapTypeHandler<WireFormatLite::TYPE_##FieldType, Type>::Clear( \ | 565 inline void MapTypeHandler<WireFormatLite::TYPE_##FieldType, Type>::Clear( \ |
579 TypeOnMemory* value, Arena* arena) { \ | 566 TypeOnMemory* value, Arena* arena) { \ |
580 value->ClearToEmpty(&::google::protobuf::internal::GetEmptyStringAlreadyInit
ed(), \ | 567 value->ClearToEmpty(&::google::protobuf::internal::GetEmptyString(), arena);
\ |
581 arena); \ | |
582 } \ | 568 } \ |
583 template <typename Type> \ | 569 template <typename Type> \ |
584 inline void MapTypeHandler<WireFormatLite::TYPE_##FieldType, Type>:: \ | 570 inline void \ |
585 ClearMaybeByDefaultEnum(TypeOnMemory* value, Arena* arena, \ | 571 MapTypeHandler<WireFormatLite::TYPE_##FieldType, \ |
586 int default_enum) { \ | 572 Type>::ClearMaybeByDefaultEnum(TypeOnMemory* value, \ |
| 573 Arena* arena, \ |
| 574 int default_enum) { \ |
587 Clear(value, arena); \ | 575 Clear(value, arena); \ |
588 } \ | 576 } \ |
589 template <typename Type> \ | 577 template <typename Type> \ |
590 inline void MapTypeHandler<WireFormatLite::TYPE_##FieldType, Type>::Merge( \ | 578 inline void MapTypeHandler<WireFormatLite::TYPE_##FieldType, Type>::Merge( \ |
591 const MapEntryAccessorType& from, TypeOnMemory* to, Arena* arena) { \ | 579 const MapEntryAccessorType& from, TypeOnMemory* to, Arena* arena) { \ |
592 to->Set(&::google::protobuf::internal::GetEmptyStringAlreadyInited(), from,
arena); \ | 580 to->Set(&::google::protobuf::internal::GetEmptyString(), from, arena);
\ |
593 } \ | 581 } \ |
594 template <typename Type> \ | 582 template <typename Type> \ |
595 void MapTypeHandler<WireFormatLite::TYPE_##FieldType, Type>::DeleteNoArena( \ | 583 void MapTypeHandler<WireFormatLite::TYPE_##FieldType, Type>::DeleteNoArena( \ |
596 TypeOnMemory& value) { \ | 584 TypeOnMemory& value) { \ |
597 value.DestroyNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyIni
ted()); \ | 585 value.DestroyNoArena(&::google::protobuf::internal::GetEmptyString());
\ |
598 } \ | 586 } \ |
599 template <typename Type> \ | 587 template <typename Type> \ |
600 inline void MapTypeHandler<WireFormatLite::TYPE_##FieldType, \ | 588 inline void MapTypeHandler<WireFormatLite::TYPE_##FieldType, \ |
601 Type>::AssignDefaultValue(TypeOnMemory* value) {} \ | 589 Type>::AssignDefaultValue(TypeOnMemory* value) {} \ |
602 template <typename Type> \ | 590 template <typename Type> \ |
603 inline void \ | 591 inline void \ |
604 MapTypeHandler<WireFormatLite::TYPE_##FieldType, Type>::Initialize( \ | 592 MapTypeHandler<WireFormatLite::TYPE_##FieldType, Type>::Initialize( \ |
605 TypeOnMemory* value, Arena* arena) { \ | 593 TypeOnMemory* value, Arena* arena) { \ |
606 value->UnsafeSetDefault( \ | 594 value->UnsafeSetDefault(&::google::protobuf::internal::GetEmptyString());
\ |
607 &::google::protobuf::internal::GetEmptyStringAlreadyInited());
\ | |
608 } \ | 595 } \ |
609 template <typename Type> \ | 596 template <typename Type> \ |
610 inline void MapTypeHandler<WireFormatLite::TYPE_##FieldType, Type>:: \ | 597 inline void \ |
611 InitializeMaybeByDefaultEnum(TypeOnMemory* value, \ | 598 MapTypeHandler<WireFormatLite::TYPE_##FieldType, \ |
612 int default_enum_value, Arena* arena) { \ | 599 Type>::InitializeMaybeByDefaultEnum(TypeOnMemory* value, \ |
| 600 int default_enum_value, \ |
| 601 Arena* arena) { \ |
613 Initialize(value, arena); \ | 602 Initialize(value, arena); \ |
614 } \ | 603 } \ |
615 template <typename Type> \ | 604 template <typename Type> \ |
616 inline typename MapTypeHandler<WireFormatLite::TYPE_##FieldType, \ | 605 inline typename MapTypeHandler<WireFormatLite::TYPE_##FieldType, \ |
617 Type>::MapEntryAccessorType* \ | 606 Type>::MapEntryAccessorType* \ |
618 MapTypeHandler<WireFormatLite::TYPE_##FieldType, Type>::EnsureMutable( \ | 607 MapTypeHandler<WireFormatLite::TYPE_##FieldType, Type>::EnsureMutable( \ |
619 TypeOnMemory* value, Arena* arena) { \ | 608 TypeOnMemory* value, Arena* arena) { \ |
620 return value->Mutable(&::google::protobuf::internal::GetEmptyStringAlreadyIn
ited(), \ | 609 return value->Mutable(&::google::protobuf::internal::GetEmptyString(), arena
); \ |
621 arena); \ | |
622 } \ | 610 } \ |
623 template <typename Type> \ | 611 template <typename Type> \ |
624 inline const typename MapTypeHandler<WireFormatLite::TYPE_##FieldType, \ | 612 inline const typename MapTypeHandler<WireFormatLite::TYPE_##FieldType, \ |
625 Type>::MapEntryAccessorType& \ | 613 Type>::MapEntryAccessorType& \ |
626 MapTypeHandler<WireFormatLite::TYPE_##FieldType, \ | 614 MapTypeHandler<WireFormatLite::TYPE_##FieldType, \ |
627 Type>::DefaultIfNotInitialized(const TypeOnMemory& value, \ | 615 Type>::DefaultIfNotInitialized(const TypeOnMemory& value, \ |
628 const TypeOnMemory& \ | 616 const TypeOnMemory& \ |
629 default_value) { \ | 617 default_value) { \ |
630 return value.Get(); \ | 618 return value.Get(&::google::protobuf::internal::GetEmptyString());
\ |
631 } \ | 619 } \ |
632 template <typename Type> \ | 620 template <typename Type> \ |
633 inline bool MapTypeHandler<WireFormatLite::TYPE_##FieldType, \ | 621 inline bool MapTypeHandler<WireFormatLite::TYPE_##FieldType, \ |
634 Type>::IsInitialized(const TypeOnMemory& value) { \ | 622 Type>::IsInitialized(const TypeOnMemory& value) { \ |
635 return true; \ | 623 return true; \ |
636 } | 624 } |
637 STRING_OR_BYTES_HANDLER_FUNCTIONS(STRING) | 625 STRING_OR_BYTES_HANDLER_FUNCTIONS(STRING) |
638 STRING_OR_BYTES_HANDLER_FUNCTIONS(BYTES) | 626 STRING_OR_BYTES_HANDLER_FUNCTIONS(BYTES) |
639 #undef STRING_OR_BYTES_HANDLER_FUNCTIONS | 627 #undef STRING_OR_BYTES_HANDLER_FUNCTIONS |
640 | 628 |
(...skipping 89 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
730 PRIMITIVE_HANDLER_FUNCTIONS(SFIXED64) | 718 PRIMITIVE_HANDLER_FUNCTIONS(SFIXED64) |
731 PRIMITIVE_HANDLER_FUNCTIONS(SFIXED32) | 719 PRIMITIVE_HANDLER_FUNCTIONS(SFIXED32) |
732 PRIMITIVE_HANDLER_FUNCTIONS(BOOL) | 720 PRIMITIVE_HANDLER_FUNCTIONS(BOOL) |
733 #undef PRIMITIVE_HANDLER_FUNCTIONS | 721 #undef PRIMITIVE_HANDLER_FUNCTIONS |
734 | 722 |
735 } // namespace internal | 723 } // namespace internal |
736 } // namespace protobuf | 724 } // namespace protobuf |
737 | 725 |
738 } // namespace google | 726 } // namespace google |
739 #endif // GOOGLE_PROTOBUF_TYPE_HANDLER_H__ | 727 #endif // GOOGLE_PROTOBUF_TYPE_HANDLER_H__ |
OLD | NEW |