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