| 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 // implementation, all in-memory types have related wire format functions to | 86 // implmentation, 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 size_t ByteSizeLong() const { | 161 int ByteSize() const { |
| 162 return entry_lite_.ByteSizeLong(); | 162 return entry_lite_.ByteSize(); |
| 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* InternalSerializeWithCachedSizesToArray(bool determ
inistic, | 169 ::google::protobuf::uint8* SerializeWithCachedSizesToArray(::google::protobuf:
:uint8* output) const { |
| 170 ::google::protobuf::uint8* ou
tput) const { | 170 return entry_lite_.SerializeWithCachedSizesToArray(output); |
| 171 return entry_lite_.InternalSerializeWithCachedSizesToArray(deterministic, | |
| 172 output); | |
| 173 } | 171 } |
| 174 | 172 |
| 175 int GetCachedSize() const { | 173 int GetCachedSize() const { |
| 176 return entry_lite_.GetCachedSize(); | 174 return entry_lite_.GetCachedSize(); |
| 177 } | 175 } |
| 178 | 176 |
| 179 bool IsInitialized() const { | 177 bool IsInitialized() const { |
| 180 return entry_lite_.IsInitialized(); | 178 return entry_lite_.IsInitialized(); |
| 181 } | 179 } |
| 182 | 180 |
| (...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 237 Arena* GetArena() const { | 235 Arena* GetArena() const { |
| 238 return entry_lite_.GetArena(); | 236 return entry_lite_.GetArena(); |
| 239 } | 237 } |
| 240 | 238 |
| 241 // Create default MapEntry instance for given descriptor. Descriptor has to be | 239 // Create default MapEntry instance for given descriptor. Descriptor has to be |
| 242 // given when creating default MapEntry instance because different map field | 240 // given when creating default MapEntry instance because different map field |
| 243 // may have the same type and MapEntry class. The given descriptor is needed | 241 // may have the same type and MapEntry class. The given descriptor is needed |
| 244 // to distinguish instances of the same MapEntry class. | 242 // to distinguish instances of the same MapEntry class. |
| 245 static MapEntry* CreateDefaultInstance(const Descriptor* descriptor) { | 243 static MapEntry* CreateDefaultInstance(const Descriptor* descriptor) { |
| 246 MapEntry* entry = new MapEntry; | 244 MapEntry* entry = new MapEntry; |
| 247 ReflectionSchema schema = { | 245 const Reflection* reflection = new GeneratedMessageReflection( |
| 248 entry, | 246 descriptor, entry, offsets_, |
| 249 offsets_, | |
| 250 has_bits_, | |
| 251 GOOGLE_PROTOBUF_GENERATED_MESSAGE_FIELD_OFFSET(MapEntry, entry_lite_._ha
s_bits_), | 247 GOOGLE_PROTOBUF_GENERATED_MESSAGE_FIELD_OFFSET(MapEntry, entry_lite_._ha
s_bits_), |
| 252 GOOGLE_PROTOBUF_GENERATED_MESSAGE_FIELD_OFFSET(MapEntry, _internal_metad
ata_), | 248 GOOGLE_PROTOBUF_GENERATED_MESSAGE_FIELD_OFFSET(MapEntry, _unknown_fields
_), -1, |
| 253 -1, | 249 DescriptorPool::generated_pool(), |
| 254 NULL, | 250 ::google::protobuf::MessageFactory::generated_factory(), |
| 255 -1, | 251 sizeof(MapEntry), |
| 256 sizeof(MapEntry)}; | 252 GOOGLE_PROTOBUF_GENERATED_MESSAGE_FIELD_OFFSET(MapEntry, _internal_metad
ata_)); |
| 257 const Reflection* reflection = new GeneratedMessageReflection( | |
| 258 descriptor, schema, DescriptorPool::generated_pool(), | |
| 259 MessageFactory::generated_factory()); | |
| 260 entry->descriptor_ = descriptor; | 253 entry->descriptor_ = descriptor; |
| 261 entry->reflection_ = reflection; | 254 entry->reflection_ = reflection; |
| 262 entry->set_default_instance(entry); | 255 entry->set_default_instance(entry); |
| 263 entry->InitAsDefaultInstance(); | 256 entry->InitAsDefaultInstance(); |
| 264 RegisterMapEntryDefaultInstance(entry); | 257 RegisterMapEntryDefaultInstance(entry); |
| 265 return entry; | 258 return entry; |
| 266 } | 259 } |
| 267 | 260 |
| 268 private: | 261 private: |
| 269 MapEntry() | 262 MapEntry() |
| 270 : _internal_metadata_(NULL), default_instance_(NULL), entry_lite_() {} | 263 : _internal_metadata_(NULL), default_instance_(NULL), entry_lite_() {} |
| 271 | 264 |
| 272 explicit MapEntry(Arena* arena) | 265 explicit MapEntry(Arena* arena) |
| 273 : _internal_metadata_(arena), | 266 : _internal_metadata_(arena), |
| 274 default_instance_(NULL), | 267 default_instance_(NULL), |
| 275 entry_lite_(arena) {} | 268 entry_lite_(arena) {} |
| 276 | 269 |
| 277 inline Arena* GetArenaNoVirtual() const { | 270 inline Arena* GetArenaNoVirtual() const { |
| 278 return entry_lite_.GetArenaNoVirtual(); | 271 return entry_lite_.GetArenaNoVirtual(); |
| 279 } | 272 } |
| 280 | 273 |
| 281 void set_default_instance(MapEntry* default_instance) { | 274 void set_default_instance(MapEntry* default_instance) { |
| 282 default_instance_ = default_instance; | 275 default_instance_ = default_instance; |
| 283 entry_lite_.set_default_instance(&default_instance->entry_lite_); | 276 entry_lite_.set_default_instance(&default_instance->entry_lite_); |
| 284 } | 277 } |
| 285 | 278 |
| 286 static uint32 offsets_[2]; | 279 static int offsets_[2]; |
| 287 static uint32 has_bits_[2]; | 280 UnknownFieldSet _unknown_fields_; |
| 288 InternalMetadataWithArena _internal_metadata_; | 281 InternalMetadataWithArena _internal_metadata_; |
| 289 MapEntry* default_instance_; | 282 MapEntry* default_instance_; |
| 290 EntryLiteType entry_lite_; | 283 EntryLiteType entry_lite_; |
| 291 | 284 |
| 292 friend class ::google::protobuf::Arena; | 285 friend class ::google::protobuf::Arena; |
| 293 typedef void InternalArenaConstructable_; | 286 typedef void InternalArenaConstructable_; |
| 294 typedef void DestructorSkippable_; | 287 typedef void DestructorSkippable_; |
| 295 template <typename K, typename V, WireFormatLite::FieldType k_wire_type, | 288 template <typename K, typename V, WireFormatLite::FieldType k_wire_type, |
| 296 WireFormatLite::FieldType, int default_enum> | 289 WireFormatLite::FieldType, int default_enum> |
| 297 friend class internal::MapField; | 290 friend class internal::MapField; |
| 298 friend class internal::GeneratedMessageReflection; | 291 friend class internal::GeneratedMessageReflection; |
| 299 | 292 |
| 300 GOOGLE_DISALLOW_EVIL_CONSTRUCTORS(MapEntry); | 293 GOOGLE_DISALLOW_EVIL_CONSTRUCTORS(MapEntry); |
| 301 }; | 294 }; |
| 302 | 295 |
| 303 template <typename Key, typename Value, WireFormatLite::FieldType kKeyFieldType, | 296 template <typename Key, typename Value, WireFormatLite::FieldType kKeyFieldType, |
| 304 WireFormatLite::FieldType kValueFieldType, int default_enum_value> | 297 WireFormatLite::FieldType kValueFieldType, int default_enum_value> |
| 305 uint32 MapEntry<Key, Value, kKeyFieldType, kValueFieldType, | 298 int MapEntry<Key, Value, kKeyFieldType, kValueFieldType, |
| 306 default_enum_value>::offsets_[2] = { | 299 default_enum_value>::offsets_[2] = { |
| 307 GOOGLE_PROTOBUF_GENERATED_MESSAGE_FIELD_OFFSET(MapEntry, entry_lite_.key_), | 300 GOOGLE_PROTOBUF_GENERATED_MESSAGE_FIELD_OFFSET(MapEntry, entry_lite_.key_), |
| 308 GOOGLE_PROTOBUF_GENERATED_MESSAGE_FIELD_OFFSET(MapEntry, entry_lite_.value_)
, | 301 GOOGLE_PROTOBUF_GENERATED_MESSAGE_FIELD_OFFSET(MapEntry, entry_lite_.value_)
, |
| 309 }; | 302 }; |
| 310 | 303 |
| 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 | |
| 316 } // namespace internal | 304 } // namespace internal |
| 317 } // namespace protobuf | 305 } // namespace protobuf |
| 318 | 306 |
| 319 } // namespace google | 307 } // namespace google |
| 320 #endif // GOOGLE_PROTOBUF_MAP_ENTRY_H__ | 308 #endif // GOOGLE_PROTOBUF_MAP_ENTRY_H__ |
| OLD | NEW |