Unverified Commit 88481be8 authored by Ge Jun's avatar Ge Jun Committed by GitHub

Merge pull request #291 from peiyuanzheng/rapidjson_namespace

change butil/third_party/rapidjson namespace to make it ABI-compatible with other versions of rapidjson used in the same project.
parents 322b87d9 cc94704b
......@@ -53,9 +53,9 @@ DEFINE_int32(consul_retry_interval_ms, 500,
constexpr char kConsulIndex[] = "X-Consul-Index";
std::string RapidjsonValueToString(const rapidjson::Value& value) {
rapidjson::StringBuffer buffer;
rapidjson::PrettyWriter<rapidjson::StringBuffer> writer(buffer);
std::string RapidjsonValueToString(const BUTIL_RAPIDJSON_NAMESPACE::Value& value) {
BUTIL_RAPIDJSON_NAMESPACE::StringBuffer buffer;
BUTIL_RAPIDJSON_NAMESPACE::PrettyWriter<BUTIL_RAPIDJSON_NAMESPACE::StringBuffer> writer(buffer);
value.Accept(writer);
return buffer.GetString();
}
......@@ -126,7 +126,7 @@ int ConsulNamingService::GetServers(const char* service_name,
// set to de-duplicate and keep the order.
std::set<ServerNode> presence;
rapidjson::Document services;
BUTIL_RAPIDJSON_NAMESPACE::Document services;
services.Parse(cntl.response_attachment().to_string().c_str());
if (!services.IsArray()) {
LOG(ERROR) << "The consul's response for "
......@@ -134,14 +134,14 @@ int ConsulNamingService::GetServers(const char* service_name,
return -1;
}
for (rapidjson::SizeType i = 0; i < services.Size(); ++i) {
for (BUTIL_RAPIDJSON_NAMESPACE::SizeType i = 0; i < services.Size(); ++i) {
if (!services[i].HasMember("Service")) {
LOG(ERROR) << "No service info in node: "
<< RapidjsonValueToString(services[i]);
continue;
}
const rapidjson::Value& service = services[i]["Service"];
const BUTIL_RAPIDJSON_NAMESPACE::Value& service = services[i]["Service"];
if (!service.HasMember("Address") ||
!service["Address"].IsString() ||
!service.HasMember("Port") ||
......
......@@ -17,7 +17,7 @@
#include "rapidjson.h"
RAPIDJSON_NAMESPACE_BEGIN
BUTIL_RAPIDJSON_NAMESPACE_BEGIN
///////////////////////////////////////////////////////////////////////////////
// Allocator
......@@ -260,6 +260,6 @@ private:
template <typename BaseAllocator>
const bool MemoryPoolAllocator<BaseAllocator>::kNeedFree;
RAPIDJSON_NAMESPACE_END
BUTIL_RAPIDJSON_NAMESPACE_END
#endif // RAPIDJSON_ENCODINGS_H_
......@@ -63,7 +63,7 @@ RAPIDJSON_DIAG_OFF(effc++)
#include <utility> // std::move
#endif
RAPIDJSON_NAMESPACE_BEGIN
BUTIL_RAPIDJSON_NAMESPACE_BEGIN
// Forward declaration.
template <typename Encoding, typename Allocator>
......@@ -2030,7 +2030,7 @@ GenericValue<Encoding,Allocator>::GenericValue(const GenericValue<Encoding,Sourc
}
}
RAPIDJSON_NAMESPACE_END
BUTIL_RAPIDJSON_NAMESPACE_END
#if defined(_MSC_VER) || defined(__GNUC__)
RAPIDJSON_DIAG_POP
......
......@@ -22,7 +22,7 @@ RAPIDJSON_DIAG_PUSH
RAPIDJSON_DIAG_OFF(effc++)
#endif
RAPIDJSON_NAMESPACE_BEGIN
BUTIL_RAPIDJSON_NAMESPACE_BEGIN
//! Input byte stream wrapper with a statically bound encoding.
/*!
......@@ -252,7 +252,7 @@ private:
#undef RAPIDJSON_ENCODINGS_FUNC
RAPIDJSON_NAMESPACE_END
BUTIL_RAPIDJSON_NAMESPACE_END
#ifdef __GNUC__
RAPIDJSON_DIAG_POP
......
......@@ -27,7 +27,7 @@ RAPIDJSON_DIAG_OFF(effc++)
RAPIDJSON_DIAG_OFF(overflow)
#endif
RAPIDJSON_NAMESPACE_BEGIN
BUTIL_RAPIDJSON_NAMESPACE_BEGIN
///////////////////////////////////////////////////////////////////////////////
// Encoding
......@@ -616,7 +616,7 @@ struct Transcoder<Encoding, Encoding> {
}
};
RAPIDJSON_NAMESPACE_END
BUTIL_RAPIDJSON_NAMESPACE_END
#if defined(__GNUC__) || defined(_MSV_VER)
RAPIDJSON_DIAG_POP
......
......@@ -17,7 +17,7 @@
#include "error.h"
RAPIDJSON_NAMESPACE_BEGIN
BUTIL_RAPIDJSON_NAMESPACE_BEGIN
//! Maps error code of parsing into error message.
/*!
......@@ -60,6 +60,6 @@ inline const RAPIDJSON_ERROR_CHARTYPE* GetParseError_En(ParseErrorCode parseErro
}
}
RAPIDJSON_NAMESPACE_END
BUTIL_RAPIDJSON_NAMESPACE_END
#endif // RAPIDJSON_ERROR_EN_H__
......@@ -47,7 +47,7 @@
#define RAPIDJSON_ERROR_STRING(x) x
#endif
RAPIDJSON_NAMESPACE_BEGIN
BUTIL_RAPIDJSON_NAMESPACE_BEGIN
///////////////////////////////////////////////////////////////////////////////
// ParseErrorCode
......@@ -142,6 +142,6 @@ private:
*/
typedef const RAPIDJSON_ERROR_CHARTYPE* (*GetParseErrorFunc)(ParseErrorCode);
RAPIDJSON_NAMESPACE_END
BUTIL_RAPIDJSON_NAMESPACE_END
#endif // RAPIDJSON_ERROR_ERROR_H__
......@@ -18,7 +18,7 @@
#include "rapidjson.h"
#include <cstdio>
RAPIDJSON_NAMESPACE_BEGIN
BUTIL_RAPIDJSON_NAMESPACE_BEGIN
//! File byte stream for input using fread().
/*!
......@@ -83,6 +83,6 @@ private:
bool eof_;
};
RAPIDJSON_NAMESPACE_END
BUTIL_RAPIDJSON_NAMESPACE_END
#endif // RAPIDJSON_FILESTREAM_H_
......@@ -18,7 +18,7 @@
#include "rapidjson.h"
#include <cstdio>
RAPIDJSON_NAMESPACE_BEGIN
BUTIL_RAPIDJSON_NAMESPACE_BEGIN
//! Wrapper of C file stream for input using fread().
/*!
......@@ -86,6 +86,6 @@ inline void PutN(FileWriteStream& stream, char c, size_t n) {
stream.PutN(c, n);
}
RAPIDJSON_NAMESPACE_END
BUTIL_RAPIDJSON_NAMESPACE_END
#endif // RAPIDJSON_FILESTREAM_H_
......@@ -21,7 +21,7 @@
#include <intrin.h> // for _umul128
#endif
RAPIDJSON_NAMESPACE_BEGIN
BUTIL_RAPIDJSON_NAMESPACE_BEGIN
namespace internal {
class BigInteger {
......@@ -275,6 +275,6 @@ private:
};
} // namespace internal
RAPIDJSON_NAMESPACE_END
BUTIL_RAPIDJSON_NAMESPACE_END
#endif // RAPIDJSON_BIGINTEGER_H_
......@@ -26,7 +26,7 @@
#pragma intrinsic(_BitScanReverse64)
#endif
RAPIDJSON_NAMESPACE_BEGIN
BUTIL_RAPIDJSON_NAMESPACE_BEGIN
namespace internal {
#ifdef __GNUC__
......@@ -242,6 +242,6 @@ RAPIDJSON_DIAG_POP
#endif
} // namespace internal
RAPIDJSON_NAMESPACE_END
BUTIL_RAPIDJSON_NAMESPACE_END
#endif // RAPIDJSON_DIYFP_H_
......@@ -23,7 +23,7 @@
#include "diyfp.h"
#include "ieee754.h"
RAPIDJSON_NAMESPACE_BEGIN
BUTIL_RAPIDJSON_NAMESPACE_BEGIN
namespace internal {
#ifdef __GNUC__
......@@ -212,6 +212,6 @@ RAPIDJSON_DIAG_POP
#endif
} // namespace internal
RAPIDJSON_NAMESPACE_END
BUTIL_RAPIDJSON_NAMESPACE_END
#endif // RAPIDJSON_DTOA_
......@@ -17,7 +17,7 @@
#include "../rapidjson.h"
RAPIDJSON_NAMESPACE_BEGIN
BUTIL_RAPIDJSON_NAMESPACE_BEGIN
namespace internal {
class Double {
......@@ -72,6 +72,6 @@ private:
};
} // namespace internal
RAPIDJSON_NAMESPACE_END
BUTIL_RAPIDJSON_NAMESPACE_END
#endif // RAPIDJSON_IEEE754_
......@@ -17,7 +17,7 @@
#include "../rapidjson.h"
RAPIDJSON_NAMESPACE_BEGIN
BUTIL_RAPIDJSON_NAMESPACE_BEGIN
namespace internal {
inline const char* GetDigitsLut() {
......@@ -299,6 +299,6 @@ inline char* i64toa(int64_t value, char* buffer) {
}
} // namespace internal
RAPIDJSON_NAMESPACE_END
BUTIL_RAPIDJSON_NAMESPACE_END
#endif // RAPIDJSON_ITOA_
......@@ -31,7 +31,7 @@ RAPIDJSON_DIAG_OFF(6334)
#endif
//@cond RAPIDJSON_INTERNAL
RAPIDJSON_NAMESPACE_BEGIN
BUTIL_RAPIDJSON_NAMESPACE_BEGIN
namespace internal {
// Helper to wrap/convert arbitrary types to void, useful for arbitrary type matching
......@@ -149,29 +149,29 @@ template <typename T> struct RemoveSfinaeTag;
template <typename T> struct RemoveSfinaeTag<SfinaeTag&(*)(T)> { typedef T Type; };
#define RAPIDJSON_REMOVEFPTR_(type) \
typename ::RAPIDJSON_NAMESPACE::internal::RemoveSfinaeTag \
< ::RAPIDJSON_NAMESPACE::internal::SfinaeTag&(*) type>::Type
typename ::BUTIL_RAPIDJSON_NAMESPACE::internal::RemoveSfinaeTag \
< ::BUTIL_RAPIDJSON_NAMESPACE::internal::SfinaeTag&(*) type>::Type
#define RAPIDJSON_ENABLEIF(cond) \
typename ::RAPIDJSON_NAMESPACE::internal::EnableIf \
typename ::BUTIL_RAPIDJSON_NAMESPACE::internal::EnableIf \
<RAPIDJSON_REMOVEFPTR_(cond)>::Type * = NULL
#define RAPIDJSON_DISABLEIF(cond) \
typename ::RAPIDJSON_NAMESPACE::internal::DisableIf \
typename ::BUTIL_RAPIDJSON_NAMESPACE::internal::DisableIf \
<RAPIDJSON_REMOVEFPTR_(cond)>::Type * = NULL
#define RAPIDJSON_ENABLEIF_RETURN(cond,returntype) \
typename ::RAPIDJSON_NAMESPACE::internal::EnableIf \
typename ::BUTIL_RAPIDJSON_NAMESPACE::internal::EnableIf \
<RAPIDJSON_REMOVEFPTR_(cond), \
RAPIDJSON_REMOVEFPTR_(returntype)>::Type
#define RAPIDJSON_DISABLEIF_RETURN(cond,returntype) \
typename ::RAPIDJSON_NAMESPACE::internal::DisableIf \
typename ::BUTIL_RAPIDJSON_NAMESPACE::internal::DisableIf \
<RAPIDJSON_REMOVEFPTR_(cond), \
RAPIDJSON_REMOVEFPTR_(returntype)>::Type
} // namespace internal
RAPIDJSON_NAMESPACE_END
BUTIL_RAPIDJSON_NAMESPACE_END
//@endcond
#if defined(__GNUC__) || defined(_MSC_VER)
......
......@@ -17,7 +17,7 @@
#include "../rapidjson.h"
RAPIDJSON_NAMESPACE_BEGIN
BUTIL_RAPIDJSON_NAMESPACE_BEGIN
namespace internal {
//! Computes integer powers of 10 in double (10.0^n).
......@@ -50,6 +50,6 @@ inline double Pow10(int n) {
}
} // namespace internal
RAPIDJSON_NAMESPACE_END
BUTIL_RAPIDJSON_NAMESPACE_END
#endif // RAPIDJSON_POW10_
......@@ -17,7 +17,7 @@
#include "../rapidjson.h"
RAPIDJSON_NAMESPACE_BEGIN
BUTIL_RAPIDJSON_NAMESPACE_BEGIN
namespace internal {
///////////////////////////////////////////////////////////////////////////////
......@@ -174,6 +174,6 @@ private:
};
} // namespace internal
RAPIDJSON_NAMESPACE_END
BUTIL_RAPIDJSON_NAMESPACE_END
#endif // RAPIDJSON_STACK_H_
......@@ -17,7 +17,7 @@
#include "../rapidjson.h"
RAPIDJSON_NAMESPACE_BEGIN
BUTIL_RAPIDJSON_NAMESPACE_BEGIN
namespace internal {
//! Custom strlen() which works on different character types.
......@@ -34,6 +34,6 @@ inline SizeType StrLen(const Ch* s) {
}
} // namespace internal
RAPIDJSON_NAMESPACE_END
BUTIL_RAPIDJSON_NAMESPACE_END
#endif // RAPIDJSON_INTERNAL_STRFUNC_H_
......@@ -21,7 +21,7 @@
#include "diyfp.h"
#include "pow10.h"
RAPIDJSON_NAMESPACE_BEGIN
BUTIL_RAPIDJSON_NAMESPACE_BEGIN
namespace internal {
inline double FastPath(double significand, int exp) {
......@@ -265,6 +265,6 @@ inline double StrtodFullPrecision(double d, int p, const char* decimals, size_t
}
} // namespace internal
RAPIDJSON_NAMESPACE_END
BUTIL_RAPIDJSON_NAMESPACE_END
#endif // RAPIDJSON_STRTOD_
......@@ -18,7 +18,7 @@
#include "rapidjson.h"
#include "internal/stack.h"
RAPIDJSON_NAMESPACE_BEGIN
BUTIL_RAPIDJSON_NAMESPACE_BEGIN
//! Represents an in-memory output byte stream.
/*!
......@@ -65,6 +65,6 @@ inline void PutN(MemoryBuffer& memoryBuffer, char c, size_t n) {
std::memset(memoryBuffer.stack_.Push<char>(n), c, n * sizeof(c));
}
RAPIDJSON_NAMESPACE_END
BUTIL_RAPIDJSON_NAMESPACE_END
#endif // RAPIDJSON_MEMORYBUFFER_H_
......@@ -17,7 +17,7 @@
#include "rapidjson.h"
RAPIDJSON_NAMESPACE_BEGIN
BUTIL_RAPIDJSON_NAMESPACE_BEGIN
//! Represents an in-memory input byte stream.
/*!
......@@ -56,6 +56,6 @@ struct MemoryStream {
size_t size_; //!< Size of the stream.
};
RAPIDJSON_NAMESPACE_END
BUTIL_RAPIDJSON_NAMESPACE_END
#endif // RAPIDJSON_MEMORYBUFFER_H_
......@@ -7,7 +7,7 @@
#include "writer.h"
RAPIDJSON_NAMESPACE_BEGIN
BUTIL_RAPIDJSON_NAMESPACE_BEGIN
//! Optimized writer
/*! This class mainly inherit writer class in rapidjson
......@@ -96,6 +96,6 @@ private:
OptimizedWriter(const OptimizedWriter&);
OptimizedWriter& operator=(const OptimizedWriter&);
};
RAPIDJSON_NAMESPACE_END
BUTIL_RAPIDJSON_NAMESPACE_END
#endif // RAPIDJSON_OPTIMIZED_WRITER_H
......@@ -18,7 +18,7 @@
#include "document.h"
#include "internal/itoa.h"
RAPIDJSON_NAMESPACE_BEGIN
BUTIL_RAPIDJSON_NAMESPACE_BEGIN
static const SizeType kPointerInvalidIndex = ~SizeType(0); //!< Represents an invalid index in GenericPointer::Token
......@@ -1308,6 +1308,6 @@ bool EraseValueByPointer(T& root, const CharType(&source)[N]) {
//@}
RAPIDJSON_NAMESPACE_END
BUTIL_RAPIDJSON_NAMESPACE_END
#endif // RAPIDJSON_POINTER_H_
......@@ -22,7 +22,7 @@ RAPIDJSON_DIAG_PUSH
RAPIDJSON_DIAG_OFF(effc++)
#endif
RAPIDJSON_NAMESPACE_BEGIN
BUTIL_RAPIDJSON_NAMESPACE_BEGIN
//! Writer with indentation and spacing.
/*!
......@@ -198,7 +198,7 @@ private:
PrettyWriter& operator=(const PrettyWriter&);
};
RAPIDJSON_NAMESPACE_END
BUTIL_RAPIDJSON_NAMESPACE_END
#ifdef __GNUC__
RAPIDJSON_DIAG_POP
......
......@@ -109,14 +109,21 @@
\brief provide custom rapidjson namespace (closing expression)
\see RAPIDJSON_NAMESPACE
*/
#ifndef RAPIDJSON_NAMESPACE
#define RAPIDJSON_NAMESPACE rapidjson
// NOTE:
// Add prefix 'BUTIL_' to original 'RAPIDJSON_NAMESPACE', 'RAPIDJSON_NAMESPACE_BEGIN'
// and 'RAPIDJSON_NAMESPACE_END', and set BUTIL_RAPIDJSON_NAMESPACE to butil::rapidjson,
// in order to distinguish with other version RapidJSON in a single binary. (Please refer
// to the reason mentioned in the comments above)
// When using RapidJSON API inside brpc, please use 'BUTIL_RAPIDJSON_NAMESPACE::' instead of
// 'rapidjson::'.
#ifndef BUTIL_RAPIDJSON_NAMESPACE
#define BUTIL_RAPIDJSON_NAMESPACE butil::rapidjson
#endif
#ifndef RAPIDJSON_NAMESPACE_BEGIN
#define RAPIDJSON_NAMESPACE_BEGIN namespace RAPIDJSON_NAMESPACE {
#ifndef BUTIL_RAPIDJSON_NAMESPACE_BEGIN
#define BUTIL_RAPIDJSON_NAMESPACE_BEGIN namespace butil { namespace rapidjson {
#endif
#ifndef RAPIDJSON_NAMESPACE_END
#define RAPIDJSON_NAMESPACE_END }
#ifndef BUTIL_RAPIDJSON_NAMESPACE_END
#define BUTIL_RAPIDJSON_NAMESPACE_END } }
#endif
///////////////////////////////////////////////////////////////////////////////
......@@ -313,20 +320,20 @@
#ifdef RAPIDJSON_DOXYGEN_RUNNING
#define RAPIDJSON_NO_SIZETYPEDEFINE
#endif
RAPIDJSON_NAMESPACE_BEGIN
BUTIL_RAPIDJSON_NAMESPACE_BEGIN
//! Size type (for string lengths, array sizes, etc.)
/*! RapidJSON uses 32-bit array/string indices even on 64-bit platforms,
instead of using \c size_t. Users may override the SizeType by defining
\ref RAPIDJSON_NO_SIZETYPEDEFINE.
*/
typedef unsigned SizeType;
RAPIDJSON_NAMESPACE_END
BUTIL_RAPIDJSON_NAMESPACE_END
#endif
// always import std::size_t to rapidjson namespace
RAPIDJSON_NAMESPACE_BEGIN
BUTIL_RAPIDJSON_NAMESPACE_BEGIN
using std::size_t;
RAPIDJSON_NAMESPACE_END
BUTIL_RAPIDJSON_NAMESPACE_END
///////////////////////////////////////////////////////////////////////////////
// RAPIDJSON_ASSERT
......@@ -350,11 +357,11 @@ RAPIDJSON_NAMESPACE_END
// Adopt from boost
#ifndef RAPIDJSON_STATIC_ASSERT
//!@cond RAPIDJSON_HIDDEN_FROM_DOXYGEN
RAPIDJSON_NAMESPACE_BEGIN
BUTIL_RAPIDJSON_NAMESPACE_BEGIN
template <bool x> struct STATIC_ASSERTION_FAILURE;
template <> struct STATIC_ASSERTION_FAILURE<true> { enum { value = 1 }; };
template<int x> struct StaticAssertTest {};
RAPIDJSON_NAMESPACE_END
BUTIL_RAPIDJSON_NAMESPACE_END
#define RAPIDJSON_JOIN(X, Y) RAPIDJSON_DO_JOIN(X, Y)
#define RAPIDJSON_DO_JOIN(X, Y) RAPIDJSON_DO_JOIN2(X, Y)
......@@ -373,8 +380,8 @@ RAPIDJSON_NAMESPACE_END
\hideinitializer
*/
#define RAPIDJSON_STATIC_ASSERT(x) \
typedef ::RAPIDJSON_NAMESPACE::StaticAssertTest< \
sizeof(::RAPIDJSON_NAMESPACE::STATIC_ASSERTION_FAILURE<bool(x) >)> \
typedef ::BUTIL_RAPIDJSON_NAMESPACE::StaticAssertTest< \
sizeof(::BUTIL_RAPIDJSON_NAMESPACE::STATIC_ASSERTION_FAILURE<bool(x) >)> \
RAPIDJSON_JOIN(StaticAssertTypedef, __LINE__) RAPIDJSON_STATIC_ASSERT_UNUSED_ATTRIBUTE
#endif
......@@ -496,9 +503,9 @@ RAPIDJSON_NAMESPACE_END
/*! \namespace rapidjson
\brief main RapidJSON namespace
\see RAPIDJSON_NAMESPACE
\see BUTIL_RAPIDJSON_NAMESPACE
*/
RAPIDJSON_NAMESPACE_BEGIN
BUTIL_RAPIDJSON_NAMESPACE_BEGIN
///////////////////////////////////////////////////////////////////////////////
// Stream
......@@ -655,6 +662,6 @@ enum Type {
kNumberType = 6 //!< number
};
RAPIDJSON_NAMESPACE_END
BUTIL_RAPIDJSON_NAMESPACE_END
#endif // RAPIDJSON_RAPIDJSON_H_
......@@ -115,7 +115,7 @@ RAPIDJSON_DIAG_OFF(effc++)
#include "error/error.h" // ParseErrorCode, ParseResult
RAPIDJSON_NAMESPACE_BEGIN
BUTIL_RAPIDJSON_NAMESPACE_BEGIN
template<class T, class U>
struct is_same {
......@@ -1552,7 +1552,7 @@ private:
//! Reader with UTF8 encoding and default allocator.
typedef GenericReader<UTF8<>, UTF8<> > Reader;
RAPIDJSON_NAMESPACE_END
BUTIL_RAPIDJSON_NAMESPACE_END
#ifdef __GNUC__
RAPIDJSON_DIAG_POP
......
......@@ -23,7 +23,7 @@
#include "internal/stack.h"
RAPIDJSON_NAMESPACE_BEGIN
BUTIL_RAPIDJSON_NAMESPACE_BEGIN
//! Represents an in-memory output stream.
/*!
......@@ -92,6 +92,6 @@ inline void PutN(GenericStringBuffer<UTF8<> >& stream, char c, size_t n) {
std::memset(stream.stack_.Push<char>(n), c, n * sizeof(c));
}
RAPIDJSON_NAMESPACE_END
BUTIL_RAPIDJSON_NAMESPACE_END
#endif // RAPIDJSON_STRINGBUFFER_H_
......@@ -32,7 +32,7 @@ RAPIDJSON_DIAG_PUSH
RAPIDJSON_DIAG_OFF(4127) // conditional expression is constant
#endif
RAPIDJSON_NAMESPACE_BEGIN
BUTIL_RAPIDJSON_NAMESPACE_BEGIN
//! JSON writer
/*! Writer implements the concept Handler.
......@@ -386,7 +386,7 @@ inline bool Writer<StringBuffer>::WriteDouble(double d) {
return true;
}
RAPIDJSON_NAMESPACE_END
BUTIL_RAPIDJSON_NAMESPACE_END
#ifdef _MSC_VER
RAPIDJSON_DIAG_POP
......
......@@ -41,7 +41,7 @@ enum MatchType {
OPTIONAL_TYPE_MISMATCH = 0x02
};
static void string_append_value(const rapidjson::Value& value,
static void string_append_value(const BUTIL_RAPIDJSON_NAMESPACE::Value& value,
std::string* output) {
if (value.IsNull()) {
output->append("null");
......@@ -75,7 +75,7 @@ static void string_append_value(const rapidjson::Value& value,
//and ends with ',' and return true.
//otherwise will append error into error message and return false.
inline bool value_invalid(const google::protobuf::FieldDescriptor* field, const char* type,
const rapidjson::Value& value, std::string* err) {
const BUTIL_RAPIDJSON_NAMESPACE::Value& value, std::string* err) {
bool optional = field->is_optional();
if (err) {
if (!err->empty()) {
......@@ -101,7 +101,7 @@ inline bool convert_string_to_double_float_type(
google::protobuf::Message* message,
const google::protobuf::FieldDescriptor* field,
const google::protobuf::Reflection* reflection,
const rapidjson::Value& item,
const BUTIL_RAPIDJSON_NAMESPACE::Value& item,
std::string* err) {
const char* limit_type = item.GetString(); // MUST be string here
if (std::numeric_limits<T>::has_quiet_NaN &&
......@@ -122,7 +122,7 @@ inline bool convert_string_to_double_float_type(
return value_invalid(field, typeid(T).name(), item, err);
}
inline bool convert_float_type(const rapidjson::Value& item, bool repeated,
inline bool convert_float_type(const BUTIL_RAPIDJSON_NAMESPACE::Value& item, bool repeated,
google::protobuf::Message* message,
const google::protobuf::FieldDescriptor* field,
const google::protobuf::Reflection* reflection,
......@@ -146,7 +146,7 @@ inline bool convert_float_type(const rapidjson::Value& item, bool repeated,
return true;
}
inline bool convert_double_type(const rapidjson::Value& item, bool repeated,
inline bool convert_double_type(const BUTIL_RAPIDJSON_NAMESPACE::Value& item, bool repeated,
google::protobuf::Message* message,
const google::protobuf::FieldDescriptor* field,
const google::protobuf::Reflection* reflection,
......@@ -170,7 +170,7 @@ inline bool convert_double_type(const rapidjson::Value& item, bool repeated,
return true;
}
inline bool convert_enum_type(const rapidjson::Value&item, bool repeated,
inline bool convert_enum_type(const BUTIL_RAPIDJSON_NAMESPACE::Value&item, bool repeated,
google::protobuf::Message* message,
const google::protobuf::FieldDescriptor* field,
const google::protobuf::Reflection* reflection,
......@@ -192,7 +192,7 @@ inline bool convert_enum_type(const rapidjson::Value&item, bool repeated,
return true;
}
bool JsonValueToProtoMessage(const rapidjson::Value& json_value,
bool JsonValueToProtoMessage(const BUTIL_RAPIDJSON_NAMESPACE::Value& json_value,
google::protobuf::Message* message,
const Json2PbOptions& options,
std::string* err);
......@@ -219,7 +219,7 @@ bool JsonValueToProtoMessage(const rapidjson::Value& json_value,
match_type; \
})
static bool JsonValueToProtoField(const rapidjson::Value& value,
static bool JsonValueToProtoField(const BUTIL_RAPIDJSON_NAMESPACE::Value& value,
const google::protobuf::FieldDescriptor* field,
google::protobuf::Message* message,
const Json2PbOptions& options,
......@@ -245,9 +245,9 @@ static bool JsonValueToProtoField(const rapidjson::Value& value,
#define CASE_FIELD_TYPE(cpptype, method, jsontype) \
case google::protobuf::FieldDescriptor::CPPTYPE_##cpptype: { \
if (field->is_repeated()) { \
const rapidjson::SizeType size = value.Size(); \
for (rapidjson::SizeType index = 0; index < size; ++index) { \
const rapidjson::Value & item = value[index]; \
const BUTIL_RAPIDJSON_NAMESPACE::SizeType size = value.Size(); \
for (BUTIL_RAPIDJSON_NAMESPACE::SizeType index = 0; index < size; ++index) { \
const BUTIL_RAPIDJSON_NAMESPACE::Value & item = value[index]; \
if (TYPE_MATCH == J2PCHECKTYPE(item, cpptype, jsontype)) { \
reflection->Add##method(message, field, item.Get##jsontype()); \
} \
......@@ -266,9 +266,9 @@ static bool JsonValueToProtoField(const rapidjson::Value& value,
case google::protobuf::FieldDescriptor::CPPTYPE_FLOAT:
if (field->is_repeated()) {
const rapidjson::SizeType size = value.Size();
for (rapidjson::SizeType index = 0; index < size; ++index) {
const rapidjson::Value & item = value[index];
const BUTIL_RAPIDJSON_NAMESPACE::SizeType size = value.Size();
for (BUTIL_RAPIDJSON_NAMESPACE::SizeType index = 0; index < size; ++index) {
const BUTIL_RAPIDJSON_NAMESPACE::Value & item = value[index];
if (!convert_float_type(item, true, message, field,
reflection, err)) {
return false;
......@@ -282,9 +282,9 @@ static bool JsonValueToProtoField(const rapidjson::Value& value,
case google::protobuf::FieldDescriptor::CPPTYPE_DOUBLE:
if (field->is_repeated()) {
const rapidjson::SizeType size = value.Size();
for (rapidjson::SizeType index = 0; index < size; ++index) {
const rapidjson::Value & item = value[index];
const BUTIL_RAPIDJSON_NAMESPACE::SizeType size = value.Size();
for (BUTIL_RAPIDJSON_NAMESPACE::SizeType index = 0; index < size; ++index) {
const BUTIL_RAPIDJSON_NAMESPACE::Value & item = value[index];
if (!convert_double_type(item, true, message, field,
reflection, err)) {
return false;
......@@ -298,9 +298,9 @@ static bool JsonValueToProtoField(const rapidjson::Value& value,
case google::protobuf::FieldDescriptor::CPPTYPE_STRING:
if (field->is_repeated()) {
const rapidjson::SizeType size = value.Size();
for (rapidjson::SizeType index = 0; index < size; ++index) {
const rapidjson::Value & item = value[index];
const BUTIL_RAPIDJSON_NAMESPACE::SizeType size = value.Size();
for (BUTIL_RAPIDJSON_NAMESPACE::SizeType index = 0; index < size; ++index) {
const BUTIL_RAPIDJSON_NAMESPACE::Value & item = value[index];
if (TYPE_MATCH == J2PCHECKTYPE(item, string, String)) {
std::string str(item.GetString(), item.GetStringLength());
if (field->type() == google::protobuf::FieldDescriptor::TYPE_BYTES &&
......@@ -332,9 +332,9 @@ static bool JsonValueToProtoField(const rapidjson::Value& value,
case google::protobuf::FieldDescriptor::CPPTYPE_ENUM:
if (field->is_repeated()) {
const rapidjson::SizeType size = value.Size();
for (rapidjson::SizeType index = 0; index < size; ++index) {
const rapidjson::Value & item = value[index];
const BUTIL_RAPIDJSON_NAMESPACE::SizeType size = value.Size();
for (BUTIL_RAPIDJSON_NAMESPACE::SizeType index = 0; index < size; ++index) {
const BUTIL_RAPIDJSON_NAMESPACE::Value & item = value[index];
if (!convert_enum_type(item, true, message, field,
reflection, err)) {
return false;
......@@ -348,9 +348,9 @@ static bool JsonValueToProtoField(const rapidjson::Value& value,
case google::protobuf::FieldDescriptor::CPPTYPE_MESSAGE:
if (field->is_repeated()) {
const rapidjson::SizeType size = value.Size();
for (rapidjson::SizeType index = 0; index < size; ++index) {
const rapidjson::Value& item = value[index];
const BUTIL_RAPIDJSON_NAMESPACE::SizeType size = value.Size();
for (BUTIL_RAPIDJSON_NAMESPACE::SizeType index = 0; index < size; ++index) {
const BUTIL_RAPIDJSON_NAMESPACE::Value& item = value[index];
if (TYPE_MATCH == J2PCHECKTYPE(item, message, Object)) {
if (!JsonValueToProtoMessage(
item, reflection->AddMessage(message, field), options, err)) {
......@@ -367,7 +367,7 @@ static bool JsonValueToProtoField(const rapidjson::Value& value,
return true;
}
bool JsonMapToProtoMap(const rapidjson::Value& value,
bool JsonMapToProtoMap(const BUTIL_RAPIDJSON_NAMESPACE::Value& value,
const google::protobuf::FieldDescriptor* map_desc,
google::protobuf::Message* message,
const Json2PbOptions& options,
......@@ -384,7 +384,7 @@ bool JsonMapToProtoMap(const rapidjson::Value& value,
const google::protobuf::FieldDescriptor* value_desc =
map_desc->message_type()->FindFieldByName(VALUE_NAME);
for (rapidjson::Value::ConstMemberIterator it =
for (BUTIL_RAPIDJSON_NAMESPACE::Value::ConstMemberIterator it =
value.MemberBegin(); it != value.MemberEnd(); ++it) {
google::protobuf::Message* entry = reflection->AddMessage(message, map_desc);
const google::protobuf::Reflection* entry_reflection = entry->GetReflection();
......@@ -398,7 +398,7 @@ bool JsonMapToProtoMap(const rapidjson::Value& value,
return true;
}
bool JsonValueToProtoMessage(const rapidjson::Value& json_value,
bool JsonValueToProtoMessage(const BUTIL_RAPIDJSON_NAMESPACE::Value& json_value,
google::protobuf::Message* message,
const Json2PbOptions& options,
std::string* err) {
......@@ -429,7 +429,7 @@ bool JsonValueToProtoMessage(const rapidjson::Value& json_value,
}
std::string field_name_str_temp;
const rapidjson::Value* value_ptr = NULL;
const BUTIL_RAPIDJSON_NAMESPACE::Value* value_ptr = NULL;
for (size_t i = 0; i < fields.size(); ++i) {
const google::protobuf::FieldDescriptor* field = fields[i];
......@@ -438,7 +438,7 @@ bool JsonValueToProtoMessage(const rapidjson::Value& json_value,
const std::string& field_name_str = (res ? field_name_str_temp : orig_name);
#ifndef RAPIDJSON_VERSION_0_1
rapidjson::Value::ConstMemberIterator member =
BUTIL_RAPIDJSON_NAMESPACE::Value::ConstMemberIterator member =
json_value.FindMember(field_name_str.data());
if (member == json_value.MemberEnd()) {
if (field->is_required()) {
......@@ -449,7 +449,7 @@ bool JsonValueToProtoMessage(const rapidjson::Value& json_value,
}
value_ptr = &(member->value);
#else
const rapidjson::Value::Member* member =
const BUTIL_RAPIDJSON_NAMESPACE::Value::Member* member =
json_value.FindMember(field_name_str.data());
if (member == NULL) {
if (field->is_required()) {
......@@ -475,10 +475,10 @@ bool JsonValueToProtoMessage(const rapidjson::Value& json_value,
return true;
}
bool ZeroCopyStreamToJson(rapidjson::Document *dest,
bool ZeroCopyStreamToJson(BUTIL_RAPIDJSON_NAMESPACE::Document *dest,
google::protobuf::io::ZeroCopyInputStream *stream) {
ZeroCopyStreamReader stream_reader(stream);
dest->ParseStream<0, rapidjson::UTF8<> >(stream_reader);
dest->ParseStream<0, BUTIL_RAPIDJSON_NAMESPACE::UTF8<> >(stream_reader);
return !dest->HasParseError();
}
......@@ -489,7 +489,7 @@ inline bool JsonToProtoMessageInline(const std::string& json_string,
if (error) {
error->clear();
}
rapidjson::Document d;
BUTIL_RAPIDJSON_NAMESPACE::Document d;
d.Parse<0>(json_string.c_str());
return json2pb::JsonValueToProtoMessage(d, message, options, error);
}
......@@ -508,7 +508,7 @@ bool JsonToProtoMessage(google::protobuf::io::ZeroCopyInputStream* stream,
if (error) {
error->clear();
}
rapidjson::Document d;
BUTIL_RAPIDJSON_NAMESPACE::Document d;
if (!json2pb::ZeroCopyStreamToJson(&d, stream)) {
J2PERROR(error, "Invalid json format");
return false;
......@@ -538,7 +538,7 @@ bool JsonToProtoMessage(google::protobuf::io::ZeroCopyInputStream *stream,
if (error) {
error->clear();
}
rapidjson::Document d;
BUTIL_RAPIDJSON_NAMESPACE::Document d;
if (!json2pb::ZeroCopyStreamToJson(&d, stream)) {
J2PERROR(error, "Invalid json format");
return false;
......
......@@ -268,10 +268,10 @@ bool ProtoMessageToJsonStream(const google::protobuf::Message& message,
PbToJsonConverter converter(options);
bool succ = false;
if (options.pretty_json) {
rapidjson::PrettyWriter<OutputStream> writer(os);
BUTIL_RAPIDJSON_NAMESPACE::PrettyWriter<OutputStream> writer(os);
succ = converter.Convert(message, writer);
} else {
rapidjson::OptimizedWriter<OutputStream> writer(os);
BUTIL_RAPIDJSON_NAMESPACE::OptimizedWriter<OutputStream> writer(os);
succ = converter.Convert(message, writer);
}
if (!succ && error) {
......@@ -287,7 +287,7 @@ bool ProtoMessageToJson(const google::protobuf::Message& message,
std::string* error) {
// TODO(gejun): We could further wrap a std::string as a buffer to reduce
// a copying.
rapidjson::StringBuffer buffer;
BUTIL_RAPIDJSON_NAMESPACE::StringBuffer buffer;
if (json2pb::ProtoMessageToJsonStream(message, options, buffer, error)) {
json->append(buffer.GetString(), buffer.GetSize());
return true;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment