This is an automated email from the ASF dual-hosted git repository.

wasphin pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/brpc.git


The following commit(s) were added to refs/heads/master by this push:
     new f0f72fda Refactor NULL with nullptr in json2pb (#3455)
f0f72fda is described below

commit f0f72fdaa56a81dd4f3505b22395e3bc36df784a
Author: Bright Chen <[email protected]>
AuthorDate: Tue Aug 18 13:50:38 2026 +0800

    Refactor NULL with nullptr in json2pb (#3455)
---
 src/json2pb/json_to_pb.cpp            | 12 ++++++------
 src/json2pb/json_to_pb.h              |  6 +++---
 src/json2pb/pb_to_json.cpp            |  4 ++--
 src/json2pb/pb_to_json.h              | 14 +++++++-------
 src/json2pb/protobuf_map.cpp          |  6 +++---
 src/json2pb/zero_copy_stream_reader.h |  8 ++++----
 src/json2pb/zero_copy_stream_writer.h | 10 +++++-----
 7 files changed, 30 insertions(+), 30 deletions(-)

diff --git a/src/json2pb/json_to_pb.cpp b/src/json2pb/json_to_pb.cpp
index 00e12d98..63a965c6 100644
--- a/src/json2pb/json_to_pb.cpp
+++ b/src/json2pb/json_to_pb.cpp
@@ -218,7 +218,7 @@ inline bool convert_enum_type(const 
BUTIL_RAPIDJSON_NAMESPACE::Value&item, bool
                               const google::protobuf::FieldDescriptor* field,
                               const google::protobuf::Reflection* reflection,
                               std::string* err) {
-    const google::protobuf::EnumValueDescriptor * enum_value_descriptor = 
NULL; 
+    const google::protobuf::EnumValueDescriptor * enum_value_descriptor = 
nullptr; 
     if (item.IsInt()) {
         enum_value_descriptor = 
field->enum_type()->FindValueByNumber(item.GetInt()); 
     } else if (item.IsString()) {                                          
@@ -582,7 +582,7 @@ bool JsonValueToProtoMessage(const 
BUTIL_RAPIDJSON_NAMESPACE::Value& json_value,
     }
 
     std::string field_name_str_temp; 
-    const BUTIL_RAPIDJSON_NAMESPACE::Value* value_ptr = NULL;
+    const BUTIL_RAPIDJSON_NAMESPACE::Value* value_ptr = nullptr;
     for (size_t i = 0; i < fields.size(); ++i) {
         const google::protobuf::FieldDescriptor* field = fields[i];
         
@@ -604,7 +604,7 @@ bool JsonValueToProtoMessage(const 
BUTIL_RAPIDJSON_NAMESPACE::Value& json_value,
 #else 
         const BUTIL_RAPIDJSON_NAMESPACE::Value::Member* member =
                 json_value.FindMember(field_name_str.data());
-        if (member == NULL) {
+        if (member == nullptr) {
             if (field->is_required()) {
                 J2PERROR(err, "Missing required field: %s", 
butil::EnsureString(field->full_name()).c_str());
                 return false;
@@ -736,7 +736,7 @@ bool 
ProtoJsonToProtoMessage(google::protobuf::io::ZeroCopyInputStream* json,
 #if GOOGLE_PROTOBUF_VERSION >= 6031000
     auto st = google::protobuf::json::JsonStreamToMessage(json, message, 
options);
     bool ok = st.ok();
-    if (!ok && NULL != error) {
+    if (!ok && nullptr != error) {
         *error = st.ToString();
     }
     return ok;
@@ -748,7 +748,7 @@ bool 
ProtoJsonToProtoMessage(google::protobuf::io::ZeroCopyInputStream* json,
     auto st = google::protobuf::util::JsonToBinaryStream(
         type_resolver.get(), type_url, json, &output_stream, options);
     if (!st.ok()) {
-        if (NULL != error) {
+        if (nullptr != error) {
             *error = st.ToString();
         }
         return false;
@@ -757,7 +757,7 @@ bool 
ProtoJsonToProtoMessage(google::protobuf::io::ZeroCopyInputStream* json,
     butil::IOBufAsZeroCopyInputStream input_stream(buf);
     google::protobuf::io::CodedInputStream decoder(&input_stream);
     bool ok = message->ParseFromCodedStream(&decoder);
-    if (!ok && NULL != error) {
+    if (!ok && nullptr != error) {
         *error = "Fail to ParseFromCodedStream";
     }
     return ok;
diff --git a/src/json2pb/json_to_pb.h b/src/json2pb/json_to_pb.h
index 3734ef31..dae7aff2 100644
--- a/src/json2pb/json_to_pb.h
+++ b/src/json2pb/json_to_pb.h
@@ -45,7 +45,7 @@ struct Json2PbOptions {
 };
 
 // Convert `json' to protobuf `message' according to `options'.
-// Returns true on success. `error' (if not NULL) will be set with error
+// Returns true on success. `error' (if not nullptr) will be set with error
 // message on failure.
 //
 // [When options.allow_remaining_bytes_after_parsing is true]
@@ -93,10 +93,10 @@ using ProtoJson2PbOptions = 
google::protobuf::util::JsonParseOptions;
 bool ProtoJsonToProtoMessage(google::protobuf::io::ZeroCopyInputStream* json,
                              google::protobuf::Message* message,
                              const ProtoJson2PbOptions& options = 
ProtoJson2PbOptions(),
-                             std::string* error = NULL);
+                             std::string* error = nullptr);
 bool ProtoJsonToProtoMessage(const std::string& json, 
google::protobuf::Message* message,
                              const ProtoJson2PbOptions& options = 
ProtoJson2PbOptions(),
-                             std::string* error = NULL);
+                             std::string* error = nullptr);
 
 } // namespace json2pb
 
diff --git a/src/json2pb/pb_to_json.cpp b/src/json2pb/pb_to_json.cpp
index c1fd5286..5ec3a90e 100644
--- a/src/json2pb/pb_to_json.cpp
+++ b/src/json2pb/pb_to_json.cpp
@@ -419,7 +419,7 @@ bool ProtoMessageToProtoJson(const 
google::protobuf::Message& message,
 #if GOOGLE_PROTOBUF_VERSION >= 6031000
     auto st = google::protobuf::json::MessageToJsonStream(message, json, 
options);
     bool ok = st.ok();
-    if (!ok && NULL != error) {
+    if (!ok && nullptr != error) {
         *error = st.ToString();
     }
     return ok;
@@ -436,7 +436,7 @@ bool ProtoMessageToProtoJson(const 
google::protobuf::Message& message,
             type_resolver.get(), GetTypeUrl(message), &input_stream, json, 
options);
 
     bool ok = st.ok();
-    if (!ok && NULL != error) {
+    if (!ok && nullptr != error) {
         *error = st.ToString();
     }
     return ok;
diff --git a/src/json2pb/pb_to_json.h b/src/json2pb/pb_to_json.h
index 4dda3a76..1cc3a71c 100644
--- a/src/json2pb/pb_to_json.h
+++ b/src/json2pb/pb_to_json.h
@@ -72,25 +72,25 @@ struct Pb2JsonOptions {
 };
 
 // Convert protobuf `messge' to `json' according to `options'.
-// Returns true on success. `error' (if not NULL) will be set with error
+// Returns true on success. `error' (if not nullptr) will be set with error
 // message on failure.
 bool ProtoMessageToJson(const google::protobuf::Message& message,
                         std::string* json,
                         const Pb2JsonOptions& options,
-                        std::string* error = NULL);
+                        std::string* error = nullptr);
 // send output to ZeroCopyOutputStream instead of std::string.
 bool ProtoMessageToJson(const google::protobuf::Message& message,
                         google::protobuf::io::ZeroCopyOutputStream* json,
                         const Pb2JsonOptions& options,
-                        std::string* error = NULL);
+                        std::string* error = nullptr);
 
 // Using default Pb2JsonOptions.
 bool ProtoMessageToJson(const google::protobuf::Message& message,
                         std::string* json,
-                        std::string* error = NULL);
+                        std::string* error = nullptr);
 bool ProtoMessageToJson(const google::protobuf::Message& message,
                         google::protobuf::io::ZeroCopyOutputStream* json,
-                        std::string* error = NULL);
+                        std::string* error = nullptr);
 
 // See <google/protobuf/util/json_util.h> for details.
 #if GOOGLE_PROTOBUF_VERSION >= 6030000
@@ -110,10 +110,10 @@ using Pb2ProtoJsonOptions = 
google::protobuf::util::JsonOptions;
 bool ProtoMessageToProtoJson(const google::protobuf::Message& message,
                              google::protobuf::io::ZeroCopyOutputStream* json,
                              const Pb2ProtoJsonOptions& options = 
Pb2ProtoJsonOptions(),
-                             std::string* error = NULL);
+                             std::string* error = nullptr);
 bool ProtoMessageToProtoJson(const google::protobuf::Message& message, 
std::string* json,
                              const Pb2ProtoJsonOptions& options = 
Pb2ProtoJsonOptions(),
-                             std::string* error = NULL);
+                             std::string* error = nullptr);
 } // namespace json2pb
 
 #endif // BRPC_JSON2PB_PB_TO_JSON_H
diff --git a/src/json2pb/protobuf_map.cpp b/src/json2pb/protobuf_map.cpp
index 75535234..0fcb0f3d 100644
--- a/src/json2pb/protobuf_map.cpp
+++ b/src/json2pb/protobuf_map.cpp
@@ -28,21 +28,21 @@ bool IsProtobufMap(const FieldDescriptor* field) {
         return false;
     }
     const Descriptor* entry_desc = field->message_type();
-    if (entry_desc == NULL) {
+    if (entry_desc == nullptr) {
         return false;
     }
     if (entry_desc->field_count() != 2) {
         return false;
     }
     const FieldDescriptor* key_desc = entry_desc->field(KEY_INDEX);
-    if (NULL == key_desc
+    if (nullptr == key_desc
         || key_desc->is_repeated()
         || key_desc->cpp_type() != FieldDescriptor::CPPTYPE_STRING
         || key_desc->name() != KEY_NAME) {
         return false;
     }
     const FieldDescriptor* value_desc = entry_desc->field(VALUE_INDEX);
-    if (NULL == value_desc
+    if (nullptr == value_desc
         || value_desc->name() != VALUE_NAME) {
         return false;
     }
diff --git a/src/json2pb/zero_copy_stream_reader.h 
b/src/json2pb/zero_copy_stream_reader.h
index 6c19d330..d1f515c2 100644
--- a/src/json2pb/zero_copy_stream_reader.h
+++ b/src/json2pb/zero_copy_stream_reader.h
@@ -26,7 +26,7 @@ class ZeroCopyStreamReader {
 public:
     typedef char Ch;
     ZeroCopyStreamReader(google::protobuf::io::ZeroCopyInputStream *stream)
-            : _data(NULL), _data_size(0), _nread(0), _stream(stream) {
+            : _data(nullptr), _data_size(0), _nread(0), _stream(stream) {
     }
     //Take a charactor and return its address.
     const char* PeekAddr() { 
@@ -38,7 +38,7 @@ public:
                 return _data;
             }
         }
-        return NULL;
+        return nullptr;
     }
     const char* TakeWithAddr() {
         const char* c = PeekAddr();
@@ -47,7 +47,7 @@ public:
             --_data_size;
             return _data++;
         }
-        return NULL;
+        return nullptr;
     }
     char Take() {
         const char* c = PeekAddr();
@@ -71,7 +71,7 @@ public:
     size_t Tell() { return _nread; }
     void Put(char) {}
     void Flush() {}
-    char *PutBegin() { return NULL; }
+    char *PutBegin() { return nullptr; }
     size_t PutEnd(char *) { return 0; }
 private:
     const char *_data;
diff --git a/src/json2pb/zero_copy_stream_writer.h 
b/src/json2pb/zero_copy_stream_writer.h
index 64042119..43e9ac70 100644
--- a/src/json2pb/zero_copy_stream_writer.h
+++ b/src/json2pb/zero_copy_stream_writer.h
@@ -42,14 +42,14 @@ class ZeroCopyStreamWriter {
 public:
     typedef char Ch;
     ZeroCopyStreamWriter(google::protobuf::io::ZeroCopyOutputStream *stream)
-        : _stream(stream), _data(NULL), 
-          _cursor(NULL), _data_size(0) {
+        : _stream(stream), _data(nullptr), 
+          _cursor(nullptr), _data_size(0) {
     }
     ~ZeroCopyStreamWriter() {
         if (_stream && _data) {
             _stream->BackUp(RemainSize());
         }
-        _stream = NULL;
+        _stream = nullptr;
     }
 
     void Put(char c) {
@@ -84,14 +84,14 @@ public:
     char Peek() { return 0; }
     char Take() { return 0; }
     size_t Tell() { return 0; }
-    char *PutBegin() { return NULL; }
+    char *PutBegin() { return nullptr; }
     size_t PutEnd(char *) { return 0; }
 private:
     bool AcquireNextBuf() {
         if (__builtin_expect(!_stream, 0)) {
             return false;
         }
-        if (_data == NULL || _cursor == _data + _data_size) {
+        if (_data == nullptr || _cursor == _data + _data_size) {
             if (!_stream->Next((void **)&_data, &_data_size)) {
                 return false;
             } 


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to