aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/google/protobuf/message.cc
diff options
context:
space:
mode:
authorGravatar Feng Xiao <xfxyjwf@gmail.com>2014-11-10 17:34:54 -0800
committerGravatar Feng Xiao <xfxyjwf@gmail.com>2014-11-10 17:34:54 -0800
commit6ef984af4b0c63c1c33127a12dcfc8e6359f0c9e (patch)
treed17c61ff9f3ae28224fbddac6d26bfc59e2cf755 /src/google/protobuf/message.cc
parentbaca1a8a1aa180c42de6278d3b8286c4496c6a10 (diff)
Down-integrate from internal code base.
Diffstat (limited to 'src/google/protobuf/message.cc')
-rw-r--r--src/google/protobuf/message.cc89
1 files changed, 89 insertions, 0 deletions
diff --git a/src/google/protobuf/message.cc b/src/google/protobuf/message.cc
index 1324ed9b..aab00fdf 100644
--- a/src/google/protobuf/message.cc
+++ b/src/google/protobuf/message.cc
@@ -40,6 +40,7 @@
#include <google/protobuf/stubs/common.h>
#include <google/protobuf/stubs/once.h>
+#include <google/protobuf/reflection_internal.h>
#include <google/protobuf/io/coded_stream.h>
#include <google/protobuf/io/zero_copy_stream_impl.h>
#include <google/protobuf/descriptor.pb.h>
@@ -49,6 +50,7 @@
#include <google/protobuf/wire_format.h>
#include <google/protobuf/stubs/strutil.h>
#include <google/protobuf/stubs/map_util.h>
+#include <google/protobuf/stubs/singleton.h>
#include <google/protobuf/stubs/stl_util.h>
namespace google {
@@ -222,6 +224,38 @@ void* Reflection::MutableRawRepeatedString(
}
+// Default EnumValue API implementations. Real reflection implementations should
+// override these. However, there are several legacy implementations that do
+// not, and cannot easily be changed at the same time as the Reflection API, so
+// we provide these for now.
+// TODO: Remove these once all Reflection implementations are updated.
+int Reflection::GetEnumValue(const Message& message,
+ const FieldDescriptor* field) const {
+ GOOGLE_LOG(FATAL) << "Unimplemented EnumValue API.";
+ return 0;
+}
+void Reflection::SetEnumValue(Message* message,
+ const FieldDescriptor* field,
+ int value) const {
+ GOOGLE_LOG(FATAL) << "Unimplemented EnumValue API.";
+}
+int Reflection::GetRepeatedEnumValue(
+ const Message& message,
+ const FieldDescriptor* field, int index) const {
+ GOOGLE_LOG(FATAL) << "Unimplemented EnumValue API.";
+ return 0;
+}
+void Reflection::SetRepeatedEnumValue(Message* message,
+ const FieldDescriptor* field, int index,
+ int value) const {
+ GOOGLE_LOG(FATAL) << "Unimplemented EnumValue API.";
+}
+void Reflection::AddEnumValue(Message* message,
+ const FieldDescriptor* field,
+ int value) const {
+ GOOGLE_LOG(FATAL) << "Unimplemented EnumValue API.";
+}
+
// =============================================================================
// MessageFactory
@@ -354,5 +388,60 @@ void MessageFactory::InternalRegisterGeneratedMessage(
}
+MessageFactory* Reflection::GetMessageFactory() const {
+ GOOGLE_LOG(FATAL) << "Not implemented.";
+ return NULL;
+}
+
+void* Reflection::RepeatedFieldData(
+ Message* message, const FieldDescriptor* field,
+ FieldDescriptor::CppType cpp_type,
+ const Descriptor* message_type) const {
+ GOOGLE_LOG(FATAL) << "Not implemented.";
+ return NULL;
+}
+
+namespace internal {
+RepeatedFieldAccessor::~RepeatedFieldAccessor() {
+}
+} // namespace internal
+
+const internal::RepeatedFieldAccessor* Reflection::RepeatedFieldAccessor(
+ const FieldDescriptor* field) const {
+ GOOGLE_CHECK(field->is_repeated());
+ switch (field->cpp_type()) {
+#define HANDLE_PRIMITIVE_TYPE(TYPE, type) \
+ case FieldDescriptor::CPPTYPE_ ## TYPE: \
+ return internal::Singleton<internal::RepeatedFieldPrimitiveAccessor<type> >::get();
+ HANDLE_PRIMITIVE_TYPE(INT32, int32)
+ HANDLE_PRIMITIVE_TYPE(UINT32, uint32)
+ HANDLE_PRIMITIVE_TYPE(INT64, int64)
+ HANDLE_PRIMITIVE_TYPE(UINT64, uint64)
+ HANDLE_PRIMITIVE_TYPE(FLOAT, float)
+ HANDLE_PRIMITIVE_TYPE(DOUBLE, double)
+ HANDLE_PRIMITIVE_TYPE(BOOL, bool)
+ HANDLE_PRIMITIVE_TYPE(ENUM, int32)
+#undef HANDLE_PRIMITIVE_TYPE
+ case FieldDescriptor::CPPTYPE_STRING:
+ switch (field->options().ctype()) {
+ default:
+ case FieldOptions::STRING:
+ return internal::Singleton<internal::RepeatedPtrFieldStringAccessor>::get();
+ }
+ break;
+ case FieldDescriptor::CPPTYPE_MESSAGE:
+ return internal::Singleton<internal::RepeatedPtrFieldMessageAccessor>::get();
+ }
+ GOOGLE_LOG(FATAL) << "Should not reach here.";
+ return NULL;
+}
+
+namespace internal {
+// Macro defined in repeated_field.h. We can only define the Message-specific
+// GenericTypeHandler specializations here because we depend on Message, which
+// is not part of proto2-lite hence is not available in repeated_field.h.
+DEFINE_SPECIALIZATIONS_FOR_BASE_PROTO_TYPES_NOINLINE(Message);
+} // namespace internal
+
} // namespace protobuf
} // namespace google