Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 6 additions & 6 deletions src/json2pb/json_to_pb.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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()) {
Expand Down Expand Up @@ -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];

Expand All @@ -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;
Expand Down Expand Up @@ -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;
Expand All @@ -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;
Expand All @@ -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;
Expand Down
6 changes: 3 additions & 3 deletions src/json2pb/json_to_pb.h
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand Down Expand Up @@ -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

Expand Down
4 changes: 2 additions & 2 deletions src/json2pb/pb_to_json.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
Expand Down
14 changes: 7 additions & 7 deletions src/json2pb/pb_to_json.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
6 changes: 3 additions & 3 deletions src/json2pb/protobuf_map.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down
8 changes: 4 additions & 4 deletions src/json2pb/zero_copy_stream_reader.h
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand All @@ -38,7 +38,7 @@ class ZeroCopyStreamReader {
return _data;
}
}
return NULL;
return nullptr;
}
const char* TakeWithAddr() {
const char* c = PeekAddr();
Expand All @@ -47,7 +47,7 @@ class ZeroCopyStreamReader {
--_data_size;
return _data++;
}
return NULL;
return nullptr;
}
char Take() {
const char* c = PeekAddr();
Expand All @@ -71,7 +71,7 @@ class ZeroCopyStreamReader {
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;
Expand Down
10 changes: 5 additions & 5 deletions src/json2pb/zero_copy_stream_writer.h
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down Expand Up @@ -84,14 +84,14 @@ class ZeroCopyStreamWriter {
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;
}
Expand Down
Loading