| 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 65 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 76 | 76 |
| 77 const Descriptor* descriptor_; | 77 const Descriptor* descriptor_; |
| 78 const Reflection* reflection_; | 78 const Reflection* reflection_; |
| 79 }; | 79 }; |
| 80 | 80 |
| 81 // MapEntry is the returned google::protobuf::Message when calling AddMessage of | 81 // MapEntry is the returned google::protobuf::Message when calling AddMessage of |
| 82 // google::protobuf::Reflection. In order to let it work with generated message | 82 // google::protobuf::Reflection. In order to let it work with generated message |
| 83 // reflection, its in-memory type is the same as generated message with the same | 83 // reflection, its in-memory type is the same as generated message with the same |
| 84 // fields. However, in order to decide the in-memory type of key/value, we need | 84 // fields. However, in order to decide the in-memory type of key/value, we need |
| 85 // to know both their cpp type in generated api and proto type. In | 85 // to know both their cpp type in generated api and proto type. In |
| 86 // implmentation, all in-memory types have related wire format functions to | 86 // implementation, all in-memory types have related wire format functions to |
| 87 // support except ArenaStringPtr. Therefore, we need to define another type with | 87 // support except ArenaStringPtr. Therefore, we need to define another type with |
| 88 // supporting wire format functions. Since this type is only used as return type | 88 // supporting wire format functions. Since this type is only used as return type |
| 89 // of MapEntry accessors, it's named MapEntry accessor type. | 89 // of MapEntry accessors, it's named MapEntry accessor type. |
| 90 // | 90 // |
| 91 // cpp type: the type visible to users in public API. | 91 // cpp type: the type visible to users in public API. |
| 92 // proto type: WireFormatLite::FieldType of the field. | 92 // proto type: WireFormatLite::FieldType of the field. |
| 93 // in-memory type: type of the data member used to stored this field. | 93 // in-memory type: type of the data member used to stored this field. |
| 94 // MapEntry accessor type: type used in MapEntry getters/mutators to access the | 94 // MapEntry accessor type: type used in MapEntry getters/mutators to access the |
| 95 // field. | 95 // field. |
| 96 // | 96 // |
| (...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 151 inline ValueMapEntryAccessorType* mutable_value() { | 151 inline ValueMapEntryAccessorType* mutable_value() { |
| 152 return entry_lite_.mutable_value(); | 152 return entry_lite_.mutable_value(); |
| 153 } | 153 } |
| 154 | 154 |
| 155 // implements Message ============================================= | 155 // implements Message ============================================= |
| 156 | 156 |
| 157 bool MergePartialFromCodedStream(::google::protobuf::io::CodedInputStream* inp
ut) { | 157 bool MergePartialFromCodedStream(::google::protobuf::io::CodedInputStream* inp
ut) { |
| 158 return entry_lite_.MergePartialFromCodedStream(input); | 158 return entry_lite_.MergePartialFromCodedStream(input); |
| 159 } | 159 } |
| 160 | 160 |
| 161 int ByteSize() const { | 161 size_t ByteSizeLong() const { |
| 162 return entry_lite_.ByteSize(); | 162 return entry_lite_.ByteSizeLong(); |
| 163 } | 163 } |
| 164 | 164 |
| 165 void SerializeWithCachedSizes(::google::protobuf::io::CodedOutputStream* outpu
t) const { | 165 void SerializeWithCachedSizes(::google::protobuf::io::CodedOutputStream* outpu
t) const { |
| 166 entry_lite_.SerializeWithCachedSizes(output); | 166 entry_lite_.SerializeWithCachedSizes(output); |
| 167 } | 167 } |
| 168 | 168 |
| 169 ::google::protobuf::uint8* SerializeWithCachedSizesToArray(::google::protobuf:
:uint8* output) const { | 169 ::google::protobuf::uint8* InternalSerializeWithCachedSizesToArray(bool determ
inistic, |
| 170 return entry_lite_.SerializeWithCachedSizesToArray(output); | 170 ::google::protobuf::uint8* ou
tput) const { |
| 171 return entry_lite_.InternalSerializeWithCachedSizesToArray(deterministic, |
| 172 output); |
| 171 } | 173 } |
| 172 | 174 |
| 173 int GetCachedSize() const { | 175 int GetCachedSize() const { |
| 174 return entry_lite_.GetCachedSize(); | 176 return entry_lite_.GetCachedSize(); |
| 175 } | 177 } |
| 176 | 178 |
| 177 bool IsInitialized() const { | 179 bool IsInitialized() const { |
| 178 return entry_lite_.IsInitialized(); | 180 return entry_lite_.IsInitialized(); |
| 179 } | 181 } |
| 180 | 182 |
| (...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 235 Arena* GetArena() const { | 237 Arena* GetArena() const { |
| 236 return entry_lite_.GetArena(); | 238 return entry_lite_.GetArena(); |
| 237 } | 239 } |
| 238 | 240 |
| 239 // Create default MapEntry instance for given descriptor. Descriptor has to be | 241 // Create default MapEntry instance for given descriptor. Descriptor has to be |
| 240 // given when creating default MapEntry instance because different map field | 242 // given when creating default MapEntry instance because different map field |
| 241 // may have the same type and MapEntry class. The given descriptor is needed | 243 // may have the same type and MapEntry class. The given descriptor is needed |
| 242 // to distinguish instances of the same MapEntry class. | 244 // to distinguish instances of the same MapEntry class. |
| 243 static MapEntry* CreateDefaultInstance(const Descriptor* descriptor) { | 245 static MapEntry* CreateDefaultInstance(const Descriptor* descriptor) { |
| 244 MapEntry* entry = new MapEntry; | 246 MapEntry* entry = new MapEntry; |
| 247 ReflectionSchema schema = { |
| 248 entry, |
| 249 offsets_, |
| 250 has_bits_, |
| 251 GOOGLE_PROTOBUF_GENERATED_MESSAGE_FIELD_OFFSET(MapEntry, entry_lite_._ha
s_bits_), |
| 252 GOOGLE_PROTOBUF_GENERATED_MESSAGE_FIELD_OFFSET(MapEntry, _internal_metad
ata_), |
| 253 -1, |
| 254 NULL, |
| 255 -1, |
| 256 sizeof(MapEntry)}; |
| 245 const Reflection* reflection = new GeneratedMessageReflection( | 257 const Reflection* reflection = new GeneratedMessageReflection( |
| 246 descriptor, entry, offsets_, | 258 descriptor, schema, DescriptorPool::generated_pool(), |
| 247 GOOGLE_PROTOBUF_GENERATED_MESSAGE_FIELD_OFFSET(MapEntry, entry_lite_._ha
s_bits_), | 259 MessageFactory::generated_factory()); |
| 248 GOOGLE_PROTOBUF_GENERATED_MESSAGE_FIELD_OFFSET(MapEntry, _unknown_fields
_), -1, | |
| 249 DescriptorPool::generated_pool(), | |
| 250 ::google::protobuf::MessageFactory::generated_factory(), | |
| 251 sizeof(MapEntry), | |
| 252 GOOGLE_PROTOBUF_GENERATED_MESSAGE_FIELD_OFFSET(MapEntry, _internal_metad
ata_)); | |
| 253 entry->descriptor_ = descriptor; | 260 entry->descriptor_ = descriptor; |
| 254 entry->reflection_ = reflection; | 261 entry->reflection_ = reflection; |
| 255 entry->set_default_instance(entry); | 262 entry->set_default_instance(entry); |
| 256 entry->InitAsDefaultInstance(); | 263 entry->InitAsDefaultInstance(); |
| 257 RegisterMapEntryDefaultInstance(entry); | 264 RegisterMapEntryDefaultInstance(entry); |
| 258 return entry; | 265 return entry; |
| 259 } | 266 } |
| 260 | 267 |
| 261 private: | 268 private: |
| 262 MapEntry() | 269 MapEntry() |
| 263 : _internal_metadata_(NULL), default_instance_(NULL), entry_lite_() {} | 270 : _internal_metadata_(NULL), default_instance_(NULL), entry_lite_() {} |
| 264 | 271 |
| 265 explicit MapEntry(Arena* arena) | 272 explicit MapEntry(Arena* arena) |
| 266 : _internal_metadata_(arena), | 273 : _internal_metadata_(arena), |
| 267 default_instance_(NULL), | 274 default_instance_(NULL), |
| 268 entry_lite_(arena) {} | 275 entry_lite_(arena) {} |
| 269 | 276 |
| 270 inline Arena* GetArenaNoVirtual() const { | 277 inline Arena* GetArenaNoVirtual() const { |
| 271 return entry_lite_.GetArenaNoVirtual(); | 278 return entry_lite_.GetArenaNoVirtual(); |
| 272 } | 279 } |
| 273 | 280 |
| 274 void set_default_instance(MapEntry* default_instance) { | 281 void set_default_instance(MapEntry* default_instance) { |
| 275 default_instance_ = default_instance; | 282 default_instance_ = default_instance; |
| 276 entry_lite_.set_default_instance(&default_instance->entry_lite_); | 283 entry_lite_.set_default_instance(&default_instance->entry_lite_); |
| 277 } | 284 } |
| 278 | 285 |
| 279 static int offsets_[2]; | 286 static uint32 offsets_[2]; |
| 280 UnknownFieldSet _unknown_fields_; | 287 static uint32 has_bits_[2]; |
| 281 InternalMetadataWithArena _internal_metadata_; | 288 InternalMetadataWithArena _internal_metadata_; |
| 282 MapEntry* default_instance_; | 289 MapEntry* default_instance_; |
| 283 EntryLiteType entry_lite_; | 290 EntryLiteType entry_lite_; |
| 284 | 291 |
| 285 friend class ::google::protobuf::Arena; | 292 friend class ::google::protobuf::Arena; |
| 286 typedef void InternalArenaConstructable_; | 293 typedef void InternalArenaConstructable_; |
| 287 typedef void DestructorSkippable_; | 294 typedef void DestructorSkippable_; |
| 288 template <typename K, typename V, WireFormatLite::FieldType k_wire_type, | 295 template <typename K, typename V, WireFormatLite::FieldType k_wire_type, |
| 289 WireFormatLite::FieldType, int default_enum> | 296 WireFormatLite::FieldType, int default_enum> |
| 290 friend class internal::MapField; | 297 friend class internal::MapField; |
| 291 friend class internal::GeneratedMessageReflection; | 298 friend class internal::GeneratedMessageReflection; |
| 292 | 299 |
| 293 GOOGLE_DISALLOW_EVIL_CONSTRUCTORS(MapEntry); | 300 GOOGLE_DISALLOW_EVIL_CONSTRUCTORS(MapEntry); |
| 294 }; | 301 }; |
| 295 | 302 |
| 296 template <typename Key, typename Value, WireFormatLite::FieldType kKeyFieldType, | 303 template <typename Key, typename Value, WireFormatLite::FieldType kKeyFieldType, |
| 297 WireFormatLite::FieldType kValueFieldType, int default_enum_value> | 304 WireFormatLite::FieldType kValueFieldType, int default_enum_value> |
| 298 int MapEntry<Key, Value, kKeyFieldType, kValueFieldType, | 305 uint32 MapEntry<Key, Value, kKeyFieldType, kValueFieldType, |
| 299 default_enum_value>::offsets_[2] = { | 306 default_enum_value>::offsets_[2] = { |
| 300 GOOGLE_PROTOBUF_GENERATED_MESSAGE_FIELD_OFFSET(MapEntry, entry_lite_.key_), | 307 GOOGLE_PROTOBUF_GENERATED_MESSAGE_FIELD_OFFSET(MapEntry, entry_lite_.key_), |
| 301 GOOGLE_PROTOBUF_GENERATED_MESSAGE_FIELD_OFFSET(MapEntry, entry_lite_.value_)
, | 308 GOOGLE_PROTOBUF_GENERATED_MESSAGE_FIELD_OFFSET(MapEntry, entry_lite_.value_)
, |
| 302 }; | 309 }; |
| 303 | 310 |
| 311 template <typename Key, typename Value, WireFormatLite::FieldType kKeyFieldType, |
| 312 WireFormatLite::FieldType kValueFieldType, int default_enum_value> |
| 313 uint32 MapEntry<Key, Value, kKeyFieldType, kValueFieldType, |
| 314 default_enum_value>::has_bits_[2] = {0, 1}; |
| 315 |
| 304 } // namespace internal | 316 } // namespace internal |
| 305 } // namespace protobuf | 317 } // namespace protobuf |
| 306 | 318 |
| 307 } // namespace google | 319 } // namespace google |
| 308 #endif // GOOGLE_PROTOBUF_MAP_ENTRY_H__ | 320 #endif // GOOGLE_PROTOBUF_MAP_ENTRY_H__ |
| OLD | NEW |