diff options
Diffstat (limited to 'src/google/protobuf/util/internal/protostream_objectsource.cc')
-rw-r--r-- | src/google/protobuf/util/internal/protostream_objectsource.cc | 132 |
1 files changed, 69 insertions, 63 deletions
diff --git a/src/google/protobuf/util/internal/protostream_objectsource.cc b/src/google/protobuf/util/internal/protostream_objectsource.cc index b0d86c17..97a8bb48 100644 --- a/src/google/protobuf/util/internal/protostream_objectsource.cc +++ b/src/google/protobuf/util/internal/protostream_objectsource.cc @@ -30,9 +30,9 @@ #include <google/protobuf/util/internal/protostream_objectsource.h> +#include <unordered_map> #include <utility> -#include <google/protobuf/stubs/casts.h> #include <google/protobuf/stubs/logging.h> #include <google/protobuf/stubs/common.h> #include <google/protobuf/stubs/stringprintf.h> @@ -40,16 +40,22 @@ #include <google/protobuf/io/coded_stream.h> #include <google/protobuf/io/zero_copy_stream_impl.h> #include <google/protobuf/descriptor.h> +#include <google/protobuf/stubs/once.h> #include <google/protobuf/wire_format.h> #include <google/protobuf/wire_format_lite.h> #include <google/protobuf/util/internal/field_mask_utility.h> #include <google/protobuf/util/internal/constants.h> #include <google/protobuf/util/internal/utility.h> #include <google/protobuf/stubs/strutil.h> +#include <google/protobuf/stubs/casts.h> + + #include <google/protobuf/stubs/map_util.h> #include <google/protobuf/stubs/status_macros.h> +#include <google/protobuf/port_def.inc> + namespace google { namespace protobuf { namespace util { @@ -60,12 +66,8 @@ using util::error::Code; using util::error::INTERNAL; } namespace converter { - -using google::protobuf::Descriptor; -using google::protobuf::EnumValueDescriptor; -using google::protobuf::FieldDescriptor; -using google::protobuf::internal::WireFormat; -using google::protobuf::internal::WireFormatLite; +using ::PROTOBUF_NAMESPACE_ID::internal::WireFormat; +using ::PROTOBUF_NAMESPACE_ID::internal::WireFormatLite; using util::Status; using util::StatusOr; @@ -113,7 +115,7 @@ StatusOr<string> MapKeyDefaultValueAsString( ProtoStreamObjectSource::ProtoStreamObjectSource( - google::protobuf::io::CodedInputStream* stream, TypeResolver* type_resolver, + io::CodedInputStream* stream, TypeResolver* type_resolver, const google::protobuf::Type& type) : stream_(stream), typeinfo_(TypeInfo::NewTypeInfo(type_resolver)), @@ -131,7 +133,7 @@ ProtoStreamObjectSource::ProtoStreamObjectSource( } ProtoStreamObjectSource::ProtoStreamObjectSource( - google::protobuf::io::CodedInputStream* stream, const TypeInfo* typeinfo, + io::CodedInputStream* stream, const TypeInfo* typeinfo, const google::protobuf::Type& type) : stream_(stream), typeinfo_(typeinfo), @@ -194,7 +196,7 @@ Status ProtoStreamObjectSource::WriteMessage(const google::protobuf::Type& type, string field_name; // last_tag set to dummy value that is different from tag. uint32 tag = stream_->ReadTag(), last_tag = tag + 1; - google::protobuf::UnknownFieldSet unknown_fields; + UnknownFieldSet unknown_fields; if (include_start_and_end) { ow->StartObject(name); @@ -246,8 +248,8 @@ Status ProtoStreamObjectSource::WriteMessage(const google::protobuf::Type& type, } StatusOr<uint32> ProtoStreamObjectSource::RenderList( - const google::protobuf::Field* field, StringPiece name, uint32 list_tag, - ObjectWriter* ow) const { + const google::protobuf::Field* field, StringPiece name, + uint32 list_tag, ObjectWriter* ow) const { uint32 tag_to_return = 0; ow->StartList(name); if (IsPackable(*field) && @@ -268,8 +270,8 @@ StatusOr<uint32> ProtoStreamObjectSource::RenderList( } StatusOr<uint32> ProtoStreamObjectSource::RenderMap( - const google::protobuf::Field* field, StringPiece name, uint32 list_tag, - ObjectWriter* ow) const { + const google::protobuf::Field* field, StringPiece name, + uint32 list_tag, ObjectWriter* ow) const { const google::protobuf::Type* field_type = typeinfo_->GetTypeByTypeUrl(field->type_url()); uint32 tag_to_return = 0; @@ -332,9 +334,9 @@ Status ProtoStreamObjectSource::RenderTimestamp( int64 seconds = p.first; int32 nanos = p.second; if (seconds > kTimestampMaxSeconds || seconds < kTimestampMinSeconds) { - return Status( - util::error::INTERNAL, - StrCat("Timestamp seconds exceeds limit for field: ", field_name)); + return Status(util::error::INTERNAL, + StrCat("Timestamp seconds exceeds limit for field: ", + field_name)); } if (nanos < 0 || nanos >= kNanosPerSecond) { @@ -370,10 +372,11 @@ Status ProtoStreamObjectSource::RenderDuration( string sign = ""; if (seconds < 0) { if (nanos > 0) { - return Status(util::error::INTERNAL, - StrCat("Duration nanos is non-negative, but seconds is " - "negative for field: ", - field_name)); + return Status( + util::error::INTERNAL, + StrCat("Duration nanos is non-negative, but seconds is " + "negative for field: ", + field_name)); } sign = "-"; seconds = -seconds; @@ -383,7 +386,7 @@ Status ProtoStreamObjectSource::RenderDuration( nanos = -nanos; } string formatted_duration = StringPrintf( - "%s%lld%ss", sign.c_str(), seconds, + "%s%lld%ss", sign.c_str(), static_cast<long long>(seconds), // NOLINT FormatNanos(nanos, os->add_trailing_zeros_for_timestamp_and_duration_) .c_str()); ow->RenderString(field_name, formatted_duration); @@ -400,7 +403,7 @@ Status ProtoStreamObjectSource::RenderDouble(const ProtoStreamObjectSource* os, os->stream_->ReadLittleEndian64(&buffer64); os->stream_->ReadTag(); } - ow->RenderDouble(field_name, bit_cast<double>(buffer64)); + ow->RenderDouble(field_name, ::google::protobuf::bit_cast<double>(buffer64)); return util::Status(); } @@ -414,7 +417,7 @@ Status ProtoStreamObjectSource::RenderFloat(const ProtoStreamObjectSource* os, os->stream_->ReadLittleEndian32(&buffer32); os->stream_->ReadTag(); } - ow->RenderFloat(field_name, bit_cast<float>(buffer32)); + ow->RenderFloat(field_name, ::google::protobuf::bit_cast<float>(buffer32)); return util::Status(); } @@ -428,7 +431,7 @@ Status ProtoStreamObjectSource::RenderInt64(const ProtoStreamObjectSource* os, os->stream_->ReadVarint64(&buffer64); os->stream_->ReadTag(); } - ow->RenderInt64(field_name, bit_cast<int64>(buffer64)); + ow->RenderInt64(field_name, ::google::protobuf::bit_cast<int64>(buffer64)); return util::Status(); } @@ -442,7 +445,7 @@ Status ProtoStreamObjectSource::RenderUInt64(const ProtoStreamObjectSource* os, os->stream_->ReadVarint64(&buffer64); os->stream_->ReadTag(); } - ow->RenderUint64(field_name, bit_cast<uint64>(buffer64)); + ow->RenderUint64(field_name, ::google::protobuf::bit_cast<uint64>(buffer64)); return util::Status(); } @@ -456,7 +459,7 @@ Status ProtoStreamObjectSource::RenderInt32(const ProtoStreamObjectSource* os, os->stream_->ReadVarint32(&buffer32); os->stream_->ReadTag(); } - ow->RenderInt32(field_name, bit_cast<int32>(buffer32)); + ow->RenderInt32(field_name, ::google::protobuf::bit_cast<int32>(buffer32)); return util::Status(); } @@ -470,7 +473,7 @@ Status ProtoStreamObjectSource::RenderUInt32(const ProtoStreamObjectSource* os, os->stream_->ReadVarint32(&buffer32); os->stream_->ReadTag(); } - ow->RenderUint32(field_name, bit_cast<uint32>(buffer32)); + ow->RenderUint32(field_name, ::google::protobuf::bit_cast<uint32>(buffer32)); return util::Status(); } @@ -642,8 +645,8 @@ Status ProtoStreamObjectSource::RenderAny(const ProtoStreamObjectSource* os, // nested_type cannot be null at this time. const google::protobuf::Type* nested_type = resolved_type.ValueOrDie(); - google::protobuf::io::ArrayInputStream zero_copy_stream(value.data(), value.size()); - google::protobuf::io::CodedInputStream in_stream(&zero_copy_stream); + io::ArrayInputStream zero_copy_stream(value.data(), value.size()); + io::CodedInputStream in_stream(&zero_copy_stream); // We know the type so we can render it. Recursively parse the nested stream // using a nested ProtoStreamObjectSource using our nested type information. ProtoStreamObjectSource nested_os(&in_stream, os->typeinfo_, *nested_type); @@ -696,12 +699,13 @@ Status ProtoStreamObjectSource::RenderFieldMask( } -hash_map<string, ProtoStreamObjectSource::TypeRenderer>* +std::unordered_map<string, ProtoStreamObjectSource::TypeRenderer>* ProtoStreamObjectSource::renderers_ = NULL; -GOOGLE_PROTOBUF_DECLARE_ONCE(source_renderers_init_); +PROTOBUF_NAMESPACE_ID::internal::once_flag source_renderers_init_; void ProtoStreamObjectSource::InitRendererMap() { - renderers_ = new hash_map<string, ProtoStreamObjectSource::TypeRenderer>(); + renderers_ = + new std::unordered_map<string, ProtoStreamObjectSource::TypeRenderer>(); (*renderers_)["google.protobuf.Timestamp"] = &ProtoStreamObjectSource::RenderTimestamp; (*renderers_)["google.protobuf.Duration"] = @@ -744,7 +748,8 @@ void ProtoStreamObjectSource::DeleteRendererMap() { // static ProtoStreamObjectSource::TypeRenderer* ProtoStreamObjectSource::FindTypeRenderer(const string& type_url) { - ::google::protobuf::GoogleOnceInit(&source_renderers_init_, &InitRendererMap); + PROTOBUF_NAMESPACE_ID::internal::call_once(source_renderers_init_, + InitRendererMap); return FindOrNull(*renderers_, type_url); } @@ -762,9 +767,10 @@ Status ProtoStreamObjectSource::RenderField( const google::protobuf::Type* type = typeinfo_->GetTypeByTypeUrl(field->type_url()); if (type == nullptr) { - return Status(util::error::INTERNAL, - StrCat("Invalid configuration. Could not find the type: ", - field->type_url())); + return Status( + util::error::INTERNAL, + StrCat("Invalid configuration. Could not find the type: ", + field->type_url())); } // Short-circuit any special type rendering to save call-stack space. @@ -806,22 +812,22 @@ Status ProtoStreamObjectSource::RenderNonMessageField( } case google::protobuf::Field_Kind_TYPE_INT32: { stream_->ReadVarint32(&buffer32); - ow->RenderInt32(field_name, bit_cast<int32>(buffer32)); + ow->RenderInt32(field_name, ::google::protobuf::bit_cast<int32>(buffer32)); break; } case google::protobuf::Field_Kind_TYPE_INT64: { stream_->ReadVarint64(&buffer64); - ow->RenderInt64(field_name, bit_cast<int64>(buffer64)); + ow->RenderInt64(field_name, ::google::protobuf::bit_cast<int64>(buffer64)); break; } case google::protobuf::Field_Kind_TYPE_UINT32: { stream_->ReadVarint32(&buffer32); - ow->RenderUint32(field_name, bit_cast<uint32>(buffer32)); + ow->RenderUint32(field_name, ::google::protobuf::bit_cast<uint32>(buffer32)); break; } case google::protobuf::Field_Kind_TYPE_UINT64: { stream_->ReadVarint64(&buffer64); - ow->RenderUint64(field_name, bit_cast<uint64>(buffer64)); + ow->RenderUint64(field_name, ::google::protobuf::bit_cast<uint64>(buffer64)); break; } case google::protobuf::Field_Kind_TYPE_SINT32: { @@ -836,32 +842,32 @@ Status ProtoStreamObjectSource::RenderNonMessageField( } case google::protobuf::Field_Kind_TYPE_SFIXED32: { stream_->ReadLittleEndian32(&buffer32); - ow->RenderInt32(field_name, bit_cast<int32>(buffer32)); + ow->RenderInt32(field_name, ::google::protobuf::bit_cast<int32>(buffer32)); break; } case google::protobuf::Field_Kind_TYPE_SFIXED64: { stream_->ReadLittleEndian64(&buffer64); - ow->RenderInt64(field_name, bit_cast<int64>(buffer64)); + ow->RenderInt64(field_name, ::google::protobuf::bit_cast<int64>(buffer64)); break; } case google::protobuf::Field_Kind_TYPE_FIXED32: { stream_->ReadLittleEndian32(&buffer32); - ow->RenderUint32(field_name, bit_cast<uint32>(buffer32)); + ow->RenderUint32(field_name, ::google::protobuf::bit_cast<uint32>(buffer32)); break; } case google::protobuf::Field_Kind_TYPE_FIXED64: { stream_->ReadLittleEndian64(&buffer64); - ow->RenderUint64(field_name, bit_cast<uint64>(buffer64)); + ow->RenderUint64(field_name, ::google::protobuf::bit_cast<uint64>(buffer64)); break; } case google::protobuf::Field_Kind_TYPE_FLOAT: { stream_->ReadLittleEndian32(&buffer32); - ow->RenderFloat(field_name, bit_cast<float>(buffer32)); + ow->RenderFloat(field_name, ::google::protobuf::bit_cast<float>(buffer32)); break; } case google::protobuf::Field_Kind_TYPE_DOUBLE: { stream_->ReadLittleEndian64(&buffer64); - ow->RenderDouble(field_name, bit_cast<double>(buffer64)); + ow->RenderDouble(field_name, ::google::protobuf::bit_cast<double>(buffer64)); break; } case google::protobuf::Field_Kind_TYPE_ENUM: { @@ -932,25 +938,25 @@ const string ProtoStreamObjectSource::ReadFieldValueAsString( case google::protobuf::Field_Kind_TYPE_INT32: { uint32 buffer32; stream_->ReadVarint32(&buffer32); - result = SimpleItoa(bit_cast<int32>(buffer32)); + result = SimpleItoa(::google::protobuf::bit_cast<int32>(buffer32)); break; } case google::protobuf::Field_Kind_TYPE_INT64: { uint64 buffer64; stream_->ReadVarint64(&buffer64); - result = SimpleItoa(bit_cast<int64>(buffer64)); + result = SimpleItoa(::google::protobuf::bit_cast<int64>(buffer64)); break; } case google::protobuf::Field_Kind_TYPE_UINT32: { uint32 buffer32; stream_->ReadVarint32(&buffer32); - result = SimpleItoa(bit_cast<uint32>(buffer32)); + result = SimpleItoa(::google::protobuf::bit_cast<uint32>(buffer32)); break; } case google::protobuf::Field_Kind_TYPE_UINT64: { uint64 buffer64; stream_->ReadVarint64(&buffer64); - result = SimpleItoa(bit_cast<uint64>(buffer64)); + result = SimpleItoa(::google::protobuf::bit_cast<uint64>(buffer64)); break; } case google::protobuf::Field_Kind_TYPE_SINT32: { @@ -968,37 +974,37 @@ const string ProtoStreamObjectSource::ReadFieldValueAsString( case google::protobuf::Field_Kind_TYPE_SFIXED32: { uint32 buffer32; stream_->ReadLittleEndian32(&buffer32); - result = SimpleItoa(bit_cast<int32>(buffer32)); + result = SimpleItoa(::google::protobuf::bit_cast<int32>(buffer32)); break; } case google::protobuf::Field_Kind_TYPE_SFIXED64: { uint64 buffer64; stream_->ReadLittleEndian64(&buffer64); - result = SimpleItoa(bit_cast<int64>(buffer64)); + result = SimpleItoa(::google::protobuf::bit_cast<int64>(buffer64)); break; } case google::protobuf::Field_Kind_TYPE_FIXED32: { uint32 buffer32; stream_->ReadLittleEndian32(&buffer32); - result = SimpleItoa(bit_cast<uint32>(buffer32)); + result = SimpleItoa(::google::protobuf::bit_cast<uint32>(buffer32)); break; } case google::protobuf::Field_Kind_TYPE_FIXED64: { uint64 buffer64; stream_->ReadLittleEndian64(&buffer64); - result = SimpleItoa(bit_cast<uint64>(buffer64)); + result = SimpleItoa(::google::protobuf::bit_cast<uint64>(buffer64)); break; } case google::protobuf::Field_Kind_TYPE_FLOAT: { uint32 buffer32; stream_->ReadLittleEndian32(&buffer32); - result = SimpleFtoa(bit_cast<float>(buffer32)); + result = SimpleFtoa(::google::protobuf::bit_cast<float>(buffer32)); break; } case google::protobuf::Field_Kind_TYPE_DOUBLE: { uint64 buffer64; stream_->ReadLittleEndian64(&buffer64); - result = SimpleDtoa(bit_cast<double>(buffer64)); + result = SimpleDtoa(::google::protobuf::bit_cast<double>(buffer64)); break; } case google::protobuf::Field_Kind_TYPE_ENUM: { @@ -1044,7 +1050,7 @@ bool ProtoStreamObjectSource::IsMap( const google::protobuf::Type* field_type = typeinfo_->GetTypeByTypeUrl(field.type_url()); return field.kind() == google::protobuf::Field_Kind_TYPE_MESSAGE && - google::protobuf::util::converter::IsMap(field, *field_type); + util::converter::IsMap(field, *field_type); } std::pair<int64, int32> ProtoStreamObjectSource::ReadSecondsAndNanos( @@ -1066,11 +1072,11 @@ std::pair<int64, int32> ProtoStreamObjectSource::ReadSecondsAndNanos( if (field->number() == 1) { // read seconds stream_->ReadVarint64(&seconds); - signed_seconds = bit_cast<int64>(seconds); + signed_seconds = ::google::protobuf::bit_cast<int64>(seconds); } else if (field->number() == 2) { // read nanos stream_->ReadVarint32(&nanos); - signed_nanos = bit_cast<int32>(nanos); + signed_nanos = ::google::protobuf::bit_cast<int32>(nanos); } } return std::pair<int64, int32>(signed_seconds, signed_nanos); @@ -1082,7 +1088,7 @@ Status ProtoStreamObjectSource::IncrementRecursionDepth( return Status( util::error::INVALID_ARGUMENT, StrCat("Message too deep. Max recursion depth reached for type '", - type_name, "', field '", field_name, "'")); + type_name, "', field '", field_name, "'")); } return util::Status(); } @@ -1104,8 +1110,8 @@ const google::protobuf::Field* FindFieldByNumber( bool IsPackable(const google::protobuf::Field& field) { return field.cardinality() == google::protobuf::Field_Cardinality_CARDINALITY_REPEATED && - google::protobuf::FieldDescriptor::IsTypePackable( - static_cast<google::protobuf::FieldDescriptor::Type>(field.kind())); + FieldDescriptor::IsTypePackable( + static_cast<FieldDescriptor::Type>(field.kind())); } // TODO(skarvaje): Speed this up by not doing a linear scan. |