aboutsummaryrefslogtreecommitdiff
path: root/src/google/protobuf/message.cc
diff options
context:
space:
mode:
Diffstat (limited to 'src/google/protobuf/message.cc')
-rw-r--r--src/google/protobuf/message.cc102
1 files changed, 40 insertions, 62 deletions
diff --git a/src/google/protobuf/message.cc b/src/google/protobuf/message.cc
index 032748bd..810db233 100644
--- a/src/google/protobuf/message.cc
+++ b/src/google/protobuf/message.cc
@@ -38,20 +38,22 @@
#include <google/protobuf/message.h>
+#include <google/protobuf/stubs/casts.h>
#include <google/protobuf/stubs/logging.h>
#include <google/protobuf/stubs/common.h>
#include <google/protobuf/stubs/mutex.h>
#include <google/protobuf/stubs/once.h>
+#include <google/protobuf/descriptor.pb.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>
-#include <google/protobuf/map_field.h>
#include <google/protobuf/descriptor.h>
#include <google/protobuf/generated_message_util.h>
+#include <google/protobuf/map_field.h>
#include <google/protobuf/reflection_ops.h>
#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>
@@ -62,14 +64,12 @@ namespace protobuf {
using internal::WireFormat;
using internal::ReflectionOps;
-Message::~Message() {}
-
void Message::MergeFrom(const Message& from) {
const Descriptor* descriptor = GetDescriptor();
GOOGLE_CHECK_EQ(from.GetDescriptor(), descriptor)
<< ": Tried to merge from a message with a different type. "
"to: " << descriptor->full_name() << ", "
- "from:" << from.GetDescriptor()->full_name();
+ "from: " << from.GetDescriptor()->full_name();
ReflectionOps::Merge(from, this);
}
@@ -82,7 +82,7 @@ void Message::CopyFrom(const Message& from) {
GOOGLE_CHECK_EQ(from.GetDescriptor(), descriptor)
<< ": Tried to copy from a message with a different type. "
"to: " << descriptor->full_name() << ", "
- "from:" << from.GetDescriptor()->full_name();
+ "from: " << from.GetDescriptor()->full_name();
ReflectionOps::Copy(from, this);
}
@@ -98,12 +98,12 @@ bool Message::IsInitialized() const {
return ReflectionOps::IsInitialized(*this);
}
-void Message::FindInitializationErrors(vector<string>* errors) const {
+void Message::FindInitializationErrors(std::vector<string>* errors) const {
return ReflectionOps::FindInitializationErrors(*this, "", errors);
}
string Message::InitializationErrorString() const {
- vector<string> errors;
+ std::vector<string> errors;
FindInitializationErrors(&errors);
return Join(errors, ", ");
}
@@ -132,12 +132,12 @@ bool Message::ParsePartialFromFileDescriptor(int file_descriptor) {
return ParsePartialFromZeroCopyStream(&input) && input.GetErrno() == 0;
}
-bool Message::ParseFromIstream(istream* input) {
+bool Message::ParseFromIstream(std::istream* input) {
io::IstreamInputStream zero_copy_input(input);
return ParseFromZeroCopyStream(&zero_copy_input) && input->eof();
}
-bool Message::ParsePartialFromIstream(istream* input) {
+bool Message::ParsePartialFromIstream(std::istream* input) {
io::IstreamInputStream zero_copy_input(input);
return ParsePartialFromZeroCopyStream(&zero_copy_input) && input->eof();
}
@@ -145,12 +145,18 @@ bool Message::ParsePartialFromIstream(istream* input) {
void Message::SerializeWithCachedSizes(
io::CodedOutputStream* output) const {
- WireFormat::SerializeWithCachedSizes(*this, GetCachedSize(), output);
+ const internal::SerializationTable* table =
+ static_cast<const internal::SerializationTable*>(InternalGetTable());
+ if (table == 0) {
+ WireFormat::SerializeWithCachedSizes(*this, GetCachedSize(), output);
+ } else {
+ internal::TableSerialize(*this, table, output);
+ }
}
-int Message::ByteSize() const {
- int size = WireFormat::ByteSize(*this);
- SetCachedSize(size);
+size_t Message::ByteSizeLong() const {
+ size_t size = WireFormat::ByteSize(*this);
+ SetCachedSize(internal::ToCachedSize(size));
return size;
}
@@ -160,21 +166,21 @@ void Message::SetCachedSize(int /* size */) const {
"Must implement one or the other.";
}
-int Message::SpaceUsed() const {
- return GetReflection()->SpaceUsed(*this);
+size_t Message::SpaceUsedLong() const {
+ return GetReflection()->SpaceUsedLong(*this);
}
bool Message::SerializeToFileDescriptor(int file_descriptor) const {
io::FileOutputStream output(file_descriptor);
- return SerializeToZeroCopyStream(&output);
+ return SerializeToZeroCopyStream(&output) && output.Flush();
}
bool Message::SerializePartialToFileDescriptor(int file_descriptor) const {
io::FileOutputStream output(file_descriptor);
- return SerializePartialToZeroCopyStream(&output);
+ return SerializePartialToZeroCopyStream(&output) && output.Flush();
}
-bool Message::SerializeToOstream(ostream* output) const {
+bool Message::SerializeToOstream(std::ostream* output) const {
{
io::OstreamOutputStream zero_copy_output(output);
if (!SerializeToZeroCopyStream(&zero_copy_output)) return false;
@@ -182,7 +188,7 @@ bool Message::SerializeToOstream(ostream* output) const {
return output->good();
}
-bool Message::SerializePartialToOstream(ostream* output) const {
+bool Message::SerializePartialToOstream(std::ostream* output) const {
io::OstreamOutputStream zero_copy_output(output);
return SerializePartialToZeroCopyStream(&zero_copy_output);
}
@@ -193,6 +199,10 @@ bool Message::SerializePartialToOstream(ostream* output) const {
Reflection::~Reflection() {}
+void Reflection::AddAllocatedMessage(Message* /* message */,
+ const FieldDescriptor* /*field */,
+ Message* /* new_entry */) const {}
+
#define HANDLE_TYPE(TYPE, CPPTYPE, CTYPE) \
template<> \
const RepeatedField<TYPE>& Reflection::GetRepeatedField<TYPE>( \
@@ -227,38 +237,6 @@ 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.";
-}
-
MapIterator Reflection::MapBegin(
Message* message,
const FieldDescriptor* field) const {
@@ -301,8 +279,8 @@ class GeneratedMessageFactory : public MessageFactory {
hash_map<const char*, RegistrationFunc*,
hash<const char*>, streq> file_map_;
- // Initialized lazily, so requires locking.
Mutex mutex_;
+ // Initialized lazily, so requires locking.
hash_map<const Descriptor*, const Message*> type_map_;
};
@@ -485,27 +463,27 @@ struct ShutdownRepeatedFieldRegister {
namespace internal {
template<>
-#if defined(_MSC_VER) && (_MSC_VER >= 1900)
-// Note: force noinline to workaround MSVC 2015 compiler bug, issue #240
-GOOGLE_ATTRIBUTE_NOINLINE
+#if defined(_MSC_VER) && (_MSC_VER >= 1800)
+// Note: force noinline to workaround MSVC compiler bug with /Zc:inline, issue #240
+GOOGLE_PROTOBUF_ATTRIBUTE_NOINLINE
#endif
Message* GenericTypeHandler<Message>::NewFromPrototype(
const Message* prototype, google::protobuf::Arena* arena) {
return prototype->New(arena);
}
template<>
-#if defined(_MSC_VER) && (_MSC_VER >= 1900)
-// Note: force noinline to workaround MSVC 2015 compiler bug, issue #240
-GOOGLE_ATTRIBUTE_NOINLINE
+#if defined(_MSC_VER) && (_MSC_VER >= 1800)
+// Note: force noinline to workaround MSVC compiler bug with /Zc:inline, issue #240
+GOOGLE_PROTOBUF_ATTRIBUTE_NOINLINE
#endif
google::protobuf::Arena* GenericTypeHandler<Message>::GetArena(
Message* value) {
return value->GetArena();
}
template<>
-#if defined(_MSC_VER) && (_MSC_VER >= 1900)
-// Note: force noinline to workaround MSVC 2015 compiler bug, issue #240
-GOOGLE_ATTRIBUTE_NOINLINE
+#if defined(_MSC_VER) && (_MSC_VER >= 1800)
+// Note: force noinline to workaround MSVC compiler bug with /Zc:inline, issue #240
+GOOGLE_PROTOBUF_ATTRIBUTE_NOINLINE
#endif
void* GenericTypeHandler<Message>::GetMaybeArenaPointer(
Message* value) {